eslint-plugin-fast-import 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +29 -5
  3. package/dist/module/computePackageInfo.d.ts +2 -0
  4. package/dist/module/computePackageInfo.js +4 -0
  5. package/dist/module/computePackageInfo.js.map +1 -0
  6. package/dist/module/computeRepoInfo.d.ts +5 -0
  7. package/dist/module/computeRepoInfo.js +100 -0
  8. package/dist/module/computeRepoInfo.js.map +1 -0
  9. package/dist/plugin.d.ts +1 -1
  10. package/dist/plugin.js +4 -1
  11. package/dist/plugin.js.map +1 -1
  12. package/dist/rules/no-cycle/cycle.d.ts +4 -0
  13. package/dist/rules/no-cycle/cycle.js +140 -0
  14. package/dist/rules/no-cycle/cycle.js.map +1 -0
  15. package/dist/rules/no-cycle/rule.d.ts +4 -0
  16. package/dist/rules/no-cycle/rule.js +319 -0
  17. package/dist/rules/no-cycle/rule.js.map +1 -0
  18. package/dist/rules/no-empty-entry-points/rule.d.ts +3 -0
  19. package/dist/rules/no-empty-entry-points/rule.js +57 -0
  20. package/dist/rules/no-empty-entry-points/rule.js.map +1 -0
  21. package/dist/rules/no-entry-point-imports/entryPoint.d.ts +3 -0
  22. package/dist/rules/no-entry-point-imports/entryPoint.js +57 -0
  23. package/dist/rules/no-entry-point-imports/entryPoint.js.map +1 -0
  24. package/dist/rules/no-entry-point-imports/rule.d.ts +3 -0
  25. package/dist/rules/no-entry-point-imports/rule.js +60 -0
  26. package/dist/rules/no-entry-point-imports/rule.js.map +1 -0
  27. package/dist/rules/no-external-barrel-reexports/externalBarrelReexports.d.ts +3 -0
  28. package/dist/rules/no-external-barrel-reexports/externalBarrelReexports.js +42 -0
  29. package/dist/rules/no-external-barrel-reexports/externalBarrelReexports.js.map +1 -0
  30. package/dist/rules/no-external-barrel-reexports/rule.d.ts +3 -0
  31. package/dist/rules/no-external-barrel-reexports/rule.js +42 -0
  32. package/dist/rules/no-external-barrel-reexports/rule.js.map +1 -0
  33. package/dist/rules/no-named-as-default/namedAsDefault.d.ts +3 -0
  34. package/dist/rules/no-named-as-default/namedAsDefault.js +77 -0
  35. package/dist/rules/no-named-as-default/namedAsDefault.js.map +1 -0
  36. package/dist/rules/no-named-as-default/rule.d.ts +3 -0
  37. package/dist/rules/no-named-as-default/rule.js +79 -0
  38. package/dist/rules/no-named-as-default/rule.js.map +1 -0
  39. package/dist/rules/no-node-builtins/nodeBuiltins.d.ts +3 -0
  40. package/dist/rules/no-node-builtins/nodeBuiltins.js +48 -0
  41. package/dist/rules/no-node-builtins/nodeBuiltins.js.map +1 -0
  42. package/dist/rules/no-node-builtins/rule.d.ts +3 -0
  43. package/dist/rules/no-node-builtins/rule.js +49 -0
  44. package/dist/rules/no-node-builtins/rule.js.map +1 -0
  45. package/dist/rules/no-restricted-imports/restricted.d.ts +31 -0
  46. package/dist/rules/no-restricted-imports/restricted.js +196 -0
  47. package/dist/rules/no-restricted-imports/restricted.js.map +1 -0
  48. package/dist/rules/no-restricted-imports/rule.d.ts +31 -0
  49. package/dist/rules/no-restricted-imports/rule.js +204 -0
  50. package/dist/rules/no-restricted-imports/rule.js.map +1 -0
  51. package/dist/rules/no-test-imports-in-prod/rule.d.ts +3 -0
  52. package/dist/rules/no-test-imports-in-prod/rule.js +57 -0
  53. package/dist/rules/no-test-imports-in-prod/rule.js.map +1 -0
  54. package/dist/rules/no-test-imports-in-prod/testInProd.d.ts +3 -0
  55. package/dist/rules/no-test-imports-in-prod/testInProd.js +49 -0
  56. package/dist/rules/no-test-imports-in-prod/testInProd.js.map +1 -0
  57. package/dist/rules/no-test-only-imports/rule.d.ts +3 -0
  58. package/dist/rules/no-test-only-imports/rule.js +69 -0
  59. package/dist/rules/no-test-only-imports/rule.js.map +1 -0
  60. package/dist/rules/no-unnamed-entry-point-exports/rule.d.ts +3 -0
  61. package/dist/rules/no-unnamed-entry-point-exports/rule.js +41 -0
  62. package/dist/rules/no-unnamed-entry-point-exports/rule.js.map +1 -0
  63. package/dist/rules/no-unresolved-imports/rule.d.ts +3 -0
  64. package/dist/rules/no-unresolved-imports/rule.js +139 -0
  65. package/dist/rules/no-unresolved-imports/rule.js.map +1 -0
  66. package/dist/rules/no-unresolved-imports/unresolved.d.ts +3 -0
  67. package/dist/rules/no-unresolved-imports/unresolved.js +135 -0
  68. package/dist/rules/no-unresolved-imports/unresolved.js.map +1 -0
  69. package/dist/rules/no-unused-exports/rule.d.ts +3 -0
  70. package/dist/rules/no-unused-exports/rule.js +60 -0
  71. package/dist/rules/no-unused-exports/rule.js.map +1 -0
  72. package/dist/rules/no-unused-package-exports/rule.d.ts +3 -0
  73. package/dist/rules/no-unused-package-exports/rule.js +57 -0
  74. package/dist/rules/no-unused-package-exports/rule.js.map +1 -0
  75. package/dist/rules/prefer-alias-imports/alias.d.ts +6 -0
  76. package/dist/rules/prefer-alias-imports/alias.js +210 -0
  77. package/dist/rules/prefer-alias-imports/alias.js.map +1 -0
  78. package/dist/rules/prefer-alias-imports/rule.d.ts +6 -0
  79. package/dist/rules/prefer-alias-imports/rule.js +214 -0
  80. package/dist/rules/prefer-alias-imports/rule.js.map +1 -0
  81. package/dist/rules/require-node-prefix/nodePrefix.d.ts +3 -0
  82. package/dist/rules/require-node-prefix/nodePrefix.js +59 -0
  83. package/dist/rules/require-node-prefix/nodePrefix.js.map +1 -0
  84. package/dist/rules/require-node-prefix/rule.d.ts +3 -0
  85. package/dist/rules/require-node-prefix/rule.js +60 -0
  86. package/dist/rules/require-node-prefix/rule.js.map +1 -0
  87. package/dist/settings/framework.d.ts +3 -0
  88. package/dist/settings/framework.js +91 -0
  89. package/dist/settings/framework.js.map +1 -0
  90. package/dist/settings/package.d.ts +6 -0
  91. package/dist/settings/package.js +64 -0
  92. package/dist/settings/package.js.map +1 -0
  93. package/dist/settings/repo.d.ts +1 -0
  94. package/dist/settings/repo.js +6 -0
  95. package/dist/settings/repo.js.map +1 -0
  96. package/dist/util/getSubpathEntry.d.ts +4 -0
  97. package/dist/util/getSubpathEntry.js +22 -0
  98. package/dist/util/getSubpathEntry.js.map +1 -0
  99. package/fast-import.config.json +3 -4
  100. package/package.json +12 -8
  101. package/dist/package/package.d.ts +0 -8
  102. package/dist/package/package.js +0 -41
  103. package/dist/package/package.js.map +0 -1
