@nx/js 24.0.0-pr.37405.acdaf31 → 24.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/internal.d.ts +2 -0
  2. package/dist/internal.js +8 -2
  3. package/dist/node.d.ts +1 -0
  4. package/dist/node.js +6 -0
  5. package/dist/ready-signal.d.ts +1 -0
  6. package/dist/ready-signal.js +6 -0
  7. package/dist/src/executors/release-publish/release-publish.impl.js +44 -27
  8. package/dist/src/generators/init/init.js +3 -33
  9. package/dist/src/generators/init/schema.d.ts +0 -1
  10. package/dist/src/generators/library/library.d.ts +1 -1
  11. package/dist/src/generators/library/library.js +5 -18
  12. package/dist/src/generators/library/schema.d.ts +0 -5
  13. package/dist/src/generators/library/schema.json +0 -6
  14. package/dist/src/generators/setup-build/generator.js +0 -5
  15. package/dist/src/plugins/scripts/create-script-nodes.d.ts +24 -0
  16. package/dist/src/plugins/scripts/create-script-nodes.js +149 -0
  17. package/dist/src/plugins/scripts/node-plugin.d.ts +10 -0
  18. package/dist/src/plugins/scripts/node-plugin.js +52 -0
  19. package/dist/src/plugins/scripts/shebang.d.ts +19 -0
  20. package/dist/src/plugins/scripts/shebang.js +67 -0
  21. package/dist/src/plugins/scripts/target-name.d.ts +9 -0
  22. package/dist/src/plugins/scripts/target-name.js +19 -0
  23. package/dist/src/plugins/scripts/tsx-plugin.d.ts +3 -0
  24. package/dist/src/plugins/scripts/tsx-plugin.js +11 -0
  25. package/dist/src/plugins/typescript/build-typechecks.d.ts +8 -0
  26. package/dist/src/plugins/typescript/build-typechecks.js +45 -0
  27. package/dist/src/plugins/typescript/plugin.js +120 -39
  28. package/dist/src/plugins/typescript/typecheck-target.d.ts +58 -0
  29. package/dist/src/plugins/typescript/typecheck-target.js +86 -0
  30. package/dist/src/release/version-actions.js +21 -6
  31. package/dist/src/utils/add-linting-to-project.d.ts +0 -2
  32. package/dist/src/utils/add-linting-to-project.js +0 -3
  33. package/dist/src/utils/npm-config.js +18 -6
  34. package/dist/src/utils/swc/compile-swc.d.ts +2 -0
  35. package/dist/src/utils/swc/compile-swc.js +2 -1
  36. package/dist/src/utils/typescript/add-typescript-plugin.d.ts +22 -0
  37. package/dist/src/utils/typescript/add-typescript-plugin.js +145 -0
  38. package/dist/src/utils/typescript/ts-solution-setup.d.ts +1 -1
  39. package/dist/src/utils/typescript/ts-solution-setup.js +1 -10
  40. package/dist/tsx.d.ts +1 -0
  41. package/dist/tsx.js +6 -0
  42. package/package.json +35 -11
