@nx/js 0.0.0-pr-28229-afe192c → 0.0.0-pr-28453-54fa63c

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/babel.js CHANGED
@@ -13,7 +13,7 @@ module.exports = function (api, options = {}) {
13
13
  const emitDecoratorMetadata = api.caller((caller) => caller?.emitDecoratorMetadata ?? true);
14
14
  // Determine settings for `@babel//babel-plugin-transform-class-properties`,
15
15
  // so that we can sync the `loose` option with `@babel/preset-env`.
16
- // TODO(v20): Remove classProperties since it's no longer needed, now that the class props transform is in preset-env.
16
+ // TODO(v21): Remove classProperties since it's no longer needed, now that the class props transform is in preset-env.
17
17
  const loose = options.classProperties?.loose ?? options.loose ?? true;
18
18
  if (options.classProperties) {
19
19
  devkit_1.logger.warn(`Use =\`loose\` option instead of \`classProperties.loose\`. The \`classProperties\` option will be removed in Nx 20`);
package/migrations.json CHANGED
@@ -1,23 +1,5 @@
1
1
  {
2
2
  "generators": {
3
- "update-16-0-0-add-nx-packages": {
4
- "cli": "nx",
5
- "version": "16.0.0-beta.1",
6
- "description": "Replace @nrwl/js with @nx/js",
7
- "implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
8
- },
9
- "explicitly-set-projects-to-update-buildable-deps": {
10
- "cli": "nx",
11
- "version": "16.6.0-beta.0",
12
- "description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.",
13
- "factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps"
14
- },
15
- "16-8-2-update-swcrc": {
16
- "cli": "nx",
17
- "version": "16.8.2-beta.0",
18
- "description": "Remove invalid options (strict, noInterop) for ES6 type modules.",
19
- "factory": "./src/migrations/update-16-8-2/update-swcrc"
20
- },
21
3
  "update-17-0-0-remove-deprecated-build-options": {
22
4
  "cli": "nx",
23
5
  "version": "17.0.2",
@@ -26,65 +8,6 @@
26
8
  }
27
9
  },
28
10
  "packageJsonUpdates": {
29
- "16.0.0": {
30
- "version": "16.0.0-beta.3",
31
- "packages": {
32
- "@swc/cli": {
33
- "version": "~0.1.62",
34
- "alwaysAddToPackageJson": false
35
- },
36
- "@swc/helpers": {
37
- "version": "~0.5.0",
38
- "alwaysAddToPackageJson": false
39
- }
40
- }
41
- },
42
- "16.1.0": {
43
- "version": "16.1.0-beta.0",
44
- "x-prompt": "Do you want to update to TypeScript v5.0?",
45
- "requires": {
46
- "typescript": ">=4.9.5 <5.0.0"
47
- },
48
- "packages": {
49
- "typescript": {
50
- "version": "~5.0.2"
51
- }
52
- }
53
- },
54
- "16.4.0": {
55
- "version": "16.4.0-beta.11",
56
- "x-prompt": "Do you want to update to TypeScript v5.1?",
57
- "requires": {
58
- "typescript": ">=5.0.0 <5.1.0"
59
- },
60
- "packages": {
61
- "typescript": {
62
- "version": "~5.1.3"
63
- }
64
- }
65
- },
66
- "16.8.2": {
67
- "version": "16.8.2-beta.0",
68
- "packages": {
69
- "@swc/core": {
70
- "version": "~1.3.85",
71
- "alwaysAddToPackageJson": false
72
- },
73
- "@swc/helpers": {
74
- "version": "~0.5.2",
75
- "alwaysAddToPackageJson": false
76
- }
77
- }
78
- },
79
- "16.9.2": {
80
- "version": "16.9.2-beta.0",
81
- "packages": {
82
- "@swc-node/register": {
83
- "version": "~1.6.7",
84
- "alwaysAddToPackageJson": false
85
- }
86
- }
87
- },
88
11
  "17.0.0": {
89
12
  "version": "17.0.0-rc.2",
90
13
  "packages": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "0.0.0-pr-28229-afe192c",
3
+ "version": "0.0.0-pr-28453-54fa63c",
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": "0.0.0-pr-28229-afe192c",
43
- "@nx/workspace": "0.0.0-pr-28229-afe192c",
42
+ "@nx/devkit": "0.0.0-pr-28453-54fa63c",
43
+ "@nx/workspace": "0.0.0-pr-28453-54fa63c",
44
44
  "@zkochan/js-yaml": "0.0.7",
45
45
  "babel-plugin-const-enum": "^1.0.1",
46
46
  "babel-plugin-macros": "^2.8.0",
@@ -96,7 +96,6 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
96
96
  env: processEnv(true),
97
97
  cwd: context.root,
98
98
  stdio: ['ignore', 'pipe', 'pipe'],
99
- windowsHide: true,
100
99
  });
101
100
  const resultJson = JSON.parse(result.toString());
102
101
  const distTags = resultJson['dist-tags'] || {};
@@ -117,7 +116,6 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
117
116
  env: processEnv(true),
118
117
  cwd: context.root,
119
118
  stdio: 'ignore',
120
- windowsHide: true,
121
119
  });
122
120
  console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
123
121
  }
@@ -204,7 +202,6 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
204
202
  env: processEnv(true),
205
203
  cwd: context.root,
206
204
  stdio: ['ignore', 'pipe', 'pipe'],
207
- windowsHide: true,
208
205
  });
