@nx/devkit 18.1.0-beta.1 → 18.1.0-beta.10

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/devkit",
3
- "version": "18.1.0-beta.1",
3
+ "version": "18.1.0-beta.10",
4
4
  "private": false,
5
5
  "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "tslib": "^2.3.0",
36
36
  "semver": "^7.5.3",
37
37
  "yargs-parser": "21.1.1",
38
- "@nrwl/devkit": "18.1.0-beta.1"
38
+ "@nrwl/devkit": "18.1.0-beta.10"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "nx": ">= 16 <= 18"
@@ -289,7 +289,7 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
289
289
  }
290
290
  }
291
291
  if (process.env.NX_DRY_RUN && process.env.NX_DRY_RUN !== 'false') {
292
- throw new Error('NOTE: This generator does not support --dry-run. If you are running this in Nx Console, it should execute fine once you hit the "Run" button.\n');
292
+ throw new Error('NOTE: This generator does not support --dry-run. If you are running this in Nx Console, it should execute fine once you hit the "Generate" button.\n');
293
293
  }
294
294
  const { dir: tempDir } = createTempNpmDirectory?.() ?? {
295
295
  dir: (0, tmp_1.dirSync)().name,
@@ -1,3 +1,2 @@
1
- import type { Tree } from 'nx/src/generators/tree';
2
- import type { CreateNodes } from 'nx/src/utils/nx-plugin';
1
+ import type { Tree, CreateNodes } from 'nx/src/devkit-exports';
3
2
  export declare function replaceProjectConfigurationsWithPlugin<T = unknown>(tree: Tree, rootMappings: Map<string, string>, pluginPath: string, createNodes: CreateNodes<T>, pluginOptions: T): Promise<void>;
@@ -1,3 +1,2 @@
1
- import type { Tree } from 'nx/src/generators/tree';
2
- import type { CreateNodes } from 'nx/src/utils/nx-plugin';
1
+ import type { CreateNodes, Tree } from 'nx/src/devkit-exports';
3
2
  export declare function updatePackageScripts(tree: Tree, createNodesTuple: CreateNodes): Promise<void>;
@@ -29,9 +29,7 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
29
29
  if (!targetCommands.length) {
30
30
  return;
31
31
  }
32
- // exclude package.json scripts from nx
33
- packageJson.nx ??= {};
34
- packageJson.nx.includedScripts ??= [];
32
+ const replacedTargets = new Set();
35
33
  for (const targetCommand of targetCommands) {
36
34
  const { command, target, configuration } = targetCommand;
37
35
  const targetCommandRegex = new RegExp(`(?<=^|&)((?: )*(?:[^&\\r\\n\\s]+ )*)(${command})((?: [^&\\r\\n\\s]+)*(?: )*)(?=$|&)`, 'g');
@@ -42,7 +40,7 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
42
40
  packageJson.scripts[scriptName] = script.replace(targetCommandRegex, configuration
43
41
  ? `$1nx ${target} --configuration=${configuration}$3`
44
42
  : `$1nx ${target}$3`);
45
- excludeScriptFromPackageJson(packageJson, scriptName);
43
+ replacedTargets.add(target);
46
44
  }
47
45
  else {
48
46
  /**
@@ -101,18 +99,37 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
101
99
  packageJson.scripts[scriptName] = packageJson.scripts[scriptName].replace(match, match.replace(commandRegex, configuration
102
100
  ? `$1nx ${target} --configuration=${configuration}$4`
103
101
  : `$1nx ${target}$4`));
102
+ replacedTargets.add(target);
104
103
  }
105
104
  else {
106
105
  // there are different args or the script has extra args, replace with the command leaving the args
107
106
  packageJson.scripts[scriptName] = packageJson.scripts[scriptName].replace(match, match.replace(commandRegex, configuration
108
107
  ? `$1nx ${target} --configuration=${configuration}$3`
109
108
  : `$1nx ${target}$3`));
109
+ replacedTargets.add(target);
110
110
  }
111
- excludeScriptFromPackageJson(packageJson, scriptName);
112
111
  }
113
112
  }
114
113
  }
115
114
  }
115
+ if (process.env.NX_RUNNING_NX_INIT === 'true') {
116
+ // running `nx init` so we want to exclude everything by default
117
+ packageJson.nx ??= {};
118
+ packageJson.nx.includedScripts = [];
119
+ }
120
+ else if (replacedTargets.size) {
121
+ /**
122
+ * Running `nx add`. In this case we want to:
123
+ * - if `includedScripts` is already set: exclude scripts that match inferred targets that were used to replace a script
124
+ * - if `includedScripts` is not set: set `includedScripts` with all scripts except the ones that match an inferred target that was used to replace a script
125
+ */
126
+ const includedScripts = packageJson.nx?.includedScripts ?? Object.keys(packageJson.scripts);
127
+ const filteredScripts = includedScripts.filter((s) => !replacedTargets.has(s));
128
+ if (filteredScripts.length !== includedScripts.length) {
129
+ packageJson.nx ??= {};
130
+ packageJson.nx.includedScripts = filteredScripts;
131
+ }
132
+ }
116
133
  writeJson(tree, packageJsonPath, packageJson);
117
134
  }
118
135
  function getInferredTargetCommands(result) {
@@ -153,9 +170,6 @@ function getInferredTargetCommands(result) {
153
170
  }
154
171
  return targetCommands;
155
172
  }
156
- function excludeScriptFromPackageJson(packageJson, scriptName) {
157
- packageJson.nx.includedScripts = packageJson.nx.includedScripts.filter((s) => s !== scriptName);
158
- }
159
173
  function getProjectRootFromConfigFile(file) {
160
174
  let projectRoot = (0, path_1.dirname)(file);
161
175
  if ((0, path_1.basename)(projectRoot) === '.storybook') {