@@ -7,6 +7,7 @@ export { PNPM_INSTALL_SETTINGS_INPUTS, PNPM_MAJOR_RUNTIME_INPUT, pnpmInstallSett
7
7
  export { addPnpmDeployOutputCacheInputs } from './src/utils/pnpm-deploy-output-cache-inputs';
8
8
  export type { MatchedTargetRef } from './src/utils/target-defaults-matching';
9
9
  export { TS_SOLUTION_SETUP_TSCONFIG_INPUT, addProjectToTsSolutionWorkspace, assertNotUsingTsSolutionSetup, findRuntimeTsConfigName, getDefinedCustomConditionName, getProjectSourceRoot, getProjectType, isUsingTsSolutionSetup, shouldConfigureTsSolutionSetup, updateTsconfigFiles, } from './src/utils/typescript/ts-solution-setup';
10
+ export { ensureTypescriptPlugin, registerTypescriptPluginForTypecheck, } from './src/utils/typescript/add-typescript-plugin';
10
11
  export { getTsConfigBaseOptions } from './src/utils/typescript/create-ts-config';
11
12
  export { createTreeParseConfigHost, type TreeParseConfigHost, } from './src/utils/typescript/ts-config';
12
13
  export { ensureTypescript } from './src/utils/typescript/ensure-typescript';
@@ -23,6 +24,7 @@ export { getNpmScope } from './src/utils/package-json/get-npm-scope';
23
24
  export { getProjectPackageManagerWorkspaceState, getProjectPackageManagerWorkspaceStateWarningTask, } from './src/utils/package-manager-workspaces';
24
25
  export { findNpmDependencies } from './src/utils/find-npm-dependencies';
25
26
  export { addBuildAndWatchDepsTargets, isValidPackageJsonBuildConfig, } from './src/plugins/typescript/util';
27
+ export { createTypecheckTarget, selectTypecheckTsConfig, type TypecheckTargetOptions, } from './src/plugins/typescript/typecheck-target';
26
28
  export { normalizeLinterOption, normalizeUnitTestRunnerOption, } from './src/utils/generator-prompts';
27
29
  export { detectLinters } from './src/utils/linter';
28
30
  export { addLintingToProject, type AddLintingToProjectOptions, } from './src/utils/add-linting-to-project';
package/dist/internal.js CHANGED
@@ -5,8 +5,8 @@
5
5
  // internal consumers and may change without semver protection. Consider it
6
6
  // the @nx/js equivalent of `@nx/devkit/internal`.
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.isValidPackageJsonBuildConfig = exports.addBuildAndWatchDepsTargets = exports.findNpmDependencies = exports.getProjectPackageManagerWorkspaceStateWarningTask = exports.getProjectPackageManagerWorkspaceState = exports.getNpmScope = exports.sortPackageJsonFields = exports.CopyAssetsHandler = exports.addSwcRegisterDependencies = exports.addSwcDependencies = exports.acknowledgeSwcBuildScripts = exports.addSwcTestConfig = exports.addSwcConfig = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateProjectDependencies = exports.calculateProjectBuildableDependencies = exports.compileTypeScript = exports.getNeededCompilerOptionOverrides = exports.isTypescriptVersionAtLeast = exports.getTsConfigModuleResolution = exports.getRangeMinimum = exports.ensureTypescript = exports.createTreeParseConfigHost = exports.getTsConfigBaseOptions = exports.updateTsconfigFiles = exports.shouldConfigureTsSolutionSetup = exports.isUsingTsSolutionSetup = exports.getProjectType = exports.getProjectSourceRoot = exports.getDefinedCustomConditionName = exports.findRuntimeTsConfigName = exports.assertNotUsingTsSolutionSetup = exports.addProjectToTsSolutionWorkspace = exports.TS_SOLUTION_SETUP_TSCONFIG_INPUT = exports.addPnpmDeployOutputCacheInputs = exports.shouldIncludePnpmMajorRuntimeInput = exports.pnpmInstallSettingsInputsForInferredTarget = exports.PNPM_MAJOR_RUNTIME_INPUT = exports.PNPM_INSTALL_SETTINGS_INPUTS = exports.isEsmProject = exports.walkTsconfigExtendsChain = exports.findProjectsNpmDependencies = exports.isBuiltinModuleImport = exports.TargetProjectLocator = exports.requireWithTsconfigFallback = exports.registerTsConfigPaths = exports.registerTsProject = exports.loadTsFile = exports.forceRegisterEsmLoader = void 0;
9
- exports.typesNodeVersion = exports.tsLibVersion = exports.swcNodeVersion = exports.swcHelpersVersion = exports.swcCoreVersion = exports.swcCliVersion = exports.prettierVersion = exports.esbuildVersion = exports.nxVersion = exports.releaseTasks = exports.addReleaseConfigForTsSolution = exports.addReleaseConfigForNonTsSolution = exports.addLocalRegistryScripts = exports.stripGlobToBaseDir = exports.getImportPath = exports.createGlobPatternsForDependencies = exports.addLintingToProject = exports.detectLinters = exports.normalizeUnitTestRunnerOption = exports.normalizeLinterOption = void 0;
8
+ exports.findNpmDependencies = exports.getProjectPackageManagerWorkspaceStateWarningTask = exports.getProjectPackageManagerWorkspaceState = exports.getNpmScope = exports.sortPackageJsonFields = exports.CopyAssetsHandler = exports.addSwcRegisterDependencies = exports.addSwcDependencies = exports.acknowledgeSwcBuildScripts = exports.addSwcTestConfig = exports.addSwcConfig = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateProjectDependencies = exports.calculateProjectBuildableDependencies = exports.compileTypeScript = exports.getNeededCompilerOptionOverrides = exports.isTypescriptVersionAtLeast = exports.getTsConfigModuleResolution = exports.getRangeMinimum = exports.ensureTypescript = exports.createTreeParseConfigHost = exports.getTsConfigBaseOptions = exports.registerTypescriptPluginForTypecheck = exports.ensureTypescriptPlugin = exports.updateTsconfigFiles = exports.shouldConfigureTsSolutionSetup = exports.isUsingTsSolutionSetup = exports.getProjectType = exports.getProjectSourceRoot = exports.getDefinedCustomConditionName = exports.findRuntimeTsConfigName = exports.assertNotUsingTsSolutionSetup = exports.addProjectToTsSolutionWorkspace = exports.TS_SOLUTION_SETUP_TSCONFIG_INPUT = exports.addPnpmDeployOutputCacheInputs = exports.shouldIncludePnpmMajorRuntimeInput = exports.pnpmInstallSettingsInputsForInferredTarget = exports.PNPM_MAJOR_RUNTIME_INPUT = exports.PNPM_INSTALL_SETTINGS_INPUTS = exports.isEsmProject = exports.walkTsconfigExtendsChain = exports.findProjectsNpmDependencies = exports.isBuiltinModuleImport = exports.TargetProjectLocator = exports.requireWithTsconfigFallback = exports.registerTsConfigPaths = exports.registerTsProject = exports.loadTsFile = exports.forceRegisterEsmLoader = void 0;
9
+ exports.typesNodeVersion = exports.tsLibVersion = exports.swcNodeVersion = exports.swcHelpersVersion = exports.swcCoreVersion = exports.swcCliVersion = exports.prettierVersion = exports.esbuildVersion = exports.nxVersion = exports.releaseTasks = exports.addReleaseConfigForTsSolution = exports.addReleaseConfigForNonTsSolution = exports.addLocalRegistryScripts = exports.stripGlobToBaseDir = exports.getImportPath = exports.createGlobPatternsForDependencies = exports.addLintingToProject = exports.detectLinters = exports.normalizeUnitTestRunnerOption = exports.normalizeLinterOption = exports.selectTypecheckTsConfig = exports.createTypecheckTarget = exports.isValidPackageJsonBuildConfig = exports.addBuildAndWatchDepsTargets = void 0;
10
10
  // Re-exports of nx-source internals.
11
11
  var internal_1 = require("@nx/devkit/internal");
12
12
  Object.defineProperty(exports, "forceRegisterEsmLoader", { enumerable: true, get: function () { return internal_1.forceRegisterEsmLoader; } });
@@ -46,6 +46,9 @@ Object.defineProperty(exports, "getProjectType", { enumerable: true, get: functi
46
46
  Object.defineProperty(exports, "isUsingTsSolutionSetup", { enumerable: true, get: function () { return ts_solution_setup_1.isUsingTsSolutionSetup; } });
47
47
  Object.defineProperty(exports, "shouldConfigureTsSolutionSetup", { enumerable: true, get: function () { return ts_solution_setup_1.shouldConfigureTsSolutionSetup; } });
48
48
  Object.defineProperty(exports, "updateTsconfigFiles", { enumerable: true, get: function () { return ts_solution_setup_1.updateTsconfigFiles; } });
49
+ var add_typescript_plugin_1 = require("./src/utils/typescript/add-typescript-plugin");
50
+ Object.defineProperty(exports, "ensureTypescriptPlugin", { enumerable: true, get: function () { return add_typescript_plugin_1.ensureTypescriptPlugin; } });
51
+ Object.defineProperty(exports, "registerTypescriptPluginForTypecheck", { enumerable: true, get: function () { return add_typescript_plugin_1.registerTypescriptPluginForTypecheck; } });
49
52
  // TypeScript helpers. resolvePathsBaseUrl, extractTsConfigBase,
50
53
  // tsConfigBaseOptions, addTsLibDependencies, and resolveModuleByImport ship via
51
54
  // the public @nx/js entry. getTsConfigBaseOptions is public too, but is
@@ -94,6 +97,9 @@ Object.defineProperty(exports, "findNpmDependencies", { enumerable: true, get: f
94
97
  var util_1 = require("./src/plugins/typescript/util");
95
98
  Object.defineProperty(exports, "addBuildAndWatchDepsTargets", { enumerable: true, get: function () { return util_1.addBuildAndWatchDepsTargets; } });
96
99
  Object.defineProperty(exports, "isValidPackageJsonBuildConfig", { enumerable: true, get: function () { return util_1.isValidPackageJsonBuildConfig; } });
100
+ var typecheck_target_1 = require("./src/plugins/typescript/typecheck-target");
101
+ Object.defineProperty(exports, "createTypecheckTarget", { enumerable: true, get: function () { return typecheck_target_1.createTypecheckTarget; } });
102
+ Object.defineProperty(exports, "selectTypecheckTsConfig", { enumerable: true, get: function () { return typecheck_target_1.selectTypecheckTsConfig; } });
97
103
  // Generator helpers
98
104
  var generator_prompts_1 = require("./src/utils/generator-prompts");
99
105
  Object.defineProperty(exports, "normalizeLinterOption", { enumerable: true, get: function () { return generator_prompts_1.normalizeLinterOption; } });
package/dist/node.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes, createNodesV2, type NodeScriptsPluginOptions, } from './src/plugins/scripts/node-plugin';
package/dist/node.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodesV2 = exports.createNodes = void 0;
4
+ var node_plugin_1 = require("./src/plugins/scripts/node-plugin");
5
+ Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return node_plugin_1.createNodes; } });
6
+ Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return node_plugin_1.createNodesV2; } });
@@ -0,0 +1 @@
1
+ export { emitReadySignal } from '@nx/devkit';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitReadySignal = void 0;
4
+ // The entry generated servers import to report readiness to Nx
5
+ var devkit_1 = require("@nx/devkit");
6
+ Object.defineProperty(exports, "emitReadySignal", { enumerable: true, get: function () { return devkit_1.emitReadySignal; } });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = runExecutor;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const child_process_1 = require("child_process");
5
+ const internal_1 = require("@nx/devkit/internal");
6
6
  const fs_1 = require("fs");