209
206
  /**
210
207
  * We cannot JSON.parse the output directly because if the user is using lifecycle scripts, npm/pnpm will mix its publish output with the JSON output all on stdout.
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.swcExecutor = swcExecutor;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const assets_1 = require("../../utils/assets/assets");
6
5
  const fast_glob_1 = require("fast-glob");
7
6
  const node_fs_1 = require("node:fs");
8
7
  const path_1 = require("path");
9
- const assets_2 = require("../../utils/assets");
8
+ const assets_1 = require("../../utils/assets");
9
+ const assets_2 = require("../../utils/assets/assets");
10
10
  const check_dependencies_1 = require("../../utils/check-dependencies");
11
11
  const compiler_helper_dependency_1 = require("../../utils/compiler-helper-dependency");
12
12
  const inline_1 = require("../../utils/inline");
@@ -14,7 +14,20 @@ const package_json_1 = require("../../utils/package-json");
14
14
  const compile_swc_1 = require("../../utils/swc/compile-swc");
15
15
  const get_swcrc_path_1 = require("../../utils/swc/get-swcrc-path");
16
16
  const inline_2 = require("../../utils/swc/inline");
17
+ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
17
18
  function normalizeOptions(options, root, sourceRoot, projectRoot) {
19
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
20
+ if (isTsSolutionSetup) {
21
+ if (options.generateLockfile) {
22
+ throw new Error(`Setting 'generateLockfile: true' is not supported with the current TypeScript setup. Unset the 'generateLockfile' option and try again.`);
23
+ }
24
+ if (options.generateExportsField) {
25
+ throw new Error(`Setting 'generateExportsField: true' is not supported with the current TypeScript setup. Set 'exports' field in the 'package.json' file at the project root and unset the 'generateExportsField' option.`);
26
+ }
27
+ if (options.additionalEntryPoints?.length) {
28
+ throw new Error(`Setting 'additionalEntryPoints' is not supported with the current TypeScript setup. Set additional entry points in the 'package.json' file at the project root and unset the 'additionalEntryPoints' option.`);
29
+ }
30
+ }
18
31
  const outputPath = (0, path_1.join)(root, options.outputPath);
19
32
  if (options.skipTypeCheck == null) {
20
33
  options.skipTypeCheck = false;
@@ -34,7 +47,7 @@ function normalizeOptions(options, root, sourceRoot, projectRoot) {
34
47
  options.external = firstItem;
35
48
  }
36
49
  }
37
- const files = (0, assets_1.assetGlobsToFiles)(options.assets, root, outputPath);
50
+ const files = (0, assets_2.assetGlobsToFiles)(options.assets, root, outputPath);
38
51
  // Always execute from root of project, same as with SWC CLI.
39
52
  const swcCwd = (0, path_1.join)(root, projectRoot);
40
53
  const { swcrcPath, tmpSwcrcPath } = (0, get_swcrc_path_1.getSwcrcPath)(options, root, projectRoot);
@@ -57,34 +70,39 @@ function normalizeOptions(options, root, sourceRoot, projectRoot) {
57
70
  tsConfig: (0, path_1.join)(root, options.tsConfig),
58
71
  swcCliOptions,
59
72
  tmpSwcrcPath,
73
+ isTsSolutionSetup: isTsSolutionSetup,
60
74
  };
61
75
  }
62
76
  async function* swcExecutor(_options, context) {
63
77
  const { sourceRoot, root } = context.projectsConfigurations.projects[context.projectName];
64
78
  const options = normalizeOptions(_options, context.root, sourceRoot, root);
65
- const { tmpTsConfig, dependencies } = (0, check_dependencies_1.checkDependencies)(context, options.tsConfig);
66
- if (tmpTsConfig) {
67
- options.tsConfig = tmpTsConfig;
68
- }
69
- const swcHelperDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.swc, options.swcCliOptions.swcrcPath, dependencies, context.projectGraph);
70
- if (swcHelperDependency) {
71
- dependencies.push(swcHelperDependency);
72
- }
73
- const inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
74
- if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
75
- if (options.stripLeadingPaths) {
76
- throw new Error(`Cannot use --strip-leading-paths with inlining.`);
79
+ let swcHelperDependency;
80
+ let inlineProjectGraph;
81
+ if (!options.isTsSolutionSetup) {
82
+ const { tmpTsConfig, dependencies } = (0, check_dependencies_1.checkDependencies)(context, options.tsConfig);
83
+ if (tmpTsConfig) {
84
+ options.tsConfig = tmpTsConfig;
85
+ }
86
+ swcHelperDependency = (0, compiler_helper_dependency_1.getHelperDependency)(compiler_helper_dependency_1.HelperDependency.swc, options.swcCliOptions.swcrcPath, dependencies, context.projectGraph);
87
+ if (swcHelperDependency) {
88
+ dependencies.push(swcHelperDependency);
89
+ }
90
+ inlineProjectGraph = (0, inline_1.handleInliningBuild)(context, options, options.tsConfig);
91
+ if (!(0, inline_1.isInlineGraphEmpty)(inlineProjectGraph)) {
92
+ if (options.stripLeadingPaths) {
93
+ throw new Error(`Cannot use --strip-leading-paths with inlining.`);
94
+ }
95
+ options.projectRoot = '.'; // set to root of workspace to include other libs for type check
96
+ // remap paths for SWC compilation
97
+ options.inline = true;
98
+ options.swcCliOptions.swcCwd = '.';
99
+ options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
100
+ options.swcCliOptions.destPath = (0, path_1.join)(options.swcCliOptions.destPath.split((0, path_1.normalize)('../')).at(-1), options.swcCliOptions.srcPath);
101
+ // tmp swcrc with dependencies to exclude
102
+ // - buildable libraries
103
+ // - other libraries that are not dependent on the current project
104
+ options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath, options.tmpSwcrcPath);
77
105
  }
78
- options.projectRoot = '.'; // set to root of workspace to include other libs for type check
79
- // remap paths for SWC compilation
80
- options.inline = true;
81
- options.swcCliOptions.swcCwd = '.';
82
- options.swcCliOptions.srcPath = options.swcCliOptions.swcCwd;
83
- options.swcCliOptions.destPath = (0, path_1.join)(options.swcCliOptions.destPath.split((0, path_1.normalize)('../')).at(-1), options.swcCliOptions.srcPath);
84
- // tmp swcrc with dependencies to exclude
85
- // - buildable libraries
86
- // - other libraries that are not dependent on the current project
87
- options.swcCliOptions.swcrcPath = (0, inline_2.generateTmpSwcrc)(inlineProjectGraph, options.swcCliOptions.swcrcPath, options.tmpSwcrcPath);
88
106
  }
89
107
  function determineModuleFormatFromSwcrc(absolutePathToSwcrc) {
90
108
  const swcrc = (0, devkit_1.readJsonFile)(absolutePathToSwcrc);
@@ -95,14 +113,17 @@ async function* swcExecutor(_options, context) {
95
113
  process.on('SIGINT', () => disposeFn());
96
114
  process.on('SIGTERM', () => disposeFn());
97
115
  return yield* (0, compile_swc_1.compileSwcWatch)(context, options, async () => {
98
- const assetResult = await (0, assets_2.copyAssets)(options, context);
99
- const packageJsonResult = await (0, package_json_1.copyPackageJson)({
100
- ...options,
101
- additionalEntryPoints: createEntryPoints(options, context),
102
- format: [
103
- determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
104
- ],
105
- }, context);
116
+ const assetResult = await (0, assets_1.copyAssets)(options, context);
117
+ let packageJsonResult;
118
+ if (!options.isTsSolutionSetup) {
119
+ packageJsonResult = await (0, package_json_1.copyPackageJson)({
120
+ ...options,
121
+ additionalEntryPoints: createEntryPoints(options, context),
122
+ format: [
123
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
124
+ ],
125
+ }, context);
126
+ }
106
127
  removeTmpSwcrc(options.swcCliOptions.swcrcPath);
107
128
  disposeFn = () => {
108
129
  assetResult?.stop();
@@ -112,17 +133,19 @@ async function* swcExecutor(_options, context) {
112
133
  }
113
134
  else {
114
135
  return yield (0, compile_swc_1.compileSwc)(context, options, async () => {
115
- await (0, assets_2.copyAssets)(options, context);
116
- await (0, package_json_1.copyPackageJson)({
117
- ...options,
118
- additionalEntryPoints: createEntryPoints(options, context),
119
- format: [
120
- determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
121
- ],
122
- extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
123
- }, context);
136
+ await (0, assets_1.copyAssets)(options, context);
137
+ if (!options.isTsSolutionSetup) {
138
+ await (0, package_json_1.copyPackageJson)({
139
+ ...options,
140
+ additionalEntryPoints: createEntryPoints(options, context),
141
+ format: [
142
+ determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
143
+ ],
144
+ extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
145
+ }, context);
146
+ (0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
147
+ }
124
148
  removeTmpSwcrc(options.swcCliOptions.swcrcPath);
125
- (0, inline_1.postProcessInlinedDependencies)(options.outputPath, options.originalProjectRoot, inlineProjectGraph);
126
149
  });
127
150
  }
128
151
  }
@@ -55,7 +55,7 @@ async function initGeneratorInternal(tree, schema) {
55
55
  process.env.NX_ADD_PLUGINS !== 'false' &&
56
56
  nxJson.useInferencePlugins !== false;
57
57
  schema.addTsPlugin ??=
58
- schema.addPlugin && process.env.NX_ADD_TS_PLUGIN === 'true';
58
+ schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';
59
59
  if (schema.addTsPlugin) {
60
60
  await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
61
61
  typecheck: [
@@ -157,17 +157,6 @@ async function configureProject(tree, options) {
157
157
  }
158
158
  (0, devkit_1.updateNxJson)(tree, nxJson);
159
159
  }
160
- if (!options.useProjectJson) {
161
- if (options.name !== options.importPath) {
162
- // if the name is different than the package.json name, we need to set
163
- // the proper name in the configuration
164
- (0, devkit_1.updateProjectConfiguration)(tree, options.name, {
165
- name: options.name,
166
- root: options.projectRoot,
167
- });
168
- }
169
- return;
170
- }
171
160
  const projectConfiguration = {
172
161
  root: options.projectRoot,
173
162
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
@@ -175,36 +164,46 @@ async function configureProject(tree, options) {
175
164
  targets: {},
176
165
  tags: options.parsedTags,
177
166
  };
178
- if (options.bundler &&
179
- options.bundler !== 'none' &&
180
- options.config !== 'npm-scripts') {
181
- if (options.bundler !== 'rollup') {
182
- const outputPath = getOutputPath(options);
183
- const executor = getBuildExecutor(options.bundler);
184
- (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, executor);
185
- projectConfiguration.targets.build = {
186
- executor,
187
- outputs: ['{options.outputPath}'],
188
- options: {
189
- outputPath,
190
- main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
191
- tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
192
- assets: [],
193
- },
194
- };
167
+ if (options.config !== 'npm-scripts' &&
168
+ (options.bundler === 'swc' ||
169
+ options.bundler === 'esbuild' ||
170
+ (!options.isUsingTsSolutionConfig && options.bundler === 'tsc'))) {
171
+ const outputPath = getOutputPath(options);
172
+ const executor = getBuildExecutor(options.bundler);
173
+ (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, executor);
174
+ projectConfiguration.targets.build = {
175
+ executor,
176
+ outputs: ['{options.outputPath}'],
177
+ options: {
178
+ outputPath,
179
+ main: `${options.projectRoot}/src/index` + (options.js ? '.js' : '.ts'),
180
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
181
+ },
182
+ };
183
+ if (options.bundler === 'esbuild') {
184
+ projectConfiguration.targets.build.options.format = ['cjs'];
185
+ }
186
+ if (options.bundler === 'swc' && options.skipTypeCheck) {
187
+ projectConfiguration.targets.build.options.skipTypeCheck = true;
188
+ }
189
+ if (options.isUsingTsSolutionConfig) {
195
190
  if (options.bundler === 'esbuild') {
196
- projectConfiguration.targets.build.options.generatePackageJson = true;
197
- projectConfiguration.targets.build.options.format = ['cjs'];
191
+ projectConfiguration.targets.build.options.declarationRootDir = `${options.projectRoot}/src`;
198
192
  }
199
- if (options.bundler === 'swc' && options.skipTypeCheck) {
200
- projectConfiguration.targets.build.options.skipTypeCheck = true;
193
+ }
194
+ else {
195
+ projectConfiguration.targets.build.options.assets = [];
196
+ if (options.bundler === 'esbuild') {
197
+ projectConfiguration.targets.build.options.generatePackageJson = true;
201
198
  }
202
199
  if (!options.minimal) {
203
200
  projectConfiguration.targets.build.options.assets ??= [];
204
201
  projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
205
202
  }
206
203
  }
207
- if (options.publishable) {
204
+ }
205
+ if (options.publishable) {
206
+ if (!options.isUsingTsSolutionConfig) {
208
207
  const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
209
208
  projectConfiguration.targets ??= {};
210
209
  projectConfiguration.targets['nx-release-publish'] = {
@@ -222,10 +221,20 @@ async function configureProject(tree, options) {
222
221
  },
223
222
  },
224
223
  };
225
- await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
226
224
  }
225
+ await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
227
226
  }
228
- if (options.config === 'workspace' || options.config === 'project') {
227
+ if (!options.useProjectJson) {
228
+ // we want the package.json as clean as possible, with the bare minimum
229
+ if (!projectConfiguration.tags?.length) {
230
+ delete projectConfiguration.tags;
231
+ }
232
+ // automatically inferred as `library`
233
+ delete projectConfiguration.projectType;
234
+ // empty targets are cleaned up automatically by `updateProjectConfiguration`
235
+ (0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfiguration);
236
+ }
237
+ else if (options.config === 'workspace' || options.config === 'project') {
229
238
  (0, devkit_1.addProjectConfiguration)(tree, options.name, projectConfiguration);
230
239
  }
231
240
  else {
@@ -480,23 +489,6 @@ async function normalizeOptions(tree, options) {
480
489
  const hasPlugin = (0, ts_solution_setup_1.isUsingTypeScriptPlugin)(tree);
481
490
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
482
491
  if (isUsingTsSolutionConfig) {
483
- if (options.bundler === 'esbuild' || options.bundler === 'swc') {
484
- throw new Error(`Cannot use the "${options.bundler}" bundler when using the @nx/js/typescript plugin.`);
485
- }
486
- if (options.bundler === undefined && options.compiler === undefined) {
487
- options.bundler = await promptWhenInteractive({
488
- type: 'select',
489
- name: 'bundler',
490
- message: `Which bundler would you like to use to build the library? Choose 'none' to skip build setup.`,
491
- choices: [
492
- { name: 'tsc' },
493
- { name: 'rollup' },
494
- { name: 'vite' },
495
- { name: 'none' },
496
- ],
497
- initial: 0,
498
- }, { bundler: 'tsc' }).then(({ bundler }) => bundler);
499
- }
500
492
  options.linter ??= await promptWhenInteractive({
501
493
  type: 'select',
502
494
  name: 'linter',
@@ -513,46 +505,6 @@ async function normalizeOptions(tree, options) {
513
505
  }, { unitTestRunner: 'none' }).then(({ unitTestRunner }) => unitTestRunner);
514
506
  }
515
507
  else {
516
- if (options.bundler === undefined && options.compiler === undefined) {
517
- options.bundler = await promptWhenInteractive({
518
- type: 'select',
519
- name: 'bundler',
520
- message: `Which bundler would you like to use to build the library? Choose 'none' to skip build setup.`,
521
- choices: [
522
- { name: 'swc' },
523
- { name: 'tsc' },
524
- { name: 'rollup' },
525
- { name: 'vite' },
526
- { name: 'esbuild' },
527
- { name: 'none' },
528
- ],
529
- initial: 1,
530
- }, { bundler: 'tsc' }).then(({ bundler }) => bundler);
531
- }
532
- else {
533
- /**
534
- * We are deprecating the compiler and the buildable options.
535
- * However, we want to keep the existing behavior for now.
536
- *
537
- * So, if the user has not provided a bundler, we will use the compiler option, if any.
538
- *
539
- * If the user has not provided a bundler and no compiler, but has set buildable to true,
540
- * we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
541
- * and no compiler was provided.
542
- *
543
- * If the user has not provided a bundler and no compiler, and has not set buildable to true, then
544
- * set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
545
- *
546
- * If it's publishable, we need to build the code before publishing it, so again
547
- * we default to `tsc`. In the previous version of this, it would set `buildable` to true
548
- * and that would default to `tsc`.
549
- *
550
- * In the past, the only way to get a non-buildable library was to set buildable to false.
551
- * Now, the only way to get a non-buildble library is to set bundler to none.
552
- * By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
553
- */
554
- options.bundler ??= options.compiler;
555
- }
556
508
  options.linter ??= await promptWhenInteractive({
557
509
  type: 'select',
558
510
  name: 'linter',
@@ -574,6 +526,28 @@ async function normalizeOptions(tree, options) {
574
526
  options.unitTestRunner = 'jest';
575
527
  }
576
528
  }
529
+ /**
530
+ * We are deprecating the compiler and the buildable options.
531
+ * However, we want to keep the existing behavior for now.
532
+ *
533
+ * So, if the user has not provided a bundler, we will use the compiler option, if any.
534
+ *
535
+ * If the user has not provided a bundler and no compiler, but has set buildable to true,
536
+ * we will use tsc, since that is the compiler the old generator used to default to, if buildable was true
537
+ * and no compiler was provided.
538
+ *
539
+ * If the user has not provided a bundler and no compiler, and has not set buildable to true, then
540
+ * set the bundler to tsc, to preserve old default behaviour (buildable: true by default).
541
+ *
542
+ * If it's publishable, we need to build the code before publishing it, so again
543
+ * we default to `tsc`. In the previous version of this, it would set `buildable` to true
544
+ * and that would default to `tsc`.
545
+ *
546
+ * In the past, the only way to get a non-buildable library was to set buildable to false.
547
+ * Now, the only way to get a non-buildble library is to set bundler to none.
548
+ * By default, with nothing provided, libraries are buildable with `@nx/js:tsc`.
549
+ */
550
+ options.bundler ??= options.compiler ?? 'tsc';
577
551
  // ensure programmatic runs have an expected default
578
552
  if (!options.config) {
579
553
  options.config = 'project';
@@ -583,7 +557,7 @@ async function normalizeOptions(tree, options) {
583
557
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
584
558
  }
585
559
  if (options.bundler === 'none') {
586
- options.bundler = 'tsc';
560
+ throw new Error(`Publishable libraries can't be generated with "--bundler=none". Please select a valid bundler.`);
587
561
  }
588
562
  }
589
563
  // This is to preserve old behavior, buildable: false
@@ -677,6 +651,10 @@ function getBuildExecutor(bundler) {
677
651
  }
678
652
  }
