@nx/devkit 18.1.0 → 18.1.1
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 +2 -2
- package/src/utils/convert-nx-executor.js +1 -2
- package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -2
- package/src/utils/replace-project-configuration-with-plugin.js +1 -0
- package/src/utils/update-package-scripts.d.ts +1 -2
- package/src/utils/update-package-scripts.js +31 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "18.1.
|
|
3
|
+
"version": "18.1.1",
|
|
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.
|
|
38
|
+
"@nrwl/devkit": "18.1.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"nx": ">= 16 <= 18"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertNxExecutor = void 0;
|
|
4
4
|
const nx_1 = require("../../nx");
|
|
5
|
-
const { Workspaces, readNxJsonFromDisk, retrieveProjectConfigurationsWithAngularProjects,
|
|
5
|
+
const { Workspaces, readNxJsonFromDisk, retrieveProjectConfigurationsWithAngularProjects, } = (0, nx_1.requireNx)();
|
|
6
6
|
/**
|
|
7
7
|
* Convert an Nx Executor into an Angular Devkit Builder
|
|
8
8
|
*
|
|
@@ -26,7 +26,6 @@ function convertNxExecutor(executor) {
|
|
|
26
26
|
workspaces.readProjectsConfigurations({
|
|
27
27
|
_includeProjectsFromAngularJson: true,
|
|
28
28
|
});
|
|
29
|
-
shutdownPluginWorkers?.();
|
|
30
29
|
const context = {
|
|
31
30
|
root: builderContext.workspaceRoot,
|
|
32
31
|
projectName: builderContext.target.project,
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { Tree } from 'nx/src/
|
|
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>;
|
|
@@ -24,6 +24,7 @@ async function replaceProjectConfigurationsWithPlugin(tree, rootMappings, plugin
|
|
|
24
24
|
const nodes = await createNodesFunction(configFile, pluginOptions, {
|
|
25
25
|
workspaceRoot: tree.root,
|
|
26
26
|
nxJsonConfiguration: readNxJson(tree),
|
|
27
|
+
configFiles,
|
|
27
28
|
});
|
|
28
29
|
const node = nodes.projects[Object.keys(nodes.projects)[0]];
|
|
29
30
|
for (const [targetName, targetConfig] of Object.entries(node.targets)) {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { Tree } from 'nx/src/
|
|
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>;
|
|
@@ -8,14 +8,14 @@ const { glob, readJson, readNxJson, workspaceRoot, writeJson } = (0, nx_1.requir
|
|
|
8
8
|
async function updatePackageScripts(tree, createNodesTuple) {
|
|
9
9
|
const nxJson = readNxJson(tree);
|
|
10
10
|
const [pattern, createNodes] = createNodesTuple;
|
|
11
|
-
const
|
|
12
|
-
for (const file of
|
|
11
|
+
const matchingFiles = glob(tree, [pattern]);
|
|
12
|
+
for (const file of matchingFiles) {
|
|
13
13
|
const projectRoot = getProjectRootFromConfigFile(file);
|
|
14
|
-
await processProject(tree, projectRoot, file, createNodes, nxJson);
|
|
14
|
+
await processProject(tree, projectRoot, file, createNodes, nxJson, matchingFiles);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.updatePackageScripts = updatePackageScripts;
|
|
18
|
-
async function processProject(tree, projectRoot, projectConfigurationFile, createNodesFunction, nxJsonConfiguration) {
|
|
18
|
+
async function processProject(tree, projectRoot, projectConfigurationFile, createNodesFunction, nxJsonConfiguration, configFiles) {
|
|
19
19
|
const packageJsonPath = `${projectRoot}/package.json`;
|
|
20
20
|
if (!tree.exists(packageJsonPath)) {
|
|
21
21
|
return;
|
|
@@ -24,14 +24,16 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
|
|
|
24
24
|
if (!packageJson.scripts || !Object.keys(packageJson.scripts).length) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
const result = await createNodesFunction(projectConfigurationFile, {}, {
|
|
27
|
+
const result = await createNodesFunction(projectConfigurationFile, {}, {
|
|
28
|
+
nxJsonConfiguration,
|
|
29
|
+
workspaceRoot,
|
|
30
|
+
configFiles,
|
|
31
|
+
});
|
|
28
32
|
const targetCommands = getInferredTargetCommands(result);
|
|
29
33
|
if (!targetCommands.length) {
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
packageJson.nx ??= {};
|
|
34
|
-
packageJson.nx.includedScripts ??= [];
|
|
36
|
+
const replacedTargets = new Set();
|
|
35
37
|
for (const targetCommand of targetCommands) {
|
|
36
38
|
const { command, target, configuration } = targetCommand;
|
|
37
39
|
const targetCommandRegex = new RegExp(`(?<=^|&)((?: )*(?:[^&\\r\\n\\s]+ )*)(${command})((?: [^&\\r\\n\\s]+)*(?: )*)(?=$|&)`, 'g');
|
|
@@ -42,7 +44,7 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
|
|
|
42
44
|
packageJson.scripts[scriptName] = script.replace(targetCommandRegex, configuration
|
|
43
45
|
? `$1nx ${target} --configuration=${configuration}$3`
|
|
44
46
|
: `$1nx ${target}$3`);
|
|
45
|
-
|
|
47
|
+
replacedTargets.add(target);
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
50
|
/**
|
|
@@ -101,18 +103,37 @@ async function processProject(tree, projectRoot, projectConfigurationFile, creat
|
|
|
101
103
|
packageJson.scripts[scriptName] = packageJson.scripts[scriptName].replace(match, match.replace(commandRegex, configuration
|
|
102
104
|
? `$1nx ${target} --configuration=${configuration}$4`
|
|
103
105
|
: `$1nx ${target}$4`));
|
|
106
|
+
replacedTargets.add(target);
|
|
104
107
|
}
|
|
105
108
|
else {
|
|
106
109
|
// there are different args or the script has extra args, replace with the command leaving the args
|
|
107
110
|
packageJson.scripts[scriptName] = packageJson.scripts[scriptName].replace(match, match.replace(commandRegex, configuration
|
|
108
111
|
? `$1nx ${target} --configuration=${configuration}$3`
|
|
109
112
|
: `$1nx ${target}$3`));
|
|
113
|
+
replacedTargets.add(target);
|
|
110
114
|
}
|
|
111
|
-
excludeScriptFromPackageJson(packageJson, scriptName);
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
if (process.env.NX_RUNNING_NX_INIT === 'true') {
|
|
120
|
+
// running `nx init` so we want to exclude everything by default
|
|
121
|
+
packageJson.nx ??= {};
|
|
122
|
+
packageJson.nx.includedScripts = [];
|
|
123
|
+
}
|
|
124
|
+
else if (replacedTargets.size) {
|
|
125
|
+
/**
|
|
126
|
+
* Running `nx add`. In this case we want to:
|
|
127
|
+
* - if `includedScripts` is already set: exclude scripts that match inferred targets that were used to replace a script
|
|
128
|
+
* - 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
|
|
129
|
+
*/
|
|
130
|
+
const includedScripts = packageJson.nx?.includedScripts ?? Object.keys(packageJson.scripts);
|
|
131
|
+
const filteredScripts = includedScripts.filter((s) => !replacedTargets.has(s));
|
|
132
|
+
if (filteredScripts.length !== includedScripts.length) {
|
|
133
|
+
packageJson.nx ??= {};
|
|
134
|
+
packageJson.nx.includedScripts = filteredScripts;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
116
137
|
writeJson(tree, packageJsonPath, packageJson);
|
|
117
138
|
}
|
|
118
139
|
function getInferredTargetCommands(result) {
|
|
@@ -153,9 +174,6 @@ function getInferredTargetCommands(result) {
|
|
|
153
174
|
}
|
|
154
175
|
return targetCommands;
|
|
155
176
|
}
|
|
156
|
-
function excludeScriptFromPackageJson(packageJson, scriptName) {
|
|
157
|
-
packageJson.nx.includedScripts = packageJson.nx.includedScripts.filter((s) => s !== scriptName);
|
|
158
|
-
}
|
|
159
177
|
function getProjectRootFromConfigFile(file) {
|
|
160
178
|
let projectRoot = (0, path_1.dirname)(file);
|
|
161
179
|
if ((0, path_1.basename)(projectRoot) === '.storybook') {
|