7
7
  const npm_run_path_1 = require("npm-run-path");
8
8
  const path_1 = require("path");
@@ -58,9 +58,7 @@ async function runExecutor(options, context) {
58
58
  let isNpmInstalled = false;
59
59
  try {
60
60
  isNpmInstalled =
61
- (0, child_process_1.execSync)('npm --version', {
62
- encoding: 'utf-8',
63
- windowsHide: true,
61
+ (0, internal_1.safeExecFileSync)('npm', ['--version'], {
64
62
  stdio: ['ignore', 'pipe', 'ignore'],
65
63
  }).trim() !== '';
66
64
  }
@@ -160,14 +158,38 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
160
158
  // Use bun info when bun is the package manager, otherwise use npm view
161
159
  // (npm view works across npm/pnpm/yarn environments and is the established default)
162
160
  const npmViewDistTagField = `dist-tags[${tag}]`;
163
- const npmViewCommandSegments = pm === 'bun'
164
- ? ['bun info', packageName, `--json --"${registryConfigKey}=${registry}"`]
165
- : [
166
- `npm view ${packageName}@${packageJson.version} name version "${npmViewDistTagField}" --json --"${registryConfigKey}=${registry}"`,
167
- ];
168
- const npmDistTagAddCommandSegments = [
169
- `npm dist-tag add ${packageName}@${packageJson.version} ${tag} --"${registryConfigKey}=${registry}"`,
170
- ];
161
+ const npmViewCommand = pm === 'bun'
162
+ ? {
163
+ command: 'bun',
164
+ args: [
165
+ 'info',
166
+ packageName,
167
+ '--json',
168
+ `--${registryConfigKey}=${registry}`,
169
+ ],
170
+ }
171
+ : {
172
+ command: 'npm',
173
+ args: [
174
+ 'view',
175
+ `${packageName}@${packageJson.version}`,
176
+ 'name',
177
+ 'version',
178
+ npmViewDistTagField,
179
+ '--json',
180
+ `--${registryConfigKey}=${registry}`,
181
+ ],
182
+ };
183
+ const npmDistTagAddCommand = {
184
+ command: 'npm',
185
+ args: [
186
+ 'dist-tag',
187
+ 'add',
188
+ `${packageName}@${packageJson.version}`,
189
+ tag,
190
+ `--${registryConfigKey}=${registry}`,
191
+ ],
192
+ };
171
193
  /**
172
194
  * In a dry-run scenario, it is most likely that all commands are being run with dry-run, therefore
173
195
  * the most up to date/relevant version might not exist on disk for us to read and make the npm view
@@ -179,16 +201,15 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
179
201
  if (!isDryRun && !options.firstRelease) {
180
202
  const currentVersion = packageJson.version;
181
203
  try {
182
- const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
204
+ const result = (0, internal_1.safeExecFileSync)(npmViewCommand.command, npmViewCommand.args, {
183
205
  env: processEnv(true),
184
206
  cwd: context.root,
185
207
  stdio: ['ignore', 'pipe', 'pipe'],
186
- windowsHide: true,
187
208
  });
188
209
  // `npm view`/`bun info` can exit 0 with empty stdout when the package exists in the registry but has
189
210
  // no published versions or dist-tags yet (e.g. GitHub packages). Treat empty output the same as
190
211
  // package not existing yet and continue to the publish step.
191
- const output = result.toString().trim();
212
+ const output = result.trim();
192
213
  let distTagVersion;
193
214
  let versionExists;
194
215
  if (!output) {
@@ -228,11 +249,10 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
228
249
  if (versionExists) {
229
250
  try {
230
251
  if (!isDryRun) {
231
- (0, child_process_1.execSync)(npmDistTagAddCommandSegments.join(' '), {
252
+ (0, internal_1.safeExecFileSync)(npmDistTagAddCommand.command, npmDistTagAddCommand.args, {
232
253
  env: processEnv(true),
233
254
  cwd: context.root,
234
255
  stdio: 'ignore',
235
- windowsHide: true,
236
256
  });
237
257
  console.log(`Added the dist-tag ${tag} to v${currentVersion} for registry ${registry}.\n`);
238
258
  }
@@ -323,25 +343,22 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
323
343
  function runPublish(ctx) {
324
344
  const { pm, options, context, packageRoot, packageJson, registry, registryConfigKey, tag, isDryRun, isNpmInstalled, packageTxt, } = ctx;
325
345
  const pmCommand = (0, devkit_1.getPackageManagerCommand)(pm);
326
- const publishCommandSegments = [
327
- pmCommand.publish(packageRoot, registry, registryConfigKey, tag),
328
- ];
346
+ const { command: publishCommand, args: publishArgs } = pmCommand.publishArgv(packageRoot, registry, registryConfigKey, tag);
329
347
  if (options.otp) {
330
- publishCommandSegments.push(`--otp=${options.otp}`);
348
+ publishArgs.push(`--otp=${options.otp}`);
331
349
  }
332
350
  if (options.access) {
333
- publishCommandSegments.push(`--access=${options.access}`);
351
+ publishArgs.push(`--access=${options.access}`);
334
352
  }
335
353
  if (isDryRun) {
336
- publishCommandSegments.push(`--dry-run`);
354
+ publishArgs.push(`--dry-run`);
337
355
  }
338
356
  try {
339
- const output = (0, child_process_1.execSync)(publishCommandSegments.join(' '), {
357
+ const output = (0, internal_1.safeExecFileSync)(publishCommand, publishArgs, {
340
358
  maxBuffer: LARGE_BUFFER,
341
359
  env: processEnv(true),
342
360
  cwd: context.root,
343
361
  stdio: ['ignore', 'pipe', 'pipe'],
344
- windowsHide: true,
345
362
  });
346
363
  // If in dry-run mode, the version on disk will not represent the version that would be published, so we scrub it from the output to avoid confusion.
347
364
  const dryRunVersionPlaceholder = 'X.X.X-dry-run';
@@ -350,7 +367,7 @@ function runPublish(ctx) {
350
367
  : `Published to ${registry} with tag "${tag}"`;
351
368
  // bun publish does not support outputting JSON, so we need to modify and print the output string directly
352
369
  if (pm === 'bun') {
353
- let outputStr = output.toString();
370
+ let outputStr = output;
354
371
  if (isDryRun) {
355
372
  outputStr = outputStr.replace(new RegExp(`${packageJson.name}@${packageJson.version}`, 'g'), `${packageJson.name}@${dryRunVersionPlaceholder}`);
356
373
  }
@@ -364,7 +381,7 @@ function runPublish(ctx) {
364
381
  * 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.
365
382
  * Additionally, we want to capture and show the lifecycle script outputs as beforeJsonData and afterJsonData and print them accordingly below.
366
383
  */
367
- const { beforeJsonData, jsonData, afterJsonData } = (0, extract_npm_publish_json_data_1.extractNpmPublishJsonData)(output.toString());
384
+ const { beforeJsonData, jsonData, afterJsonData } = (0, extract_npm_publish_json_data_1.extractNpmPublishJsonData)(output);
368
385
  if (!jsonData) {
369
386
  console.error(`The ${pm} publish output data could not be extracted. Please report this issue on https://github.com/nrwl/nx`);
370
387
  return {
@@ -5,8 +5,8 @@ exports.initGeneratorInternal = initGeneratorInternal;
5
5
  const internal_1 = require("@nx/devkit/internal");
6
6
  const devkit_1 = require("@nx/devkit");
7
7
  const path_1 = require("path");
8
- const plugin_1 = require("../../plugins/typescript/plugin");
9
8
  const assert_supported_typescript_version_1 = require("../../utils/assert-supported-typescript-version");
9
+ const add_typescript_plugin_1 = require("../../utils/typescript/add-typescript-plugin");
10
10
  const formatter_setup_1 = require("../../utils/formatter-setup");
11
11
  const nx_formatter_internals_1 = require("../../utils/nx-formatter-internals");
12
12
  const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
@@ -36,39 +36,9 @@ async function initGenerator(tree, schema) {
36
36
  async function initGeneratorInternal(tree, schema) {
37
37
  (0, assert_supported_typescript_version_1.assertSupportedTypescriptVersion)(tree);
38
38
  const tasks = [];
39
- const nxJson = (0, devkit_1.readNxJson)(tree);
40
- schema.addPlugin ??=
41
- process.env.NX_ADD_PLUGINS !== 'false' &&
42
- nxJson.useInferencePlugins !== false;
43
- schema.addTsPlugin ??= schema.addPlugin;
39
+ schema.addTsPlugin ??= true;
44
40
  if (schema.addTsPlugin) {
45
- await (0, internal_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
46
- typecheck: [
47
- { targetName: 'typecheck' },
48
- { targetName: 'tsc:typecheck' },
49
- { targetName: 'tsc-typecheck' },
50
- ],
51
- build: [
52
- {
53
- targetName: 'build',
54
- configName: 'tsconfig.lib.json',
55
- buildDepsName: 'build-deps',
56
- watchDepsName: 'watch-deps',
57
- },
58
- {
59
- targetName: 'tsc:build',
60
- configName: 'tsconfig.lib.json',
61
- buildDepsName: 'tsc:build-deps',
62
- watchDepsName: 'tsc:watch-deps',
63
- },
64
- {
65
- targetName: 'tsc-build',
66
- configName: 'tsconfig.lib.json',
67
- buildDepsName: 'tsc-build-deps',
68
- watchDepsName: 'tsc-watch-deps',
69
- },
70
- ],
71
- }, schema.updatePackageScripts);
41
+ await (0, add_typescript_plugin_1.addTypescriptPlugin)(tree, schema.updatePackageScripts);
72
42
  }
73
43
  if (schema.addTsConfigBase && !(0, ts_config_1.getRootTsConfigFileName)(tree)) {
74
44
  if (schema.addTsPlugin) {
@@ -6,7 +6,6 @@ export interface InitSchema {
6
6
  skipFormat?: boolean;
7
7
  skipPackageJson?: boolean;
8
8
  tsConfigName?: string;
9
- addPlugin?: boolean;
10
9
  updatePackageScripts?: boolean;
11
10
  addTsPlugin?: boolean;
12
11
  platform?: 'web' | 'node';
@@ -2,6 +2,6 @@ import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import type { LibraryGeneratorSchema, NormalizedLibraryGeneratorOptions } from './schema';
3
3
  export declare function libraryGenerator(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
4
4
  export declare function libraryGeneratorInternal(tree: Tree, schema: LibraryGeneratorSchema): Promise<GeneratorCallback>;
5
- export type AddLintOptions = Pick<NormalizedLibraryGeneratorOptions, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'enableTypedLinting' | 'setParserOptionsProject' | 'rootProject' | 'bundler' | 'addPlugin' | 'isUsingTsSolutionConfig'>;
5
+ export type AddLintOptions = Pick<NormalizedLibraryGeneratorOptions, 'name' | 'linter' | 'projectRoot' | 'unitTestRunner' | 'js' | 'enableTypedLinting' | 'rootProject' | 'bundler' | 'isUsingTsSolutionConfig'>;
6
6
  export declare function addLint(tree: Tree, options: AddLintOptions): Promise<GeneratorCallback>;
7
7
  export default libraryGenerator;
@@ -26,7 +26,6 @@ const add_release_config_1 = require("./utils/add-release-config");
26
26
  const defaultOutputDirectory = 'dist';
27
27
  async function libraryGenerator(tree, schema) {
28
28
  return await libraryGeneratorInternal(tree, {
29
- addPlugin: false,
30
29
  useProjectJson: true,
31
30
  ...schema,
32
31
  });
@@ -34,7 +33,7 @@ async function libraryGenerator(tree, schema) {
34
33
  async function libraryGeneratorInternal(tree, schema) {
35
34
  (0, assert_supported_typescript_version_1.assertSupportedTypescriptVersion)(tree);
36
35
  const tasks = [];
37
- const addTsPlugin = (0, ts_solution_setup_1.shouldConfigureTsSolutionSetup)(tree, schema.addPlugin);
36
+ const addTsPlugin = (0, ts_solution_setup_1.shouldConfigureTsSolutionSetup)(tree);
38
37
  tasks.push(await (0, init_1.default)(tree, {
39
38
  ...schema,
40
39
  skipFormat: true,
@@ -72,7 +71,6 @@ async function libraryGeneratorInternal(tree, schema) {
72
71
  includeLib: true,
73
72
  skipFormat: true,
74
73
  testEnvironment: options.testEnvironment,
75
- addPlugin: options.addPlugin,
76
74
  });
77
75
  tasks.push(viteTask);
78
76
  createOrEditViteConfig(tree, {
@@ -111,7 +109,6 @@ async function libraryGeneratorInternal(tree, schema) {
111
109
  compiler: options.compiler === 'swc' ? 'swc' : 'babel',
112
110
  passWithNoTests: options.passWithNoTests,
113
111
  skipPackageJson: options.skipPackageJson,
114
- addPlugin: options.addPlugin,
115
112
  });
116
113
  tasks.push(vitestTask);
117
114
  }
@@ -255,13 +252,12 @@ async function addLint(tree, options) {
255
252
  return (0, add_linting_to_project_1.addLintingToProject)(tree, {
256
253
  linter: options.linter,
257
254
  project: options.name,
258
- addPlugin: options.addPlugin,
259
255
  rootProject: options.rootProject,
260
256
  unitTestRunner: options.unitTestRunner,
261
257
  });
262
258
  }
263
259
  const { lintProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/eslint', versions_1.nxVersion);
264
- const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig, addIgnoresToLintConfig, isTypedLintingEnabled,
260
+ const { addOverrideToLintConfig, lintConfigHasOverride, isEslintConfigSupported, updateOverrideInLintConfig, addIgnoresToLintConfig,
265
261
  // nx-ignore-next-line
266
262
  } = require('@nx/eslint/internal');
267
263
  const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.name);
@@ -273,9 +269,8 @@ async function addLint(tree, options) {
273
269
  (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
274
270
  ],
275
271
  unitTestRunner: options.unitTestRunner,
276
- enableTypedLinting: isTypedLintingEnabled(options),
272
+ enableTypedLinting: options.enableTypedLinting,
277
273
  rootProject: options.rootProject,
278
- addPlugin: options.addPlugin,
279
274
  // Since the build target is inferred now, we need to let the generator know to add @nx/dependency-checks regardless.
280
275
  addPackageJsonDependencyChecks: options.bundler !== 'none',
281
276
  });
@@ -552,13 +547,10 @@ function replaceJestConfig(tree, options) {
552
547
  }
553
548
  async function normalizeOptions(tree, options) {
554
549
  await (0, internal_1.ensureRootProjectName)(options, 'library');
555
- const nxJson = (0, devkit_1.readNxJson)(tree);
556
- options.addPlugin ??=
557
- process.env.NX_ADD_PLUGINS !== 'false' &&
558
- nxJson.useInferencePlugins !== false;
559
550
  options.linter = await (0, generator_prompts_1.normalizeLinterOption)(tree, options.linter);
560
- const hasPlugin = (0, ts_solution_setup_1.isUsingTypeScriptPlugin)(tree);
561
551
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
552
+ // Outside TS solution setups the plugin may be registered for typecheck only.
553
+ const hasPlugin = isUsingTsSolutionConfig && (0, ts_solution_setup_1.isUsingTypeScriptPlugin)(tree);
562
554
  if (isUsingTsSolutionConfig) {
563
555
  options.unitTestRunner ??= (0, internal_1.isInteractive)()
564
556
  ? await (0, internal_1.selectPrompt)({
@@ -704,14 +696,9 @@ function getBuildExecutor(bundler) {
704
696
  switch (bundler) {
705
697
  case 'esbuild':
706
698
  return `@nx/esbuild:esbuild`;
707
- case 'rollup':
708
- return `@nx/rollup:rollup`;
709
699
  case 'swc':
710
700
  case 'tsc':
711
701
  return `@nx/js:${bundler}`;
712
- case 'vite':
713
- return `@nx/vite:build`;
714
- case 'none':
715
702
  default:
716
703
  return undefined;
717
704
  }
@@ -24,17 +24,12 @@ export interface LibraryGeneratorSchema {
24
24
  publishable?: boolean;
25
25
  buildable?: boolean;
26
26
  enableTypedLinting?: boolean;
27
- /**
28
- * @deprecated Use `enableTypedLinting` instead. This option will be removed in Nx v24.
29
- */
30
- setParserOptionsProject?: boolean;
31
27
  config?: 'workspace' | 'project' | 'npm-scripts';
32
28
  compiler?: Compiler;
33
29
  bundler?: Bundler;
34
30
  skipTypeCheck?: boolean;
35
31
  minimal?: boolean;
36
32
  rootProject?: boolean;
37
- addPlugin?: boolean;
38
33
  useProjectJson?: boolean;
39
34
  useTscExecutor?: boolean;
40
35
  /** @internal Only honored by the vitest setup. */
@@ -109,12 +109,6 @@
109
109
  "description": "Whether to enable typed linting. For flat configs, this configures the recommended `parserOptions.projectService` and `tsconfigRootDir`. For legacy `.eslintrc` configs, this configures `parserOptions.project`. We do not enable this by default for lint performance reasons.",
110
110
  "default": false
111
111
  },
112
- "setParserOptionsProject": {
113
- "type": "boolean",
114
- "description": "Deprecated alias for `enableTypedLinting`.",
115
- "default": false,
116
- "x-deprecated": "Use `enableTypedLinting` instead. This option will be removed in Nx v24."
117
- },
118
112
  "config": {
119
113
  "type": "string",
120
114
  "enum": ["workspace", "project", "npm-scripts"],
@@ -72,9 +72,6 @@ async function setupBuildGenerator(tree, options) {
72
72
  }
73
73
  options.tsConfig = tsConfigFile;
74
74
  const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree);
75
- const nxJson = (0, devkit_1.readNxJson)(tree);
76
- const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
77
- nxJson.useInferencePlugins !== false;
78
75
  switch (options.bundler) {
79
76
  case 'vite': {
80
77
  const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
@@ -85,7 +82,6 @@ async function setupBuildGenerator(tree, options) {
85
82
  uiFramework: 'none',
86
83
  includeVitest: false,
87
84
  includeLib: true,
88
- addPlugin,
89
85
  skipFormat: true,
90
86
  });
91
87
  tasks.push(task);
@@ -113,7 +109,6 @@ async function setupBuildGenerator(tree, options) {
113
109
  project: options.project,
114
110
  compiler: 'tsc',
115
111
  format: isTsSolutionSetup ? ['esm'] : ['cjs', 'esm'],
116
- addPlugin,
117
112
  skipFormat: true,
118
113
  skipValidation: true,
119
114
  });
@@ -0,0 +1,24 @@
1
+ import { type CreateNodes, type TargetConfiguration } from '@nx/devkit';
2
+ import { type Shebang } from './shebang';
3
+ export interface ScriptPluginOptions {
4
+ /** Runs claimed scripts in watch mode as continuous targets. */
5
+ watch?: boolean;
6
+ }
7
+ export interface ScriptPluginDefinition<T extends ScriptPluginOptions> {
8
+ /** Prefix of the plugin's cache file. */
9
+ cacheName: string;
10
+ technology: string;
11
+ /** Only files whose shebang the plugin claims become targets. */
12
+ claims(shebang: Shebang): boolean;
13
+ /** `file` is relative to the target's cwd. */
14
+ command(file: string, shebang: Shebang, watch: boolean): string;
15
+ /** Targets not tied to a shebang; claimed scripts win on name clashes. */
16
+ extraTargets?(projectRoot: string, workspaceRoot: string, options: T): Promise<ScriptTargets>;
17
+ }
18
+ export type ScriptTargets = Record<string, TargetConfiguration>;
19
+ export declare function createScriptNodes<T extends ScriptPluginOptions>(definition: ScriptPluginDefinition<T>): CreateNodes<T>;
20
+ /**
21
+ * Quotes a path for a shell command when the shell would split or expand it.
22
+ * Double quotes keep spaces intact in sh and cmd.exe; cmd.exe still expands `%VAR%`.
23
+ */
24
+ export declare function quoteShellArg(arg: string): string;
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createScriptNodes = createScriptNodes;
4
+ exports.quoteShellArg = quoteShellArg;
5
+ const internal_1 = require("@nx/devkit/internal");
6
+ const node_path_1 = require("node:path");
7
+ const shebang_1 = require("./shebang");
8
+ const target_name_1 = require("./target-name");
9
+ const SCRIPT_GLOB = '**/*.{js,cjs,mjs,ts,cts,mts}';
10
+ const PROJECT_MARKERS = ['package.json', 'project.json'];
11
+ function createScriptNodes(definition) {
12
+ return [
13
+ (0, internal_1.combineGlobPatterns)([
14
+ SCRIPT_GLOB,
15
+ ...PROJECT_MARKERS.map((marker) => `**/${marker}`),
16
+ ]),
17
+ async (files, options, context) => {
18
+ const scriptsByRoot = groupScriptsByProjectRoot(files, !!definition.extraTargets);
19
+ const projectRoots = [...scriptsByRoot.keys()];
20
+ if (!projectRoots.length) {
21
+ return [];
22
+ }
23
+ const cache = new internal_1.PluginCache((0, node_path_1.join)(internal_1.workspaceDataDirectory, `${definition.cacheName}-${(0, internal_1.hashObject)(options ?? {})}.hash`));
24
+ try {
25
+ const hashes = await (0, internal_1.calculateHashesForCreateNodes)(projectRoots, options ?? {}, context);
26
+ const results = [];
27
+ for (const [i, projectRoot] of projectRoots.entries()) {
28
+ const { marker, scripts } = scriptsByRoot.get(projectRoot);
29
+ // include/exclude can change which scripts a project gets without
30
+ // changing its contents.
31
+ const key = (0, internal_1.hashObject)([hashes[i], [...scripts].sort()]);
32
+ if (!cache.has(key)) {
33
+ cache.set(key, {
34
+ ...(await definition.extraTargets?.(projectRoot, context.workspaceRoot, options)),
35
+ ...createTargets(definition, context.workspaceRoot, projectRoot, scripts, options?.watch === true),
36
+ });
37
+ }
38
+ const targets = cache.get(key);
39
+ if (Object.keys(targets).length) {
40
+ results.push([
41
+ scripts[0] ?? marker,
42
+ { projects: { [projectRoot]: { root: projectRoot, targets } } },
43
+ ]);
44
+ }
45
+ }
46
+ return results;
47
+ }
48
+ finally {
49
+ cache.writeToDisk();
50
+ }
51
+ },
52
+ ];
53
+ }
54
+ /**
55
+ * Assigns each script to its nearest enclosing project root. Roots without
56
+ * scripts are kept only when `includeAllRoots` is set.
57
+ */
58
+ function groupScriptsByProjectRoot(files, includeAllRoots) {
59
+ const markers = new Map();
60
+ const scripts = [];
61
+ for (const file of files) {
62
+ if (PROJECT_MARKERS.includes((0, node_path_1.basename)(file))) {
63
+ markers.set((0, node_path_1.dirname)(file), file);
64
+ }
65
+ else {
66
+ scripts.push(file);
67
+ }
68
+ }
69
+ const byRoot = new Map();
70
+ if (includeAllRoots) {
71
+ for (const [root, marker] of markers) {
72
+ byRoot.set(root, { marker, scripts: [] });
73
+ }
74
+ }
75
+ for (const script of scripts) {
76
+ let dir = (0, node_path_1.dirname)(script);
77
+ while (!markers.has(dir) && dir !== '.') {
78
+ dir = (0, node_path_1.dirname)(dir);
79
+ }
80
+ if (!markers.has(dir)) {
81
+ continue;
82
+ }
83
+ if (!byRoot.has(dir)) {
84
+ byRoot.set(dir, { marker: markers.get(dir), scripts: [] });
85
+ }
86
+ byRoot.get(dir).scripts.push(script);
87
+ }
88
+ return byRoot;
89
+ }
90
+ function createTargets(definition, workspaceRoot, projectRoot, scripts, watch) {
91
+ const claimed = [];
92
+ for (const script of scripts) {
93
+ const header = (0, shebang_1.readScriptHeader)((0, node_path_1.join)(workspaceRoot, script));
94
+ const shebang = header === null ? null : (0, shebang_1.parseShebang)((0, shebang_1.getShebangLine)(header));
95
+ if (!shebang || !definition.claims(shebang)) {
96
+ continue;
97
+ }
98
+ const { name, warnings } = (0, target_name_1.parseTargetName)(header);
99
+ for (const warning of warnings) {
100
+ (0, internal_1.emitPluginWorkerLog)('warn', `${script}: ${warning}.`);
101
+ }
102
+ claimed.push({
103
+ path: script,
104
+ relativePath: node_path_1.posix.relative(projectRoot, script),
105
+ shebang,
106
+ targetName: name,
107
+ });
108
+ }
109
+ const baseNameCounts = new Map();
110
+ for (const { relativePath } of claimed) {
111
+ const name = withoutExtension((0, node_path_1.basename)(relativePath));
112
+ baseNameCounts.set(name, (baseNameCounts.get(name) ?? 0) + 1);
113
+ }
114
+ const targets = {};
115
+ for (const script of claimed) {
116
+ const baseName = withoutExtension((0, node_path_1.basename)(script.relativePath));
117
+ const name = script.targetName ??
118
+ (baseNameCounts.get(baseName) > 1
119
+ ? withoutExtension(script.relativePath)
120
+ : baseName);
121
+ targets[name] = createTarget(definition, projectRoot, script, watch);
122
+ }
123
+ return targets;
124
+ }
125
+ function createTarget(definition, projectRoot, { path, relativePath, shebang }, watch) {
126
+ return {
127
+ command: definition.command(quoteShellArg(node_path_1.posix.relative(projectRoot, path)), shebang, watch),
128
+ options: { cwd: projectRoot },
129
+ cache: false,
130
+ ...(watch && { continuous: true }),
131
+ metadata: {
132
+ technologies: [definition.technology],
133
+ description: `Runs ${relativePath}`,
134
+ },
135
+ };
136
+ }
137
+ /**
138
+ * Quotes a path for a shell command when the shell would split or expand it.
139
+ * Double quotes keep spaces intact in sh and cmd.exe; cmd.exe still expands `%VAR%`.
140
+ */
141
+ function quoteShellArg(arg) {
142
+ if (/^[\w@%+=:,./-]+$/.test(arg)) {
143
+ return arg;
144
+ }
145
+ return '"' + arg.replace(/(["\\$`])/g, '\\$1') + '"';
146
+ }
147
+ function withoutExtension(path) {
148
+ return path.slice(0, path.length - (0, node_path_1.extname)(path).length);
149
+ }
@@ -0,0 +1,10 @@
1
+ import { type ScriptPluginOptions } from './create-script-nodes';
2
+ export interface NodeScriptsPluginOptions extends ScriptPluginOptions {
3
+ /**
4
+ * `dependsOn` for `bin` targets whose file is build output (not a tracked
5
+ * workspace file). Defaults to `["build"]`.
6
+ */
7
+ binDependsOn?: string[];
8
+ }
9
+ export declare const createNodes: import("@nx/devkit").CreateNodes<NodeScriptsPluginOptions>;
10
+ export declare const createNodesV2: import("@nx/devkit").CreateNodes<NodeScriptsPluginOptions>;