@nx/devkit 20.0.0-canary.20241002-1d10a19 → 20.0.0-canary.20241003-84a5c7a

Sign up to get free protection for your applications and to get access to all the features.
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": "20.0.0-canary.20241002-1d10a19",
3
+ "version": "20.0.0-canary.20241003-84a5c7a",
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": {
@@ -1,2 +0,0 @@
1
- import type { Tree } from 'nx/src/devkit-exports';
2
- export default function replacePackage(tree: Tree): Promise<void>;
@@ -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,3 +0,0 @@
1
- import { GeneratorCallback, Tree } from 'nx/src/devkit-exports';
2
- declare const _default: (tree: Tree) => Promise<GeneratorCallback | void>;
3
- export default _default;
@@ -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
- }