@nx/devkit 0.0.0-pr-28229-afe192c → 0.0.0-pr-28517-630ecca
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/migrations.json +1 -14
- package/package.json +2 -2
- package/src/executors/parse-target-string.d.ts +0 -4
- package/src/executors/read-target-options.js +2 -2
- package/src/generators/format-files.d.ts +6 -1
- package/src/generators/format-files.js +9 -2
- package/src/tasks/install-packages-task.js +1 -1
- package/src/utils/package-json.js +2 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +0 -3
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +0 -200
package/migrations.json
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"update-16-0-0-add-nx-packages": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "16.0.0-beta.1",
|
|
6
|
-
"description": "Replace @nrwl/devkit with @nx/devkit",
|
|
7
|
-
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
-
},
|
|
9
|
-
"update-16-9-0-migrate-mf-usage-to-webpack": {
|
|
10
|
-
"cli": "nx",
|
|
11
|
-
"version": "16.9.0-beta.1",
|
|
12
|
-
"description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
|
|
13
|
-
"implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
2
|
+
"generators": {},
|
|
16
3
|
"packageJsonUpdates": {},
|
|
17
4
|
"version": "0.1"
|
|
18
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-28517-630ecca",
|
|
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": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"enquirer": "~2.3.6"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"nx": ">=
|
|
41
|
+
"nx": ">= 19 <= 21"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { ExecutorContext, ProjectGraph, Target } from 'nx/src/devkit-exports';
|
|
2
|
-
/**
|
|
3
|
-
* @deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseTargetString(targetString: string): Target;
|
|
6
2
|
/**
|
|
7
3
|
* Parses a target string into {project, target, configuration}
|
|
8
4
|
*
|
|
@@ -9,7 +9,7 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
|
9
9
|
* Works as if you invoked the target yourself without passing any command lint overrides.
|
|
10
10
|
*/
|
|
11
11
|
function readTargetOptions({ project, target, configuration }, context) {
|
|
12
|
-
const projectConfiguration =
|
|
12
|
+
const projectConfiguration = context.projectsConfigurations.projects[project];
|
|
13
13
|
if (!projectConfiguration) {
|
|
14
14
|
throw new Error(`Unable to find project ${project}`);
|
|
15
15
|
}
|
|
@@ -18,7 +18,7 @@ function readTargetOptions({ project, target, configuration }, context) {
|
|
|
18
18
|
throw new Error(`Unable to find target ${target} for project ${project}`);
|
|
19
19
|
}
|
|
20
20
|
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
|
|
21
|
-
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects
|
|
21
|
+
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects);
|
|
22
22
|
const defaultProject = (0, devkit_internals_1.calculateDefaultProjectName)(context.cwd, context.root, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration);
|
|
23
23
|
return (0, devkit_internals_1.combineOptionsForExecutor)({}, configuration ?? targetConfiguration.defaultConfiguration ?? '', targetConfiguration, schema, defaultProject, (0, path_1.relative)(context.root, context.cwd));
|
|
24
24
|
}
|
|
@@ -3,4 +3,9 @@ import { Tree } from 'nx/src/devkit-exports';
|
|
|
3
3
|
* Formats all the created or updated files using Prettier
|
|
4
4
|
* @param tree - the file system tree
|
|
5
5
|
*/
|
|
6
|
-
export declare function formatFiles(tree: Tree
|
|
6
|
+
export declare function formatFiles(tree: Tree,
|
|
7
|
+
/**
|
|
8
|
+
* TODO(v21): Stop sorting tsconfig paths by default, paths are now less common/important
|
|
9
|
+
* in Nx workspace setups, and the sorting causes comments to be lost.
|
|
10
|
+
*/
|
|
11
|
+
sortRootTsConfigPaths?: boolean): Promise<void>;
|
|
@@ -8,13 +8,20 @@ const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
|
8
8
|
* Formats all the created or updated files using Prettier
|
|
9
9
|
* @param tree - the file system tree
|
|
10
10
|
*/
|
|
11
|
-
async function formatFiles(tree
|
|
11
|
+
async function formatFiles(tree,
|
|
12
|
+
/**
|
|
13
|
+
* TODO(v21): Stop sorting tsconfig paths by default, paths are now less common/important
|
|
14
|
+
* in Nx workspace setups, and the sorting causes comments to be lost.
|
|
15
|
+
*/
|
|
16
|
+
sortRootTsConfigPaths = true) {
|
|
12
17
|
let prettier;
|
|
13
18
|
try {
|
|
14
19
|
prettier = await Promise.resolve().then(() => require('prettier'));
|
|
15
20
|
}
|
|
16
21
|
catch { }
|
|
17
|
-
|
|
22
|
+
if (sortRootTsConfigPaths) {
|
|
23
|
+
sortTsConfig(tree);
|
|
24
|
+
}
|
|
18
25
|
if (!prettier)
|
|
19
26
|
return;
|
|
20
27
|
const files = new Set(tree.listChanges().filter((file) => file.type !== 'DELETE'));
|
|
@@ -27,7 +27,7 @@ function installPackagesTask(tree, alwaysRun = false, cwd = '', packageManager =
|
|
|
27
27
|
const execSyncOptions = {
|
|
28
28
|
cwd: (0, path_1.join)(tree.root, cwd),
|
|
29
29
|
stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit',
|
|
30
|
-
windowsHide:
|
|
30
|
+
windowsHide: false,
|
|
31
31
|
};
|
|
32
32
|
// ensure local registry from process is not interfering with the install
|
|
33
33
|
// when we start the process from temp folder the local registry would override the custom registry
|
|
@@ -305,7 +305,7 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
|
|
|
305
305
|
(0, child_process_1.execSync)(preInstallCommand, {
|
|
306
306
|
cwd: tempDir,
|
|
307
307
|
stdio: isVerbose ? 'inherit' : 'ignore',
|
|
308
|
-
windowsHide:
|
|
308
|
+
windowsHide: false,
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
let addCommand = (0, devkit_exports_1.getPackageManagerCommand)(packageManager).addDev;
|
|
@@ -315,7 +315,7 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
|
|
|
315
315
|
(0, child_process_1.execSync)(`${addCommand} ${pkg}@${requiredVersion}`, {
|
|
316
316
|
cwd: tempDir,
|
|
317
317
|
stdio: isVerbose ? 'inherit' : 'ignore',
|
|
318
|
-
windowsHide:
|
|
318
|
+
windowsHide: false,
|
|
319
319
|
});
|
|
320
320
|
addToNodePath((0, path_1.join)(devkit_exports_1.workspaceRoot, 'node_modules'));
|
|
321
321
|
addToNodePath((0, path_1.join)(tempDir, 'node_modules'));
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = replacePackage;
|
|
4
|
-
const format_files_1 = require("../../generators/format-files");
|
|
5
|
-
const replace_package_1 = require("../../utils/replace-package");
|
|
6
|
-
async function replacePackage(tree) {
|
|
7
|
-
await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/devkit', '@nx/devkit');
|
|
8
|
-
await (0, format_files_1.formatFiles)(tree);
|
|
9
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const visit_not_ignored_files_1 = require("../../generators/visit-not-ignored-files");
|
|
4
|
-
const format_files_1 = require("../../generators/format-files");
|
|
5
|
-
const package_json_1 = require("../../utils/package-json");
|
|
6
|
-
const versions_1 = require("../../utils/versions");
|
|
7
|
-
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
8
|
-
let tsModule;
|
|
9
|
-
const MODULE_FEDERATION_PUBLIC_TOKENS = [
|
|
10
|
-
'AdditionalSharedConfig',
|
|
11
|
-
'ModuleFederationConfig',
|
|
12
|
-
'SharedLibraryConfig',
|
|
13
|
-
'SharedWorkspaceLibraryConfig',
|
|
14
|
-
'WorkspaceLibrary',
|
|
15
|
-
'SharedFunction',
|
|
16
|
-
'WorkspaceLibrarySecondaryEntryPoint',
|
|
17
|
-
'Remotes',
|
|
18
|
-
'ModuleFederationLibrary',
|
|
19
|
-
'applySharedFunction',
|
|
20
|
-
'applyAdditionalShared',
|
|
21
|
-
'getNpmPackageSharedConfig',
|
|
22
|
-
'shareWorkspaceLibraries',
|
|
23
|
-
'sharePackages',
|
|
24
|
-
'mapRemotes',
|
|
25
|
-
'mapRemotesForSSR',
|
|
26
|
-
'getDependentPackagesForProject',
|
|
27
|
-
'readRootPackageJson',
|
|
28
|
-
];
|
|
29
|
-
exports.default = async (tree) => {
|
|
30
|
-
let hasFileToMigrate = false;
|
|
31
|
-
(0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '/', (path) => {
|
|
32
|
-
if (!path.endsWith('.ts') && !path.endsWith('.js')) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
let fileContents = tree.read(path, 'utf-8');
|
|
36
|
-
if (MODULE_FEDERATION_PUBLIC_TOKENS.every((token) => !fileContents.includes(token))) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
hasFileToMigrate = true;
|
|
40
|
-
fileContents = replaceTSImports(tree, path, fileContents);
|
|
41
|
-
fileContents = replaceRequireCalls(tree, path, fileContents);
|
|
42
|
-
fileContents = replaceJSDoc(tree, path, fileContents);
|
|
43
|
-
tree.write(path, fileContents);
|
|
44
|
-
});
|
|
45
|
-
if (hasFileToMigrate) {
|
|
46
|
-
await (0, format_files_1.formatFiles)(tree);
|
|
47
|
-
const pkgJson = (0, devkit_exports_1.readJson)(tree, 'package.json');
|
|
48
|
-
const nxVersion = pkgJson.devDependencies?.['nx'] ??
|
|
49
|
-
pkgJson.dependencies?.['nx'] ??
|
|
50
|
-
'17.0.0';
|
|
51
|
-
return (0, package_json_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': nxVersion });
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
function replaceJSDoc(tree, path, fileContents) {
|
|
55
|
-
let newFileContents = fileContents;
|
|
56
|
-
for (const token of MODULE_FEDERATION_PUBLIC_TOKENS) {
|
|
57
|
-
newFileContents = newFileContents.replaceAll(new RegExp(`(@type)+\\s({)+(\\s)*(import\\(('|")+@nx\/devkit('|")+\\)\.)+(${token})+\\s*(})+`, 'g'), `@type {import('@nx/webpack').${token}}`);
|
|
58
|
-
}
|
|
59
|
-
return newFileContents;
|
|
60
|
-
}
|
|
61
|
-
function replaceRequireCalls(tree, path, fileContents) {
|
|
62
|
-
if (!tsModule) {
|
|
63
|
-
tsModule = (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
|
|
64
|
-
}
|
|
65
|
-
const sourceFile = tsModule.createSourceFile(path, fileContents, tsModule.ScriptTarget.Latest, true);
|
|
66
|
-
const allDevkitRequires = findNodes(sourceFile, tsModule.SyntaxKind.VariableStatement)
|
|
67
|
-
.filter((node) => [`require("@nx/devkit")`, `require('@nx/devkit')`].some((r) => node.getText().includes(r)))
|
|
68
|
-
.filter((node) => findNodes(node, tsModule.SyntaxKind.ObjectBindingPattern).length);
|
|
69
|
-
const mfUtilRequires = allDevkitRequires.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText().includes(token)));
|
|
70
|
-
if (!mfUtilRequires.length) {
|
|
71
|
-
return fileContents;
|
|
72
|
-
}
|
|
73
|
-
const mfUtilTokens = mfUtilRequires.map((node) => {
|
|
74
|
-
const allTokens = findNodes(node, tsModule.SyntaxKind.BindingElement);
|
|
75
|
-
const mfTokens = allTokens.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText() === token));
|
|
76
|
-
return {
|
|
77
|
-
requireNode: node,
|
|
78
|
-
onlyMf: allTokens.length === mfTokens.length,
|
|
79
|
-
mfTokens,
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
const changes = [];
|
|
83
|
-
for (const mfUtilRequireData of mfUtilTokens) {
|
|
84
|
-
if (mfUtilRequireData.onlyMf) {
|
|
85
|
-
changes.push({
|
|
86
|
-
startPosition: mfUtilRequireData.requireNode.getStart(),
|
|
87
|
-
endPosition: mfUtilRequireData.requireNode.getEnd(),
|
|
88
|
-
content: '',
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
for (const mfToken of mfUtilRequireData.mfTokens) {
|
|
93
|
-
const replaceTrailingComma = mfToken.getText().charAt(mfToken.getEnd() + 1) === ',';
|
|
94
|
-
changes.push({
|
|
95
|
-
startPosition: mfToken.getStart(),
|
|
96
|
-
endPosition: replaceTrailingComma
|
|
97
|
-
? mfToken.getEnd() + 1
|
|
98
|
-
: mfToken.getEnd(),
|
|
99
|
-
content: '',
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
changes.push({
|
|
105
|
-
startPosition: mfUtilTokens[mfUtilTokens.length - 1].requireNode.getEnd(),
|
|
106
|
-
content: `\nconst { ${mfUtilTokens
|
|
107
|
-
.map((mfUtilToken) => mfUtilToken.mfTokens.map((node) => node.getText()))
|
|
108
|
-
.join(', ')} } = require('@nx/webpack');`,
|
|
109
|
-
});
|
|
110
|
-
let newFileContents = fileContents;
|
|
111
|
-
while (changes.length) {
|
|
112
|
-
const change = changes.pop();
|
|
113
|
-
newFileContents = `${newFileContents.substring(0, change.startPosition)}${change.content}${newFileContents.substring(change.endPosition ? change.endPosition : change.startPosition)}`;
|
|
114
|
-
}
|
|
115
|
-
return newFileContents;
|
|
116
|
-
}
|
|
117
|
-
function replaceTSImports(tree, path, fileContents) {
|
|
118
|
-
if (!tsModule) {
|
|
119
|
-
tsModule = (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
|
|
120
|
-
}
|
|
121
|
-
const sourceFile = tsModule.createSourceFile(path, fileContents, tsModule.ScriptTarget.Latest, true);
|
|
122
|
-
const allImports = findNodes(sourceFile, tsModule.SyntaxKind.ImportDeclaration);
|
|
123
|
-
const devkitImports = allImports.filter((i) => i.getText().includes(`'@nx/devkit';`));
|
|
124
|
-
const mfUtilsImports = devkitImports.filter((i) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => i.getText().includes(token)));
|
|
125
|
-
if (!mfUtilsImports.length) {
|
|
126
|
-
return fileContents;
|
|
127
|
-
}
|
|
128
|
-
const mfUtilsWithMultipleImports = mfUtilsImports.map((i) => {
|
|
129
|
-
const importSpecifierNodes = findNodes(i, tsModule.SyntaxKind.ImportSpecifier);
|
|
130
|
-
const mfImportSpecifierNodes = importSpecifierNodes.filter((node) => MODULE_FEDERATION_PUBLIC_TOKENS.some((token) => node.getText().includes(token)));
|
|
131
|
-
return {
|
|
132
|
-
importDeclarationNode: i,
|
|
133
|
-
onlyMf: mfImportSpecifierNodes.length === importSpecifierNodes.length,
|
|
134
|
-
mfImportSpecifierNodes,
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
const changes = [];
|
|
138
|
-
for (const importDeclaration of mfUtilsWithMultipleImports) {
|
|
139
|
-
if (importDeclaration.onlyMf) {
|
|
140
|
-
changes.push({
|
|
141
|
-
startPosition: importDeclaration.importDeclarationNode.getStart(),
|
|
142
|
-
endPosition: importDeclaration.importDeclarationNode.getEnd(),
|
|
143
|
-
content: '',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
for (const mfImportSpecifierNodes of importDeclaration.mfImportSpecifierNodes) {
|
|
148
|
-
const replaceTrailingComma = importDeclaration.importDeclarationNode
|
|
149
|
-
.getText()
|
|
150
|
-
.charAt(mfImportSpecifierNodes.getEnd() + 1) === ',';
|
|
151
|
-
changes.push({
|
|
152
|
-
startPosition: mfImportSpecifierNodes.getStart(),
|
|
153
|
-
endPosition: replaceTrailingComma
|
|
154
|
-
? mfImportSpecifierNodes.getEnd() + 1
|
|
155
|
-
: mfImportSpecifierNodes.getEnd(),
|
|
156
|
-
content: '',
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
changes.push({
|
|
162
|
-
startPosition: mfUtilsWithMultipleImports[mfUtilsWithMultipleImports.length - 1].importDeclarationNode.getEnd(),
|
|
163
|
-
content: `\nimport { ${mfUtilsWithMultipleImports
|
|
164
|
-
.map((importDeclaration) => importDeclaration.mfImportSpecifierNodes.map((node) => node.getText()))
|
|
165
|
-
.join(', ')} } from '@nx/webpack';`,
|
|
166
|
-
});
|
|
167
|
-
let newFileContents = fileContents;
|
|
168
|
-
while (changes.length) {
|
|
169
|
-
const change = changes.pop();
|
|
170
|
-
newFileContents = `${newFileContents.substring(0, change.startPosition)}${change.content}${newFileContents.substring(change.endPosition ? change.endPosition : change.startPosition)}`;
|
|
171
|
-
}
|
|
172
|
-
return newFileContents;
|
|
173
|
-
}
|
|
174
|
-
function findNodes(node, kind, max = Infinity) {
|
|
175
|
-
if (!node || max == 0) {
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
const arr = [];
|
|
179
|
-
const hasMatch = Array.isArray(kind)
|
|
180
|
-
? kind.includes(node.kind)
|
|
181
|
-
: node.kind === kind;
|
|
182
|
-
if (hasMatch) {
|
|
183
|
-
arr.push(node);
|
|
184
|
-
max--;
|
|
185
|
-
}
|
|
186
|
-
if (max > 0) {
|
|
187
|
-
for (const child of node.getChildren()) {
|
|
188
|
-
findNodes(child, kind, max).forEach((node) => {
|
|
189
|
-
if (max > 0) {
|
|
190
|
-
arr.push(node);
|
|
191
|
-
}
|
|
192
|
-
max--;
|
|
193
|
-
});
|
|
194
|
-
if (max <= 0) {
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return arr;
|
|
200
|
-
}
|