@nx/js 17.0.2 → 17.0.4

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 (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/babel.js +37 -16
  4. package/executors.json +1 -1
  5. package/migrations.json +62 -0
  6. package/package.json +10 -9
  7. package/src/executors/node/node.impl.js +1 -1
  8. package/src/executors/node/schema.json +1 -1
  9. package/src/executors/release-publish/release-publish.impl.js +135 -32
  10. package/src/executors/release-publish/schema.d.ts +2 -0
  11. package/src/executors/release-publish/schema.json +1 -1
  12. package/src/executors/swc/schema.json +1 -1
  13. package/src/executors/swc/swc.impl.js +6 -7
  14. package/src/executors/verdaccio/schema.json +1 -1
  15. package/src/executors/verdaccio/verdaccio.impl.js +1 -1
  16. package/src/generators/convert-to-swc/schema.json +1 -1
  17. package/src/generators/init/init.js +3 -2
  18. package/src/generators/init/schema.d.ts +1 -0
  19. package/src/generators/init/schema.json +7 -1
  20. package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +5 -1
  21. package/src/generators/library/files/{lib → readme}/README.md +1 -1
  22. package/src/generators/library/library.d.ts +1 -1
  23. package/src/generators/library/library.js +173 -29
  24. package/src/generators/library/schema.json +8 -2
  25. package/src/generators/release-version/release-version.d.ts +2 -1
  26. package/src/generators/release-version/release-version.js +341 -86
  27. package/src/generators/release-version/schema.json +26 -4
  28. package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +7 -1
  29. package/src/generators/release-version/utils/resolve-local-package-dependencies.js +14 -4
  30. package/src/generators/release-version/utils/resolve-version-spec.js +4 -1
  31. package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
  32. package/src/generators/release-version/utils/update-lock-file.js +105 -0
  33. package/src/generators/setup-build/generator.js +3 -0
  34. package/src/generators/setup-build/schema.json +1 -1
  35. package/src/generators/setup-verdaccio/schema.json +1 -1
  36. package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +2 -1
  37. package/src/utils/add-local-registry-scripts.js +26 -6
  38. package/src/utils/assets/copy-assets-handler.js +4 -4
  39. package/src/utils/buildable-libs-utils.js +6 -2
  40. package/src/utils/find-npm-dependencies.d.ts +2 -1
  41. package/src/utils/find-npm-dependencies.js +28 -11
  42. package/src/utils/inline.js +6 -4
  43. package/src/utils/npm-config.d.ts +25 -0
  44. package/src/utils/npm-config.js +90 -0
  45. package/src/utils/schema.d.ts +3 -0
  46. package/src/utils/swc/get-swcrc-path.d.ts +4 -1
  47. package/src/utils/swc/get-swcrc-path.js +6 -1
  48. package/src/utils/swc/inline.d.ts +1 -1
  49. package/src/utils/swc/inline.js +1 -2
  50. package/src/utils/typescript/ast-utils.js +2 -3
  51. package/src/utils/typescript/ts-config.js +1 -0
  52. package/src/utils/versions.d.ts +4 -4
  53. package/src/utils/versions.js +4 -4
  54. package/src/utils/minimal-publish-script.d.ts +0 -2
  55. package/src/utils/minimal-publish-script.js +0 -74
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateLockFile = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const child_process_1 = require("child_process");
6
+ const client_1 = require("nx/src/daemon/client/client");
7
+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports
8
+ const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
9
+ const semver_1 = require("semver");
10
+ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
11
+ if (generatorOptions?.skipLockFileUpdate) {
12
+ if (verbose) {
13
+ console.log('\nSkipped lock file update because skipLockFileUpdate was set.');
14
+ }
15
+ return [];
16
+ }
17
+ const packageManager = (0, devkit_1.detectPackageManager)(cwd);
18
+ if (packageManager === 'yarn' &&
19
+ !(0, semver_1.gte)((0, devkit_1.getPackageManagerVersion)(packageManager), '2.0.0')) {
20
+ // yarn classic does not store workspace data in the lock file, so we don't need to update it
21
+ if (verbose) {
22
+ console.log('\nSkipped lock file update because it is not necessary for Yarn Classic.');
23
+ }
24
+ return [];
25
+ }
26
+ const workspacesEnabled = (0, devkit_1.isWorkspacesEnabled)(packageManager, cwd);
27
+ if (!workspacesEnabled) {
28
+ if (verbose) {
29
+ console.log(`\nSkipped lock file update because ${packageManager} workspaces are not enabled.`);
30
+ }
31
+ return [];
32
+ }
33
+ const isDaemonEnabled = client_1.daemonClient.enabled();
34
+ if (!dryRun && isDaemonEnabled) {
35
+ // if not in dry-run temporarily stop the daemon, as it will error if the lock file is updated
36
+ await client_1.daemonClient.stop();
37
+ }
38
+ const packageManagerCommands = (0, devkit_1.getPackageManagerCommand)(packageManager);
39
+ let installArgs = generatorOptions?.installArgs || '';
40
+ devkit_1.output.logSingleLine(`Updating ${packageManager} lock file`);
41
+ let env = {};
42
+ if (generatorOptions?.installIgnoreScripts) {
43
+ if (packageManager === 'yarn') {
44
+ env = { YARN_ENABLE_SCRIPTS: 'false' };
45
+ }
46
+ else {
47
+ // npm and pnpm use the same --ignore-scripts option
48
+ installArgs = `${installArgs} --ignore-scripts`.trim();
49
+ }
50
+ }
51
+ const lockFile = (0, lock_file_1.getLockFileName)(packageManager);
52
+ const command = `${packageManagerCommands.updateLockFile} ${installArgs}`.trim();
53
+ if (verbose) {
54
+ if (dryRun) {
55
+ console.log(`Would update ${lockFile} with the following command, but --dry-run was set:`);
56
+ }
57
+ else {
58
+ console.log(`Updating ${lockFile} with the following command:`);
59
+ }
60
+ console.log(command);
61
+ }
62
+ if (dryRun) {
63
+ return [];
64
+ }
65
+ execLockFileUpdate(command, cwd, env);
66
+ if (isDaemonEnabled) {
67
+ try {
68
+ await client_1.daemonClient.startInBackground();
69
+ }
70
+ catch (e) {
71
+ // If the daemon fails to start, we don't want to prevent the user from continuing, so we just log the error and move on
72
+ if (verbose) {
73
+ devkit_1.output.warn({
74
+ title: 'Unable to restart the Nx Daemon. It will be disabled until you run "nx reset"',
75
+ bodyLines: [e.message],
76
+ });
77
+ }
78
+ }
79
+ }
80
+ return [lockFile];
81
+ }
82
+ exports.updateLockFile = updateLockFile;
83
+ function execLockFileUpdate(command, cwd, env = {}) {
84
+ try {
85
+ (0, child_process_1.execSync)(command, {
86
+ cwd,
87
+ env: {
88
+ ...process.env,
89
+ ...env,
90
+ },
91
+ });
92
+ }
93
+ catch (e) {
94
+ devkit_1.output.error({
95
+ title: `Error updating lock file with command '${command}'`,
96
+ bodyLines: [
97
+ `Verify that '${command}' succeeds when run from the workspace root.`,
98
+ `To configure a string of arguments to be passed to this command, set the 'release.version.generatorOptions.installArgs' property in nx.json.`,
99
+ `To ignore install lifecycle scripts, set 'release.version.generatorOptions.installIgnoreScripts' to true in nx.json.`,
100
+ `To disable this step entirely, set 'release.version.skipLockFileUpdate' to true in nx.json.`,
101
+ ],
102
+ });
103
+ throw e;
104
+ }
105
+ }
@@ -5,6 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const add_swc_config_1 = require("../../utils/swc/add-swc-config");
6
6
  const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
