@nx/js 19.7.2 → 19.8.0-canary.20240911-2a3307c

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/js",
3
- "version": "19.7.2",
3
+ "version": "19.8.0-canary.20240911-2a3307c",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -39,8 +39,8 @@
39
39
  "@babel/preset-env": "^7.23.2",
40
40
  "@babel/preset-typescript": "^7.22.5",
41
41
  "@babel/runtime": "^7.22.6",
42
- "@nx/devkit": "19.7.2",
43
- "@nx/workspace": "19.7.2",
42
+ "@nx/devkit": "19.8.0-canary.20240911-2a3307c",
43
+ "@nx/workspace": "19.8.0-canary.20240911-2a3307c",
44
44
  "babel-plugin-const-enum": "^1.0.1",
45
45
  "babel-plugin-macros": "^2.8.0",
46
46
  "babel-plugin-transform-typescript-metadata": "^0.3.1",
@@ -61,7 +61,7 @@
61
61
  "ts-node": "10.9.1",
62
62
  "tsconfig-paths": "^4.1.2",
63
63
  "tslib": "^2.3.0",
64
- "@nrwl/js": "19.7.2"
64
+ "@nrwl/js": "19.8.0-canary.20240911-2a3307c"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "verdaccio": "^5.0.4"
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.syncGenerator = syncGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const ignore_1 = require("ignore");
5
6
  const jsonc_parser_1 = require("jsonc-parser");
6
7
  const posix_1 = require("node:path/posix");
7
8
  const ts = require("typescript");
@@ -84,28 +85,30 @@ async function syncGenerator(tree) {
84
85
  patchTsconfigJsonReferences(tree, rawTsconfigContentsCache, rootTsconfigPath, updatedReferences);
85
86
  }
86
87
  }
87
- const runtimeTsConfigFileNames = nxJson.sync?.generatorOptions?.['@nx/js:typescript-sync']
88
- ?.runtimeTsConfigFileNames ??
89
- COMMON_RUNTIME_TS_CONFIG_FILE_NAMES;
88
+ const userOptions = nxJson.sync?.generatorOptions?.['@nx/js:typescript-sync'];
89
+ const { runtimeTsConfigFileNames } = {
90
+ runtimeTsConfigFileNames: userOptions?.runtimeTsConfigFileNames ??
91
+ COMMON_RUNTIME_TS_CONFIG_FILE_NAMES,
92
+ };
90
93
  const collectedDependencies = new Map();
91
- for (const [name, data] of Object.entries(projectGraph.dependencies)) {
92
- if (!projectGraph.nodes[name] ||
93
- projectGraph.nodes[name].data.root === '.' ||
94
+ for (const [projectName, data] of Object.entries(projectGraph.dependencies)) {
95
+ if (!projectGraph.nodes[projectName] ||
96
+ projectGraph.nodes[projectName].data.root === '.' ||
94
97
  !data.length) {
95
98
  continue;
96
99
  }
97
100
  // Get the source project nodes for the source and target
98
- const sourceProjectNode = projectGraph.nodes[name];
101
+ const sourceProjectNode = projectGraph.nodes[projectName];
99
102
  // Find the relevant tsconfig file for the source project
100
103
  const sourceProjectTsconfigPath = (0, devkit_1.joinPathFragments)(sourceProjectNode.data.root, 'tsconfig.json');
101
104
  if (!tsconfigExists(tree, rawTsconfigContentsCache, sourceProjectTsconfigPath)) {
102
105
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
103
- devkit_1.logger.warn(`Skipping project "${name}" as there is no tsconfig.json file found in the project root "${sourceProjectNode.data.root}".`);
106
+ devkit_1.logger.warn(`Skipping project "${projectName}" as there is no tsconfig.json file found in the project root "${sourceProjectNode.data.root}".`);
104
107
  }
105
108
  continue;
106
109
  }
107
110
  // Collect the dependencies of the source project
108
- const dependencies = collectProjectDependencies(tree, name, projectGraph, collectedDependencies);
111
+ const dependencies = collectProjectDependencies(tree, projectName, projectGraph, collectedDependencies);
109
112
  if (!dependencies.length) {
110
113
  continue;
111
114
  }
@@ -152,6 +155,7 @@ function tsconfigExists(tree, rawTsconfigContentsCache, tsconfigPath) {
152
155
  function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache, tsconfigHasCompositeEnabledCache, tsConfigPath, dependencies, projectRoot, projectRoots, runtimeTsConfigFileName, possibleRuntimeTsConfigFileNames) {
153
156
  const stringifiedJsonContents = readRawTsconfigContents(tree, rawTsconfigContentsCache, tsConfigPath);
154
157
  const tsConfig = (0, devkit_1.parseJson)(stringifiedJsonContents);
158
+ const ignoredReferences = new Set(tsConfig.nx?.sync?.ignoredReferences ?? []);
155
159
  // We have at least one dependency so we can safely set it to an empty array if not already set
156
160
  const references = [];
157
161
  const originalReferencesSet = new Set();
@@ -159,10 +163,17 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
159
163
  for (const ref of tsConfig.references ?? []) {
160
164
  const normalizedPath = normalizeReferencePath(ref.path);
161
165
  originalReferencesSet.add(normalizedPath);
166
+ if (ignoredReferences.has(ref.path)) {
167
+ // we keep the user-defined ignored references
168
+ references.push(ref);
169
+ newReferencesSet.add(normalizedPath);
170
+ continue;
171
+ }
162
172
  // reference path is relative to the tsconfig file
163
173
  const resolvedRefPath = getTsConfigPathFromReferencePath(tree, tsConfigPath, ref.path);
164
- if (isProjectReferenceWithinNxProject(tree, rawTsconfigContentsCache, resolvedRefPath, projectRoot, projectRoots)) {
165
- // we keep all references within the current Nx project
174
+ if (isProjectReferenceWithinNxProject(tree, rawTsconfigContentsCache, resolvedRefPath, projectRoot, projectRoots) ||
175
+ isProjectReferenceIgnored(tree, resolvedRefPath)) {
176
+ // we keep all references within the current Nx project or that are ignored
166
177
  references.push(ref);
167
178
  newReferencesSet.add(normalizedPath);
168
179
  }
@@ -277,6 +288,17 @@ function isProjectReferenceWithinNxProject(tree, rawTsconfigContentsCache, refTs
277
288
  // it's inside the project root, so it's an internal project reference
278
289
  return true;
279
290
  }
291
+ function isProjectReferenceIgnored(tree, refTsConfigPath) {
292
+ const ig = (0, ignore_1.default)();
293
+ if (tree.exists('.gitignore')) {
294
+ ig.add('.git');
295
+ ig.add(tree.read('.gitignore', 'utf-8'));
296
+ }
297
+ if (tree.exists('.nxignore')) {
298
+ ig.add(tree.read('.nxignore', 'utf-8'));
299
+ }
300
+ return ig.ignores(refTsConfigPath);
301
+ }
280
302
  function getTsConfigDirName(tree, rawTsconfigContentsCache, tsConfigPath) {
281
303
  return (rawTsconfigContentsCache.has(tsConfigPath)
282
304
  ? true