@nx/js 0.0.0-pr-28667-37ba4e7 → 0.0.0-pr-28682-017d55a

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": "0.0.0-pr-28667-37ba4e7",
3
+ "version": "0.0.0-pr-28682-017d55a",
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-28667-37ba4e7",
43
- "@nx/workspace": "0.0.0-pr-28667-37ba4e7",
42
+ "@nx/devkit": "0.0.0-pr-28682-017d55a",
43
+ "@nx/workspace": "0.0.0-pr-28682-017d55a",
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",
@@ -29,8 +29,7 @@ async function* nodeExecutor(options, context) {
29
29
  throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
30
30
  }
31
31
  const buildTargetExecutor = project.data.targets[buildTarget.target]?.executor;
32
- if (buildTargetExecutor === 'nx:run-commands' ||
33
- buildTargetExecutor === '@nrwl/workspace:run-commands') {
32
+ if (buildTargetExecutor === 'nx:run-commands') {
34
33
  // Run commands does not emit build event, so we have to switch to run entire build through Nx CLI.
35
34
  options.runBuildTargetDependencies = true;
36
35
  }
@@ -113,13 +113,13 @@
113
113
  "description": "Generate a lockfile (e.g. package-lock.json) that matches the workspace lockfile to ensure package versions match.",
114
114
  "default": false,
115
115
  "x-priority": "internal"
116
+ },
117
+ "stripLeadingPaths": {
118
+ "type": "boolean",
119
+ "description": "Remove leading directory from output (e.g. src). See: https://swc.rs/docs/usage/cli#--strip-leading-paths",
120
+ "default": false
116
121
  }
117
122
  },
118
- "stripLeadingPaths": {
119
- "type": "boolean",
120
- "description": "Remove leading directory from output (e.g. src). See: https://swc.rs/docs/usage/cli#--strip-leading-paths",
121
- "default": false
122
- },
123
123
  "required": ["main", "outputPath", "tsConfig"],