679
653
  function getOutputPath(options) {
654
+ if (options.isUsingTsSolutionConfig) {
655
+ // Executors expect paths relative to workspace root, so we prepend the project root
656
+ return (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist');
657
+ }
680
658
  const parts = [defaultOutputDirectory];
681
659
  if (options.projectRoot === '.') {
682
660
  parts.push(options.name);
@@ -816,8 +794,12 @@ function determineEntryFields(options) {
816
794
  case 'swc':
817
795
  return {
818
796
  type: 'commonjs',
819
- main: './src/index.js',
820
- typings: './src/index.d.ts',
797
+ main: options.isUsingTsSolutionConfig
798
+ ? './dist/src/index.js'
799
+ : './src/index.js',
800
+ typings: options.isUsingTsSolutionConfig
801
+ ? './dist/src/index.d.ts'
802
+ : './src/index.d.ts',
821
803
  };
822
804
  case 'rollup':
823
805
  return {
@@ -848,8 +830,12 @@ function determineEntryFields(options) {
848
830
  // For libraries intended for Node, use CJS.
849
831
  return {
850
832
  type: 'commonjs',
851
- main: './index.cjs',
852
- // typings is missing for esbuild currently
833
+ main: options.isUsingTsSolutionConfig
834
+ ? './dist/index.cjs'
835
+ : './index.cjs',
836
+ typings: options.isUsingTsSolutionConfig
837
+ ? './dist/index.d.ts'
838
+ : './index.d.ts',
853
839
  };
854
840
  default: {
855
841
  return {
@@ -24,6 +24,8 @@
24
24
  "description": "The bundler to use. Choosing 'none' means this library is not buildable.",
25
25
  "type": "string",
26
26
  "enum": ["swc", "tsc", "rollup", "vite", "esbuild", "none"],
27
+ "default": "tsc",
28
+ "x-prompt": "Which bundler would you like to use to build the library? Choose 'none' to skip build setup.",
27
29
  "x-priority": "important"
28
30
  },
29
31
  "linter": {
@@ -45,11 +45,12 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
45
45
  options.fallbackCurrentVersionResolver = 'disk';
46
46
  }
47
47
  // Set default for updateDependents
48
- const updateDependents = options.updateDependents ?? 'never';
48
+ const updateDependents = options.updateDependents ?? 'auto';
49
49
  const updateDependentsBump = 'patch';
50
50
  // Sort the projects topologically if update dependents is enabled
51
51
  // TODO: maybe move this sorting to the command level?
52
- const projects = updateDependents === 'never'
52
+ const projects = updateDependents === 'never' ||
53
+ options.releaseGroup.projectsRelationship !== 'independent'
53
54
  ? options.projects
54
55
  : (0, sort_projects_topologically_1.sortProjectsTopologically)(options.projectGraph, options.projects);
55
56
  const projectToDependencyBumps = new Map();
@@ -270,6 +271,7 @@ To fix this you will either need to add a package.json file at that location, or
270
271
  specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromConventionalCommits)(previousVersionRef, options.projectGraph, affectedProjects, options.conventionalCommitsConfig);
271
272
  if (!specifier) {
272
273
  if (updateDependents !== 'never' &&
274
+ options.releaseGroup.projectsRelationship === 'independent' &&
273
275
  projectToDependencyBumps.has(projectName)) {
274
276
  // No applicable changes to the project directly by the user, but one or more dependencies have been bumped and updateDependents is enabled
275
277
  specifier = updateDependentsBump;
@@ -352,6 +354,7 @@ To fix this you will either need to add a package.json file at that location, or
352
354
  }
353
355
  if (!specifier) {
354
356
  if (updateDependents !== 'never' &&
357
+ options.releaseGroup.projectsRelationship === 'independent' &&
355
358
  projectToDependencyBumps.has(projectName)) {
356
359
  // No applicable changes to the project directly by the user, but one or more dependencies have been bumped and updateDependents is enabled
357
360
  specifier = updateDependentsBump;
@@ -395,7 +398,8 @@ To fix this you will either need to add a package.json file at that location, or
395
398
  .filter((localPackageDependency) => {
396
399
  return localPackageDependency.target === project.name;
397
400
  });
398
- const includeTransitiveDependents = updateDependents === 'auto';
401
+ const includeTransitiveDependents = updateDependents !== 'never' &&
402
+ options.releaseGroup.projectsRelationship === 'independent';
399
403
  const transitiveLocalPackageDependents = [];
400
404
  if (includeTransitiveDependents) {
401
405
  for (const directDependent of allDependentProjects) {
@@ -435,7 +439,8 @@ To fix this you will either need to add a package.json file at that location, or
435
439
  }
436
440
  }
437
441
  // If not always updating dependents (when they don't already appear in the batch itself), print a warning to the user about what is being skipped and how to change it
438
- if (updateDependents === 'never') {
442
+ if (updateDependents === 'never' ||
443
+ options.releaseGroup.projectsRelationship !== 'independent') {
439
444
  if (dependentProjectsOutsideCurrentBatch.length > 0) {
440
445
  let logMsg = `⚠️ Warning, the following packages depend on "${project.name}"`;
441
446
  const reason = options.specifierSource === 'version-plans'
@@ -453,7 +458,7 @@ To fix this you will either need to add a package.json file at that location, or
453
458
  logMsg += `\n${dependentProjectsOutsideCurrentBatch
454
459
  .map((dependentProject) => `${indent}- ${dependentProject.source}`)
455
460
  .join('\n')}`;
456
- logMsg += `\n${indent}=> You can adjust this behavior by setting \`version.generatorOptions.updateDependents\` to "auto"`;
461
+ logMsg += `\n${indent}=> You can adjust this behavior by removing the usage of \`version.generatorOptions.updateDependents\` with "never"`;
457
462
  logger.buffer(logMsg);
458
463
  }
459
464
  }
@@ -463,7 +468,8 @@ To fix this you will either need to add a package.json file at that location, or
463
468
  versionData[projectName] = {
464
469
  currentVersion,
465
470
  newVersion: null, // will stay as null in the final result in the case that no changes are detected
466
- dependentProjects: updateDependents === 'auto'
471
+ dependentProjects: updateDependents === 'auto' &&
472
+ options.releaseGroup.projectsRelationship === 'independent'
467
473
  ? allDependentProjects
468
474
  : dependentProjectsInCurrentBatch,
469
475
  };
@@ -483,7 +489,8 @@ To fix this you will either need to add a package.json file at that location, or
483
489
  });
484
490
  logger.buffer(`✍️ New version ${newVersion} written to ${packageJsonPath}`);
485
491
  if (allDependentProjects.length > 0) {
486
- const totalProjectsToUpdate = updateDependents === 'auto'
492
+ const totalProjectsToUpdate = updateDependents === 'auto' &&
493
+ options.releaseGroup.projectsRelationship === 'independent'
487
494
  ? allDependentProjects.length +
488
495
  transitiveLocalPackageDependents.length -
489
496
  // There are two entries per circular dep
@@ -568,7 +575,8 @@ To fix this you will either need to add a package.json file at that location, or
568
575
  forceVersionBump: false,
569
576
  });
570
577
  }
571
- if (updateDependents === 'auto') {
578
+ if (updateDependents === 'auto' &&
579
+ options.releaseGroup.projectsRelationship === 'independent') {
572
580
  for (const dependentProject of dependentProjectsOutsideCurrentBatch) {
573
581
  if (options.specifierSource === 'version-plans' &&
574
582
  !projectToDependencyBumps.has(dependentProject.source)) {
@@ -19,7 +19,7 @@ packages:
19
19
  proxy: npmjs
20
20
 
21
21
  # log settings
22
- logs:
22
+ log:
23
23
  type: stdout
24
24
  format: pretty
25
25
  level: warn
@@ -30,28 +30,35 @@ async function syncGenerator(tree) {
30
30
  `The "${plugin_1.PLUGIN_NAME}" plugin must be added to the "plugins" array in "nx.json" in order to sync the project graph information to the TypeScript configuration files.`,
31
31
  ]);
32
32
  }
33
+ const tsconfigInfoCaches = {
34
+ composite: new Map(),
35
+ content: new Map(),
36
+ exists: new Map(),
37
+ isFile: new Map(),
38
+ };
33
39
  // Root tsconfig containing project references for the whole workspace
34
40
  const rootTsconfigPath = 'tsconfig.json';
35
- if (!tree.exists(rootTsconfigPath)) {
41
+ if (!tsconfigExists(tree, tsconfigInfoCaches, rootTsconfigPath)) {
36
42
  throw new sync_generators_1.SyncError('Missing root "tsconfig.json"', [
37
43
  `A "tsconfig.json" file must exist in the workspace root in order to sync the project graph information to the TypeScript configuration files.`,
38
44
  ]);
39
45
  }
40
- const rawTsconfigContentsCache = new Map();
41
- const stringifiedRootJsonContents = readRawTsconfigContents(tree, rawTsconfigContentsCache, rootTsconfigPath);
46
+ const stringifiedRootJsonContents = readRawTsconfigContents(tree, tsconfigInfoCaches, rootTsconfigPath);
42
47
  const rootTsconfig = (0, devkit_1.parseJson)(stringifiedRootJsonContents);
43
48
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
44
49
  const projectRoots = new Set();
45
- const tsconfigHasCompositeEnabledCache = new Map();
46
50
  const tsconfigProjectNodeValues = Object.values(projectGraph.nodes).filter((node) => {
47
51
  projectRoots.add(node.data.root);
48
52
  const projectTsconfigPath = (0, devkit_1.joinPathFragments)(node.data.root, 'tsconfig.json');
49
- return tsconfigExists(tree, rawTsconfigContentsCache, projectTsconfigPath);
53
+ return tsconfigExists(tree, tsconfigInfoCaches, projectTsconfigPath);
50
54
  });
51
55
  const tsSysFromTree = {
52
56
  ...ts.sys,
57
+ fileExists(path) {
58
+ return tsconfigExists(tree, tsconfigInfoCaches, path);
59
+ },
53
60
  readFile(path) {
54
- return readRawTsconfigContents(tree, rawTsconfigContentsCache, path);
61
+ return readRawTsconfigContents(tree, tsconfigInfoCaches, path);
55
62
  },
56
63
  };
57
64
  // Track if any changes were made to the tsconfig files. We check the changes
@@ -63,8 +70,8 @@ async function syncGenerator(tree) {
63
70
  const referencesSet = new Set();
64
71
  for (const ref of rootTsconfig.references ?? []) {
65
72
  // reference path is relative to the tsconfig file
66
- const resolvedRefPath = getTsConfigPathFromReferencePath(tree, rootTsconfigPath, ref.path);
67
- if (tsconfigExists(tree, rawTsconfigContentsCache, resolvedRefPath)) {
73
+ const resolvedRefPath = getTsConfigPathFromReferencePath(tree, rootTsconfigPath, ref.path, tsconfigInfoCaches);
74
+ if (tsconfigExists(tree, tsconfigInfoCaches, resolvedRefPath)) {
68
75
  // we only keep the references that still exist
69
76
  referencesSet.add(normalizeReferencePath(ref.path));
70
77
  }
@@ -83,11 +90,11 @@ async function syncGenerator(tree) {
83
90
  if (hasChanges) {
84
91
  const updatedReferences = Array.from(referencesSet)
85
92
  // Check composite is true in the internal reference before proceeding
86
- .filter((ref) => hasCompositeEnabled(tsSysFromTree, tsconfigHasCompositeEnabledCache, (0, devkit_1.joinPathFragments)(ref, 'tsconfig.json')))
93
+ .filter((ref) => hasCompositeEnabled(tsSysFromTree, tsconfigInfoCaches, (0, devkit_1.joinPathFragments)(ref, 'tsconfig.json')))
87
94
  .map((ref) => ({
88
95
  path: `./${ref}`,
89
96
  }));
90
- patchTsconfigJsonReferences(tree, rawTsconfigContentsCache, rootTsconfigPath, updatedReferences);
97
+ patchTsconfigJsonReferences(tree, tsconfigInfoCaches, rootTsconfigPath, updatedReferences);
91
98
  }
92
99
  }
93
100
  const userOptions = nxJson.sync?.generatorOptions?.['@nx/js:typescript-sync'];
@@ -105,7 +112,7 @@ async function syncGenerator(tree) {
105
112
  const sourceProjectNode = projectGraph.nodes[projectName];
106
113
  // Find the relevant tsconfig file for the source project
107
114
  const sourceProjectTsconfigPath = (0, devkit_1.joinPathFragments)(sourceProjectNode.data.root, 'tsconfig.json');
108
- if (!tsconfigExists(tree, rawTsconfigContentsCache, sourceProjectTsconfigPath)) {
115
+ if (!tsconfigExists(tree, tsconfigInfoCaches, sourceProjectTsconfigPath)) {
109
116
  if (process.env.NX_VERBOSE_LOGGING === 'true') {
110
117
  devkit_1.logger.warn(`Skipping project "${projectName}" as there is no tsconfig.json file found in the project root "${sourceProjectNode.data.root}".`);
111
118
  }
@@ -115,16 +122,16 @@ async function syncGenerator(tree) {
115
122
  const dependencies = collectProjectDependencies(tree, projectName, projectGraph, collectedDependencies);
116
123
  for (const runtimeTsConfigFileName of runtimeTsConfigFileNames) {
117
124
  const runtimeTsConfigPath = (0, devkit_1.joinPathFragments)(sourceProjectNode.data.root, runtimeTsConfigFileName);
118
- if (!tsconfigExists(tree, rawTsconfigContentsCache, runtimeTsConfigPath)) {
125
+ if (!tsconfigExists(tree, tsconfigInfoCaches, runtimeTsConfigPath)) {
119
126
  continue;
120
127
  }
121
128
  // Update project references for the runtime tsconfig
122
129
  hasChanges =
123
- updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache, tsconfigHasCompositeEnabledCache, runtimeTsConfigPath, dependencies, sourceProjectNode.data.root, projectRoots, runtimeTsConfigFileName, runtimeTsConfigFileNames) || hasChanges;
130
+ updateTsConfigReferences(tree, tsSysFromTree, tsconfigInfoCaches, runtimeTsConfigPath, dependencies, sourceProjectNode.data.root, projectRoots, runtimeTsConfigFileName, runtimeTsConfigFileNames) || hasChanges;
124
131
  }
125
132
  // Update project references for the tsconfig.json file
126
133
  hasChanges =
127
- updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache, tsconfigHasCompositeEnabledCache, sourceProjectTsconfigPath, dependencies, sourceProjectNode.data.root, projectRoots) || hasChanges;
134
+ updateTsConfigReferences(tree, tsSysFromTree, tsconfigInfoCaches, sourceProjectTsconfigPath, dependencies, sourceProjectNode.data.root, projectRoots) || hasChanges;
128
135
  }
129
136
  if (hasChanges) {
130
137
  await (0, devkit_1.formatFiles)(tree);
@@ -138,23 +145,24 @@ exports.default = syncGenerator;
138
145
  * Within the context of a sync generator, performance is a key concern,
139
146
  * so avoid FS interactions whenever possible.
140
147
  */
141
- function readRawTsconfigContents(tree, rawTsconfigContentsCache, tsconfigPath) {
142
- if (!rawTsconfigContentsCache.has(tsconfigPath)) {
143
- rawTsconfigContentsCache.set(tsconfigPath, tree.read(tsconfigPath, 'utf-8'));
148
+ function readRawTsconfigContents(tree, tsconfigInfoCaches, tsconfigPath) {
149
+ if (!tsconfigInfoCaches.content.has(tsconfigPath)) {
150
+ tsconfigInfoCaches.content.set(tsconfigPath, tree.read(tsconfigPath, 'utf-8'));
144
151
  }
145
- return rawTsconfigContentsCache.get(tsconfigPath);
152
+ return tsconfigInfoCaches.content.get(tsconfigPath);
146
153
  }
147
154
  /**
148
155
  * Within the context of a sync generator, performance is a key concern,
149
156
  * so avoid FS interactions whenever possible.
150
157
  */
151
- function tsconfigExists(tree, rawTsconfigContentsCache, tsconfigPath) {
152
- return rawTsconfigContentsCache.has(tsconfigPath)
153
- ? true
154
- : tree.exists(tsconfigPath);
158
+ function tsconfigExists(tree, tsconfigInfoCaches, tsconfigPath) {
159
+ if (!tsconfigInfoCaches.exists.has(tsconfigPath)) {
160
+ tsconfigInfoCaches.exists.set(tsconfigPath, tree.exists(tsconfigPath));
161
+ }
162
+ return tsconfigInfoCaches.exists.get(tsconfigPath);
155
163
  }
156
- function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache, tsconfigHasCompositeEnabledCache, tsConfigPath, dependencies, projectRoot, projectRoots, runtimeTsConfigFileName, possibleRuntimeTsConfigFileNames) {
157
- const stringifiedJsonContents = readRawTsconfigContents(tree, rawTsconfigContentsCache, tsConfigPath);
164
+ function updateTsConfigReferences(tree, tsSysFromTree, tsconfigInfoCaches, tsConfigPath, dependencies, projectRoot, projectRoots, runtimeTsConfigFileName, possibleRuntimeTsConfigFileNames) {
165
+ const stringifiedJsonContents = readRawTsconfigContents(tree, tsconfigInfoCaches, tsConfigPath);
158
166
  const tsConfig = (0, devkit_1.parseJson)(stringifiedJsonContents);
159
167
  const ignoredReferences = new Set(tsConfig.nx?.sync?.ignoredReferences ?? []);
160
168
  // We have at least one dependency so we can safely set it to an empty array if not already set
@@ -171,8 +179,8 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
171
179
  continue;
172
180
  }
173
181
  // reference path is relative to the tsconfig file
174
- const resolvedRefPath = getTsConfigPathFromReferencePath(tree, tsConfigPath, ref.path);
175
- if (isProjectReferenceWithinNxProject(tree, rawTsconfigContentsCache, resolvedRefPath, projectRoot, projectRoots) ||
182
+ const resolvedRefPath = getTsConfigPathFromReferencePath(tree, tsConfigPath, ref.path, tsconfigInfoCaches);
183
+ if (isProjectReferenceWithinNxProject(tree, tsconfigInfoCaches, resolvedRefPath, projectRoot, projectRoots) ||
176
184
  isProjectReferenceIgnored(tree, resolvedRefPath)) {
177
185
  // we keep all references within the current Nx project or that are ignored
178
186
  references.push(ref);
@@ -185,9 +193,9 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
185
193
  let referencePath = dep.data.root;
186
194
  if (runtimeTsConfigFileName) {
187
195
  const runtimeTsConfigPath = (0, devkit_1.joinPathFragments)(dep.data.root, runtimeTsConfigFileName);
188
- if (tsconfigExists(tree, rawTsconfigContentsCache, runtimeTsConfigPath)) {
196
+ if (tsconfigExists(tree, tsconfigInfoCaches, runtimeTsConfigPath)) {
189
197
  // Check composite is true in the dependency runtime tsconfig file before proceeding
190
- if (!hasCompositeEnabled(tsSysFromTree, tsconfigHasCompositeEnabledCache, runtimeTsConfigPath)) {
198
+ if (!hasCompositeEnabled(tsSysFromTree, tsconfigInfoCaches, runtimeTsConfigPath)) {
191
199
  continue;
192
200
  }
193
201
  referencePath = runtimeTsConfigPath;
@@ -198,9 +206,9 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
198
206
  for (const possibleRuntimeTsConfigFileName of possibleRuntimeTsConfigFileNames ??
199
207
  []) {
200
208
  const possibleRuntimeTsConfigPath = (0, devkit_1.joinPathFragments)(dep.data.root, possibleRuntimeTsConfigFileName);
201
- if (tsconfigExists(tree, rawTsconfigContentsCache, possibleRuntimeTsConfigPath)) {
209
+ if (tsconfigExists(tree, tsconfigInfoCaches, possibleRuntimeTsConfigPath)) {
202
210
  // Check composite is true in the dependency runtime tsconfig file before proceeding
203
- if (!hasCompositeEnabled(tsSysFromTree, tsconfigHasCompositeEnabledCache, possibleRuntimeTsConfigPath)) {
211
+ if (!hasCompositeEnabled(tsSysFromTree, tsconfigInfoCaches, possibleRuntimeTsConfigPath)) {
204
212
  continue;
205
213
  }
206
214
  referencePath = possibleRuntimeTsConfigPath;
@@ -211,7 +219,7 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
211
219
  }
212
220
  else {
213
221
  // Check composite is true in the dependency tsconfig.json file before proceeding
214
- if (!hasCompositeEnabled(tsSysFromTree, tsconfigHasCompositeEnabledCache, (0, devkit_1.joinPathFragments)(dep.data.root, 'tsconfig.json'))) {
222
+ if (!hasCompositeEnabled(tsSysFromTree, tsconfigInfoCaches, (0, devkit_1.joinPathFragments)(dep.data.root, 'tsconfig.json'))) {
215
223
  continue;
216
224
  }
217
225
  }
@@ -227,7 +235,7 @@ function updateTsConfigReferences(tree, tsSysFromTree, rawTsconfigContentsCache,
227
235
  }
228
236
  hasChanges ||= newReferencesSet.size !== originalReferencesSet.size;
229
237
  if (hasChanges) {
230
- patchTsconfigJsonReferences(tree, rawTsconfigContentsCache, tsConfigPath, references);
238
+ patchTsconfigJsonReferences(tree, tsconfigInfoCaches, tsConfigPath, references);
231
239
  }
232
240
  return hasChanges;
233
241
  }
@@ -273,8 +281,8 @@ function normalizeReferencePath(path) {
273
281
  .replace(/\/tsconfig.json$/, '')
274
282
  .replace(/^\.\//, '');
275
283
  }
276
- function isProjectReferenceWithinNxProject(tree, rawTsconfigContentsCache, refTsConfigPath, projectRoot, projectRoots) {
277
- let currentPath = getTsConfigDirName(tree, rawTsconfigContentsCache, refTsConfigPath);
284
+ function isProjectReferenceWithinNxProject(tree, tsconfigInfoCaches, refTsConfigPath, projectRoot, projectRoots) {
285
+ let currentPath = getTsConfigDirName(tree, tsconfigInfoCaches, refTsConfigPath);
278
286
  if ((0, posix_1.relative)(projectRoot, currentPath).startsWith('..')) {
279
287
  // it's outside of the project root, so it's an external project reference
280
288
  return false;
@@ -300,16 +308,14 @@ function isProjectReferenceIgnored(tree, refTsConfigPath) {
300
308
  }
301
309
  return ig.ignores(refTsConfigPath);
302
310
  }
303
- function getTsConfigDirName(tree, rawTsconfigContentsCache, tsConfigPath) {
304
- return (rawTsconfigContentsCache.has(tsConfigPath)
305
- ? true
306
- : tree.isFile(tsConfigPath))
311
+ function getTsConfigDirName(tree, tsconfigInfoCaches, tsConfigPath) {
312
+ return tsconfigIsFile(tree, tsconfigInfoCaches, tsConfigPath)
307
313
  ? (0, posix_1.dirname)(tsConfigPath)
308
314
  : (0, posix_1.normalize)(tsConfigPath);
309
315
  }
310
- function getTsConfigPathFromReferencePath(tree, ownerTsConfigPath, referencePath) {
316
+ function getTsConfigPathFromReferencePath(tree, ownerTsConfigPath, referencePath, tsconfigInfoCaches) {
311
317
  const resolvedRefPath = (0, devkit_1.joinPathFragments)((0, posix_1.dirname)(ownerTsConfigPath), referencePath);
312
- return tree.isFile(resolvedRefPath)
318
+ return tsconfigIsFile(tree, tsconfigInfoCaches, resolvedRefPath)
313
319
  ? resolvedRefPath
314
320
  : (0, devkit_1.joinPathFragments)(resolvedRefPath, 'tsconfig.json');
315
321
  }
@@ -317,18 +323,29 @@ function getTsConfigPathFromReferencePath(tree, ownerTsConfigPath, referencePath
317
323
  * Minimally patch just the "references" property within the tsconfig file at a given path.
318
324
  * This allows comments in other sections of the file to remain intact when syncing is run.
319
325
  */
320
- function patchTsconfigJsonReferences(tree, rawTsconfigContentsCache, tsconfigPath, updatedReferences) {
321
- const stringifiedJsonContents = readRawTsconfigContents(tree, rawTsconfigContentsCache, tsconfigPath);
326
+ function patchTsconfigJsonReferences(tree, tsconfigInfoCaches, tsconfigPath, updatedReferences) {
327
+ const stringifiedJsonContents = readRawTsconfigContents(tree, tsconfigInfoCaches, tsconfigPath);
322
328
  const edits = (0, jsonc_parser_1.modify)(stringifiedJsonContents, ['references'], updatedReferences, {});
323
329
  const updatedJsonContents = (0, jsonc_parser_1.applyEdits)(stringifiedJsonContents, edits);
324
330
  // The final contents will be formatted by formatFiles() later
325
331
  tree.write(tsconfigPath, updatedJsonContents);
326
332
  }
327
- function hasCompositeEnabled(tsSysFromTree, tsconfigHasCompositeEnabledCache, tsconfigPath) {
328
- if (!tsconfigHasCompositeEnabledCache.has(tsconfigPath)) {
333
+ function hasCompositeEnabled(tsSysFromTree, tsconfigInfoCaches, tsconfigPath) {
334
+ if (!tsconfigInfoCaches.composite.has(tsconfigPath)) {
329
335
  const parsed = ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfigPath, tsSysFromTree.readFile).config, tsSysFromTree, (0, posix_1.dirname)(tsconfigPath));
330
- const enabledVal = parsed.options.composite === true;
331
- tsconfigHasCompositeEnabledCache.set(tsconfigPath, enabledVal);
336
+ tsconfigInfoCaches.composite.set(tsconfigPath, parsed.options.composite === true);
337
+ }
338
+ return tsconfigInfoCaches.composite.get(tsconfigPath);
339
+ }
340
+ function tsconfigIsFile(tree, tsconfigInfoCaches, tsconfigPath) {
341
+ if (tsconfigInfoCaches.isFile.has(tsconfigPath)) {
342
+ return tsconfigInfoCaches.isFile.get(tsconfigPath);
343
+ }
344
+ if (tsconfigInfoCaches.content.has(tsconfigPath)) {
345
+ // if it has content, it's a file
346
+ tsconfigInfoCaches.isFile.set(tsconfigPath, true);
347
+ return true;
332
348
  }
333
- return tsconfigHasCompositeEnabledCache.get(tsconfigPath);
349
+ tsconfigInfoCaches.isFile.set(tsconfigPath, tree.isFile(tsconfigPath));
350
+ return tsconfigInfoCaches.isFile.get(tsconfigPath);
334
351
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNodes = exports.createNodesV2 = exports.PLUGIN_NAME = exports.createDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
6
5
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
7
6
  const minimatch_1 = require("minimatch");
8
7
  const node_fs_1 = require("node:fs");
@@ -37,8 +36,9 @@ exports.createNodesV2 = [
37
36
  const cachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, `tsc-${optionsHash}.hash`);
38
37
  const targetsCache = readTargetsCache(cachePath);
39
38
  const normalizedOptions = normalizePluginOptions(options);
39
+ const lockFileName = (0, lock_file_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
40
40
  try {
41
- return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, normalizedOptions, context);
41
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, lockFileName, targetsCache), configFilePaths, normalizedOptions, context);
42
42
  }
43
43
  finally {
44
44
  writeTargetsToCache(cachePath, targetsCache);
@@ -50,10 +50,11 @@ exports.createNodes = [
50
50
  async (configFilePath, options, context) => {
51
51
  devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
52
52
  const normalizedOptions = normalizePluginOptions(options);
53
- return createNodesInternal(configFilePath, normalizedOptions, context, {});
53
+ const lockFileName = (0, lock_file_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot));
54
+ return createNodesInternal(configFilePath, normalizedOptions, context, lockFileName, {});
54
55
  },
55
56
  ];
56
- async function createNodesInternal(configFilePath, options, context, targetsCache) {
57
+ async function createNodesInternal(configFilePath, options, context, lockFileName, targetsCache) {
57
58
  const projectRoot = (0, node_path_1.dirname)(configFilePath);
58
59
  const fullConfigPath = (0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath);
59
60
  // Do not create a project for the workspace root tsconfig files.
@@ -71,8 +72,20 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
71
72
  !siblingFiles.includes('tsconfig.json')) {
72
73
  return {};
73
74
  }
74
- const nodeHash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, lock_file_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
75
- // The hash is calculated at the node/project level, so we add the config file path to avoid conflicts when caching
75
+ /**
76
+ * The cache key is composed by:
77
+ * - hashes of the content of the relevant files that can affect what's inferred by the plugin:
78
+ * - current config file
79
+ * - config files extended by the current config file (recursively up to the root config file)
80
+ * - lock file
81
+ * - hash of the plugin options
82
+ * - current config file path
83
+ */
84
+ const extendedConfigFiles = getExtendedConfigFiles(fullConfigPath, readCachedTsConfig(fullConfigPath));
85
+ const nodeHash = (0, file_hasher_1.hashArray)([
86
+ ...[configFilePath, ...extendedConfigFiles, lockFileName].map(file_hasher_1.hashFile),
87
+ (0, file_hasher_1.hashObject)(options),
88
+ ]);
76
89
  const cacheKey = `${nodeHash}_${configFilePath}`;
77
90
  targetsCache[cacheKey] ??= buildTscTargets(fullConfigPath, projectRoot, options, context);
78
91
  const { targets } = targetsCache[cacheKey];
@@ -53,7 +53,8 @@ export interface NormalizedSwcExecutorOptions
53
53
  skipTypeCheck: boolean;
54
54
  swcCliOptions: SwcCliOptions;
55
55
  tmpSwcrcPath: string;
56
+ isTsSolutionSetup: boolean;
56
57
  sourceRoot?: string;
57
- // TODO(v20): remove inline feature
58
+ // TODO(v21): remove inline feature
58
59
  inline?: boolean;
59
60
  }
@@ -13,7 +13,7 @@ const path_1 = require("path");
13
13
  function getSwcCmd({ swcCliOptions: { swcrcPath, destPath, stripLeadingPaths }, root, projectRoot, originalProjectRoot, sourceRoot, inline, }, watch = false) {
14
14
  const swcCLI = require.resolve('@swc/cli/bin/swc.js');
15
15
  let inputDir;
16
- // TODO(v20): remove inline feature
16
+ // TODO(v21): remove inline feature
17
17
  if (inline) {
18
18
  inputDir = originalProjectRoot.split('/')[0];
19
19
  }
@@ -1,3 +1,4 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare function isUsingTypeScriptPlugin(tree: Tree): boolean;
3
- export declare function isUsingTsSolutionSetup(tree: Tree): boolean;
3
+ export declare function isUsingTsSolutionSetup(tree?: Tree): boolean;
4
+ export declare function assertNotUsingTsSolutionSetup(tree: Tree, pluginName: string, generatorName: string): void;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isUsingTypeScriptPlugin = isUsingTypeScriptPlugin;
4
4
  exports.isUsingTsSolutionSetup = isUsingTsSolutionSetup;
5
+ exports.assertNotUsingTsSolutionSetup = assertNotUsingTsSolutionSetup;
5
6
  const devkit_1 = require("@nx/devkit");
7
+ const tree_1 = require("nx/src/generators/tree");
6
8
  const package_manager_workspaces_1 = require("../package-manager-workspaces");
7
9
  function isUsingTypeScriptPlugin(tree) {
8
10
  const nxJson = (0, devkit_1.readNxJson)(tree);
@@ -11,6 +13,7 @@ function isUsingTypeScriptPlugin(tree) {
11
13
  : p.plugin === '@nx/js/typescript') ?? false);
12
14
  }
13
15
  function isUsingTsSolutionSetup(tree) {
16
+ tree ??= new tree_1.FsTree(devkit_1.workspaceRoot, false);
14
17
  return ((0, package_manager_workspaces_1.isUsingPackageManagerWorkspaces)(tree) &&
15
18
  isWorkspaceSetupWithTsSolution(tree));
16
19
  }
@@ -46,3 +49,19 @@ function isWorkspaceSetupWithTsSolution(tree) {
46
49
  }
47
50
  return true;
48
51
  }
52
+ function assertNotUsingTsSolutionSetup(tree, pluginName, generatorName) {
53
+ if (process.env.NX_IGNORE_UNSUPPORTED_TS_SETUP === 'true' ||
54
+ !isUsingTsSolutionSetup(tree)) {
55
+ return;
56
+ }
57
+ const artifactString = generatorName === 'init'
58
+ ? `"@nx/${pluginName}" plugin`
59
+ : `"@nx/${pluginName}:${generatorName}" generator`;
60
+ devkit_1.output.error({
61
+ title: `The ${artifactString} doesn't yet support the existing TypeScript setup`,
62
+ bodyLines: [
63
+ `We're working hard to support the existing TypeScript setup with the ${artifactString}. We'll soon release a new version of Nx with support for it.`,
64
+ ],
65
+ });
66
+ process.exit(1);
67
+ }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function replacePackage(tree: Tree): Promise<void>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = replacePackage;
4
- const devkit_1 = require("@nx/devkit");
5
- const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
6
- async function replacePackage(tree) {
7
- await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/js', '@nx/js');
8
- await (0, devkit_1.formatFiles)(tree);
9
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function (tree: Tree): Promise<void>;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = default_1;
4
- const devkit_1 = require("@nx/devkit");
5
- const executors = new Set([
6
- '@nx/js:swc',
7
- '@nrwl/js:swc',
8
- '@nx/js:tsc',
9
- '@nrwl/js:tsc',
10
- ]);
11
- async function default_1(tree) {
12
- // use project graph to get the expanded target configurations
13
- const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
14
- for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
15
- if (projectData.projectType !== 'library') {
16
- continue;
17
- }
18
- for (const [targetName, target] of Object.entries(projectData.targets || {})) {
19
- if (!executors.has(target.executor)) {
20
- continue;
21
- }
22
- if (!target.options ||
23
- target.options.updateBuildableProjectDepsInPackageJson === undefined) {
24
- // read the project configuration to write the explicit project configuration
25
- // and avoid writing the expanded target configuration
26
- const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
27
- project.targets[targetName].options ??= {};
28
- project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
29
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
30
- }
31
- }
32
- }
33
- await (0, devkit_1.formatFiles)(tree);
34
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): Promise<void>;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = update;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- async function update(tree) {
7
- const projects = (0, devkit_1.getProjects)(tree);
8
- for (const config of projects.values()) {
9
- const swcrcPath = (0, path_1.join)(config.root, '.swcrc');
10
- if (!tree.exists(swcrcPath))
11
- continue;
12
- const json = (0, devkit_1.readJson)(tree, swcrcPath);
13
- // No longer need strict or noInterop for es6 modules
14
- // See: https://github.com/swc-project/swc/commit/7e8d72d
15
- if (json.module?.type === 'es6' &&
16
- (json.module?.strict || json.module?.noInterop)) {
17
- delete json.module.noInterop;
18
- delete json.module.strict;
19
- (0, devkit_1.writeJson)(tree, swcrcPath, json);
20
- }
21
- }
22
- await (0, devkit_1.formatFiles)(tree);
23
- }