@@ -0,0 +1,214 @@
1
+ import { dirname, relative, resolve } from 'node:path';
2
+ import { z } from 'zod';
3
+ import { exitWithInternalError } from '../../util/error.js';
4
+ import { createRule, getESMInfo, getLocFromRange } from '../util.js';
5
+ const MODE_DEFAULT = 'relative-if-local';
6
+ const MIN_SHARED_PATH_DEPTH_DEFAULT = 1;
7
+ const schema = z
8
+ .strictObject({
9
+ mode: z.enum(['always', 'relative-if-local']).optional(),
10
+ minSharedPathDepth: z.number().int().min(0).optional(),
11
+ })
12
+ .optional();
13
+ /**
14
+ * Find the best matching wildcard alias for an absolute path.
15
+ * Returns the entry with the longest (most specific) path match.
16
+ */
17
+ function findBestWildcardAlias(absolutePath, wildcardAliases) {
18
+ let best;
19
+ for (const [symbol, path] of Object.entries(wildcardAliases)) {
20
+ if (absolutePath.startsWith(path) &&
21
+ (!best || path.length > best.path.length)) {
22
+ best = { symbol, path };
23
+ }
24
+ }
25
+ return best;
26
+ }
27
+ function getAliasInternalPathSegments(absolutePath, aliasPath) {
28
+ if (!absolutePath.startsWith(aliasPath)) {
29
+ return;
30
+ }
31
+ return absolutePath
32
+ .slice(aliasPath.length)
33
+ .split(/[/\\]+/)
34
+ .filter(Boolean);
35
+ }
36
+ function getSharedPathDepth(sourcePath, targetPath, aliasPath) {
37
+ const sourceSegments = getAliasInternalPathSegments(sourcePath, aliasPath);
38
+ const targetSegments = getAliasInternalPathSegments(targetPath, aliasPath);
39
+ if (!sourceSegments || !targetSegments) {
40
+ return;
41
+ }
42
+ let sharedPathDepth = 0;
43
+ while (sharedPathDepth < sourceSegments.length &&
44
+ sharedPathDepth < targetSegments.length &&
45
+ sourceSegments[sharedPathDepth] === targetSegments[sharedPathDepth]) {
46
+ sharedPathDepth++;
47
+ }
48
+ return sharedPathDepth;
49
+ }
50
+ export const preferAliasImports = createRule({
51
+ name: 'prefer-alias-imports',
52
+ meta: {
53
+ docs: {
54
+ description: 'Enforces the use of alias imports instead of relative paths when an alias is available, and vice versa for sufficiently local files under the same alias',
55
+ },
56
+ schema: [schema.toJSONSchema()],
57
+ fixable: 'code',
58
+ type: 'suggestion',
59
+ messages: {
60
+ preferAlias: 'Use alias import "{{alias}}" instead of relative path "{{relative}}"',
61
+ preferRelative: 'Use relative import "{{relative}}" instead of alias "{{alias}}" for local files under the same alias',
62
+ },
63
+ },
64
+ defaultOptions: [{ mode: MODE_DEFAULT }],
65
+ create(context) {
66
+ const esmInfo = getESMInfo(context);
67
+ /* istanbul ignore if */
68
+ if (!esmInfo) {
69
+ return {};
70
+ }
71
+ const { fileInfo, packageSettings } = esmInfo;
72
+ /* istanbul ignore if */
73
+ if (fileInfo.fileType !== 'code') {
74
+ return {};
75
+ }
76
+ const { wildcardAliases, fixedAliases } = packageSettings;
77
+ // No aliases configured — nothing to enforce
78
+ if (Object.keys(wildcardAliases).length === 0 &&
79
+ Object.keys(fixedAliases).length === 0) {
80
+ return {};
81
+ }
82
+ const { mode = MODE_DEFAULT, minSharedPathDepth = MIN_SHARED_PATH_DEPTH_DEFAULT, } = context.options[0] ?? {};
83
+ // Pre-compute the current file's "home alias" for relative-if-local mode
84
+ const homeAlias = findBestWildcardAlias(context.filename, wildcardAliases);
85
+ for (const importEntry of [
86
+ ...fileInfo.singleImports,
87
+ ...fileInfo.barrelImports,
88
+ ...fileInfo.dynamicImports,
89
+ ...fileInfo.sideEffectImports,
90
+ ...fileInfo.singleReexports,
91
+ ...fileInfo.barrelReexports,
92
+ ]) {
93
+ const { moduleSpecifier, resolvedModuleType, statementNodeRange } = importEntry;
94
+ if (!moduleSpecifier ||
95
+ (resolvedModuleType !== 'firstPartyCode' &&
96
+ resolvedModuleType !== 'firstPartyOther')) {
97
+ continue;
98
+ }
99
+ if (moduleSpecifier.startsWith('.')) {
100
+ // --- Relative import: check if it should use an alias ---
101
+ // Check fixed aliases first (exact resolvedModulePath match)
102
+ const { resolvedModulePath } = importEntry;
103
+ let matchedAliasName;
104
+ let matchedAliasSymbol;
105
+ let matchedAliasPath;
106
+ if (resolvedModulePath) {
107
+ for (const [alias, path] of Object.entries(fixedAliases)) {
108
+ if (resolvedModulePath === path) {
109
+ matchedAliasName = alias;
110
+ break;
111
+ }
112
+ }
113
+ }
114
+ // Check wildcard aliases
115
+ if (!matchedAliasName && resolvedModulePath) {
116
+ const match = findBestWildcardAlias(resolvedModulePath, wildcardAliases);
117
+ if (match) {
118
+ matchedAliasSymbol = match.symbol;
119
+ matchedAliasPath = match.path;
120
+ }
121
+ }
122
+ if (!matchedAliasName && !matchedAliasSymbol) {
123
+ continue;
124
+ }
125
+ const sharedPathDepth = homeAlias &&
126
+ resolvedModulePath &&
127
+ matchedAliasSymbol === homeAlias.symbol &&
128
+ matchedAliasPath === homeAlias.path
129
+ ? getSharedPathDepth(context.filename, resolvedModulePath, homeAlias.path)
130
+ : undefined;
131
+ // In relative-if-local mode, skip if the files are local enough
132
+ if (mode === 'relative-if-local') {
133
+ if (matchedAliasName) {
134
+ // Fixed alias — always different from a wildcard home alias, so report
135
+ }
136
+ else if (homeAlias &&
137
+ matchedAliasSymbol === homeAlias.symbol &&
138
+ matchedAliasPath === homeAlias.path &&
139
+ sharedPathDepth !== undefined &&
140
+ sharedPathDepth >= minSharedPathDepth) {
141
+ continue;
142
+ }
143
+ }
144
+ let newSpecifier;
145
+ if (matchedAliasName) {
146
+ newSpecifier = matchedAliasName;
147
+ }
148
+ else if (matchedAliasSymbol && matchedAliasPath) {
149
+ newSpecifier =
150
+ matchedAliasSymbol +
151
+ resolve(dirname(context.filename), moduleSpecifier).slice(matchedAliasPath.length);
152
+ }
153
+ else {
154
+ continue;
155
+ }
156
+ context.report({
157
+ messageId: 'preferAlias',
158
+ loc: getLocFromRange(context, importEntry.reportNodeRange),
159
+ data: { alias: newSpecifier, relative: moduleSpecifier },
160
+ fix(fixer) {
161
+ const sourceNode = context.sourceCode.getNodeByRangeIndex(statementNodeRange[0]);
162
+ /* istanbul ignore if */
163
+ if (!('raw' in sourceNode.source)) {
164
+ exitWithInternalError(`Property "raw" is missing in sourceNode.source`);
165
+ }
166
+ return fixer.replaceText(sourceNode.source, sourceNode.source.raw.replace(moduleSpecifier, newSpecifier));
167
+ },
168
+ });
169
+ }
170
+ else if (mode === 'relative-if-local') {
171
+ // --- Alias import: check if it should be relative ---
172
+ if (moduleSpecifier in fixedAliases) {
173
+ continue;
174
+ }
175
+ if (!importEntry.resolvedModulePath) {
176
+ continue;
177
+ }
178
+ const matchedAlias = findBestWildcardAlias(importEntry.resolvedModulePath, wildcardAliases);
179
+ const sharedPathDepth = homeAlias && matchedAlias && matchedAlias.path === homeAlias.path
180
+ ? getSharedPathDepth(context.filename, importEntry.resolvedModulePath, homeAlias.path)
181
+ : undefined;
182
+ if (matchedAlias &&
183
+ homeAlias &&
184
+ matchedAlias.symbol === homeAlias.symbol &&
185
+ matchedAlias.path === homeAlias.path &&
186
+ sharedPathDepth !== undefined &&
187
+ sharedPathDepth >= minSharedPathDepth) {
188
+ let newSpecifier = relative(dirname(context.filename), resolve(matchedAlias.path, moduleSpecifier.slice(matchedAlias.symbol.length)));
189
+ if (!newSpecifier.startsWith('.')) {
190
+ newSpecifier = './' + newSpecifier;
191
+ }
192
+ context.report({
193
+ messageId: 'preferRelative',
194
+ loc: getLocFromRange(context, importEntry.reportNodeRange),
195
+ data: { relative: newSpecifier, alias: moduleSpecifier },
196
+ fix(fixer) {
197
+ const sourceNode = context.sourceCode.getNodeByRangeIndex(statementNodeRange[0]);
198
+ /* istanbul ignore if */
199
+ if (!('raw' in sourceNode.source)) {
200
+ exitWithInternalError(`Property "raw" is missing in sourceNode.source`);
201
+ }
202
+ return fixer.replaceText(sourceNode.source, sourceNode.source.raw.replace(moduleSpecifier, newSpecifier));
203
+ },
204
+ });
205
+ }
206
+ // Fixed aliases that match the home alias scope could also be flagged,
207
+ // but fixed aliases are exact-match by nature — they don't have a
208
+ // "scope" in the same way. We leave them alone.
209
+ }
210
+ }
211
+ return {};
212
+ },
213
+ });
214
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../../../src/rules/prefer-alias-imports/rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAOrE,MAAM,YAAY,GAAG,mBAAmB,CAAC;AACzC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAExC,MAAM,MAAM,GAAG,CAAC;KACb,YAAY,CAAC;IACZ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAC,QAAQ,EAAE;IACxD,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CACvD,CAAC;KACD,QAAQ,EAAE,CAAC;AAGd;;;GAGG;AACH,SAAS,qBAAqB,CAC5B,YAAoB,EACpB,eAAuC;IAEvC,IAAI,IAAkD,CAAC;IACvD,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QAC7D,IACE,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC;YAC7B,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI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B,GAAG,EAAE,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,eAAe,CAAC;wBAC1D,IAAI,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE;wBACxD,GAAG,CAAC,KAAK;4BACP,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,mBAAmB,CACvD,kBAAkB,CAAC,CAAC,CAAC,CACqB,CAAC;4BAC7C,wBAAwB;4BACxB,IAAI,CAAC,CAAC,KAAK,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gCAClC,qBAAqB,CACnB,gDAAgD,CACjD,CAAC;4BACJ,CAAC;4BACD,OAAO,KAAK,CAAC,WAAW,CACtB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,CAC7D,CAAC;wBACJ,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;gBAED,uEAAuE;gBACvE,kEAAkE;gBAClE,gDAAgD;YAClD,CAAC;QACH,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const nodePrefix: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingNodePrefix", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
@@ -0,0 +1,59 @@
1
+ import { InternalError } from '../../util/error.js';
2
+ import { createRule, getESMInfo, getLocFromRange } from '../util.js';
3
+ export const nodePrefix = createRule({
4
+ name: 'require-node-prefix',
5
+ meta: {
6
+ docs: {
7
+ description: 'Ensures that imports of Node.js modules use the `node:` prefix',
8
+ },
9
+ schema: [],
10
+ fixable: 'code',
11
+ type: 'problem',
12
+ messages: {
13
+ missingNodePrefix: 'Import of Node.js built-in modules must use the `node:` prefix',
14
+ },
15
+ },
16
+ defaultOptions: [],
17
+ create(context) {
18
+ const esmInfo = getESMInfo(context);
19
+ // No project info means this file wasn't found as part of the project, e.g.
20
+ // because it's ignored
21
+ /* istanbul ignore if */
22
+ if (!esmInfo) {
23
+ return {};
24
+ }
25
+ const { fileInfo } = esmInfo;
26
+ /* istanbul ignore if */
27
+ if (fileInfo.fileType !== 'code') {
28
+ return {};
29
+ }
30
+ for (const importEntry of [
31
+ ...fileInfo.singleImports,
32
+ ...fileInfo.barrelImports,
33
+ ...fileInfo.dynamicImports,
34
+ ...fileInfo.singleReexports,
35
+ ...fileInfo.barrelReexports,
36
+ ]) {
37
+ const { moduleSpecifier } = importEntry;
38
+ if (moduleSpecifier &&
39
+ importEntry.resolvedModuleType === 'builtin' &&
40
+ !moduleSpecifier.startsWith('node:')) {
41
+ const { statementNodeRange } = importEntry;
42
+ context.report({
43
+ loc: getLocFromRange(context, statementNodeRange),
44
+ messageId: 'missingNodePrefix',
45
+ fix(fixer) {
46
+ const sourceNode = context.sourceCode.getNodeByRangeIndex(statementNodeRange[0]);
47
+ /* istanbul ignore if */
48
+ if (!('raw' in sourceNode.source)) {
49
+ throw new InternalError(`Property "raw" is missing in sourceNode.source`);
50
+ }
51
+ return fixer.replaceText(sourceNode.source, sourceNode.source.raw.replace(moduleSpecifier, `node:${moduleSpecifier}`));
52
+ },
53
+ });
54
+ }
55
+ }
56
+ return {};
57
+ },
58
+ });
59
+ //# sourceMappingURL=nodePrefix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodePrefix.js","sourceRoot":"","sources":["../../../src/rules/require-node-prefix/nodePrefix.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAOrE,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;IACnC,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,gEAAgE;SAC9E;QACD,MA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AC,EAAE,CAAC;4BAClC,MAAM,IAAI,aAAa,CAAC,gDAAgD,CAAC,CAAC;wBAC5E,CAAC;wBACD,OAAO,KAAK,CAAC,WAAW,CACtB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,eAAe,EAAE,CAAC,CAC1E,CAAC;oBACJ,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const requireNodePrefix: import("@typescript-eslint/utils/ts-eslint").RuleModule<"missingNodePrefix", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
2
+ name: string;
3
+ };
@@ -0,0 +1,60 @@
1
+ import { exitWithInternalError } from '../../util/error.js';
2
+ import { createRule, getESMInfo, getLocFromRange } from '../util.js';
3
+ export const requireNodePrefix = createRule({
4
+ name: 'require-node-prefix',
5
+ meta: {
6
+ docs: {
7
+ description: 'Ensures that imports of Node.js modules use the `node:` prefix',
8
+ },
9
+ schema: [],
10
+ fixable: 'code',
11
+ type: 'problem',
12
+ messages: {
13
+ missingNodePrefix: 'Import of Node.js built-in modules must use the `node:` prefix',
14
+ },
15
+ },
16
+ defaultOptions: [],
17
+ create(context) {
18
+ const esmInfo = getESMInfo(context);
19
+ // No package info means this file wasn't found as part of the package, e.g.
20
+ // because it's ignored
21
+ /* istanbul ignore if */
22
+ if (!esmInfo) {
23
+ return {};
24
+ }
25
+ const { fileInfo } = esmInfo;
26
+ /* istanbul ignore if */
27
+ if (fileInfo.fileType !== 'code') {
28
+ return {};
29
+ }
30
+ for (const importEntry of [
31
+ ...fileInfo.singleImports,
32
+ ...fileInfo.barrelImports,
33
+ ...fileInfo.dynamicImports,
34
+ ...fileInfo.sideEffectImports,
35
+ ...fileInfo.singleReexports,
36
+ ...fileInfo.barrelReexports,
37
+ ]) {
38
+ const { moduleSpecifier } = importEntry;
39
+ if (moduleSpecifier &&
40
+ importEntry.resolvedModuleType === 'builtin' &&
41
+ !moduleSpecifier.startsWith('node:')) {
42
+ const { statementNodeRange } = importEntry;
43
+ context.report({
44
+ loc: getLocFromRange(context, statementNodeRange),
45
+ messageId: 'missingNodePrefix',
46
+ fix(fixer) {
47
+ const sourceNode = context.sourceCode.getNodeByRangeIndex(statementNodeRange[0]);
48
+ /* istanbul ignore if */
49
+ if (!('raw' in sourceNode.source)) {
50
+ exitWithInternalError(`Property "raw" is missing in sourceNode.source`);
51
+ }
52
+ return fixer.replaceText(sourceNode.source, sourceNode.source.raw.replace(moduleSpecifier, `node:${moduleSpecifier}`));
53
+ },
54
+ });
55
+ }
56
+ }
57
+ return {};
58
+ },
59
+ });
60
+ //# sourceMappingURL=rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule.js","sourceRoot":"","sources":["../../../src/rules/require-node-prefix/rule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAOrE,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;IAC1C,IAAI,EAAE,qBAAqB;IAC3B,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EACT,gEAAgE;SACnE;QACD,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,iBAAiB,EACf,gEAAgE;SACnE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;QAEpC,4EAA4E;QAC5E,uBAAuB;QACvB,wBAAwB;QACxB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,EA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AC;CACF,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function getFrameworkSettings(packageRootDir: string): {
2
+ externallyImportedFiles: string[];
3
+ } | undefined;
@@ -0,0 +1,91 @@
1
+ // This function attempts to detect common frameworks that need an externally
2
+ import { existsSync, readdirSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { debug } from '../util/logging.js';
5
+ function addExtensions(mappings) {
6
+ return mappings.flatMap(([file, extensions]) => {
7
+ return extensions.map((ext) => file + '.' + ext);
8
+ });
9
+ }
10
+ const CONFIG_EXTENSIONS = ['js', 'mjs', 'cjs', 'ts', 'mts', 'cts'];
11
+ const REACT_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx'];
12
+ const NEXT_JS_APP_ROUTER_EXTERNALLY_IMPORTED_FILES = addExtensions([
13
+ // App router special files (UI)
14
+ ['/app/**/page', REACT_EXTENSIONS],
15
+ ['/app/**/layout', REACT_EXTENSIONS],
16
+ ['/app/**/template', REACT_EXTENSIONS],
17
+ ['/app/**/loading', REACT_EXTENSIONS],
18
+ ['/app/**/error', REACT_EXTENSIONS],
19
+ ['/app/**/global-error', REACT_EXTENSIONS],
20
+ ['/app/**/not-found', REACT_EXTENSIONS],
21
+ ['/app/**/forbidden', REACT_EXTENSIONS],
22
+ ['/app/**/unauthorized', REACT_EXTENSIONS],
23
+ ['/app/**/default', REACT_EXTENSIONS],
24
+ // Route handlers
25
+ ['/app/**/route', REACT_EXTENSIONS],
26
+ // App router metadata files (dynamic variants)
27
+ ['/app/**/icon', REACT_EXTENSIONS],
28
+ ['/app/**/apple-icon', REACT_EXTENSIONS],
29
+ ['/app/**/opengraph-image', REACT_EXTENSIONS],
30
+ ['/app/**/twitter-image', REACT_EXTENSIONS],
31
+ ['/app/**/sitemap', REACT_EXTENSIONS],
32
+ ['/app/**/robots', REACT_EXTENSIONS],
33
+ ['/app/**/manifest', REACT_EXTENSIONS],
34
+ // Top-level entry points. Next looks for these at either the project
35
+ // root or under src/, which the caller handles via the src/ prefix.
36
+ ['/middleware', REACT_EXTENSIONS],
37
+ ['/instrumentation', REACT_EXTENSIONS],
38
+ ['/instrumentation-client', REACT_EXTENSIONS],
39
+ // Required by @next/mdx with the App Router; lives at project root or under src/.
40
+ ['/mdx-components', REACT_EXTENSIONS],
41
+ ]);
42
+ const NEXT_JS_PAGES_ROUTER_EXTERNALLY_IMPORTED_FILES = addExtensions([
43
+ // Pages router
44
+ ['/pages/**/*', REACT_EXTENSIONS],
45
+ // Top-level entry points. Next looks for these at either the project
46
+ // root or under src/, which the caller handles via the src/ prefix.
47
+ ['/middleware', REACT_EXTENSIONS],
48
+ ['/instrumentation', REACT_EXTENSIONS],
49
+ ['/instrumentation-client', REACT_EXTENSIONS],
50
+ ]);
51
+ const FRAMEWORKS = [
52
+ {
53
+ name: 'Next.js',
54
+ configFiles: addExtensions([['next.config', CONFIG_EXTENSIONS]]),
55
+ getExternallyImportedFiles(packageRootDir) {
56
+ // Detect Next's "src layout" specifically by the presence of src/app or
57
+ // src/pages, mirroring Next.js's own loader. A bare src/ folder used for
58
+ // unrelated source files should not trigger src-dir prefixing.
59
+ const hasRootApp = existsSync(join(packageRootDir, 'app'));
60
+ const hasSrcApp = existsSync(join(packageRootDir, 'src', 'app'));
61
+ const hasSrcPages = existsSync(join(packageRootDir, 'src', 'pages'));
62
+ const files = hasRootApp || hasSrcApp
63
+ ? NEXT_JS_APP_ROUTER_EXTERNALLY_IMPORTED_FILES
64
+ : NEXT_JS_PAGES_ROUTER_EXTERNALLY_IMPORTED_FILES;
65
+ const prefix = hasSrcApp || hasSrcPages ? '/src' : '';
66
+ return files.map((f) => prefix + f);
67
+ },
68
+ },
69
+ ];
70
+ // Attempts to detect common frameworks that need an externally
71
+ // imported files entry, and supplies them
72
+ export function getFrameworkSettings(packageRootDir) {
73
+ const directoryFiles = readdirSync(packageRootDir);
74
+ for (const framework of FRAMEWORKS) {
75
+ let isMatch = false;
76
+ for (const configFile of framework.configFiles) {
77
+ if (directoryFiles.includes(configFile)) {
78
+ isMatch = true;
79
+ break;
80
+ }
81
+ }
82
+ if (isMatch) {
83
+ debug(`Applying ${framework.name} externally imported files`);
84
+ return {
85
+ externallyImportedFiles: framework.getExternallyImportedFiles(packageRootDir),
86
+ };
87
+ }
88
+ }
89
+ return undefined;
90
+ }
91
+ //# sourceMappingURL=framework.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework.js","sourceRoot":"","sources":["../../src/settings/framework.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAE7E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,SAAS,aAAa,CAAC,QAA8B;IACnD,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE;QAC7C,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AACnE,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAEpD,MAAM,4CAA4C,GAAG,aAAa,CAAC;IACjE,gCAAgC;IAChC,CAAC,cAAc,EAAE,gBAAgB,CAAC;IAClC,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IACpC,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;IACtC,CAAC,iBAAiB,EAAE,gBAAgB,CAAC;IACrC,CAAC,eAAe,EAAE,gBAAgB,CAAC;IACnC,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;IAC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ackageJsonSettings = {
2
+ packageName: string | undefined;
3
+ exports: Record<string, string> | undefined;
4
+ };
5
+ export declare function getPackageJsonSettings(packageRootDir: string): PackageJsonSettings;
6
+ export {};
@@ -0,0 +1,64 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { warn } from '../util/logging.js';
3
+ export function getPackageJsonSettings(packageRootDir) {
4
+ const packageJsonPath = `${packageRootDir}/package.json`;
5
+ if (existsSync(packageJsonPath)) {
6
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
7
+ let parsedExports;
8
+ if (packageJson.exports) {
9
+ parsedExports = {};
10
+ for (const [key, value] of Object.entries(packageJson.exports)) {
11
+ if (typeof value === 'string') {
12
+ parsedExports[key] = value;
13
+ continue;
14
+ }
15
+ // For conditional exports, we follow the same precedence that Node.js
16
+ // uses as documented at https://nodejs.org/api/packages.html#conditional-exports
17
+ // This intentionally excludes other conditions, such as "types".
18
+ if (typeof value['node-addons'] === 'string') {
19
+ parsedExports[key] = value['node-addons'];
20
+ }
21
+ else if (typeof value.node === 'string') {
22
+ parsedExports[key] = value.node;
23
+ }
24
+ else if (typeof value.import === 'string') {
25
+ parsedExports[key] = value.import;
26
+ }
27
+ else if (typeof value.require === 'string') {
28
+ parsedExports[key] = value.require;
29
+ }
30
+ else if (typeof value['module-sync'] === 'string') {
31
+ parsedExports[key] = value['module-sync'];
32
+ }
33
+ else if (typeof value.default === 'string') {
34
+ parsedExports[key] = value.default;
35
+ }
36
+ else if (typeof value.types === 'string') {
37
+ // Types are not officially part of the Nodes.js spec, but are
38
+ // sometimes used for type-only packages where we still want to
39
+ // analyze their exports for use.
40
+ parsedExports[key] = value.types;
41
+ }
42
+ else {
43
+ warn(`Could not identify a valid condition for export "${key}" in ${packageJsonPath}. Got ${Object.keys(value).join(', ')} but expected a known Node.js condition`);
44
+ }
45
+ }
46
+ }
47
+ // Fall back to "main" if no exports are defined for the root subpath
48
+ if (packageJson.main) {
49
+ // unlike "exports", "main" is not required to start with `./`
50
+ if (!packageJson.main.startsWith('./')) {
51
+ packageJson.main = `./${packageJson.main}`;
52
+ }
53
+ parsedExports = {
54
+ // We set the main entry first so that packages.exports takes precedence
55
+ // if it also defines a "." entry
56
+ '.': packageJson.main,
57
+ ...parsedExports,
58
+ };
59
+ }
60
+ return { packageName: packageJson.name, exports: parsedExports };
61
+ }
62
+ return { packageName: undefined, exports: undefined };
63
+ }
64
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/settings/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAU1C,MAAM,UAAU,sBAAsB,CACpC,cAAsB;IAEtB,MAAM,eAAe,GAAG,GAAG,cAAc,eAAe,CAAC;IACzD,IAAI,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAIpE,CAAC;QACF,IAAI,aAAiD,CAAC;QACtD,IAAI,WAAW,CAAC,OAAO,EAAE,CAAC;YACxB,aAAa,GAAG,EAAE,CAAC;YACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC/D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9B,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;oBAC3B,SAAS;gBACX,CAAC;gBACD,sEAAsE;gBACtE,iFAAiF;gBACjF,iEAAiE;gBACjE,IAAI,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,QAAQ,EAAE,CAAC;oBAC7C,aAAa,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAA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EAAE,CAAC;gBACvC,WAAW,CAAC,IAAI,GAAG,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;YAC7C,CAAC;YACD,aAAa,GAAG;gBACd,wEAAwE;gBACxE,iCAAiC;gBACjC,GAAG,EAAE,WAAW,CAAC,IAAI;gBACrB,GAAG,aAAa;aACjB,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACnE,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function getRepo(repoRootDir: string): void;
@@ -0,0 +1,6 @@
1
+ import { getPackagesSync } from '@manypkg/get-packages';
2
+ export function getRepo(repoRootDir) {
3
+ const { packages } = getPackagesSync(repoRootDir);
4
+ console.log(packages);
5
+ }
6
+ //# sourceMappingURL=repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repo.js","sourceRoot":"","sources":["../../src/settings/repo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,UAAU,OAAO,CAAC,WAAmB;IACzC,MAAM,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAElD,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function getSubpathEntry<T>({ filePath, data, }: {
2
+ filePath: string;
3
+ data: Map<string, T>;
4
+ }): T | undefined;
@@ -0,0 +1,22 @@
1
+ import { splitPathIntoSegments } from './files.js';
2
+ export function getSubpathEntry({ filePath, data, }) {
3
+ const filePathSegments = splitPathIntoSegments(filePath);
4
+ let longestCommonPath;
5
+ for (const [path, value] of data) {
6
+ const splitPath = splitPathIntoSegments(path);
7
+ let isMatch = true;
8
+ for (let i = 0; i < splitPath.length; i++) {
9
+ if (filePathSegments[i] !== splitPath[i]) {
10
+ isMatch = false;
11
+ break;
12
+ }
13
+ }
14
+ if (isMatch &&
15
+ (!longestCommonPath ||
16
+ splitPath.length > splitPathIntoSegments(longestCommonPath.path).length)) {
17
+ longestCommonPath = { path, value };
18
+ }
19
+ }
20
+ return longestCommonPath ? longestCommonPath.value : undefined;
21
+ }
22
+ //# sourceMappingURL=getSubpathEntry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSubpathEntry.js","sourceRoot":"","sources":["../../src/util/getSubpathEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,UAAU,eAAe,CAAI,EACjC,QAAQ,EACR,IAAI,GAIL;IACC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACzD,IAAI,iBAAyD,CAAC;IAC9D,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,IAAI,gBAAgB,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzC,OAAO,GAAG,KAAK,CAAC;gBAChB,MAAM;YACR,CAAC;QACH,CAAC;QACD,IACE,OAAO;YACP,CAAC,CAAC,iBAAiB;gBACjB,SAAS,CAAC,MAAM,GAAG,qBAAqB,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,EAC1E,CAAC;YACD,iBAAiB,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QACtC,CAAC;IACH,CAAC;IACD,OAAO,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC"}
@@ -4,16 +4,15 @@
4
4
  "default",
5
5
  "getESMInfo",
6
6
  "registerUpdateListener",
7
+ "getLocFromRange",
7
8
  "isNonTestFile",
8
9
  "recommended",
9
10
  "all"
10
11
  ]
11
12
  },
12
13
  "externallyImported": {
13
- "*.config.*": [
14
- "default"
15
- ]
14
+ "*.config.*": ["default"]
16
15
  },
17
16
  "debugLogging": true,
18
17
  "requireFileExtensions": true
19
- }
18
+ }