@nx/eslint-plugin 23.0.0-beta.15 → 23.0.0-beta.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/eslint-plugin",
3
- "version": "23.0.0-beta.15",
3
+ "version": "23.0.0-beta.16",
4
4
  "private": false,
5
5
  "description": "The eslint-plugin package is an ESLint plugin that contains a collection of recommended ESLint rule configurations which you can extend from in your own ESLint configs, as well as an Nx-specific lint rule called enforce-module-boundaries.",
6
6
  "repository": {
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@nx/devkit": "23.0.0-beta.15",
39
- "@nx/js": "23.0.0-beta.15",
38
+ "@nx/devkit": "23.0.0-beta.16",
39
+ "@nx/js": "23.0.0-beta.16",
40
40
  "@phenomnomnominal/tsquery": "~6.2.0",
41
41
  "@typescript-eslint/type-utils": "^8.0.0",
42
42
  "@typescript-eslint/utils": "^8.0.0",
@@ -48,7 +48,7 @@
48
48
  "tslib": "^2.3.0"
49
49
  },
50
50
  "devDependencies": {
51
- "nx": "23.0.0-beta.15"
51
+ "nx": "23.0.0-beta.16"
52
52
  },
53
53
  "publishConfig": {
54
54
  "access": "public"
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-workspace-rules.d.ts","sourceRoot":"","sources":["../../../../packages/eslint-plugin/src/resolve-workspace-rules.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAKzD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAiF1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,WAAW,CAAC,CA2CtB;AAED,eAAO,MAAM,cAAc,aAgCvB,CAAC"}
1
+ {"version":3,"file":"resolve-workspace-rules.d.ts","sourceRoot":"","sources":["../../../../packages/eslint-plugin/src/resolve-workspace-rules.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AASzD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAiF1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,WAAW,CAAC,CA2FtB;AAED,eAAO,MAAM,cAAc,aA2BvB,CAAC"}
@@ -6,8 +6,11 @@ const devkit_1 = require("@nx/devkit");
6
6
  const internal_1 = require("@nx/devkit/internal");
7
7
  const internal_2 = require("@nx/js/internal");
8
8
  const fs_1 = require("fs");
9
+ const node_url_1 = require("node:url");
9
10
  const path_1 = require("path");
10
11
  const constants_1 = require("./constants");
12
+ // `new Function` keeps TS from down-leveling `import()` to `require()`.
13
+ const dynamicImport = new Function('p', 'return import(p);');
11
14
  // ESM import() cannot resolve directories to index files like require() can
12
15
  const INDEX_FILE_EXTENSIONS = [
13
16
  '.ts',
@@ -109,15 +112,71 @@ async function loadWorkspaceRules(directory, tsConfigPath) {
109
112
  console.warn(`Directory "${resolvedDirectory}" does not exist. Skipping loading ESLint rules from this directory.`);
110
113
  return {};
111
114
  }
112
- let registrationCleanup = null;
113
115
  try {
116
+ const entryFile = resolveDirectoryEntryFile(resolvedDirectory);
114
117
  const effectiveTsConfigPath = findTsConfig(resolvedDirectory, tsConfigPath);
115
- if (effectiveTsConfigPath) {
116
- registrationCleanup = (0, internal_2.registerTsProject)(effectiveTsConfigPath);
118
+ // For TS entry files, use loadTsFile directly so the explicitly-provided
119
+ // tsConfigPath threads into any swc/ts-node fallback. For other extensions
120
+ // (or when no tsconfig was found), defer to loadConfigFile's auto-discovery.
121
+ const isTs = !!effectiveTsConfigPath && /\.(c|m)?ts$/.test(entryFile);
122
+ let module;
123
+ if (isTs) {
124
+ try {
125
+ module = (0, internal_2.loadTsFile)(entryFile, effectiveTsConfigPath);
126
+ }
127
+ catch (err) {
128
+ // Top-level await (`ERR_REQUIRE_ASYNC_MODULE`) and ESM-only modules
129
+ // (`ERR_REQUIRE_ESM`) must be loaded via dynamic import(). Mirror
130
+ // devkit's loadTypeScriptModule: register tsconfig-paths first so
131
+ // workspace alias imports resolve, then try native dynamic import.
132
+ // Only escalate to forceRegisterEsmLoader on unsupported TS syntax
133
+ // (enum, runtime namespace, etc.) - surface the original ESM error
134
+ // if no loader can be installed. Without this the outer catch
135
+ // swallows the error and the lint run silently has no rules.
136
+ if (err?.code !== 'ERR_REQUIRE_ESM' &&
137
+ err?.code !== 'ERR_REQUIRE_ASYNC_MODULE') {
138
+ throw err;
139
+ }
140
+ const cleanupPaths = (0, internal_2.registerTsConfigPaths)(effectiveTsConfigPath);
141
+ try {
142
+ const entryUrl = (0, node_url_1.pathToFileURL)(entryFile).href;
143
+ try {
144
+ module = await dynamicImport(entryUrl);
145
+ }
146
+ catch (esmErr) {
147
+ if (esmErr?.code !== 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX') {
148
+ throw esmErr;
149
+ }
150
+ try {
151
+ (0, internal_2.forceRegisterEsmLoader)();
152
+ }
153
+ catch {
154
+ throw esmErr;
155
+ }
156
+ module = await dynamicImport(entryUrl);
157
+ }
158
+ }
159
+ finally {
160
+ cleanupPaths();
161
+ }
162
+ }
163
+ }
164
+ else {
165
+ // Pre-register tsconfig-paths so a `.js`/`.mjs`/`.cjs` workspace
166
+ // eslint plugin can still import workspace libs via TS path aliases
167
+ // (pre-PR behavior: loadConfigFile was always preceded by
168
+ // registerTsProject).
169
+ let cleanupPaths;
170
+ if (effectiveTsConfigPath) {
171
+ cleanupPaths = (0, internal_2.registerTsConfigPaths)(effectiveTsConfigPath);
172
+ }
173
+ try {
174
+ module = await (0, internal_1.loadConfigFile)(entryFile);
175
+ }
176
+ finally {
177
+ cleanupPaths?.();
178
+ }
117
179
  }
118
- const entryFile = resolveDirectoryEntryFile(resolvedDirectory);
119
- // Only rules are supported (not configs, processors, etc.)
120
- const module = await (0, internal_1.loadConfigFile)(entryFile);
121
180
  const rules = module.rules || module;
122
181
  return rules;
123
182
  }
@@ -125,25 +184,18 @@ async function loadWorkspaceRules(directory, tsConfigPath) {
125
184
  console.error(err);
126
185
  return {};
127
186
  }
128
- finally {
129
- if (registrationCleanup) {
130
- registrationCleanup();
131
- }
132
- }
133
187
  }
134
188
  exports.workspaceRules = (() => {
135
189
  // If `tools/eslint-rules` folder doesn't exist, there is no point trying to register and load it
136
190
  if (!(0, fs_1.existsSync)(constants_1.WORKSPACE_PLUGIN_DIR)) {
137
191
  return {};
138
192
  }
139
- // Register `tools/eslint-rules` for TS transpilation
140
- const registrationCleanup = (0, internal_2.registerTsProject)((0, path_1.join)(constants_1.WORKSPACE_PLUGIN_DIR, 'tsconfig.json'));
141
193
  try {
142
194
  /**
143
195
  * Currently we only support applying the rules from the user's workspace plugin object
144
196
  * (i.e. not other things that plugings can expose like configs, processors etc)
145
197
  */
146
- const { rules } = require(constants_1.WORKSPACE_PLUGIN_DIR);
198
+ const { rules } = (0, internal_2.loadTsFile)(constants_1.WORKSPACE_PLUGIN_DIR, (0, path_1.join)(constants_1.WORKSPACE_PLUGIN_DIR, 'tsconfig.json'));
147
199
  // Apply the namespace to the resolved rules
148
200
  const namespacedRules = {};
149
201
  for (const [ruleName, ruleConfig] of Object.entries(rules)) {
@@ -157,9 +209,4 @@ exports.workspaceRules = (() => {
157
209
  console.error(err);
158
210
  return {};
159
211
  }
160
- finally {
161
- if (registrationCleanup) {
162
- registrationCleanup();
163
- }
164
- }
165
212
  })();
@@ -1 +1 @@
1
- {"version":3,"file":"nx-plugin-checks.d.ts","sourceRoot":"","sources":["../../../../../packages/eslint-plugin/src/rules/nx-plugin-checks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAoB/C,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,qBAAqB,EAAE,MAAM,EAAE,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;CACF,CAAC;AAEF,KAAK,iBAAiB,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAWF,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,mBAAmB,GACnB,uBAAuB,GACvB,2BAA2B,GAC3B,6BAA6B,GAC7B,mCAAmC,GACnC,mBAAmB,GACnB,gBAAgB,GAChB,gBAAgB,GAChB,+BAA+B,GAC/B,4BAA4B,GAC5B,qBAAqB,CAAC;AAE1B,eAAO,MAAM,SAAS,qBAAqB,CAAC;;;;AAE5C,wBA4HG;AAqDH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,GAAG,CAAC,oBAAoB,EAClC,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,EAC5C,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,EAClD,OAAO,EAAE,iBAAiB,QAkD3B;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,GAAG,CAAC,oBAAoB,EAClC,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,EAC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AAoB,EAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,UAAU,EAC5C,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,EAClD,OAAO,EAAE,iBAAiB,GACzB,IAAI,CA4GN;AAsBD,wBAAgB,0BAA0B,CACxC,kBAAkB,EAAE,GAAG,CAAC,YAAY,EACpC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,EAClD,OAAO,EAAE,iBAAiB,QAgE3B;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,GAAG,CAAC,YAAY,EAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,EAClD,OAAO,EAAE,iBAAiB,QAuC3B;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,GAAG,CAAC,oBAAoB,EAClC,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,QAsEnD;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,GAAG,CAAC,cAAc,EACxB,OAAO,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,oBASnD;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAkCT"}
@@ -14,7 +14,6 @@ const utils_1 = require("@typescript-eslint/utils");
14
14
  const fs_1 = require("fs");
15
15
  const tsquery_1 = require("@phenomnomnominal/tsquery");
16
16
  const devkit_1 = require("@nx/devkit");
17
- const js_1 = require("@nx/js");
18
17
  const internal_1 = require("@nx/js/internal");
19
18
  const path = tslib_1.__importStar(require("path"));
20
19
  const semver_1 = require("semver");
@@ -103,10 +102,6 @@ exports.default = utils_1.ESLintUtils.RuleCreator(() => ``)({
103
102
  if (![generatorsJson, executorsJson, migrationsJson, packageJson].includes(sourceFilePath)) {
104
103
  return {};
105
104
  }
106
- if (!global.tsProjectRegistered) {
107
- (0, internal_1.registerTsProject)((0, js_1.getRootTsConfigPath)());
108
- global.tsProjectRegistered = true;
109
- }
110
105
  return {
111
106
  ['JSONExpressionStatement > JSONObjectExpression'](node) {
112
107
  if (sourceFilePath === generatorsJson) {
@@ -318,6 +313,26 @@ function validateEntry(baseNode, key, mode, context, options) {
318
313
  }
319
314
  }
320
315
  }
316
+ // Under Node's native TS strip, swc-node isn't registered, so `require.resolve`
317
+ // no longer auto-tries `.ts` extensions. Try them explicitly before giving up.
318
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
319
+ function tryResolveImplementation(modulePath) {
320
+ try {
321
+ return require.resolve(modulePath);
322
+ }
323
+ catch {
324
+ // fall through
325
+ }
326
+ for (const ext of TS_EXTENSIONS) {
327
+ try {
328
+ return require.resolve(`${modulePath}${ext}`);
329
+ }
330
+ catch {
331
+ // try next
332
+ }
333
+ }
334
+ return undefined;
335
+ }
321
336
  function validateImplementationNode(implementationNode, key, context, options) {
322
337
  if (implementationNode.value.type !== 'JSONLiteral' ||
323
338
  typeof implementationNode.value.value !== 'string') {
@@ -333,16 +348,9 @@ function validateImplementationNode(implementationNode, key, context, options) {
333
348
  const [implementationPath, identifier] = implementationNode.value.value.split('#');
334
349
  let resolvedPath;
335
350
  const modulePath = path.join(path.dirname(context.filename ?? context.getFilename()), implementationPath);
336
- try {
337
- resolvedPath = require.resolve(modulePath);
338
- }
339
- catch {
340
- try {
341
- resolvedPath = require.resolve(modulePath.replace(options.outDir, options.rootDir));
342
- }
343
- catch {
344
- // nothing, will be reported below
345
- }
351
+ resolvedPath = tryResolveImplementation(modulePath);
352
+ if (!resolvedPath && options.outDir && options.rootDir) {
353
+ resolvedPath = tryResolveImplementation(modulePath.replace(options.outDir, options.rootDir));
346
354
  }
347
355
  if (!resolvedPath) {
348
356
  context.report({
@@ -492,6 +500,8 @@ function checkIfIdentifierIsFunction(filePath, identifier) {
492
500
  // ignore
493
501
  }
494
502
  // Fallback to require()
495
- const m = require(filePath);
503
+ const m = /\.[cm]?ts$/.test(filePath)
504
+ ? (0, internal_1.loadTsFile)(filePath)
505
+ : (0, internal_1.requireWithTsconfigFallback)(filePath);
496
506
  return identifier in m && typeof m[identifier] === 'function';
497
507
  }