7
7
  const versions_1 = require("../../utils/versions");
8
+ const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
8
9
  async function setupBuildGenerator(tree, options) {
9
10
  const tasks = [];
10
11
  const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
@@ -101,6 +102,7 @@ async function setupBuildGenerator(tree, options) {
101
102
  break;
102
103
  }
103
104
  case 'tsc': {
105
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/js:tsc');
104
106
  const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
105
107
  project.targets[buildTarget] = {
106
108
  executor: `@nx/js:tsc`,
@@ -116,6 +118,7 @@ async function setupBuildGenerator(tree, options) {
116
118
  break;
117
119
  }
118
120
  case 'swc': {
121
+ (0, add_build_target_defaults_1.addBuildTargetDefaults)(tree, '@nx/js:swc');
119
122
  const outputPath = (0, devkit_1.joinPathFragments)('dist', project.root);
120
123
  project.targets[buildTarget] = {
121
124
  executor: `@nx/js:swc`,
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "$id": "SetupBuild",
4
4
  "title": "Setup Build",
5
5
  "description": "Sets up build target for a project.",
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "$id": "SetupVerdaccio",
4
4
  "title": "Setup Verdaccio",
5
5
  "description": "Setup Verdaccio local-registry.",
@@ -12,7 +12,8 @@ async function default_1(tree) {
12
12
  if (!projectConfig.targets)
13
13
  continue;
14
14
  for (const target of Object.values(projectConfig.targets)) {
15
- if (target.executor.startsWith('@nx/') &&
15
+ if (target.executor?.startsWith('@nx/') &&
16
+ target.options &&
16
17
  ('buildableProjectDepsInPackageJsonType' in target.options ||
17
18
  'updateBuildableProjectDepsInPackageJson' in target.options)) {
18
19
  delete target.options['buildableProjectDepsInPackageJsonType'];
@@ -9,6 +9,7 @@ const startLocalRegistryScript = (localRegistryTarget) => `
9
9
  */
10
10
  import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
11
11
  import { execFileSync } from 'child_process';
12
+ import { releasePublish, releaseVersion } from 'nx/release';
12
13
 
13
14
  export default async () => {
14
15
  // local registry target to run
@@ -21,12 +22,21 @@ export default async () => {
21
22
  storage,
22
23
  verbose: false,
23
24
  });
24
- const nx = require.resolve('nx');
25
- execFileSync(
26
- nx,
27
- ['run-many', '--targets', 'publish', '--ver', '1.0.0', '--tag', 'e2e'],
28
- { env: process.env, stdio: 'inherit' }
29
- );
25
+
26
+ await releaseVersion({
27
+ specifier: '0.0.0-e2e',
28
+ stageChanges: false,
29
+ gitCommit: false,
30
+ gitTag: false,
31
+ firstRelease: true,
32
+ generatorOptionsOverrides: {
33
+ skipLockFileUpdate: true
34
+ }
35
+ });
36
+ await releasePublish({
37
+ tag: 'e2e',
38
+ firstRelease: true
39
+ });
30
40
  };
31
41
  `;
32
42
  const stopLocalRegistryScript = `
@@ -49,6 +59,16 @@ function addLocalRegistryScripts(tree) {
49
59
  if (!tree.exists(startLocalRegistryPath)) {
50
60
  tree.write(startLocalRegistryPath, startLocalRegistryScript(localRegistryTarget));
51
61
  }
62
+ else {
63
+ const existingStartLocalRegistryScript = tree
64
+ .read(startLocalRegistryPath)
65
+ .toString();
66
+ if (!existingStartLocalRegistryScript.includes('nx/release')) {
67
+ devkit_1.output.warn({
68
+ title: 'Your `start-local-registry.ts` script may be outdated. To ensure that newly generated packages are published appropriately when running end to end tests, update this script to use Nx Release. See https://nx.dev/recipes/nx-release/update-local-registry-setup for details.',
69
+ });
70
+ }
71
+ }
52
72
  if (!tree.exists(stopLocalRegistryPath)) {
53
73
  tree.write(stopLocalRegistryPath, stopLocalRegistryScript);
54
74
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CopyAssetsHandler = exports.defaultFileEventHandler = void 0;
4
- const minimatch = require("minimatch");
4
+ const minimatch_1 = require("minimatch");
5
5
  const path = require("path");
6
6
  const fse = require("fs-extra");
7
7
  const ignore_1 = require("ignore");
@@ -114,8 +114,8 @@ class CopyAssetsHandler {
114
114
  for (const event of events) {
115
115
  const pathFromRoot = path.relative(this.rootDir, event.path);
116
116
  for (const ag of this.assetGlobs) {
117
- if (minimatch(pathFromRoot, ag.pattern) &&
118
- !ag.ignore?.some((ig) => minimatch(pathFromRoot, ig)) &&
117
+ if ((0, minimatch_1.minimatch)(pathFromRoot, ag.pattern) &&
118
+ !ag.ignore?.some((ig) => (0, minimatch_1.minimatch)(pathFromRoot, ig)) &&
119
119
  !this.ignore.ignores(pathFromRoot)) {
120
120
  const relPath = path.relative(ag.input, pathFromRoot);
121
121
  const destPath = relPath.startsWith('..') ? pathFromRoot : relPath;
@@ -134,7 +134,7 @@ class CopyAssetsHandler {
134
134
  }
135
135
  filesToEvent(files, assetGlob) {
136
136
  return files.reduce((acc, src) => {
137
- if (!assetGlob.ignore?.some((ig) => minimatch(src, ig)) &&
137
+ if (!assetGlob.ignore?.some((ig) => (0, minimatch_1.minimatch)(src, ig)) &&
138
138
  !this.ignore.ignores(src)) {
139
139
  const relPath = path.relative(assetGlob.input, src);
140
140
  const dest = relPath.startsWith('..') ? src : relPath;
@@ -84,7 +84,8 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
84
84
  exports.calculateProjectDependencies = calculateProjectDependencies;
85
85
  function collectDependencies(project, projGraph, acc, shallow, areTopLevelDeps = true) {
86
86
  (projGraph.dependencies[project] || []).forEach((dependency) => {
87
- if (!acc.some((dep) => dep.name === dependency.target)) {
87
+ const existingEntry = acc.find((dep) => dep.name === dependency.target);
88
+ if (!existingEntry) {
88
89
  // Temporary skip this. Currently the set of external nodes is built from package.json, not lock file.
89
90
  // As a result, some nodes might be missing. This should not cause any issues, we can just skip them.
90
91
  if (dependency.target.startsWith('npm:') &&
@@ -96,6 +97,9 @@ function collectDependencies(project, projGraph, acc, shallow, areTopLevelDeps =
96
97
  collectDependencies(dependency.target, projGraph, acc, shallow, false);
97
98
  }
98
99
  }
100
+ else if (areTopLevelDeps && !existingEntry.isTopLevel) {
101
+ existingEntry.isTopLevel = true;
102
+ }
99
103
  });
100
104
  return acc;
101
105
  }
@@ -123,7 +127,7 @@ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, proje
123
127
  const depTask = taskGraph.tasks[taskName];
124
128
  const depProjectNode = projectGraph.nodes?.[depTask.target.project];
125
129
  if (depProjectNode?.type !== 'lib') {
126
- return null;
130
+ continue;
127
131
  }
128
132
  let outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)(depTask.target, depTask.overrides, depProjectNode);
129
133
  if (outputs.length === 0) {
@@ -1,8 +1,9 @@
1
- import { type ProjectGraph, type ProjectGraphProjectNode, type ProjectFileMap } from '@nx/devkit';
1
+ import { type ProjectFileMap, type ProjectGraph, type ProjectGraphProjectNode } from '@nx/devkit';
2
2
  /**
3
3
  * Finds all npm dependencies and their expected versions for a given project.
4
4
  */
5
5
  export declare function findNpmDependencies(workspaceRoot: string, sourceProject: ProjectGraphProjectNode, projectGraph: ProjectGraph, projectFileMap: ProjectFileMap, buildTarget: string, options?: {
6
6
  includeTransitiveDependencies?: boolean;
7
7
  ignoredFiles?: string[];
8
+ useLocalPathsForWorkspaceDependencies?: boolean;
8
9
  }): Record<string, string>;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findNpmDependencies = void 0;
4
4
  const path_1 = require("path");
5
5
  const configuration_1 = require("nx/src/config/configuration");
6
- const task_hasher_1 = require("nx/src/hasher/task-hasher");
7
6
  const devkit_1 = require("@nx/devkit");
8
7
  const fileutils_1 = require("nx/src/utils/fileutils");
9
8
  const project_graph_1 = require("nx/src/config/project-graph");
10
9
  const ts_config_1 = require("./typescript/ts-config");
10
+ const task_hasher_1 = require("nx/src/hasher/task-hasher");
11
11
  /**
12
12
  * Finds all npm dependencies and their expected versions for a given project.
13
13
  */
@@ -21,7 +21,7 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
21
21
  if (seen?.has(currentProject.name))
22
22
  return;
23
23
  seen?.add(currentProject.name);
24
- collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, collectedDeps);
24
+ collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, options.useLocalPathsForWorkspaceDependencies, collectedDeps);
25
25
  collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
26
26
  if (options.includeTransitiveDependencies) {
27
27
  const projectDeps = projectGraph.dependencies[currentProject.name];
@@ -38,7 +38,7 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
38
38
  exports.findNpmDependencies = findNpmDependencies;
39
39
  // Keep track of workspace libs we already read package.json for so we don't read from disk again.
40
40
  const seenWorkspaceDeps = {};
41
- function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, ignoredFiles, npmDeps) {
41
+ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, ignoredFiles, useLocalPathsForWorkspaceDependencies, npmDeps) {
42
42
  const rawFiles = projectFileMap[sourceProject.name];
43
43
  if (!rawFiles)
44
44
  return;
@@ -82,12 +82,27 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
82
82
  workspaceDep.data.targets[buildTarget] &&
83
83
  // Make sure package.json exists and has a valid name.
84
84
  packageJson?.name) {
85
- // This is a workspace lib so we can't reliably read in a specific version since it depends on how the workspace is set up.
86
- // ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
87
- npmDeps[packageJson.name] = '*';
85
+ let version;
86
+ if (useLocalPathsForWorkspaceDependencies) {
87
+ // Find the relative `file:...` path and use that as the version value.
88
+ // This is useful for monorepos like Nx where the release will handle setting the correct version in dist.
89
+ const depRoot = (0, path_1.join)(workspaceRoot, workspaceDep.data.root);
90
+ const ownRoot = (0, path_1.join)(workspaceRoot, sourceProject.data.root);
91
+ const relativePath = (0, path_1.relative)(ownRoot, depRoot);
92
+ const filePath = (0, devkit_1.normalizePath)(relativePath); // normalize slashes for windows
93
+ version = `file:${filePath}`;
94
+ }
95
+ else {
96
+ // Otherwise, read the version from the dependencies `package.json` file.
97
+ // This is useful for monorepos that commit release versions.
98
+ // Users can also set version as "*" in source `package.json` files, which will be the value set here.
99
+ // This is useful if they use custom scripts to update them in dist.
100
+ version = packageJson.version ?? '*'; // fallback in case version is missing
101
+ }
102
+ npmDeps[packageJson.name] = version;
88
103
  seenWorkspaceDeps[workspaceDep.name] = {
89
104
  name: packageJson.name,
90
- version: '*',
105
+ version,
91
106
  };
92
107
  }
93
108
  }
@@ -106,8 +121,9 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
106
121
  return;
107
122
  if (target.executor === '@nx/js:tsc' && target.options?.tsConfig) {
108
123
  const tsConfig = (0, ts_config_1.readTsConfig)((0, path_1.join)(workspaceRoot, target.options.tsConfig));
109
- if (tsConfig?.options['importHelpers']) {
110
- npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib']?.data.version;
124
+ if (tsConfig?.options['importHelpers'] &&
125
+ projectGraph.externalNodes['npm:tslib']?.type === 'npm') {
126
+ npmDeps['tslib'] = projectGraph.externalNodes['npm:tslib'].data.version;
111
127
  }
112
128
  }
113
129
  if (target.executor === '@nx/js:swc') {
@@ -117,9 +133,10 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
117
133
  const swcConfig = (0, fileutils_1.fileExists)(swcConfigPath)
118
134
  ? (0, devkit_1.readJsonFile)(swcConfigPath)
119
135
  : {};
120
- if (swcConfig?.jsc?.externalHelpers) {
136
+ if (swcConfig?.jsc?.externalHelpers &&
137
+ projectGraph.externalNodes['npm:@swc/helpers']?.type === 'npm') {
121
138
  npmDeps['@swc/helpers'] =
122
- projectGraph.externalNodes['npm:@swc/helpers']?.data.version;
139
+ projectGraph.externalNodes['npm:@swc/helpers'].data.version;
123
140
  }
124
141
  }
125
142
  }
@@ -161,9 +161,11 @@ function movePackage(from, to) {
161
161
  (0, fs_extra_1.copySync)(from, to, { overwrite: true });
162
162
  }
163
163
  function updateImports(destOutputPath, inlinedDepsDestOutputRecord) {
164
- const importRegex = new RegExp(Object.keys(inlinedDepsDestOutputRecord)
165
- .map((pathAlias) => `["'](${pathAlias})["']`)
166
- .join('|'), 'g');
164
+ const pathAliases = Object.keys(inlinedDepsDestOutputRecord);
165
+ if (pathAliases.length == 0) {
166
+ return;
167
+ }
168
+ const importRegex = new RegExp(pathAliases.map((pathAlias) => `["'](${pathAlias})["']`).join('|'), 'g');
167
169
  recursiveUpdateImport(destOutputPath, importRegex, inlinedDepsDestOutputRecord);
168
170
  }
169
171
  function recursiveUpdateImport(dirPath, importRegex, inlinedDepsDestOutputRecord, rootParentDir) {
@@ -177,7 +179,7 @@ function recursiveUpdateImport(dirPath, importRegex, inlinedDepsDestOutputRecord
177
179
  const updatedContent = fileContent.replace(importRegex, (matched) => {
178
180
  const result = matched.replace(/['"]/g, '');
179
181
  // If a match is the same as the rootParentDir, we're checking its own files so we return the matched as in no changes.
180
- if (result === rootParentDir)
182
+ if (result === rootParentDir || !inlinedDepsDestOutputRecord[result])
181
183
  return matched;
182
184
  const importPath = `"${(0, path_1.relative)(dirPath, inlinedDepsDestOutputRecord[result])}"`;
183
185
  return (0, devkit_1.normalizePath)(importPath);
@@ -0,0 +1,25 @@
1
+ import { PackageJson } from 'nx/src/utils/package-json';
2
+ export declare function parseRegistryOptions(cwd: string, pkg: {
3
+ packageRoot: string;
4
+ packageJson: PackageJson;
5
+ }, options: {
6
+ registry?: string;
7
+ tag?: string;
8
+ }, logWarnFn?: (message: string) => void): Promise<{
9
+ registry: string;
10
+ tag: string;
11
+ registryConfigKey: string;
12
+ }>;
13
+ /**
14
+ * Returns the npm registry that is used for publishing.
15
+ *
16
+ * @param scope the scope of the package for which to determine the registry
17
+ * @param cwd the directory where the npm config should be read from
18
+ */
19
+ export declare function getNpmRegistry(cwd: string, scope?: string): Promise<string>;
20
+ /**
21
+ * Returns the npm tag that is used for publishing.
22
+ *
23
+ * @param cwd the directory where the npm config should be read from
24
+ */
25
+ export declare function getNpmTag(cwd: string): Promise<string>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNpmTag = exports.getNpmRegistry = exports.parseRegistryOptions = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const fs_1 = require("fs");
6
+ const path_1 = require("path");
7
+ async function parseRegistryOptions(cwd, pkg, options, logWarnFn = console.warn) {
8
+ const npmRcPath = (0, path_1.join)(pkg.packageRoot, '.npmrc');
9
+ if ((0, fs_1.existsSync)(npmRcPath)) {
10
+ const relativeNpmRcPath = (0, path_1.relative)(cwd, npmRcPath);
11
+ logWarnFn(`\nIgnoring .npmrc file detected in the package root: ${relativeNpmRcPath}. Nested .npmrc files are not supported by npm. Only the .npmrc file at the root of the workspace will be used. To customize the registry or tag for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
12
+ }
13
+ const scope = pkg.packageJson.name.startsWith('@')
14
+ ? pkg.packageJson.name.split('/')[0]
15
+ : '';
16
+ // If the package is scoped, then the registry argument that will
17
+ // correctly override the registry in the .npmrc file must be scoped.
18
+ const registryConfigKey = scope ? `${scope}:registry` : 'registry';
19
+ const publishConfigRegistry = pkg.packageJson.publishConfig?.[registryConfigKey];
20
+ // Even though it won't override the actual registry that's actually used,
21
+ // the user might think otherwise, so we should still warn if the user has
22
+ // set a 'registry' in 'publishConfig' for a scoped package.
23
+ if (publishConfigRegistry || pkg.packageJson.publishConfig?.registry) {
24
+ const relativePackageJsonPath = (0, path_1.relative)(cwd, (0, path_1.join)(pkg.packageRoot, 'package.json'));
25
+ if (options.registry) {
26
+ logWarnFn(`\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. This will override your registry option set in the project configuration or passed via the --registry argument, which is why configuring the registry with 'publishConfig' is not recommended. For details, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
27
+ }
28
+ else {
29
+ logWarnFn(`\nRegistry detected in the 'publishConfig' of the package manifest: ${relativePackageJsonPath}. Configuring the registry in this way is not recommended because it prevents the registry from being overridden in project configuration or via the --registry argument. To customize the registry for specific packages, see https://nx.dev/recipes/nx-release/configure-custom-registries\n`);
30
+ }
31
+ }
32
+ const registry =
33
+ // `npm publish` will always use the publishConfig registry if it exists, even over the --registry arg
34
+ publishConfigRegistry ||
35
+ options.registry ||
36
+ (await getNpmRegistry(cwd, scope));
37
+ const tag = options.tag || (await getNpmTag(cwd));
38
+ return { registry, tag, registryConfigKey };
39
+ }
40
+ exports.parseRegistryOptions = parseRegistryOptions;
41
+ /**
42
+ * Returns the npm registry that is used for publishing.
43
+ *
44
+ * @param scope the scope of the package for which to determine the registry
45
+ * @param cwd the directory where the npm config should be read from
46
+ */
47
+ async function getNpmRegistry(cwd, scope) {
48
+ let registry;
49
+ if (scope) {
50
+ registry = await getNpmConfigValue(`${scope}:registry`, cwd);
51
+ }
52
+ if (!registry) {
53
+ registry = await getNpmConfigValue('registry', cwd);
54
+ }
55
+ return registry;
56
+ }
57
+ exports.getNpmRegistry = getNpmRegistry;
58
+ /**
59
+ * Returns the npm tag that is used for publishing.
60
+ *
61
+ * @param cwd the directory where the npm config should be read from
62
+ */
63
+ async function getNpmTag(cwd) {
64
+ // npm does not support '@scope:tag' in the npm config, so we only need to check for 'tag'.
65
+ return getNpmConfigValue('tag', cwd);
66
+ }
67
+ exports.getNpmTag = getNpmTag;
68
+ async function getNpmConfigValue(key, cwd) {
69
+ try {
70
+ const result = await execAsync(`npm config get ${key}`, cwd);
71
+ return result === 'undefined' ? undefined : result;
72
+ }
73
+ catch (e) {
74
+ return Promise.resolve(undefined);
75
+ }
76
+ }
77
+ async function execAsync(command, cwd) {
78
+ // Must be non-blocking async to allow spinner to render
79
+ return new Promise((resolve, reject) => {
80
+ (0, child_process_1.exec)(command, { cwd }, (error, stdout, stderr) => {
81
+ if (error) {
82
+ return reject(error);
83
+ }
84
+ if (stderr) {
85
+ return reject(stderr);
86
+ }
87
+ return resolve(stdout.trim());
88
+ });
89
+ });
90
+ }
@@ -14,6 +14,7 @@ export interface LibraryGeneratorSchema {
14
14
  skipFormat?: boolean;
15
15
  tags?: string;
16
16
  skipTsConfig?: boolean;
17
+ skipPackageJson?: boolean;
17
18
  includeBabelRc?: boolean;
18
19
  unitTestRunner?: 'jest' | 'vitest' | 'none';
19
20
  linter?: Linter;
@@ -32,6 +33,7 @@ export interface LibraryGeneratorSchema {
32
33
  minimal?: boolean;
33
34
  rootProject?: boolean;
34
35
  simpleName?: boolean;
36
+ addPlugin?: boolean;
35
37
  }
36
38
 
37
39
  export interface ExecutorOptions {
@@ -81,4 +83,5 @@ export interface NormalizedSwcExecutorOptions
81
83
  swcExclude: string[];
82
84
  skipTypeCheck: boolean;
83
85
  swcCliOptions: SwcCliOptions;
86
+ tmpSwcrcPath: string;
84
87
  }
@@ -1,2 +1,5 @@
1
1
  import { SwcExecutorOptions } from '../schema';
2
- export declare function getSwcrcPath(options: SwcExecutorOptions, contextRoot: string, projectRoot: string): string;
2
+ export declare function getSwcrcPath(options: SwcExecutorOptions, contextRoot: string, projectRoot: string): {
3
+ swcrcPath: string;
4
+ tmpSwcrcPath: string;
5
+ };
@@ -3,8 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSwcrcPath = void 0;
4
4
  const path_1 = require("path");
5
5
  function getSwcrcPath(options, contextRoot, projectRoot) {
6
- return options.swcrc
6
+ const swcrcPath = options.swcrc
7
7
  ? (0, path_1.join)(contextRoot, options.swcrc)
8
8
  : (0, path_1.join)(contextRoot, projectRoot, '.swcrc');
9
+ const tmpSwcrcPath = (0, path_1.join)(contextRoot, projectRoot, 'tmp', '.generated.swcrc');
10
+ return {
11
+ swcrcPath,
12
+ tmpSwcrcPath,
13
+ };
9
14
  }
10
15
  exports.getSwcrcPath = getSwcrcPath;
@@ -1,2 +1,2 @@
1
1
  import type { InlineProjectGraph } from '../inline';
2
- export declare function generateTmpSwcrc(inlineProjectGraph: InlineProjectGraph, swcrcPath: string): string;
2
+ export declare function generateTmpSwcrc(inlineProjectGraph: InlineProjectGraph, swcrcPath: string, tmpSwcrcPath: string): string;
@@ -2,10 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateTmpSwcrc = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- function generateTmpSwcrc(inlineProjectGraph, swcrcPath) {
5
+ function generateTmpSwcrc(inlineProjectGraph, swcrcPath, tmpSwcrcPath) {
6
6
  const swcrc = (0, devkit_1.readJsonFile)(swcrcPath);
7
7
  swcrc['exclude'] = swcrc['exclude'].concat(Object.values(inlineProjectGraph.externals).map((external) => `${external.root}/**/.*.ts$`), 'node_modules/**/*.ts$');
8
- const tmpSwcrcPath = `tmp${swcrcPath}`;
9
8
  (0, devkit_1.writeJsonFile)(tmpSwcrcPath, swcrc);
10
9
  return tmpSwcrcPath;
11
10
  }
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findNodes = exports.findClass = exports.addMethod = exports.addParameterToConstructor = exports.replaceNodeValue = exports.getImport = exports.addGlobal = exports.insertImport = exports.removeChange = exports.replaceChange = exports.insertChange = exports.resolveModuleByImport = void 0;
4
- // TODO(colum): replace when https://github.com/nrwl/nx/pull/15497 is merged
5
- const typescript_1 = require("@nx/workspace/src/utilities/typescript");
6
4
  const ensure_typescript_1 = require("./ensure-typescript");
7
5
  const devkit_1 = require("@nx/devkit");
8
6
  const path_1 = require("path");
7
+ const get_source_nodes_1 = require("./get-source-nodes");
9
8
  const normalizedAppRoot = devkit_1.workspaceRoot.replace(/\\/g, '/');
10
9
  let tsModule;
11
10
  let compilerHost;
@@ -228,7 +227,7 @@ function findClass(source, className, silent = false) {
228
227
  if (!tsModule) {
229
228
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
230
229
  }
231
- const nodes = (0, typescript_1.getSourceNodes)(source);
230
+ const nodes = (0, get_source_nodes_1.getSourceNodes)(source);
232
231
  const clazz = nodes.filter((n) => n.kind === tsModule.SyntaxKind.ClassDeclaration &&
233
232
  n.name.text === className)[0];
234
233
  if (!clazz && !silent) {
@@ -46,6 +46,7 @@ function getRootTsConfigFileName(tree) {
46
46
  exports.getRootTsConfigFileName = getRootTsConfigFileName;
47
47
  function addTsConfigPath(tree, importPath, lookupPaths) {
48
48
  (0, devkit_1.updateJson)(tree, getRootTsConfigPathInTree(tree), (json) => {
49
+ json.compilerOptions ??= {};
49
50
  const c = json.compilerOptions;
50
51
  c.paths ??= {};
51
52
  if (c.paths[importPath]) {
@@ -4,14 +4,14 @@ export declare const prettierVersion = "^2.6.2";
4
4
  export declare const swcCliVersion = "~0.1.62";
5
5
  export declare const swcCoreVersion = "~1.3.85";
6
6
  export declare const swcHelpersVersion = "~0.5.2";
7
- export declare const swcNodeVersion = "~1.6.7";
7
+ export declare const swcNodeVersion = "~1.8.0";
8
8
  export declare const tsLibVersion = "^2.3.0";
9
- export declare const typesNodeVersion = "18.7.1";
9
+ export declare const typesNodeVersion = "18.16.9";
10
10
  export declare const verdaccioVersion = "^5.0.4";
11
- export declare const typescriptVersion = "~5.1.3";
11
+ export declare const typescriptVersion = "~5.4.2";
12
12
  /**
13
13
  * The minimum version is currently determined from the lowest version
14
14
  * that's supported by the lowest Angular supported version, e.g.
15
15
  * `npm view @angular/compiler-cli@14.0.0 peerDependencies.typescript`
16
16
  */
17
- export declare const supportedTypescriptVersions = ">=4.6.2";
17
+ export declare const supportedTypescriptVersions = ">=4.8.2";
@@ -7,15 +7,15 @@ exports.prettierVersion = '^2.6.2';
7
7
  exports.swcCliVersion = '~0.1.62';
8
8
  exports.swcCoreVersion = '~1.3.85';
9
9
  exports.swcHelpersVersion = '~0.5.2';
10
- exports.swcNodeVersion = '~1.6.7';
10
+ exports.swcNodeVersion = '~1.8.0';
11
11
  exports.tsLibVersion = '^2.3.0';
12
- exports.typesNodeVersion = '18.7.1';
12
+ exports.typesNodeVersion = '18.16.9';
13
13
  exports.verdaccioVersion = '^5.0.4';
14
14
  // Typescript
15
- exports.typescriptVersion = '~5.1.3';
15
+ exports.typescriptVersion = '~5.4.2';
16
16
  /**
17
17
  * The minimum version is currently determined from the lowest version
18
18
  * that's supported by the lowest Angular supported version, e.g.
19
19
  * `npm view @angular/compiler-cli@14.0.0 peerDependencies.typescript`
20
20
  */
21
- exports.supportedTypescriptVersions = '>=4.6.2';
21
+ exports.supportedTypescriptVersions = '>=4.8.2';