@nx/devkit 19.0.0-beta.0 → 19.0.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 +4 -3
- package/src/executors/parse-target-string.d.ts +1 -3
- package/src/executors/parse-target-string.js +5 -9
- package/src/executors/read-target-options.d.ts +1 -2
- package/src/executors/read-target-options.js +4 -17
- package/src/generators/add-build-target-defaults.d.ts +1 -1
- package/src/generators/add-build-target-defaults.js +3 -4
- package/src/generators/artifact-name-and-directory-utils.d.ts +1 -1
- package/src/generators/artifact-name-and-directory-utils.js +24 -24
- package/src/generators/executor-options-utils.d.ts +1 -2
- package/src/generators/executor-options-utils.js +3 -6
- package/src/generators/format-files.d.ts +1 -1
- package/src/generators/format-files.js +5 -8
- package/src/generators/generate-files.d.ts +1 -1
- package/src/generators/generate-files.js +2 -3
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +6 -0
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +197 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +54 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.js +78 -0
- package/src/generators/project-name-and-root-utils.d.ts +1 -2
- package/src/generators/project-name-and-root-utils.js +16 -17
- package/src/generators/run-tasks-in-serial.d.ts +1 -1
- package/src/generators/to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.js +3 -4
- package/src/generators/visit-not-ignored-files.d.ts +1 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +1 -1
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +1 -2
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +2 -3
- package/src/tasks/install-packages-task.d.ts +1 -2
- package/src/tasks/install-packages-task.js +5 -6
- package/src/utils/add-plugin.d.ts +1 -1
- package/src/utils/add-plugin.js +12 -10
- package/src/utils/calculate-hash-for-create-nodes.d.ts +1 -1
- package/src/utils/calculate-hash-for-create-nodes.js +5 -5
- package/src/utils/config-utils.d.ts +1 -0
- package/src/utils/config-utils.js +19 -9
- package/src/utils/convert-nx-executor.d.ts +1 -1
- package/src/utils/convert-nx-executor.js +21 -16
- package/src/utils/get-named-inputs.d.ts +1 -1
- package/src/utils/get-named-inputs.js +3 -4
- package/src/utils/get-workspace-layout.d.ts +1 -1
- package/src/utils/get-workspace-layout.js +2 -3
- package/src/utils/invoke-nx-generator.d.ts +1 -1
- package/src/utils/invoke-nx-generator.js +3 -5
- package/src/utils/log-show-project-command.js +2 -3
- package/src/utils/move-dir.d.ts +1 -1
- package/src/utils/move-dir.js +3 -4
- package/src/utils/package-json.d.ts +1 -2
- package/src/utils/package-json.js +13 -13
- package/src/utils/replace-package.d.ts +1 -1
- package/src/utils/replace-package.js +7 -9
- package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -1
- package/src/utils/replace-project-configuration-with-plugin.js +11 -11
- package/nx.d.ts +0 -1
- package/nx.js +0 -19
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
|
3
|
+
* Delete matching properties from current target.
|
|
4
|
+
*
|
|
5
|
+
* _Note: Deletes by reference_
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Run the plugin to get all the projects
|
|
9
|
+
* const { projects } = await createNodes[1](
|
|
10
|
+
* playwrightConfigPath,
|
|
11
|
+
* { targetName, ciTargetName: 'e2e-ci' },
|
|
12
|
+
* { workspaceRoot: tree.root, nxJsonConfiguration, configFiles }
|
|
13
|
+
* );
|
|
14
|
+
*
|
|
15
|
+
* // Find the project that matches the one that is being migrated
|
|
16
|
+
* const createdProject = Object.entries(projects ?? {}).find(
|
|
17
|
+
* ([root]) => root === projectFromGraph.data.root
|
|
18
|
+
* )[1];
|
|
19
|
+
*
|
|
20
|
+
* // Get the created TargetConfiguration for the target being migrated
|
|
21
|
+
* const createdTarget: TargetConfiguration<RunCommandsOptions> =
|
|
22
|
+
* createdProject.targets[targetName];
|
|
23
|
+
*
|
|
24
|
+
* // Delete specific run-commands options
|
|
25
|
+
* delete createdTarget.command;
|
|
26
|
+
* delete createdTarget.options?.cwd;
|
|
27
|
+
*
|
|
28
|
+
* // Get the TargetConfiguration for the target being migrated from project.json
|
|
29
|
+
* const projectConfig = readProjectConfiguration(tree, projectName);
|
|
30
|
+
* let targetToMigrate = projectConfig.targets[targetName];
|
|
31
|
+
*
|
|
32
|
+
* // Merge the target defaults for the executor to the target being migrated
|
|
33
|
+
* target = mergeTargetConfigurations(targetToMigrate, targetDefaultsForExecutor);
|
|
34
|
+
*
|
|
35
|
+
* // Delete executor and any additional options that are no longer necessary
|
|
36
|
+
* delete target.executor;
|
|
37
|
+
* delete target.options?.config;
|
|
38
|
+
*
|
|
39
|
+
* // Run deleteMatchingProperties to delete further options that match what the plugin creates
|
|
40
|
+
* deleteMatchingProperties(target, createdTarget);
|
|
41
|
+
*
|
|
42
|
+
* // Delete the target if it is now empty, otherwise, set it to the updated TargetConfiguration
|
|
43
|
+
* if (Object.keys(target).length > 0) {
|
|
44
|
+
* projectConfig.targets[targetName] = target;
|
|
45
|
+
* } else {
|
|
46
|
+
* delete projectConfig.targets[targetName];
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* updateProjectConfiguration(tree, projectName, projectConfig);
|
|
50
|
+
*
|
|
51
|
+
* @param targetToMigrate The target from project.json
|
|
52
|
+
* @param createdTarget The target created by the Plugin
|
|
53
|
+
*/
|
|
54
|
+
export declare function deleteMatchingProperties(targetToMigrate: object, createdTarget: object): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteMatchingProperties = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Iterate through the current target in the project.json and its options comparing it to the target created by the Plugin itself
|
|
6
|
+
* Delete matching properties from current target.
|
|
7
|
+
*
|
|
8
|
+
* _Note: Deletes by reference_
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Run the plugin to get all the projects
|
|
12
|
+
* const { projects } = await createNodes[1](
|
|
13
|
+
* playwrightConfigPath,
|
|
14
|
+
* { targetName, ciTargetName: 'e2e-ci' },
|
|
15
|
+
* { workspaceRoot: tree.root, nxJsonConfiguration, configFiles }
|
|
16
|
+
* );
|
|
17
|
+
*
|
|
18
|
+
* // Find the project that matches the one that is being migrated
|
|
19
|
+
* const createdProject = Object.entries(projects ?? {}).find(
|
|
20
|
+
* ([root]) => root === projectFromGraph.data.root
|
|
21
|
+
* )[1];
|
|
22
|
+
*
|
|
23
|
+
* // Get the created TargetConfiguration for the target being migrated
|
|
24
|
+
* const createdTarget: TargetConfiguration<RunCommandsOptions> =
|
|
25
|
+
* createdProject.targets[targetName];
|
|
26
|
+
*
|
|
27
|
+
* // Delete specific run-commands options
|
|
28
|
+
* delete createdTarget.command;
|
|
29
|
+
* delete createdTarget.options?.cwd;
|
|
30
|
+
*
|
|
31
|
+
* // Get the TargetConfiguration for the target being migrated from project.json
|
|
32
|
+
* const projectConfig = readProjectConfiguration(tree, projectName);
|
|
33
|
+
* let targetToMigrate = projectConfig.targets[targetName];
|
|
34
|
+
*
|
|
35
|
+
* // Merge the target defaults for the executor to the target being migrated
|
|
36
|
+
* target = mergeTargetConfigurations(targetToMigrate, targetDefaultsForExecutor);
|
|
37
|
+
*
|
|
38
|
+
* // Delete executor and any additional options that are no longer necessary
|
|
39
|
+
* delete target.executor;
|
|
40
|
+
* delete target.options?.config;
|
|
41
|
+
*
|
|
42
|
+
* // Run deleteMatchingProperties to delete further options that match what the plugin creates
|
|
43
|
+
* deleteMatchingProperties(target, createdTarget);
|
|
44
|
+
*
|
|
45
|
+
* // Delete the target if it is now empty, otherwise, set it to the updated TargetConfiguration
|
|
46
|
+
* if (Object.keys(target).length > 0) {
|
|
47
|
+
* projectConfig.targets[targetName] = target;
|
|
48
|
+
* } else {
|
|
49
|
+
* delete projectConfig.targets[targetName];
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* updateProjectConfiguration(tree, projectName, projectConfig);
|
|
53
|
+
*
|
|
54
|
+
* @param targetToMigrate The target from project.json
|
|
55
|
+
* @param createdTarget The target created by the Plugin
|
|
56
|
+
*/
|
|
57
|
+
function deleteMatchingProperties(targetToMigrate, createdTarget) {
|
|
58
|
+
for (const key in targetToMigrate) {
|
|
59
|
+
if (Array.isArray(targetToMigrate[key])) {
|
|
60
|
+
if (targetToMigrate[key].every((v) => createdTarget[key]?.includes(v)) &&
|
|
61
|
+
targetToMigrate[key].length === createdTarget[key]?.length) {
|
|
62
|
+
delete targetToMigrate[key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (typeof targetToMigrate[key] === 'object' &&
|
|
66
|
+
typeof createdTarget[key] === 'object') {
|
|
67
|
+
deleteMatchingProperties(targetToMigrate[key], createdTarget[key]);
|
|
68
|
+
}
|
|
69
|
+
else if (targetToMigrate[key] === createdTarget[key]) {
|
|
70
|
+
delete targetToMigrate[key];
|
|
71
|
+
}
|
|
72
|
+
if (typeof targetToMigrate[key] === 'object' &&
|
|
73
|
+
Object.keys(targetToMigrate[key]).length === 0) {
|
|
74
|
+
delete targetToMigrate[key];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.deleteMatchingProperties = deleteMatchingProperties;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Tree } from 'nx/src/generators/tree';
|
|
1
|
+
import { ProjectType, Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
|
4
3
|
export type ProjectGenerationOptions = {
|
|
5
4
|
name: string;
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setCwd = exports.determineProjectNameAndRootOptions = void 0;
|
|
4
4
|
const enquirer_1 = require("enquirer");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const nx_1 = require("../../nx");
|
|
7
6
|
const get_workspace_layout_1 = require("../utils/get-workspace-layout");
|
|
8
7
|
const names_1 = require("../utils/names");
|
|
9
|
-
const
|
|
8
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
10
9
|
async function determineProjectNameAndRootOptions(tree, options) {
|
|
11
10
|
if (!options.projectNameAndRootFormat &&
|
|
12
11
|
(process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
|
|
@@ -45,8 +44,8 @@ function validateName(name, projectNameAndRootFormat) {
|
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
function logDeprecationMessage(callingGenerator, formats) {
|
|
48
|
-
logger.warn(stripIndents `
|
|
49
|
-
In Nx
|
|
47
|
+
devkit_exports_1.logger.warn((0, devkit_exports_1.stripIndents) `
|
|
48
|
+
In Nx 20, generating projects will no longer derive the name and root.
|
|
50
49
|
Please provide the exact project name and root in the future.
|
|
51
50
|
Example: nx g ${callingGenerator} ${formats['derived'].projectName} --directory ${formats['derived'].projectRoot}
|
|
52
51
|
`);
|
|
@@ -86,7 +85,7 @@ async function determineFormat(formats) {
|
|
|
86
85
|
}
|
|
87
86
|
function getProjectNameAndRootFormats(tree, options) {
|
|
88
87
|
const directory = options.directory
|
|
89
|
-
? normalizePath(options.directory.replace(/^\.?\//, ''))
|
|
88
|
+
? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
|
|
90
89
|
: undefined;
|
|
91
90
|
const { name: asProvidedParsedName, directory: asProvidedParsedDirectory } = parseNameForAsProvided(options.name);
|
|
92
91
|
if (asProvidedParsedDirectory && directory) {
|
|
@@ -106,7 +105,7 @@ function getProjectNameAndRootFormats(tree, options) {
|
|
|
106
105
|
}
|
|
107
106
|
if (asProvidedOptions.projectName.startsWith('@')) {
|
|
108
107
|
if (!options.projectNameAndRootFormat) {
|
|
109
|
-
output.warn({
|
|
108
|
+
devkit_exports_1.output.warn({
|
|
110
109
|
title: `The provided name "${options.name}" contains a scoped project name and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
|
|
111
110
|
bodyLines: [
|
|
112
111
|
`The generator will try to generate the project "${asProvidedOptions.projectName}" using the "as-provided" format at "${asProvidedOptions.projectRoot}".`,
|
|
@@ -152,7 +151,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
152
151
|
projectRoot = options.directory;
|
|
153
152
|
}
|
|
154
153
|
else {
|
|
155
|
-
projectRoot = joinPathFragments(relativeCwd, options.directory);
|
|
154
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
else if (options.rootProject) {
|
|
@@ -162,7 +161,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
162
161
|
projectRoot = relativeCwd;
|
|
163
162
|
// append the project name to the current working directory if it doesn't end with it
|
|
164
163
|
if (!relativeCwd.endsWith(options.name)) {
|
|
165
|
-
projectRoot = joinPathFragments(relativeCwd, options.name);
|
|
164
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.name);
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
let importPath = undefined;
|
|
@@ -176,7 +175,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
176
175
|
const npmScope = getNpmScope(tree);
|
|
177
176
|
importPath =
|
|
178
177
|
projectRoot === '.'
|
|
179
|
-
? readJson(tree, 'package.json').name ??
|
|
178
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
|
|
180
179
|
getImportPath(npmScope, options.name)
|
|
181
180
|
: getImportPath(npmScope, options.name);
|
|
182
181
|
}
|
|
@@ -208,7 +207,7 @@ function getDerivedOptions(tree, options) {
|
|
|
208
207
|
let projectRoot = projectDirectoryWithoutLayout;
|
|
209
208
|
if (projectDirectoryWithoutLayout !== '.') {
|
|
210
209
|
// prepend the layout directory
|
|
211
|
-
projectRoot = joinPathFragments(layoutDirectory, projectRoot);
|
|
210
|
+
projectRoot = (0, devkit_exports_1.joinPathFragments)(layoutDirectory, projectRoot);
|
|
212
211
|
}
|
|
213
212
|
let importPath;
|
|
214
213
|
if (options.projectType === 'library') {
|
|
@@ -217,7 +216,7 @@ function getDerivedOptions(tree, options) {
|
|
|
217
216
|
const npmScope = getNpmScope(tree);
|
|
218
217
|
importPath =
|
|
219
218
|
projectRoot === '.'
|
|
220
|
-
? readJson(tree, 'package.json').name ??
|
|
219
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json').name ??
|
|
221
220
|
getImportPath(npmScope, projectName)
|
|
222
221
|
: getImportPath(npmScope, projectDirectoryWithoutLayout);
|
|
223
222
|
}
|
|
@@ -245,7 +244,7 @@ function getImportPath(npmScope, name) {
|
|
|
245
244
|
}
|
|
246
245
|
function getNpmScope(tree) {
|
|
247
246
|
const { name } = tree.exists('package.json')
|
|
248
|
-
? readJson(tree, 'package.json')
|
|
247
|
+
? (0, devkit_exports_1.readJson)(tree, 'package.json')
|
|
249
248
|
: { name: null };
|
|
250
249
|
return name?.startsWith('@') ? name.split('/')[0].substring(1) : undefined;
|
|
251
250
|
}
|
|
@@ -259,22 +258,22 @@ function isTTY() {
|
|
|
259
258
|
* environment variable (see here: https://docs.npmjs.com/cli/v9/commands/npm-run-script#description).
|
|
260
259
|
*/
|
|
261
260
|
function getCwd() {
|
|
262
|
-
return process.env.INIT_CWD?.startsWith(workspaceRoot)
|
|
261
|
+
return process.env.INIT_CWD?.startsWith(devkit_exports_1.workspaceRoot)
|
|
263
262
|
? process.env.INIT_CWD
|
|
264
263
|
: process.cwd();
|
|
265
264
|
}
|
|
266
265
|
function getRelativeCwd() {
|
|
267
|
-
return normalizePath((0, path_1.relative)(workspaceRoot, getCwd())).replace(/\/$/, '');
|
|
266
|
+
return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd())).replace(/\/$/, '');
|
|
268
267
|
}
|
|
269
268
|
/**
|
|
270
269
|
* Function for setting cwd during testing
|
|
271
270
|
*/
|
|
272
271
|
function setCwd(path) {
|
|
273
|
-
process.env.INIT_CWD = (0, path_1.join)(workspaceRoot, path);
|
|
272
|
+
process.env.INIT_CWD = (0, path_1.join)(devkit_exports_1.workspaceRoot, path);
|
|
274
273
|
}
|
|
275
274
|
exports.setCwd = setCwd;
|
|
276
275
|
function parseNameForAsProvided(rawName) {
|
|
277
|
-
const directory = normalizePath(rawName);
|
|
276
|
+
const directory = (0, devkit_exports_1.normalizePath)(rawName);
|
|
278
277
|
if (rawName.includes('@')) {
|
|
279
278
|
const index = directory.lastIndexOf('@');
|
|
280
279
|
if (index === 0) {
|
|
@@ -291,7 +290,7 @@ function parseNameForAsProvided(rawName) {
|
|
|
291
290
|
return { name: rawName, directory: undefined };
|
|
292
291
|
}
|
|
293
292
|
function parseNameForDerived(rawName) {
|
|
294
|
-
const parsedName = normalizePath(rawName).split('/');
|
|
293
|
+
const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
|
|
295
294
|
const name = parsedName.pop();
|
|
296
295
|
const directory = parsedName.length ? parsedName.join('/') : undefined;
|
|
297
296
|
return { name, directory };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateTsConfigsToJs = void 0;
|
|
4
|
-
const
|
|
5
|
-
const { updateJson } = (0, nx_1.requireNx)();
|
|
4
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
5
|
function updateTsConfigsToJs(tree, options) {
|
|
7
6
|
let updateConfigPath;
|
|
8
7
|
const paths = {
|
|
@@ -19,7 +18,7 @@ function updateTsConfigsToJs(tree, options) {
|
|
|
19
18
|
}
|
|
20
19
|
throw new Error(`project is missing tsconfig.lib.json or tsconfig.app.json`);
|
|
21
20
|
};
|
|
22
|
-
updateJson(tree, paths.tsConfig, (json) => {
|
|
21
|
+
(0, devkit_exports_1.updateJson)(tree, paths.tsConfig, (json) => {
|
|
23
22
|
if (json.compilerOptions) {
|
|
24
23
|
json.compilerOptions.allowJs = true;
|
|
25
24
|
}
|
|
@@ -35,7 +34,7 @@ function updateTsConfigsToJs(tree, options) {
|
|
|
35
34
|
if (projectType === 'application') {
|
|
36
35
|
updateConfigPath = paths.tsConfigApp;
|
|
37
36
|
}
|
|
38
|
-
updateJson(tree, updateConfigPath, (json) => {
|
|
37
|
+
(0, devkit_exports_1.updateJson)(tree, updateConfigPath, (json) => {
|
|
39
38
|
json.include = uniq([...json.include, 'src/**/*.js']);
|
|
40
39
|
json.exclude = uniq([
|
|
41
40
|
...json.exclude,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Tree } from 'nx/src/
|
|
1
|
+
import type { Tree } from 'nx/src/devkit-exports';
|
|
2
2
|
export default function replacePackage(tree: Tree): Promise<void>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { GeneratorCallback } from 'nx/src/config/misc-interfaces';
|
|
1
|
+
import { GeneratorCallback, Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
declare const _default: (tree: Tree) => Promise<GeneratorCallback | void>;
|
|
4
3
|
export default _default;
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const visit_not_ignored_files_1 = require("../../generators/visit-not-ignored-files");
|
|
4
4
|
const format_files_1 = require("../../generators/format-files");
|
|
5
|
-
const nx_1 = require("../../../nx");
|
|
6
5
|
const package_json_1 = require("../../utils/package-json");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
8
|
-
const
|
|
7
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
9
8
|
let tsModule;
|
|
10
9
|
const MODULE_FEDERATION_PUBLIC_TOKENS = [
|
|
11
10
|
'AdditionalSharedConfig',
|
|
@@ -45,7 +44,7 @@ exports.default = async (tree) => {
|
|
|
45
44
|
});
|
|
46
45
|
if (hasFileToMigrate) {
|
|
47
46
|
await (0, format_files_1.formatFiles)(tree);
|
|
48
|
-
const pkgJson = readJson(tree, 'package.json');
|
|
47
|
+
const pkgJson = (0, devkit_exports_1.readJson)(tree, 'package.json');
|
|
49
48
|
const nxVersion = pkgJson.devDependencies?.['nx'] ??
|
|
50
49
|
pkgJson.dependencies?.['nx'] ??
|
|
51
50
|
'17.0.0';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PackageManager } from 'nx/src/utils/package-manager';
|
|
1
|
+
import { PackageManager, Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
/**
|
|
4
3
|
* Runs `npm install` or `yarn install`. It will skip running the install if
|
|
5
4
|
* `package.json` hasn't changed at all or it hasn't changed since the last invocation.
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.installPackagesTask = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const
|
|
7
|
-
const { detectPackageManager, getPackageManagerCommand, joinPathFragments } = (0, nx_1.requireNx)();
|
|
6
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
8
7
|
/**
|
|
9
8
|
* Runs `npm install` or `yarn install`. It will skip running the install if
|
|
10
9
|
* `package.json` hasn't changed at all or it hasn't changed since the last invocation.
|
|
@@ -12,19 +11,19 @@ const { detectPackageManager, getPackageManagerCommand, joinPathFragments } = (0
|
|
|
12
11
|
* @param tree - the file system tree
|
|
13
12
|
* @param alwaysRun - always run the command even if `package.json` hasn't changed.
|
|
14
13
|
*/
|
|
15
|
-
function installPackagesTask(tree, alwaysRun = false, cwd = '', packageManager = detectPackageManager(cwd)) {
|
|
14
|
+
function installPackagesTask(tree, alwaysRun = false, cwd = '', packageManager = (0, devkit_exports_1.detectPackageManager)(cwd)) {
|
|
16
15
|
if (!tree
|
|
17
16
|
.listChanges()
|
|
18
|
-
.find((f) => f.path === joinPathFragments(cwd, 'package.json')) &&
|
|
17
|
+
.find((f) => f.path === (0, devkit_exports_1.joinPathFragments)(cwd, 'package.json')) &&
|
|
19
18
|
!alwaysRun) {
|
|
20
19
|
return;
|
|
21
20
|
}
|
|
22
|
-
const packageJsonValue = tree.read(joinPathFragments(cwd, 'package.json'), 'utf-8');
|
|
21
|
+
const packageJsonValue = tree.read((0, devkit_exports_1.joinPathFragments)(cwd, 'package.json'), 'utf-8');
|
|
23
22
|
let storedPackageJsonValue = global['__packageJsonInstallCache__'];
|
|
24
23
|
// Don't install again if install was already executed with package.json
|
|
25
24
|
if (storedPackageJsonValue != packageJsonValue || alwaysRun) {
|
|
26
25
|
global['__packageJsonInstallCache__'] = packageJsonValue;
|
|
27
|
-
const pmc = getPackageManagerCommand(packageManager);
|
|
26
|
+
const pmc = (0, devkit_exports_1.getPackageManagerCommand)(packageManager);
|
|
28
27
|
const execSyncOptions = {
|
|
29
28
|
cwd: (0, path_1.join)(tree.root, cwd),
|
|
30
29
|
stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateNodes, ProjectGraph, Tree } from 'nx/src/devkit-exports';
|
|
2
2
|
/**
|
|
3
3
|
* Iterates through various forms of plugin options to find the one which does not conflict with the current graph
|
|
4
4
|
|
package/src/utils/add-plugin.js
CHANGED
|
@@ -2,29 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateCombinations = exports.addPlugin = void 0;
|
|
4
4
|
const yargs = require("yargs-parser");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
7
7
|
/**
|
|
8
8
|
* Iterates through various forms of plugin options to find the one which does not conflict with the current graph
|
|
9
9
|
|
|
10
10
|
*/
|
|
11
11
|
async function addPlugin(tree, graph, pluginName, createNodesTuple, options, shouldUpdatePackageJsonScripts) {
|
|
12
12
|
const graphNodes = Object.values(graph.nodes);
|
|
13
|
-
const nxJson = readNxJson(tree);
|
|
13
|
+
const nxJson = (0, devkit_exports_1.readNxJson)(tree);
|
|
14
14
|
let pluginOptions;
|
|
15
15
|
let projConfigs;
|
|
16
16
|
const combinations = generateCombinations(options);
|
|
17
17
|
optionsLoop: for (const _pluginOptions of combinations) {
|
|
18
18
|
pluginOptions = _pluginOptions;
|
|
19
19
|
nxJson.plugins ??= [];
|
|
20
|
-
if (nxJson.plugins.some((p) => typeof p === 'string'
|
|
20
|
+
if (nxJson.plugins.some((p) => typeof p === 'string'
|
|
21
|
+
? p === pluginName
|
|
22
|
+
: p.plugin === pluginName && !p.include)) {
|
|
21
23
|
// Plugin has already been added
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
global.NX_GRAPH_CREATION = true;
|
|
25
27
|
try {
|
|
26
|
-
projConfigs = await retrieveProjectConfigurations([
|
|
27
|
-
new LoadedNxPlugin({
|
|
28
|
+
projConfigs = await (0, devkit_internals_1.retrieveProjectConfigurations)([
|
|
29
|
+
new devkit_internals_1.LoadedNxPlugin({
|
|
28
30
|
name: pluginName,
|
|
29
31
|
createNodes: createNodesTuple,
|
|
30
32
|
}, {
|
|
@@ -35,7 +37,7 @@ async function addPlugin(tree, graph, pluginName, createNodesTuple, options, sho
|
|
|
35
37
|
}
|
|
36
38
|
catch (e) {
|
|
37
39
|
// Errors are okay for this because we're only running 1 plugin
|
|
38
|
-
if (e instanceof ProjectConfigurationsError) {
|
|
40
|
+
if (e instanceof devkit_internals_1.ProjectConfigurationsError) {
|
|
39
41
|
projConfigs = e.partialProjectConfigurationsResult;
|
|
40
42
|
}
|
|
41
43
|
else {
|
|
@@ -65,7 +67,7 @@ async function addPlugin(tree, graph, pluginName, createNodesTuple, options, sho
|
|
|
65
67
|
plugin: pluginName,
|
|
66
68
|
options: pluginOptions,
|
|
67
69
|
});
|
|
68
|
-
updateNxJson(tree, nxJson);
|
|
70
|
+
(0, devkit_exports_1.updateNxJson)(tree, nxJson);
|
|
69
71
|
if (shouldUpdatePackageJsonScripts) {
|
|
70
72
|
updatePackageScripts(tree, projConfigs);
|
|
71
73
|
}
|
|
@@ -82,7 +84,7 @@ function processProject(tree, projectRoot, projectConfiguration) {
|
|
|
82
84
|
if (!tree.exists(packageJsonPath)) {
|
|
83
85
|
return;
|
|
84
86
|
}
|
|
85
|
-
const packageJson = readJson(tree, packageJsonPath);
|
|
87
|
+
const packageJson = (0, devkit_exports_1.readJson)(tree, packageJsonPath);
|
|
86
88
|
if (!packageJson.scripts || !Object.keys(packageJson.scripts).length) {
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
@@ -173,7 +175,7 @@ function processProject(tree, projectRoot, projectConfiguration) {
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
|
-
writeJson(tree, packageJsonPath, packageJson);
|
|
178
|
+
(0, devkit_exports_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
177
179
|
}
|
|
178
180
|
function getInferredTargetCommands(project) {
|
|
179
181
|
const targetCommands = [];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CreateNodesContext } from 'nx/src/devkit-exports';
|
|
2
2
|
export declare function calculateHashForCreateNodes(projectRoot: string, options: object, context: CreateNodesContext, additionalGlobs?: string[]): string;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateHashForCreateNodes = void 0;
|
|
4
|
-
const nx_1 = require("../../nx");
|
|
5
4
|
const path_1 = require("path");
|
|
6
|
-
const
|
|
5
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
7
7
|
function calculateHashForCreateNodes(projectRoot, options, context, additionalGlobs = []) {
|
|
8
|
-
return hashArray([
|
|
9
|
-
hashWithWorkspaceContext(context.workspaceRoot, [
|
|
8
|
+
return (0, devkit_exports_1.hashArray)([
|
|
9
|
+
(0, devkit_internals_1.hashWithWorkspaceContext)(context.workspaceRoot, [
|
|
10
10
|
(0, path_1.join)(projectRoot, '**/*'),
|
|
11
11
|
...additionalGlobs,
|
|
12
12
|
]),
|
|
13
|
-
hashObject(options),
|
|
13
|
+
(0, devkit_internals_1.hashObject)(options),
|
|
14
14
|
]);
|
|
15
15
|
}
|
|
16
16
|
exports.calculateHashForCreateNodes = calculateHashForCreateNodes;
|
|
@@ -2,3 +2,4 @@ export declare let dynamicImport: Function;
|
|
|
2
2
|
export declare function loadConfigFile<T extends object = any>(configFilePath: string): Promise<T>;
|
|
3
3
|
export declare function getRootTsConfigPath(): string | null;
|
|
4
4
|
export declare function getRootTsConfigFileName(): string | null;
|
|
5
|
+
export declare function clearRequireCache(): void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRootTsConfigFileName = exports.getRootTsConfigPath = exports.loadConfigFile = exports.dynamicImport = void 0;
|
|
3
|
+
exports.clearRequireCache = exports.getRootTsConfigFileName = exports.getRootTsConfigPath = exports.loadConfigFile = exports.dynamicImport = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
|
-
const nx_1 = require("../../nx");
|
|
7
6
|
const node_url_1 = require("node:url");
|
|
8
|
-
const
|
|
7
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
8
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
9
9
|
exports.dynamicImport = new Function('modulePath', 'return import(modulePath);');
|
|
10
10
|
async function loadConfigFile(configFilePath) {
|
|
11
11
|
{
|
|
@@ -16,7 +16,7 @@ async function loadConfigFile(configFilePath) {
|
|
|
16
16
|
? (0, path_1.join)((0, path_1.dirname)(configFilePath), 'tsconfig.json')
|
|
17
17
|
: getRootTsConfigPath();
|
|
18
18
|
if (tsConfigPath) {
|
|
19
|
-
const unregisterTsProject = registerTsProject(tsConfigPath);
|
|
19
|
+
const unregisterTsProject = (0, devkit_internals_1.registerTsProject)(tsConfigPath);
|
|
20
20
|
try {
|
|
21
21
|
module = await load(configFilePath);
|
|
22
22
|
}
|
|
@@ -37,12 +37,12 @@ async function loadConfigFile(configFilePath) {
|
|
|
37
37
|
exports.loadConfigFile = loadConfigFile;
|
|
38
38
|
function getRootTsConfigPath() {
|
|
39
39
|
const tsConfigFileName = getRootTsConfigFileName();
|
|
40
|
-
return tsConfigFileName ? (0, path_1.join)(workspaceRoot, tsConfigFileName) : null;
|
|
40
|
+
return tsConfigFileName ? (0, path_1.join)(devkit_exports_1.workspaceRoot, tsConfigFileName) : null;
|
|
41
41
|
}
|
|
42
42
|
exports.getRootTsConfigPath = getRootTsConfigPath;
|
|
43
43
|
function getRootTsConfigFileName() {
|
|
44
44
|
for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
|
|
45
|
-
const pathExists = (0, fs_1.existsSync)((0, path_1.join)(workspaceRoot, tsConfigName));
|
|
45
|
+
const pathExists = (0, fs_1.existsSync)((0, path_1.join)(devkit_exports_1.workspaceRoot, tsConfigName));
|
|
46
46
|
if (pathExists) {
|
|
47
47
|
return tsConfigName;
|
|
48
48
|
}
|
|
@@ -50,15 +50,25 @@ function getRootTsConfigFileName() {
|
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
52
|
exports.getRootTsConfigFileName = getRootTsConfigFileName;
|
|
53
|
+
const packageInstallationDirectories = [
|
|
54
|
+
`${path_1.sep}node_modules${path_1.sep}`,
|
|
55
|
+
`${path_1.sep}.yarn${path_1.sep}`,
|
|
56
|
+
];
|
|
57
|
+
function clearRequireCache() {
|
|
58
|
+
for (const k of Object.keys(require.cache)) {
|
|
59
|
+
if (!packageInstallationDirectories.some((dir) => k.includes(dir))) {
|
|
60
|
+
delete require.cache[k];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.clearRequireCache = clearRequireCache;
|
|
53
65
|
/**
|
|
54
66
|
* Load the module after ensuring that the require cache is cleared.
|
|
55
67
|
*/
|
|
56
68
|
async function load(path) {
|
|
57
69
|
// Clear cache if the path is in the cache
|
|
58
70
|
if (require.cache[path]) {
|
|
59
|
-
|
|
60
|
-
delete require.cache[k];
|
|
61
|
-
}
|
|
71
|
+
clearRequireCache();
|
|
62
72
|
}
|
|
63
73
|
try {
|
|
64
74
|
// Try using `require` first, which works for CJS modules.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertNxExecutor = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const package_json_1 = require("./package-json");
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
6
7
|
/**
|
|
7
8
|
* Convert an Nx Executor into an Angular Devkit Builder
|
|
8
9
|
*
|
|
@@ -11,21 +12,25 @@ const { Workspaces, readNxJsonFromDisk, retrieveProjectConfigurationsWithAngular
|
|
|
11
12
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
12
13
|
function convertNxExecutor(executor) {
|
|
13
14
|
const builderFunction = (options, builderContext) => {
|
|
14
|
-
const
|
|
15
|
-
const nxJsonConfiguration = readNxJsonFromDisk
|
|
16
|
-
? readNxJsonFromDisk(builderContext.workspaceRoot)
|
|
17
|
-
: // TODO(v19): remove readNxJson. This is to be backwards compatible with Nx 16.5 and below.
|
|
18
|
-
workspaces.readNxJson();
|
|
15
|
+
const nxJsonConfiguration = (0, devkit_internals_1.readNxJsonFromDisk)(builderContext.workspaceRoot);
|
|
19
16
|
const promise = async () => {
|
|
20
|
-
const projectsConfigurations =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
const projectsConfigurations = {
|
|
18
|
+
version: 2,
|
|
19
|
+
projects: await (0, devkit_internals_1.retrieveProjectConfigurationsWithAngularProjects)(builderContext.workspaceRoot, nxJsonConfiguration).then((p) => {
|
|
20
|
+
if (p.projectNodes) {
|
|
21
|
+
return p.projectNodes;
|
|
22
|
+
}
|
|
23
|
+
// v18.3.4 changed projects to be keyed by root
|
|
24
|
+
// rather than project name
|
|
25
|
+
if ((0, semver_1.lt)(package_json_1.NX_VERSION, '18.3.4')) {
|
|
26
|
+
return p.projects;
|
|
27
|
+
}
|
|
28
|
+
if (devkit_internals_1.readProjectConfigurationsFromRootMap) {
|
|
29
|
+
return (0, devkit_internals_1.readProjectConfigurationsFromRootMap)(p.projects);
|
|
30
|
+
}
|
|
31
|
+
throw new Error('Unable to successfully map Nx executor -> Angular Builder');
|
|
32
|
+
}),
|
|
33
|
+
};
|
|
29
34
|
const context = {
|
|
30
35
|
root: builderContext.workspaceRoot,
|
|
31
36
|
projectName: builderContext.target.project,
|