Skip to content

Commit c307eb1

Browse files
authored
Update export and build strategy (#6)
1 parent 0fd0f91 commit c307eb1

16 files changed

+79
-30
lines changed

.changeset/shiny-spiders-deny.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'eslint-plugin-import-sorting': patch
3+
---
4+
5+
Update export and build strategy
6+
7+
Should fix issues with plugin being unable to load, or rule definitions not being found.

LICENSE.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright Jeff Nelson
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

package.json

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@
1414
],
1515
"repository": "stormwarning/eslint-plugin-import-sorting",
1616
"author": "Jeff (https://tidaltheory.io)",
17-
"type": "module",
18-
"main": "dist/index.cjs",
17+
"type": "commonjs",
18+
"exports": {
19+
".": {
20+
"default": "./dist/index.js"
21+
}
22+
},
23+
"main": "dist/index.js",
24+
"files": [
25+
"dist",
26+
"docs",
27+
"CHANGELOG.md",
28+
"LICENSE.txt",
29+
"README.md"
30+
],
1931
"scripts": {
20-
"build": "vite build",
32+
"build": "tsc -b tsconfig.build.json",
2133
"changeset": "changeset add",
2234
"prepare": "husky install",
2335
"release": "npm run build && changeset publish",

src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { orderRule } from './lib/rules/order.js'
1+
import order from './rules/order.js'
22

3-
const plugin = {
3+
export = {
44
rules: {
5-
order: orderRule,
5+
order,
66
},
77
}
8-
9-
export default plugin

src/lib/rules/order.ts renamed to src/rules/order.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AST_NODE_TYPES, ESLintUtils, type TSESLint, type TSESTree } from '@typescript-eslint/utils'
2-
import type { Rule } from 'eslint'
32
import type { ImportDeclaration } from 'estree'
43

54
import { mutateRanksToAlphabetize } from '../utils/alphabetize-ranks.js'
@@ -118,7 +117,7 @@ const createRule = ESLintUtils.RuleCreator(
118117
`https://github.com/stormwarning/eslint-plugin-import-sorting/blob/main/docs/rules/${name}.md`,
119118
)
120119

121-
export const orderRule = createRule({
120+
export default createRule({
122121
name: 'order',
123122
meta: {
124123
type: 'layout',
@@ -167,7 +166,8 @@ export const orderRule = createRule({
167166
rank: 0,
168167
},
169168
ranks,
170-
getBlockImports(node.parent),
169+
/** @todo Maybe get better types for `parent` property? */
170+
getBlockImports(node.parent as ImportNode),
171171
)
172172
}
173173
},
@@ -181,6 +181,7 @@ export const orderRule = createRule({
181181

182182
if (node.moduleReference.type === AST_NODE_TYPES.TSExternalModuleReference) {
183183
/** @todo Not sure how to properly type this property. */
184+
// @ts-expect-error -- Need a narrower type for `expression` property.
184185
value = node.moduleReference.expression.value as string
185186
displayName = value
186187
type = 'import'
@@ -201,7 +202,8 @@ export const orderRule = createRule({
201202
rank: 0,
202203
},
203204
ranks,
204-
getBlockImports(node.parent),
205+
/** @todo Maybe get better types for `parent` property? */
206+
getBlockImports(node.parent as ImportNode),
205207
)
206208
},
207209
'Program:exit'() {
File renamed without changes.
File renamed without changes.

src/lib/utils/find-root-node.ts renamed to src/utils/find-root-node.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export function findRootNode(node: ImportNode) {
44
let parent = node
55

66
/** @todo Not sure how to properly type `parent` property. */
7+
// @ts-expect-error -- Types don't account for `body` property on `parent`.
78
// eslint-disable-next-line no-eq-null, eqeqeq
89
while (parent.parent != null && parent.parent.body == null) {
910
parent = parent.parent as ImportNode

src/lib/utils/make-newlines-between-report.ts renamed to src/utils/make-newlines-between-report.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-types */
2-
31
import type { TSESLint } from '@typescript-eslint/utils'
42
import type { AST } from 'eslint'
53

@@ -13,7 +11,7 @@ import { findRootNode } from './find-root-node.js'
1311
import { takeTokensAfterWhile } from './take-tokens.js'
1412

1513
function fixNewLineAfterImport(
16-
context: TSESLint.RuleContext<string, []>,
14+
context: TSESLint.RuleContext<string, never[]>,
1715
previousImport: ImportNodeObject,
1816
) {
1917
let previousRoot = findRootNode(previousImport.node)
@@ -33,7 +31,7 @@ function fixNewLineAfterImport(
3331
}
3432

3533
function removeNewLineAfterImport(
36-
context: TSESLint.RuleContext<string, []>,
34+
context: TSESLint.RuleContext<string, never[]>,
3735
currentImport: ImportNodeObject,
3836
previousImport: ImportNodeObject,
3937
) {
@@ -53,7 +51,7 @@ function removeNewLineAfterImport(
5351
}
5452

5553
export function makeNewlinesBetweenReport(
56-
context: TSESLint.RuleContext<string, []>,
54+
context: TSESLint.RuleContext<string, never[]>,
5755
imported: ImportNodeObject[],
5856
newlinesBetweenImports = 'always',
5957
) {

src/lib/utils/make-out-of-order-report.ts renamed to src/utils/make-out-of-order-report.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable @typescript-eslint/ban-types */
2-
31
import { AST_NODE_TYPES, type TSESLint } from '@typescript-eslint/utils'
42

53
import type { ImportNode, ImportNodeObject } from '../rules/order.js'
@@ -36,7 +34,10 @@ function isPlainImportModule(node: ImportNode) {
3634
}
3735

3836
function isPlainImportEquals(node: ImportNode): boolean {
39-
return node.type === AST_NODE_TYPES.TSImportEqualsDeclaration && node.moduleReference.expression
37+
return (
38+
node.type === AST_NODE_TYPES.TSImportEqualsDeclaration &&
39+
'expression' in node.moduleReference
40+
)
4041
}
4142

4243
function canCrossNodeWhileReorder(node: ImportNode) {
@@ -50,9 +51,13 @@ function canCrossNodeWhileReorder(node: ImportNode) {
5051
function canReorderItems(firstNode: ImportNode, secondNode: ImportNode) {
5152
let { parent } = firstNode
5253

53-
let [firstIndex, secondIndex] = (
54-
[parent.body.indexOf(firstNode), parent.body.indexOf(secondNode)] as [number, number]
55-
).sort()
54+
// @ts-expect-error -- Types don't account for `body` property on `parent`.
55+
let indices = [parent.body.indexOf(firstNode), parent.body.indexOf(secondNode)] as [
56+
number,
57+
number,
58+
]
59+
let [firstIndex, secondIndex] = indices.sort()
60+
// @ts-expect-error -- Types don't account for `body` property on `parent`.
5661
let nodesBetween = parent.body.slice(firstIndex, secondIndex + 1)
5762

5863
for (let nodeBetween of nodesBetween) {
@@ -72,7 +77,7 @@ function makeImportDescription(node: ImportNodeObject) {
7277
}
7378

7479
function fixOutOfOrder(
75-
context: TSESLint.RuleContext<string, []>,
80+
context: TSESLint.RuleContext<string, never[]>,
7681
firstNode: ImportNodeObject,
7782
secondNode: ImportNodeObject,
7883
order: OrderTerm,
@@ -126,7 +131,7 @@ function fixOutOfOrder(
126131
}
127132

128133
function reportOutOfOrder(
129-
context: TSESLint.RuleContext<string, []>,
134+
context: TSESLint.RuleContext<string, never[]>,
130135
imported: ImportNodeObject[],
131136
outOfOrder: ImportNodeObject[],
132137
order: OrderTerm,
@@ -138,7 +143,7 @@ function reportOutOfOrder(
138143
}
139144

140145
export function makeOutOfOrderReport(
141-
context: TSESLint.RuleContext<string, []>,
146+
context: TSESLint.RuleContext<string, never[]>,
142147
imported: ImportNodeObject[],
143148
) {
144149
let outOfOrder = findOutOfOrder(imported)

0 commit comments

Comments
 (0)