124
124
  "definitions": {
125
125
  "assetPattern": {
@@ -9,8 +9,8 @@ const versions_1 = require("../../utils/versions");
9
9
  async function convertToSwcGenerator(tree, schema) {
10
10
  const options = normalizeOptions(schema);
11
11
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.project);
12
- updateProjectBuildTargets(tree, projectConfiguration, options.project, options.targets);
13
- return checkSwcDependencies(tree, projectConfiguration);
12
+ const updated = updateProjectBuildTargets(tree, projectConfiguration, options.project, options.targets);
13
+ return updated ? checkSwcDependencies(tree, projectConfiguration) : () => { };
14
14
  }
15
15
  function normalizeOptions(schema) {
16
16
  const options = { ...schema };
@@ -20,15 +20,18 @@ function normalizeOptions(schema) {
20
20
  return options;
21
21
  }
22
22
  function updateProjectBuildTargets(tree, projectConfiguration, projectName, projectTargets) {
23
+ let updated = false;
23
24
  for (const target of projectTargets) {
24
- const targetConfiguration = projectConfiguration.targets[target];
25
- if (!targetConfiguration ||
26
- (targetConfiguration.executor !== '@nx/js:tsc' &&
27
- targetConfiguration.executor !== '@nrwl/js:tsc'))
25
+ const targetConfiguration = projectConfiguration.targets?.[target];
26
+ if (!targetConfiguration || targetConfiguration.executor !== '@nx/js:tsc')
28
27
  continue;
29
28
  targetConfiguration.executor = '@nx/js:swc';
29
+ updated = true;
30
30
  }
31
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
31
+ if (updated) {
32
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfiguration);
33
+ }
34
+ return updated;
32
35
  }
33
36
  function checkSwcDependencies(tree, projectConfiguration) {
34
37
  const isSwcrcPresent = tree.exists((0, path_1.join)(projectConfiguration.root, '.swcrc'));
@@ -5,11 +5,10 @@ exports.libraryGeneratorInternal = libraryGeneratorInternal;
5
5
  exports.addLint = addLint;
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
+ const prompt_1 = require("@nx/devkit/src/generators/prompt");
8
9
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
9
10
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
10
- const enquirer_1 = require("enquirer");
11
11
  const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
12
- const is_ci_1 = require("nx/src/utils/is-ci");
13
12
  const path_1 = require("path");
14
13
  const package_manager_workspaces_1 = require("../../utils/package-manager-workspaces");
15
14
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
@@ -21,8 +20,7 @@ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
21
20
  const versions_1 = require("../../utils/versions");
22
21
  const init_1 = require("../init/init");
23
22
  const generator_1 = require("../setup-verdaccio/generator");
24
- const package_manager_workspaces_2 = require("./utils/package-manager-workspaces");
25
- const plugin_registrations_1 = require("./utils/plugin-registrations");
23
+ const plugin_1 = require("../../utils/typescript/plugin");
26
24
  const defaultOutputDirectory = 'dist';
27
25
  async function libraryGenerator(tree, schema) {
28
26
  return await libraryGeneratorInternal(tree, {
@@ -134,7 +132,7 @@ async function libraryGeneratorInternal(tree, schema) {
134
132
  }
135
133
  if (options.isUsingTsSolutionConfig &&
136
134
  options.projectPackageManagerWorkspaceState !== 'included') {
137
- tasks.push((0, package_manager_workspaces_2.getProjectPackageManagerWorkspaceStateWarningTask)(options.projectPackageManagerWorkspaceState, tree.root));
135
+ tasks.push((0, package_manager_workspaces_1.getProjectPackageManagerWorkspaceStateWarningTask)(options.projectPackageManagerWorkspaceState, tree.root));
138
136
  }
139
137
  if (options.publishable) {
140
138
  tasks.push(() => {
@@ -150,10 +148,10 @@ async function configureProject(tree, options) {
150
148
  if (options.hasPlugin) {
151
149
  const nxJson = (0, devkit_1.readNxJson)(tree);
152
150
  if (options.bundler === 'none') {
153
- (0, plugin_registrations_1.ensureProjectIsExcludedFromPluginRegistrations)(nxJson, options.projectRoot);
151
+ (0, plugin_1.ensureProjectIsExcludedFromPluginRegistrations)(nxJson, options.projectRoot);
154
152
  }
155
153
  else {
156
- (0, plugin_registrations_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
154
+ (0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
157
155
  }
158
156
  (0, devkit_1.updateNxJson)(tree, nxJson);
159
157
  }
@@ -471,15 +469,6 @@ function replaceJestConfig(tree, options) {
471
469
  testEnvironment: options.testEnvironment,
472
470
  });
473
471
  }
474
- function isNonInteractive() {
475
- return ((0, is_ci_1.isCI)() || !process.stdout.isTTY || process.env.NX_INTERACTIVE !== 'true');
476
- }
477
- async function promptWhenInteractive(questions, defaultValue) {
478
- if (isNonInteractive()) {
479
- return defaultValue;
480
- }
481
- return await (0, enquirer_1.prompt)(questions);
482
- }
483
472
  async function normalizeOptions(tree, options) {
484
473
  await (0, project_name_and_root_utils_1.ensureProjectName)(tree, options, 'library');
485
474
  const nxJson = (0, devkit_1.readNxJson)(tree);
@@ -489,14 +478,14 @@ async function normalizeOptions(tree, options) {
489
478
  const hasPlugin = (0, ts_solution_setup_1.isUsingTypeScriptPlugin)(tree);
490
479
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
491
480
  if (isUsingTsSolutionConfig) {
492
- options.linter ??= await promptWhenInteractive({
481
+ options.linter ??= await (0, prompt_1.promptWhenInteractive)({
493
482
  type: 'select',
494
483
  name: 'linter',
495
484
  message: `Which linter would you like to use?`,
496
485
  choices: [{ name: 'none' }, { name: 'eslint' }],
497
486
  initial: 0,
498
487
  }, { linter: 'none' }).then(({ linter }) => linter);
499
- options.unitTestRunner ??= await promptWhenInteractive({
488
+ options.unitTestRunner ??= await (0, prompt_1.promptWhenInteractive)({
500
489
  type: 'select',
501
490
  name: 'unitTestRunner',
502
491
  message: `Which unit test runner would you like to use?`,
@@ -505,14 +494,14 @@ async function normalizeOptions(tree, options) {
505
494
  }, { unitTestRunner: 'none' }).then(({ unitTestRunner }) => unitTestRunner);
506
495
  }
507
496
  else {
508
- options.linter ??= await promptWhenInteractive({
497
+ options.linter ??= await (0, prompt_1.promptWhenInteractive)({
509
498
  type: 'select',
510
499
  name: 'linter',
511
500
  message: `Which linter would you like to use?`,
512
501
  choices: [{ name: 'eslint' }, { name: 'none' }],
513
502
  initial: 0,
514
503
  }, { linter: 'eslint' }).then(({ linter }) => linter);
515
- options.unitTestRunner ??= await promptWhenInteractive({
504
+ options.unitTestRunner ??= await (0, prompt_1.promptWhenInteractive)({
516
505
  type: 'select',
517
506
  name: 'unitTestRunner',
518
507
  message: `Which unit test runner would you like to use?`,
@@ -2,15 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupBuildGenerator = setupBuildGenerator;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
6
+ const posix_1 = require("node:path/posix");
7
+ const devkit_internals_1 = require("nx/src/devkit-internals");
8
+ const plugin_1 = require("../..//utils/typescript/plugin");
9
+ const get_import_path_1 = require("../../utils/get-import-path");
10
+ const update_package_json_1 = require("../../utils/package-json/update-package-json");
5
11
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
6
12
  const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
13
+ const ensure_typescript_1 = require("../../utils/typescript/ensure-typescript");
14
+ const ts_config_1 = require("../../utils/typescript/ts-config");
15
+ const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
7
16
  const versions_1 = require("../../utils/versions");
8
- const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
17
+ let ts;
9
18
  async function setupBuildGenerator(tree, options) {
10
19
  const tasks = [];
11
20
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
12
- const buildTarget = options.buildTarget ?? 'build';
13
- const prevBuildOptions = project.targets?.[buildTarget]?.options;
21
+ options.buildTarget ??= 'build';
22
+ const prevBuildOptions = project.targets?.[options.buildTarget]?.options;
14
23
  project.targets ??= {};
15
24
  let mainFile;
16
25
  if (prevBuildOptions?.main) {
@@ -36,6 +45,7 @@ async function setupBuildGenerator(tree, options) {
36
45
  if (!mainFile || !tree.exists(mainFile)) {
37
46
  throw new Error(`Cannot locate a main file for ${options.project}. Please specify one using --main=<file-path>.`);
38
47
  }
48
+ options.main = mainFile;
39
49
  let tsConfigFile;
40
50
  if (prevBuildOptions?.tsConfig) {
41
51
  tsConfigFile = prevBuildOptions.tsConfig;
@@ -59,16 +69,22 @@ async function setupBuildGenerator(tree, options) {
59
69
  if (!tsConfigFile || !tree.exists(tsConfigFile)) {
60
70
  throw new Error(`Cannot locate a tsConfig file for ${options.project}. Please specify one using --tsConfig=<file-path>.`);
61
71
  }
72
+ options.tsConfig = tsConfigFile;
73
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
74
+ const nxJson = (0, devkit_1.readNxJson)(tree);
75
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
76
+ nxJson.useInferencePlugins !== false;
62
77
  switch (options.bundler) {
63
78
  case 'vite': {
64
79
  const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
65
80
  const task = await viteConfigurationGenerator(tree, {
66
81
  buildTarget: options.buildTarget,
67
82
  project: options.project,
68
- newProject: true,
83
+ newProject: false,
69
84
  uiFramework: 'none',
70
85
  includeVitest: false,
71
86
  includeLib: true,
87
+ addPlugin,
72
88
  skipFormat: true,
73
89
  });
74
90
  tasks.push(task);
@@ -82,6 +98,7 @@ async function setupBuildGenerator(tree, options) {
82
98
  project: options.project,
83
99
  skipFormat: true,
84
100
  skipValidation: true,
101
+ format: ['cjs'],
85
102
  });
86
103
  tasks.push(task);
87
104
  break;
@@ -95,6 +112,7 @@ async function setupBuildGenerator(tree, options) {
95
112
  project: options.project,
96
113
  compiler: 'tsc',
97
114
  format: ['cjs', 'esm'],
115
+ addPlugin,
98
116
  skipFormat: true,
99
117
  skipValidation: true,
100
118
  });
@@ -102,40 +120,133 @@ async function setupBuildGenerator(tree, options) {
102
120
  break;
103
121
  }
104
122
  case 'tsc': {
105
- (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/js:tsc');
106
- const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
107
- project.targets[buildTarget] = {
108
- executor: `@nx/js:tsc`,
109
- outputs: ['{options.outputPath}'],
110
- options: {
111
- outputPath,
112
- main: mainFile,
113
- tsConfig: tsConfigFile,
114
- assets: [],
115
- },
116
- };
117
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
123
+ if (isTsSolutionSetup) {
124
+ const nxJson = (0, devkit_1.readNxJson)(tree);
125
+ (0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, project.root, options.buildTarget);
126
+ (0, devkit_1.updateNxJson)(tree, nxJson);
127
+ updatePackageJsonForTsc(tree, options, project);
128
+ }
129
+ else {
130
+ (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/js:tsc');
131
+ const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
132
+ project.targets[options.buildTarget] = {
133
+ executor: `@nx/js:tsc`,
134
+ outputs: ['{options.outputPath}'],
135
+ options: {
136
+ outputPath,
137
+ main: mainFile,
138
+ tsConfig: tsConfigFile,
139
+ assets: [],
140
+ },
141
+ };
142
+ (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
143
+ }
118
144
  break;
119
145
  }
120
146
  case 'swc': {
121
147
  (0, target_defaults_utils_1.addBuildTargetDefaults)(tree, '@nx/js:swc');
122
- const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
123
- project.targets[buildTarget] = {
148
+ const outputPath = isTsSolutionSetup
149
+ ? (0, devkit_1.joinPathFragments)(project.root, 'dist')
150
+ : (0, devkit_1.joinPathFragments)('dist', project.root);
151
+ project.targets[options.buildTarget] = {
124
152
  executor: `@nx/js:swc`,
125
153
  outputs: ['{options.outputPath}'],
126
154
  options: {
127
155
  outputPath,
128
156
  main: mainFile,
129
157
  tsConfig: tsConfigFile,
130
- assets: [],
131
158
  },
132
159
  };
160
+ if (isTsSolutionSetup) {
161
+ project.targets[options.buildTarget].options.stripLeadingPaths = true;
162
+ }
163
+ else {
164
+ project.targets[options.buildTarget].options.assets = [];
165
+ }
133
166
  (0, devkit_1.updateProjectConfiguration)(tree, options.project, project);
134
- (0, add_swc_dependencies_1.addSwcDependencies)(tree);
135
- (0, add_swc_config_1.addSwcConfig)(tree, project.root, 'es6');
167
+ tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(tree));
168
+ (0, add_swc_config_1.addSwcConfig)(tree, project.root, 'commonjs');
169
+ if (isTsSolutionSetup) {
170
+ updatePackageJsonForSwc(tree, options, project);
171
+ }
136
172
  }
137
173
  }
138
174
  await (0, devkit_1.formatFiles)(tree);
139
175
  return (0, devkit_1.runTasksInSerial)(...tasks);
140
176
  }
141
177
  exports.default = setupBuildGenerator;
178
+ function updatePackageJsonForTsc(tree, options, project) {
179
+ if (!ts) {
180
+ ts = (0, ensure_typescript_1.ensureTypescript)();
181
+ }
182
+ const tsconfig = (0, ts_config_1.readTsConfig)(options.tsConfig, {
183
+ ...ts.sys,
184
+ readFile: (p) => tree.read(p, 'utf-8'),
185
+ fileExists: (p) => tree.exists(p),
186
+ });
187
+ let main;
188
+ let rootDir;
189
+ let outputPath;
190
+ if (project.targets?.[options.buildTarget]) {
191
+ const mergedTarget = mergeTargetDefaults(tree, project, options.buildTarget);
192
+ ({ main, rootDir, outputPath } = mergedTarget.options);
193
+ }
194
+ else {
195
+ main = options.main;
196
+ ({ rootDir = project.root, outDir: outputPath } = tsconfig.options);
197
+ const tsOutFile = tsconfig.options.outFile;
198
+ if (tsOutFile) {
199
+ main = (0, posix_1.join)(project.root, (0, posix_1.basename)(tsOutFile));
200
+ outputPath = (0, posix_1.dirname)(tsOutFile);
201
+ }
202
+ if (!outputPath) {
203
+ outputPath = project.root;
204
+ }
205
+ }
206
+ const module = Object.keys(ts.ModuleKind).find((m) => ts.ModuleKind[m] === tsconfig.options.module);
207
+ const format = module.toLowerCase().startsWith('es')
208
+ ? ['esm']
209
+ : ['cjs'];
210
+ updatePackageJson(tree, options.project, project.root, main, outputPath, rootDir, format);
211
+ }
212
+ function updatePackageJsonForSwc(tree, options, project) {
213
+ const mergedTarget = mergeTargetDefaults(tree, project, options.buildTarget);
214
+ const { main, outputPath, swcrc: swcrcPath = (0, posix_1.join)(project.root, '.swcrc'), } = mergedTarget.options;
215
+ const swcrc = (0, devkit_1.readJson)(tree, swcrcPath);
216
+ const format = swcrc.module?.type?.startsWith('es')
217
+ ? ['esm']
218
+ : ['cjs'];
219
+ updatePackageJson(tree, options.project, project.root, main, outputPath,
220
+ // we set the `stripLeadingPaths` option, so the rootDir would match the dirname of the entry point
221
+ (0, posix_1.dirname)(main), format);
222
+ }
223
+ function updatePackageJson(tree, projectName, projectRoot, main, outputPath, rootDir, format) {
224
+ const packageJsonPath = (0, posix_1.join)(projectRoot, 'package.json');
225
+ let packageJson;
226
+ if (tree.exists(packageJsonPath)) {
227
+ packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
228
+ }
229
+ else {
230
+ packageJson = {
231
+ name: (0, get_import_path_1.getImportPath)(tree, projectName),
232
+ version: '0.0.1',
233
+ };
234
+ }
235
+ packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
236
+ main,
237
+ outputPath,
238
+ projectRoot,
239
+ generateExportsField: true,
240
+ packageJsonPath,
241
+ rootDir,
242
+ format,
243
+ });
244
+ (0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
245
+ }
246
+ function mergeTargetDefaults(tree, project, buildTarget) {
247
+ const nxJson = (0, devkit_1.readNxJson)(tree);
248
+ const projectTarget = project.targets[buildTarget];
249
+ return (0, devkit_internals_1.mergeTargetConfigurations)(projectTarget, (projectTarget.executor
250
+ ? nxJson.targetDefaults?.[projectTarget.executor]
251
+ : undefined) ?? nxJson.targetDefaults?.[buildTarget]);
252
+ }
@@ -77,13 +77,21 @@ async function createNodesInternal(configFilePath, options, context, lockFileNam
77
77
  * - hashes of the content of the relevant files that can affect what's inferred by the plugin:
78
78
  * - current config file
79
79
  * - config files extended by the current config file (recursively up to the root config file)
80
+ * - referenced config files that are internal to the owning Nx project of the current config file
80
81
  * - lock file
81
82
  * - hash of the plugin options
82
83
  * - current config file path
83
84
  */
84
- const extendedConfigFiles = getExtendedConfigFiles(fullConfigPath, readCachedTsConfig(fullConfigPath));
85
+ const tsConfig = readCachedTsConfig(fullConfigPath);
86
+ const extendedConfigFiles = getExtendedConfigFiles(fullConfigPath, tsConfig);
87
+ const internalReferencedFiles = resolveInternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
85
88
  const nodeHash = (0, file_hasher_1.hashArray)([
86
- ...[configFilePath, ...extendedConfigFiles, lockFileName].map(file_hasher_1.hashFile),
89
+ ...[
90
+ configFilePath,
91
+ ...extendedConfigFiles.files,
92
+ ...Object.keys(internalReferencedFiles),
93
+ lockFileName,
94
+ ].map(file_hasher_1.hashFile),
87
95
  (0, file_hasher_1.hashObject)(options),
88
96
  ]);
89
97
  const cacheKey = `${nodeHash}_${configFilePath}`;
@@ -169,12 +177,14 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
169
177
  }
170
178
  function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot) {
171
179
  const configFiles = new Set();
172
- const includePaths = new Set();
173
- const excludePaths = new Set();
180
+ const externalDependencies = ['typescript'];
174
181
  const extendedConfigFiles = getExtendedConfigFiles(configFilePath, tsConfig);
175
- extendedConfigFiles.forEach((configPath) => {
182
+ extendedConfigFiles.files.forEach((configPath) => {
176
183
  configFiles.add(configPath);
177
184
  });
185
+ externalDependencies.push(...extendedConfigFiles.packages);
186
+ const includePaths = new Set();
187
+ const excludePaths = new Set();
178
188
  const projectTsConfigFiles = [
179
189
  [configFilePath, tsConfig],
180
190
  ...Object.entries(internalProjectReferences),
@@ -225,7 +235,7 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
225
235
  else {
226
236
  inputs.push('production' in namedInputs ? '^production' : '^default');
227
237
  }
228
- inputs.push({ externalDependencies: ['typescript'] });
238
+ inputs.push({ externalDependencies });
229
239
  return inputs;
230
240
  }
231
241
  function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot) {
@@ -238,19 +248,24 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
238
248
  if (config.options.outFile) {
239
249
  const outFileName = (0, node_path_1.basename)(config.options.outFile, '.js');
240
250
  const outFileDir = (0, node_path_1.dirname)(config.options.outFile);
241
- outputs.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', (0, node_path_1.relative)(workspaceRoot, config.options.outFile)));
251
+ outputs.add(pathToInputOrOutput(config.options.outFile, workspaceRoot, projectRoot));
242
252
  // outFile is not be used with .cjs, .mjs, .jsx, so the list is simpler
243
253
  const outDir = (0, node_path_1.relative)(workspaceRoot, outFileDir);
244
- outputs.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', outDir, `${outFileName}.js.map`));
245
- outputs.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', outDir, `${outFileName}.d.ts`));
246
- outputs.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', outDir, `${outFileName}.d.ts.map`));
254
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.js.map`), workspaceRoot, projectRoot));
255
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.d.ts`), workspaceRoot, projectRoot));
256
+ outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.d.ts.map`), workspaceRoot, projectRoot));
247
257
  // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
248
258
  outputs.add(tsConfig.options.tsBuildInfoFile
249
259
  ? pathToInputOrOutput(tsConfig.options.tsBuildInfoFile, workspaceRoot, projectRoot)
250
- : (0, devkit_1.joinPathFragments)('{workspaceRoot}', outDir, `${outFileName}.tsbuildinfo`));
260
+ : pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.tsbuildinfo`), workspaceRoot, projectRoot));
251
261
  }
252
262
  else if (config.options.outDir) {
253
- outputs.add((0, devkit_1.joinPathFragments)('{workspaceRoot}', (0, node_path_1.relative)(workspaceRoot, config.options.outDir)));
263
+ outputs.add(pathToInputOrOutput(config.options.outDir, workspaceRoot, projectRoot));
264
+ if (config.options.tsBuildInfoFile &&
265
+ !(0, node_path_1.normalize)(config.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(config.options.outDir)}${node_path_1.sep}`)) {
266
+ // https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
267
+ outputs.add(pathToInputOrOutput(config.options.tsBuildInfoFile, workspaceRoot, projectRoot));
268
+ }
254
269
  }
255
270
  else if (config.fileNames.length) {
256
271
  // tsc produce files in place when no outDir or outFile is set
@@ -284,16 +299,26 @@ function pathToInputOrOutput(path, workspaceRoot, projectRoot) {
284
299
  }
285
300
  function getExtendedConfigFiles(tsConfigPath, tsConfig) {
286
301
  const extendedConfigFiles = new Set();
302
+ const extendedExternalPackages = new Set();
287
303
  let currentConfigPath = tsConfigPath;
288
304
  let currentConfig = tsConfig;
289
305
  while (currentConfig.raw?.extends) {
290
- const extendedConfigPath = (0, node_path_1.join)((0, node_path_1.dirname)(currentConfigPath), currentConfig.raw.extends);
291
- extendedConfigFiles.add(extendedConfigPath);
292
- const extendedConfig = readCachedTsConfig(extendedConfigPath);
293
- currentConfigPath = extendedConfigPath;
294
- currentConfig = extendedConfig;
306
+ const extendedConfigPath = resolveExtendedTsConfigPath(currentConfig.raw.extends, (0, node_path_1.dirname)(currentConfigPath));
307
+ if (!extendedConfigPath) {
308
+ break;
309
+ }
310
+ if (extendedConfigPath.externalPackage) {
311
+ extendedExternalPackages.add(extendedConfigPath.externalPackage);
312
+ break;
313
+ }
314
+ extendedConfigFiles.add(extendedConfigPath.filePath);
315
+ currentConfig = readCachedTsConfig(extendedConfigPath.filePath);
316
+ currentConfigPath = extendedConfigPath.filePath;
295
317
  }
296
- return Array.from(extendedConfigFiles);
318
+ return {
319
+ files: Array.from(extendedConfigFiles),
320
+ packages: Array.from(extendedExternalPackages),
321
+ };
297
322
  }
298
323
  function resolveInternalProjectReferences(tsConfig, workspaceRoot, projectRoot, projectReferences = {}) {
299
324
  if (!tsConfig.projectReferences?.length) {
@@ -422,3 +447,21 @@ function normalizePluginOptions(pluginOptions = {}) {
422
447
  build,
423
448
  };
424
449
  }
450
+ function resolveExtendedTsConfigPath(tsConfigPath, directory) {
451
+ try {
452
+ const resolvedPath = require.resolve(tsConfigPath, {
453
+ paths: directory ? [directory] : undefined,
454
+ });
455
+ if (tsConfigPath.startsWith('.')) {
456
+ return { filePath: resolvedPath };
457
+ }
458
+ // parse the package from the tsconfig path
459
+ const packageName = tsConfigPath.startsWith('@')
460
+ ? tsConfigPath.split('/').slice(0, 2).join('/')
461
+ : tsConfigPath.split('/')[0];
462
+ return { filePath: resolvedPath, externalPackage: packageName };
463
+ }
464
+ catch {
465
+ return null;
466
+ }
467
+ }
@@ -18,14 +18,16 @@ export interface UpdatePackageJsonOption {
18
18
  updateBuildableProjectDepsInPackageJson?: boolean;
19
19
  buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
20
20
  generateLockfile?: boolean;
21
+ packageJsonPath?: string;
21
22
  }
22
23
  export declare function updatePackageJson(options: UpdatePackageJsonOption, context: ExecutorContext, target: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], fileMap?: ProjectFileMap): void;
23
24
  interface Exports {
24
25
  '.': string;
25
26
  [name: string]: string;
26
27
  }
27
- export declare function getExports(options: Pick<UpdatePackageJsonOption, 'main' | 'rootDir' | 'projectRoot' | 'outputFileName' | 'additionalEntryPoints'> & {
28
+ export declare function getExports(options: Pick<UpdatePackageJsonOption, 'main' | 'rootDir' | 'projectRoot' | 'outputFileName' | 'additionalEntryPoints' | 'outputPath' | 'packageJsonPath'> & {
28
29
  fileExt: string;
29
30
  }): Exports;
30
31
  export declare function getUpdatedPackageJsonContent(packageJson: PackageJson, options: UpdatePackageJsonOption): PackageJson;
32
+ export declare function getOutputDir(options: Pick<UpdatePackageJsonOption, 'main' | 'rootDir' | 'projectRoot' | 'outputFileName' | 'outputPath' | 'packageJsonPath'>): string;
31
33
  export {};
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updatePackageJson = updatePackageJson;
4
4
  exports.getExports = getExports;
5
5
  exports.getUpdatedPackageJsonContent = getUpdatedPackageJsonContent;
6
+ exports.getOutputDir = getOutputDir;
6
7
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
7
8
  const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
8
9
  // eslint-disable-next-line @typescript-eslint/no-restricted-imports
@@ -111,14 +112,12 @@ function addMissingDependencies(packageJson, { projectName, targetName, configur
111
112
  });
112
113
  }
113
114
  function getExports(options) {
115
+ const outputDir = getOutputDir(options);
114
116
  const mainFile = options.outputFileName
115
117
  ? options.outputFileName.replace(/\.[tj]s$/, '')
116
118
  : (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
117
- const relativeMainFileDir = options.outputFileName
118
- ? './'
119
- : (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.rootDir ?? options.projectRoot);
120
119
  const exports = {
121
- '.': relativeMainFileDir + mainFile + options.fileExt,
120
+ '.': outputDir + mainFile + options.fileExt,
122
121
  };
123
122
  if (options.additionalEntryPoints) {
124
123
  const jsRegex = /\.[jt]sx?$/;
@@ -148,6 +147,21 @@ function getUpdatedPackageJsonContent(packageJson, options) {
148
147
  typeof packageJson.exports === 'string' ? {} : { ...packageJson.exports };
149
148
  packageJson.exports['./package.json'] ??= './package.json';
150
149
  }
150
+ if (!options.skipTypings) {
151
+ const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
152
+ const outputDir = getOutputDir(options);
153
+ const typingsFile = `${outputDir}${mainFile}.d.ts`;
154
+ packageJson.types ??= typingsFile;
155
+ if (options.generateExportsField) {
156
+ if (!packageJson.exports['.']) {
157
+ packageJson.exports['.'] = { types: typingsFile };
158
+ }
159
+ else if (typeof packageJson.exports['.'] === 'object' &&
160
+ !packageJson.exports['.'].types) {
161
+ packageJson.exports['.'].types = typingsFile;
162
+ }
163
+ }
164
+ }
151
165
  if (hasEsmFormat) {
152
166
  const esmExports = getExports({
153
167
  ...options,
@@ -160,9 +174,14 @@ function getUpdatedPackageJsonContent(packageJson, options) {
160
174
  }
161
175
  if (options.generateExportsField) {
162
176
  for (const [exportEntry, filePath] of Object.entries(esmExports)) {
163
- packageJson.exports[exportEntry] ??= hasCjsFormat
164
- ? { import: filePath }
165
- : filePath;
177
+ if (!packageJson.exports[exportEntry]) {
178
+ packageJson.exports[exportEntry] ??= hasCjsFormat
179
+ ? { import: filePath }
180
+ : filePath;
181
+ }
182
+ else if (typeof packageJson.exports[exportEntry] === 'object') {
183
+ packageJson.exports[exportEntry].import ??= filePath;
184
+ }
166
185
  }
167
186
  }
168
187
  }
@@ -180,20 +199,27 @@ function getUpdatedPackageJsonContent(packageJson, options) {
180
199
  }
181
200
  if (options.generateExportsField) {
182
201
  for (const [exportEntry, filePath] of Object.entries(cjsExports)) {
183
- if (hasEsmFormat) {
184
- packageJson.exports[exportEntry]['default'] ??= filePath;
202
+ if (!packageJson.exports[exportEntry]) {
203
+ packageJson.exports[exportEntry] ??= hasEsmFormat
204
+ ? { default: filePath }
205
+ : filePath;
185
206
  }
186
- else {
187
- packageJson.exports[exportEntry] ??= filePath;
207
+ else if (typeof packageJson.exports[exportEntry] === 'object') {
208
+ packageJson.exports[exportEntry].default ??= filePath;
188
209
  }
189
210
  }
190
211
  }
191
212
  }
192
- if (!options.skipTypings) {
193
- const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
194
- const relativeMainFileDir = (0, get_main_file_dir_1.getRelativeDirectoryToProjectRoot)(options.main, options.projectRoot);
195
- const typingsFile = `${relativeMainFileDir}${mainFile}.d.ts`;
196
- packageJson.types ??= typingsFile;
197
- }
198
213
  return packageJson;
199
214
  }
215
+ function getOutputDir(options) {
216
+ const packageJsonDir = options.packageJsonPath
217
+ ? (0, path_1.dirname)(options.packageJsonPath)
218
+ : options.outputPath;
219
+ const relativeOutputPath = (0, path_1.relative)(packageJsonDir, options.outputPath);
220
+ const relativeMainDir = options.outputFileName
221
+ ? ''
222
+ : (0, path_1.relative)(options.rootDir ?? options.projectRoot, (0, path_1.dirname)(options.main));
223
+ const outputDir = (0, path_1.join)(relativeOutputPath, relativeMainDir);
224
+ return outputDir === '.' ? `./` : `./${outputDir}/`;
225
+ }
@@ -1,4 +1,5 @@
1
- import { type Tree } from '@nx/devkit';
1
+ import { type GeneratorCallback, type Tree } from '@nx/devkit';
2
2
  export type ProjectPackageManagerWorkspaceState = 'included' | 'excluded' | 'no-workspaces';
3
3
  export declare function getProjectPackageManagerWorkspaceState(tree: Tree, projectRoot: string): ProjectPackageManagerWorkspaceState;
4
4
  export declare function isUsingPackageManagerWorkspaces(tree: Tree): boolean;
5
+ export declare function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState, workspaceRoot: string): GeneratorCallback;
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProjectPackageManagerWorkspaceState = getProjectPackageManagerWorkspaceState;
4
4
  exports.isUsingPackageManagerWorkspaces = isUsingPackageManagerWorkspaces;
5
+ exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageManagerWorkspaceStateWarningTask;
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  const minimatch_1 = require("minimatch");
7
8
  const posix_1 = require("node:path/posix");
8
9
  const package_json_1 = require("nx/src/plugins/package-json");
10
+ const semver_1 = require("semver");
9
11
  function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
10
12
  if (!isUsingPackageManagerWorkspaces(tree)) {
11
13
  return 'no-workspaces';
@@ -17,3 +19,45 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
17
19
  function isUsingPackageManagerWorkspaces(tree) {
18
20
  return (0, devkit_1.isWorkspacesEnabled)((0, devkit_1.detectPackageManager)(tree.root), tree.root);
19
21
  }
22
+ function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState, workspaceRoot) {
23
+ return () => {
24
+ if (projectPackageManagerWorkspaceState !== 'excluded') {
25
+ return;
26
+ }
27
+ const packageManager = (0, devkit_1.detectPackageManager)(workspaceRoot);
28
+ let adviseMessage = 'updating the "workspaces" option in the workspace root "package.json" file with the project root or pattern that includes it';
29
+ let packageManagerWorkspaceSetupDocs;
30
+ if (packageManager === 'pnpm') {
31
+ adviseMessage =
32
+ 'updating the "pnpm-workspace.yaml" file with the project root or pattern that includes it';
33
+ packageManagerWorkspaceSetupDocs =
34
+ 'https://pnpm.io/workspaces and https://pnpm.io/pnpm-workspace_yaml';
35
+ }
36
+ else if (packageManager === 'yarn') {
37
+ const yarnVersion = (0, devkit_1.getPackageManagerVersion)(packageManager, workspaceRoot);
38
+ if ((0, semver_1.lt)(yarnVersion, '2.0.0')) {
39
+ packageManagerWorkspaceSetupDocs =
40
+ 'https://classic.yarnpkg.com/lang/en/docs/workspaces/';
41
+ }
42
+ else {
43
+ packageManagerWorkspaceSetupDocs =
44
+ 'https://yarnpkg.com/features/workspaces';
45
+ }
46
+ }
47
+ else if (packageManager === 'npm') {
48
+ packageManagerWorkspaceSetupDocs =
49
+ 'https://docs.npmjs.com/cli/v10/using-npm/workspaces';
50
+ }
51
+ else if (packageManager === 'bun') {
52
+ packageManagerWorkspaceSetupDocs =
53
+ 'https://bun.sh/docs/install/workspaces';
54
+ }
55
+ devkit_1.output.warn({
56
+ title: `The project is not included in the package manager workspaces configuration`,
57
+ bodyLines: [
58
+ `Please add the project to the package manager workspaces configuration by ${adviseMessage}.`,
59
+ `Read more about the ${packageManager} workspaces feature and how to set it up at ${packageManagerWorkspaceSetupDocs}.`,
60
+ ],
61
+ });
62
+ };
63
+ }
@@ -1,3 +1,3 @@
1
1
  import type { NxJsonConfiguration } from '@nx/devkit';
2
- export declare function ensureProjectIsIncludedInPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string): void;
2
+ export declare function ensureProjectIsIncludedInPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string, buildTargetName?: string): void;
3
3
  export declare function ensureProjectIsExcludedFromPluginRegistrations(nxJson: NxJsonConfiguration, projectRoot: string): void;
@@ -3,11 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureProjectIsIncludedInPluginRegistrations = ensureProjectIsIncludedInPluginRegistrations;
4
4
  exports.ensureProjectIsExcludedFromPluginRegistrations = ensureProjectIsExcludedFromPluginRegistrations;
5
5
  const devkit_internals_1 = require("nx/src/devkit-internals");
6
- function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot) {
7
- if (!nxJson.plugins?.length ||
8
- !nxJson.plugins.some(isTypeScriptPluginRegistration)) {
9
- return;
10
- }
6
+ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, buildTargetName = 'build') {
7
+ nxJson.plugins ??= [];
11
8
  let isIncluded = false;
12
9
  let index = 0;
13
10
  for (const registration of nxJson.plugins) {
@@ -17,7 +14,7 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot) {
17
14
  }
18
15
  if (typeof registration === 'string') {
19
16
  // if it's a string all projects are included but the are no user-specified options
20
- // and the `build` task is not inferred by default, so we need to exclude it
17
+ // and the build task is not inferred by default, so we need to exclude it
21
18
  nxJson.plugins[index] = {
22
19
  plugin: '@nx/js/typescript',
23
20
  exclude: [`${projectRoot}/*`],
@@ -28,42 +25,54 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot) {
28
25
  const matchingConfigFiles = (0, devkit_internals_1.findMatchingConfigFiles)([`${projectRoot}/tsconfig.json`], '**/tsconfig.json', registration.include, registration.exclude);
29
26
  if (matchingConfigFiles.length) {
30
27
  // it's included by the plugin registration, check if the user-specified options would result
31
- // in a `build` task being inferred, if not, we need to exclude it
32
- if (registration.options?.typecheck && registration.options?.build) {
33
- // it has the desired options, do nothing
28
+ // in the appropriate build task being inferred, if not, we need to exclude it
29
+ if (registration.options?.typecheck !== false &&
30
+ matchesBuildTarget(registration.options?.build, buildTargetName)) {
31
+ // it has the desired options, do nothing, but continue processing
32
+ // other registrations to exclude as needed
34
33
  isIncluded = true;
35
34
  }
36
35
  else {
37
- // it would not have the `build` task inferred, so we need to exclude it
36
+ // it would not have the typecheck or build task inferred, so we need to exclude it
38
37
  registration.exclude ??= [];
39
38
  registration.exclude.push(`${projectRoot}/*`);
40
39
  }
41
40
  }
42
- else if (registration.options?.typecheck &&
43
- registration.options?.build &&
44
- !registration.exclude?.length) {
45
- // negative pattern are not supported by the `exclude` option so we
46
- // can't update it to not exclude the project, so we only update the
47
- // plugin registration if there's no `exclude` option, in which case
48
- // the plugin registration should have an `include` options that doesn't
49
- // include the project
50
- isIncluded = true;
51
- registration.include ??= [];
52
- registration.include.push(`${projectRoot}/*`);
41
+ else if (!isIncluded &&
42
+ registration.options?.typecheck !== false &&
43
+ matchesBuildTarget(registration.options?.build, buildTargetName)) {
44
+ if (!registration.exclude?.length) {
45
+ // negative pattern are not supported by the `exclude` option so we
46
+ // can't update it to not exclude the project, so we only update the
47
+ // plugin registration if there's no `exclude` option, in which case
48
+ // the plugin registration should have an `include` options that doesn't
49
+ // include the project
50
+ isIncluded = true;
51
+ registration.include ??= [];
52
+ registration.include.push(`${projectRoot}/*`);
53
+ }
54
+ else if (registration.exclude?.includes(`${projectRoot}/*`)) {
55
+ isIncluded = true;
56
+ registration.exclude = registration.exclude.filter((e) => e !== `${projectRoot}/*`);
57
+ if (!registration.exclude.length) {
58
+ // if there's no `exclude` option left, we can remove the exclude option
59
+ delete registration.exclude;
60
+ }
61
+ }
53
62
  }
54
63
  }
55
64
  index++;
56
65
  }
57
66
  if (!isIncluded) {
58
- // the project is not included by any plugin registration with an inferred `build` task,
59
- // so we create a new plugin registration for it
67
+ // the project is not included by any plugin registration with an inferred build task
68
+ // with the given name, so we create a new plugin registration for it
60
69
  nxJson.plugins.push({
61
70
  plugin: '@nx/js/typescript',
62
71
  include: [`${projectRoot}/*`],
63
72
  options: {
64
73
  typecheck: { targetName: 'typecheck' },
65
74
  build: {
66
- targetName: 'build',
75
+ targetName: buildTargetName,
67
76
  configName: 'tsconfig.lib.json',
68
77
  },
69
78
  },
@@ -106,3 +115,13 @@ function isTypeScriptPluginRegistration(plugin) {
106
115
  return ((typeof plugin === 'string' && plugin === '@nx/js/typescript') ||
107
116
  (typeof plugin !== 'string' && plugin.plugin === '@nx/js/typescript'));
108
117
  }
118
+ function matchesBuildTarget(buildOptions, buildTargetName) {
119
+ if (buildOptions === undefined || buildOptions === false) {
120
+ return false;
121
+ }
122
+ if (buildOptions === true && buildTargetName === 'build') {
123
+ return true;
124
+ }
125
+ return (typeof buildOptions === 'object' &&
126
+ buildOptions.targetName === buildTargetName);
127
+ }
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
- import * as ts from 'typescript';
3
- export declare function readTsConfig(tsConfigPath: string): ts.ParsedCommandLine;
2
+ import type * as ts from 'typescript';
3
+ export declare function readTsConfig(tsConfigPath: string, sys?: ts.System): ts.ParsedCommandLine;
4
4
  export declare function getRootTsConfigPathInTree(tree: Tree): string | null;
5
5
  export declare function getRelativePathToRootTsConfig(tree: Tree, targetPath: string): string;
6
6
  export declare function getRootTsConfigPath(): string | null;
@@ -12,12 +12,13 @@ const fs_1 = require("fs");
12
12
  const path_1 = require("path");
13
13
  const ensure_typescript_1 = require("./ensure-typescript");
14
14
  let tsModule;
15
- function readTsConfig(tsConfigPath) {
15
+ function readTsConfig(tsConfigPath, sys) {
16
16
  if (!tsModule) {
17
17
  tsModule = require('typescript');
18
18
  }
19
- const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
20
- return tsModule.parseJsonConfigFileContent(readResult.config, tsModule.sys, (0, path_1.dirname)(tsConfigPath));
19
+ sys ??= tsModule.sys;
20
+ const readResult = tsModule.readConfigFile(tsConfigPath, sys.readFile);
21
+ return tsModule.parseJsonConfigFileContent(readResult.config, sys, (0, path_1.dirname)(tsConfigPath));
21
22
  }
22
23
  function getRootTsConfigPathInTree(tree) {
23
24
  for (const path of ['tsconfig.base.json', 'tsconfig.json']) {
@@ -1,3 +0,0 @@
1
- import { type GeneratorCallback } from '@nx/devkit';
2
- import type { ProjectPackageManagerWorkspaceState } from '../../../utils/package-manager-workspaces';
3
- export declare function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState: ProjectPackageManagerWorkspaceState, workspaceRoot: string): GeneratorCallback;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageManagerWorkspaceStateWarningTask;
4
- const devkit_1 = require("@nx/devkit");
5
- const semver_1 = require("semver");
6
- function getProjectPackageManagerWorkspaceStateWarningTask(projectPackageManagerWorkspaceState, workspaceRoot) {
7
- return () => {
8
- const packageManager = (0, devkit_1.detectPackageManager)(workspaceRoot);
9
- let packageManagerWorkspaceSetupDocs;
10
- if (packageManager === 'pnpm') {
11
- packageManagerWorkspaceSetupDocs =
12
- 'https://pnpm.io/workspaces and https://pnpm.io/pnpm-workspace_yaml';
13
- }
14
- else if (packageManager === 'yarn') {
15
- const yarnVersion = (0, devkit_1.getPackageManagerVersion)(packageManager, workspaceRoot);
16
- if ((0, semver_1.lt)(yarnVersion, '2.0.0')) {
17
- packageManagerWorkspaceSetupDocs =
18
- 'https://classic.yarnpkg.com/lang/en/docs/workspaces/';
19
- }
20
- else {
21
- packageManagerWorkspaceSetupDocs =
22
- 'https://yarnpkg.com/features/workspaces';
23
- }
24
- }
25
- else if (packageManager === 'npm') {
26
- packageManagerWorkspaceSetupDocs =
27
- 'https://docs.npmjs.com/cli/v10/using-npm/workspaces';
28
- }
29
- else if (packageManager === 'bun') {
30
- packageManagerWorkspaceSetupDocs =
31
- 'https://bun.sh/docs/install/workspaces';
32
- }
33
- if (projectPackageManagerWorkspaceState === 'no-workspaces') {
34
- devkit_1.output.warn({
35
- title: `The package manager workspaces feature is not enabled in the workspace`,
36
- bodyLines: [
37
- 'You must enable the package manager workspaces feature to use the "@nx/js/typescript" plugin.',
38
- `Read more about the ${packageManager} workspaces feature and how to set it up at ${packageManagerWorkspaceSetupDocs}.`,
39
- ],
40
- });
41
- }
42
- else if (projectPackageManagerWorkspaceState === 'excluded') {
43
- devkit_1.output.warn({
44
- title: `The project is not included in the package manager workspaces configuration`,
45
- bodyLines: [
46
- 'Please add it to the workspace configuration to use the "@nx/js/typescript" plugin.',
47
- `Read more about the ${packageManager} workspaces feature and how to set it up at ${packageManagerWorkspaceSetupDocs}.`,
48
- ],
49
- });
50
- }
51
- };
52
- }