@nx/workspace 16.8.0-beta.7 → 16.8.0
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/generators.json +1 -1
- package/package.json +30 -29
- package/src/generators/convert-to-monorepo/convert-to-monorepo.js +1 -1
- package/src/generators/move/lib/check-destination.d.ts +3 -3
- package/src/generators/move/lib/check-destination.js +4 -6
- package/src/generators/move/lib/normalize-schema.d.ts +1 -1
- package/src/generators/move/lib/normalize-schema.js +166 -8
- package/src/generators/move/lib/run-angular-plugin.d.ts +3 -0
- package/src/generators/move/lib/run-angular-plugin.js +19 -0
- package/src/generators/move/lib/update-imports.js +1 -2
- package/src/generators/move/lib/update-jest-config.js +18 -6
- package/src/generators/move/lib/update-package-json.js +3 -0
- package/src/generators/move/lib/utils.js +0 -3
- package/src/generators/move/move.d.ts +1 -0
- package/src/generators/move/move.js +13 -4
- package/src/generators/move/schema.d.ts +3 -2
- package/src/generators/move/schema.json +12 -0
- package/src/generators/new/generate-workspace-files.js +0 -2
- package/src/generators/preset/preset.js +1 -1
- package/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.js +3 -3
- package/src/utilities/get-import-path.d.ts +1 -0
- package/src/utilities/get-import-path.js +2 -1
- package/src/generators/new/files-integrated-repo/tools/tsconfig.tools.json +0 -12
package/generators.json
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"hidden": true
|
|
48
48
|
},
|
|
49
49
|
"move": {
|
|
50
|
-
"factory": "./src/generators/move/move#
|
|
50
|
+
"factory": "./src/generators/move/move#moveGeneratorInternal",
|
|
51
51
|
"schema": "./src/generators/move/schema.json",
|
|
52
52
|
"aliases": ["mv"],
|
|
53
53
|
"description": "Move an application or library to another folder."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/workspace",
|
|
3
|
-
"version": "16.8.0
|
|
3
|
+
"version": "16.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Workspace plugin contains executors and generators that are useful for any Nx workspace. It should be present in every Nx workspace and other plugins build on it.",
|
|
6
6
|
"repository": {
|
|
@@ -33,39 +33,40 @@
|
|
|
33
33
|
"requirements": {},
|
|
34
34
|
"migrations": "./migrations.json",
|
|
35
35
|
"packageGroup": {
|
|
36
|
-
"@nrwl/js": "16.8.0
|
|
37
|
-
"@nrwl/jest": "16.8.0
|
|
38
|
-
"@nrwl/linter": "16.8.0
|
|
39
|
-
"@nrwl/angular": "16.8.0
|
|
40
|
-
"@nrwl/cypress": "16.8.0
|
|
41
|
-
"@nrwl/detox": "16.8.0
|
|
42
|
-
"@nrwl/devkit": "16.8.0
|
|
43
|
-
"@nrwl/esbuild": "16.8.0
|
|
44
|
-
"@nrwl/eslint-plugin-nx": "16.8.0
|
|
45
|
-
"@nrwl/expo": "16.8.0
|
|
46
|
-
"@nrwl/express": "16.8.0
|
|
47
|
-
"@nrwl/nest": "16.8.0
|
|
48
|
-
"@nrwl/next": "16.8.0
|
|
49
|
-
"@nrwl/node": "16.8.0
|
|
36
|
+
"@nrwl/js": "16.8.0",
|
|
37
|
+
"@nrwl/jest": "16.8.0",
|
|
38
|
+
"@nrwl/linter": "16.8.0",
|
|
39
|
+
"@nrwl/angular": "16.8.0",
|
|
40
|
+
"@nrwl/cypress": "16.8.0",
|
|
41
|
+
"@nrwl/detox": "16.8.0",
|
|
42
|
+
"@nrwl/devkit": "16.8.0",
|
|
43
|
+
"@nrwl/esbuild": "16.8.0",
|
|
44
|
+
"@nrwl/eslint-plugin-nx": "16.8.0",
|
|
45
|
+
"@nrwl/expo": "16.8.0",
|
|
46
|
+
"@nrwl/express": "16.8.0",
|
|
47
|
+
"@nrwl/nest": "16.8.0",
|
|
48
|
+
"@nrwl/next": "16.8.0",
|
|
49
|
+
"@nrwl/node": "16.8.0",
|
|
50
50
|
"nx-cloud": "latest",
|
|
51
|
-
"@nrwl/nx-plugin": "16.8.0
|
|
52
|
-
"@nrwl/react-native": "16.8.0
|
|
53
|
-
"@nrwl/react": "16.8.0
|
|
54
|
-
"@nrwl/rollup": "16.8.0
|
|
55
|
-
"@nrwl/storybook": "16.8.0
|
|
56
|
-
"@nrwl/tao": "16.8.0
|
|
57
|
-
"@nrwl/vite": "16.8.0
|
|
58
|
-
"@nrwl/web": "16.8.0
|
|
59
|
-
"@nrwl/webpack": "16.8.0
|
|
60
|
-
"nx": "16.8.0
|
|
51
|
+
"@nrwl/nx-plugin": "16.8.0",
|
|
52
|
+
"@nrwl/react-native": "16.8.0",
|
|
53
|
+
"@nrwl/react": "16.8.0",
|
|
54
|
+
"@nrwl/rollup": "16.8.0",
|
|
55
|
+
"@nrwl/storybook": "16.8.0",
|
|
56
|
+
"@nrwl/tao": "16.8.0",
|
|
57
|
+
"@nrwl/vite": "16.8.0",
|
|
58
|
+
"@nrwl/web": "16.8.0",
|
|
59
|
+
"@nrwl/webpack": "16.8.0",
|
|
60
|
+
"nx": "16.8.0"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@nrwl/workspace": "16.8.0
|
|
65
|
-
"@nx/devkit": "16.8.0
|
|
64
|
+
"@nrwl/workspace": "16.8.0",
|
|
65
|
+
"@nx/devkit": "16.8.0",
|
|
66
66
|
"chalk": "^4.1.0",
|
|
67
|
+
"enquirer": "~2.3.6",
|
|
67
68
|
"ignore": "^5.0.4",
|
|
68
|
-
"nx": "16.8.0
|
|
69
|
+
"nx": "16.8.0",
|
|
69
70
|
"rxjs": "^7.8.0",
|
|
70
71
|
"tslib": "^2.3.0",
|
|
71
72
|
"yargs-parser": "21.1.1"
|
|
@@ -74,5 +75,5 @@
|
|
|
74
75
|
"access": "public"
|
|
75
76
|
},
|
|
76
77
|
"type": "commonjs",
|
|
77
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "af53c7cfb21c0ebc7be2dab33b712f8d10bc81f7"
|
|
78
79
|
}
|
|
@@ -28,8 +28,8 @@ async function monorepoGenerator(tree, options) {
|
|
|
28
28
|
destination: project.projectType === 'application'
|
|
29
29
|
? (0, devkit_1.joinPathFragments)(appsDir, project.root === '.' ? project.name : project.root)
|
|
30
30
|
: (0, devkit_1.joinPathFragments)(libsDir, project.root === '.' ? project.name : project.root),
|
|
31
|
-
destinationRelativeToRoot: true,
|
|
32
31
|
updateImportPath: project.projectType === 'library',
|
|
32
|
+
projectNameAndRootFormat: 'as-provided',
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
import type { NormalizedSchema } from '../schema';
|
|
3
3
|
/**
|
|
4
4
|
* Checks whether the destination folder is valid
|
|
5
5
|
*
|
|
@@ -8,4 +8,4 @@ import { Schema } from '../schema';
|
|
|
8
8
|
*
|
|
9
9
|
* @param schema The options provided to the schematic
|
|
10
10
|
*/
|
|
11
|
-
export declare function checkDestination(tree: Tree, schema:
|
|
11
|
+
export declare function checkDestination(tree: Tree, schema: NormalizedSchema, providedDestination: string): void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkDestination = void 0;
|
|
4
|
-
const utils_1 = require("./utils");
|
|
5
4
|
/**
|
|
6
5
|
* Checks whether the destination folder is valid
|
|
7
6
|
*
|
|
@@ -10,13 +9,12 @@ const utils_1 = require("./utils");
|
|
|
10
9
|
*
|
|
11
10
|
* @param schema The options provided to the schematic
|
|
12
11
|
*/
|
|
13
|
-
function checkDestination(tree, schema,
|
|
14
|
-
const INVALID_DESTINATION = `Invalid destination: [${
|
|
15
|
-
if (
|
|
12
|
+
function checkDestination(tree, schema, providedDestination) {
|
|
13
|
+
const INVALID_DESTINATION = `Invalid destination: [${providedDestination}]`;
|
|
14
|
+
if (providedDestination.includes('..')) {
|
|
16
15
|
throw new Error(`${INVALID_DESTINATION} - Please specify explicit path.`);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
if (tree.children(destination).length > 0) {
|
|
17
|
+
if (tree.children(schema.relativeToRootDestination).length > 0) {
|
|
20
18
|
throw new Error(`${INVALID_DESTINATION} - Path is not empty.`);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
2
|
import type { NormalizedSchema, Schema } from '../schema';
|
|
3
|
-
export declare function normalizeSchema(tree: Tree, schema: Schema, projectConfiguration: ProjectConfiguration): NormalizedSchema
|
|
3
|
+
export declare function normalizeSchema(tree: Tree, schema: Schema, projectConfiguration: ProjectConfiguration): Promise<NormalizedSchema>;
|
|
@@ -1,18 +1,176 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeSchema = void 0;
|
|
4
|
-
const
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const enquirer_1 = require("enquirer");
|
|
5
6
|
const get_import_path_1 = require("../../../utilities/get-import-path");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const newProjectName =
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
async function normalizeSchema(tree, schema, projectConfiguration) {
|
|
9
|
+
const { destination, newProjectName, importPath } = await determineProjectNameAndRootOptions(tree, schema, projectConfiguration);
|
|
9
10
|
return {
|
|
10
11
|
...schema,
|
|
11
|
-
destination,
|
|
12
|
-
importPath
|
|
13
|
-
(0, utils_1.normalizePathSlashes)((0, get_import_path_1.getImportPath)(tree, destination)),
|
|
12
|
+
destination: (0, utils_1.normalizePathSlashes)(schema.destination),
|
|
13
|
+
importPath,
|
|
14
14
|
newProjectName,
|
|
15
|
-
relativeToRootDestination:
|
|
15
|
+
relativeToRootDestination: destination,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
exports.normalizeSchema = normalizeSchema;
|
|
19
|
+
async function determineProjectNameAndRootOptions(tree, options, projectConfiguration) {
|
|
20
|
+
validateName(options.newProjectName, options.projectNameAndRootFormat, projectConfiguration);
|
|
21
|
+
const formats = getProjectNameAndRootFormats(tree, options, projectConfiguration);
|
|
22
|
+
const format = options.projectNameAndRootFormat ??
|
|
23
|
+
(await determineFormat(tree, formats, options));
|
|
24
|
+
return formats[format];
|
|
25
|
+
}
|
|
26
|
+
function validateName(name, projectNameAndRootFormat, projectConfiguration) {
|
|
27
|
+
if (!name) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (projectNameAndRootFormat === 'derived' && name.startsWith('@')) {
|
|
31
|
+
throw new Error(`The new project name "${name}" cannot start with "@" when the "projectNameAndRootFormat" is "derived".`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Matches two types of project names:
|
|
35
|
+
*
|
|
36
|
+
* 1. Valid npm package names (e.g., '@scope/name' or 'name').
|
|
37
|
+
* 2. Names starting with a letter and can contain any character except whitespace and ':'.
|
|
38
|
+
*
|
|
39
|
+
* The second case is to support the legacy behavior (^[a-zA-Z].*$) with the difference
|
|
40
|
+
* that it doesn't allow the ":" character. It was wrong to allow it because it would
|
|
41
|
+
* conflict with the notation for tasks.
|
|
42
|
+
*/
|
|
43
|
+
const libraryPattern = '(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$';
|
|
44
|
+
const appPattern = '^[a-zA-Z][^:]*$';
|
|
45
|
+
if (projectConfiguration.projectType === 'application') {
|
|
46
|
+
const validationRegex = new RegExp(appPattern);
|
|
47
|
+
if (!validationRegex.test(name)) {
|
|
48
|
+
throw new Error(`The new project name should match the pattern "${appPattern}". The provided value "${name}" does not match.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (projectConfiguration.projectType === 'library') {
|
|
52
|
+
const validationRegex = new RegExp(libraryPattern);
|
|
53
|
+
if (!validationRegex.test(name)) {
|
|
54
|
+
throw new Error(`The new project name should match the pattern "${libraryPattern}". The provided value "${name}" does not match.`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function getProjectNameAndRootFormats(tree, schema, projectConfiguration) {
|
|
59
|
+
let destination = (0, utils_1.normalizePathSlashes)(schema.destination);
|
|
60
|
+
const normalizedNewProjectName = schema.newProjectName
|
|
61
|
+
? (0, devkit_1.names)(schema.newProjectName).fileName
|
|
62
|
+
: undefined;
|
|
63
|
+
const asProvidedProjectName = normalizedNewProjectName ?? schema.projectName;
|
|
64
|
+
const asProvidedDestination = destination;
|
|
65
|
+
if (normalizedNewProjectName?.startsWith('@')) {
|
|
66
|
+
return {
|
|
67
|
+
'as-provided': {
|
|
68
|
+
destination: asProvidedDestination,
|
|
69
|
+
importPath: schema.importPath ??
|
|
70
|
+
// keep the existing import path if the name didn't change
|
|
71
|
+
(normalizedNewProjectName &&
|
|
72
|
+
schema.projectName !== normalizedNewProjectName
|
|
73
|
+
? asProvidedProjectName
|
|
74
|
+
: undefined),
|
|
75
|
+
newProjectName: asProvidedProjectName,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
let npmScope;
|
|
80
|
+
let asProvidedImportPath = schema.importPath;
|
|
81
|
+
if (!asProvidedImportPath &&
|
|
82
|
+
schema.newProjectName &&
|
|
83
|
+
projectConfiguration.projectType === 'library') {
|
|
84
|
+
npmScope = (0, get_import_path_1.getNpmScope)(tree);
|
|
85
|
+
asProvidedImportPath = npmScope
|
|
86
|
+
? `${npmScope === '@' ? '' : '@'}${npmScope}/${asProvidedProjectName}`
|
|
87
|
+
: asProvidedProjectName;
|
|
88
|
+
}
|
|
89
|
+
const derivedProjectName = schema.newProjectName ?? (0, utils_1.getNewProjectName)(destination);
|
|
90
|
+
const derivedDestination = (0, utils_1.getDestination)(tree, schema, projectConfiguration);
|
|
91
|
+
let derivedImportPath;
|
|
92
|
+
if (projectConfiguration.projectType === 'library') {
|
|
93
|
+
derivedImportPath =
|
|
94
|
+
schema.importPath ??
|
|
95
|
+
(0, utils_1.normalizePathSlashes)((0, get_import_path_1.getImportPath)(tree, destination));
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
'as-provided': {
|
|
99
|
+
destination: asProvidedDestination,
|
|
100
|
+
newProjectName: asProvidedProjectName,
|
|
101
|
+
importPath: asProvidedImportPath,
|
|
102
|
+
},
|
|
103
|
+
derived: {
|
|
104
|
+
destination: derivedDestination,
|
|
105
|
+
newProjectName: derivedProjectName,
|
|
106
|
+
importPath: derivedImportPath,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function determineFormat(tree, formats, schema) {
|
|
111
|
+
if (!formats.derived) {
|
|
112
|
+
return 'as-provided';
|
|
113
|
+
}
|
|
114
|
+
if (process.env.NX_INTERACTIVE !== 'true' || !isTTY()) {
|
|
115
|
+
return 'derived';
|
|
116
|
+
}
|
|
117
|
+
const asProvidedDescription = `As provided:
|
|
118
|
+
Name: ${formats['as-provided'].newProjectName}
|
|
119
|
+
Destination: ${formats['as-provided'].destination}`;
|
|
120
|
+
const asProvidedSelectedValue = `${formats['as-provided'].newProjectName} @ ${formats['as-provided'].destination}`;
|
|
121
|
+
const derivedDescription = `Derived:
|
|
122
|
+
Name: ${formats['derived'].newProjectName}
|
|
123
|
+
Destination: ${formats['derived'].destination}`;
|
|
124
|
+
const derivedSelectedValue = `${formats['derived'].newProjectName} @ ${formats['derived'].destination}`;
|
|
125
|
+
const result = await (0, enquirer_1.prompt)({
|
|
126
|
+
type: 'select',
|
|
127
|
+
name: 'format',
|
|
128
|
+
message: 'What should be the new project name and where should it be moved to?',
|
|
129
|
+
choices: [
|
|
130
|
+
{
|
|
131
|
+
message: asProvidedDescription,
|
|
132
|
+
name: asProvidedSelectedValue,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
message: derivedDescription,
|
|
136
|
+
name: derivedSelectedValue,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
initial: 'as-provided',
|
|
140
|
+
}).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived');
|
|
141
|
+
const callingGenerator = process.env.NX_ANGULAR_MOVE_INVOKED === 'true'
|
|
142
|
+
? '@nx/angular:move'
|
|
143
|
+
: '@nx/workspace:move';
|
|
144
|
+
const deprecationWarning = (0, devkit_1.stripIndents) `
|
|
145
|
+
In Nx 18, the project name and destination will no longer be derived.
|
|
146
|
+
Please provide the exact new project name and destination in the future.`;
|
|
147
|
+
if (result === 'as-provided') {
|
|
148
|
+
const { saveDefault } = await (0, enquirer_1.prompt)({
|
|
149
|
+
type: 'confirm',
|
|
150
|
+
message: `Would you like to configure Nx to always take the project name and destination as provided for ${callingGenerator}?`,
|
|
151
|
+
name: 'saveDefault',
|
|
152
|
+
initial: true,
|
|
153
|
+
});
|
|
154
|
+
if (saveDefault) {
|
|
155
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
156
|
+
nxJson.generators ??= {};
|
|
157
|
+
nxJson.generators[callingGenerator] ??= {};
|
|
158
|
+
nxJson.generators[callingGenerator].projectNameAndRootFormat = result;
|
|
159
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
devkit_1.logger.warn(deprecationWarning);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const example = `Example: nx g ${callingGenerator} --projectName ${schema.projectName} --destination ${formats[result].destination}` +
|
|
167
|
+
(schema.projectName !== formats[result].newProjectName
|
|
168
|
+
? ` --newProjectName ${formats[result].newProjectName}`
|
|
169
|
+
: '');
|
|
170
|
+
devkit_1.logger.warn(deprecationWarning + '\n' + example);
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
function isTTY() {
|
|
175
|
+
return !!process.stdout.isTTY && process.env['CI'] !== 'true';
|
|
176
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runAngularPlugin = void 0;
|
|
4
|
+
async function runAngularPlugin(tree, schema) {
|
|
5
|
+
let move;
|
|
6
|
+
try {
|
|
7
|
+
// nx-ignore-next-line
|
|
8
|
+
move = require('@nx/angular/src/generators/move/move-impl').move;
|
|
9
|
+
}
|
|
10
|
+
catch { }
|
|
11
|
+
if (!move) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
await move(tree, {
|
|
15
|
+
oldProjectName: schema.projectName,
|
|
16
|
+
newProjectName: schema.newProjectName,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.runAngularPlugin = runAngularPlugin;
|
|
@@ -15,7 +15,6 @@ let tsModule;
|
|
|
15
15
|
*/
|
|
16
16
|
function updateImports(tree, schema, project) {
|
|
17
17
|
if (project.projectType === 'application') {
|
|
18
|
-
// These shouldn't be imported anywhere?
|
|
19
18
|
return;
|
|
20
19
|
}
|
|
21
20
|
const { libsDir } = (0, devkit_1.getWorkspaceLayout)(tree);
|
|
@@ -44,7 +43,7 @@ function updateImports(tree, schema, project) {
|
|
|
44
43
|
// if the import path doesn't start with the main entry point import path,
|
|
45
44
|
// it's a custom import path we don't know how to update the name, we keep
|
|
46
45
|
// it as-is, but we'll update the path it points to
|
|
47
|
-
to: p.startsWith(mainEntryPointImportPath)
|
|
46
|
+
to: schema.importPath && p.startsWith(mainEntryPointImportPath)
|
|
48
47
|
? p.replace(mainEntryPointImportPath, schema.importPath)
|
|
49
48
|
: null,
|
|
50
49
|
})),
|
|
@@ -13,12 +13,24 @@ function updateJestConfig(tree, schema, project) {
|
|
|
13
13
|
const jestConfigPath = path.join(schema.relativeToRootDestination, 'jest.config.ts');
|
|
14
14
|
if (tree.exists(jestConfigPath)) {
|
|
15
15
|
const oldContent = tree.read(jestConfigPath, 'utf-8');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.replace(findName, `'${schema.newProjectName}'`)
|
|
21
|
-
|
|
16
|
+
let newContent = oldContent;
|
|
17
|
+
if (schema.projectName !== schema.newProjectName) {
|
|
18
|
+
// ensure both single and double quotes are replaced
|
|
19
|
+
const findName = new RegExp(`'${schema.projectName}'|"${schema.projectName}"|\`${schema.projectName}\``, 'g');
|
|
20
|
+
newContent = oldContent.replace(findName, `'${schema.newProjectName}'`);
|
|
21
|
+
}
|
|
22
|
+
let dirRegex = new RegExp(`\\/${project.root}\\/`, 'g');
|
|
23
|
+
if (dirRegex.test(newContent)) {
|
|
24
|
+
newContent = newContent.replace(dirRegex, `/${schema.relativeToRootDestination}/`);
|
|
25
|
+
}
|
|
26
|
+
dirRegex = new RegExp(`\\/${project.root}['"\`]`, 'g');
|
|
27
|
+
if (dirRegex.test(newContent)) {
|
|
28
|
+
newContent = newContent.replace(dirRegex, `/${schema.relativeToRootDestination}'`);
|
|
29
|
+
}
|
|
30
|
+
dirRegex = new RegExp(`['"\`]${project.root}\\/`, 'g');
|
|
31
|
+
if (dirRegex.test(newContent)) {
|
|
32
|
+
newContent = newContent.replace(dirRegex, `'${schema.relativeToRootDestination}/`);
|
|
33
|
+
}
|
|
22
34
|
tree.write(jestConfigPath, newContent);
|
|
23
35
|
}
|
|
24
36
|
// update root jest.config.ts
|
|
@@ -9,6 +9,9 @@ const path = require("path");
|
|
|
9
9
|
* @param schema The options provided to the schematic
|
|
10
10
|
*/
|
|
11
11
|
function updatePackageJson(tree, schema) {
|
|
12
|
+
if (!schema.importPath) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
12
15
|
const packageJsonPath = path.join(schema.relativeToRootDestination, 'package.json');
|
|
13
16
|
if (!tree.exists(packageJsonPath)) {
|
|
14
17
|
// nothing to do
|
|
@@ -10,9 +10,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
10
10
|
* folders. In that case, they're on their own :/
|
|
11
11
|
*/
|
|
12
12
|
function getDestination(host, schema, project) {
|
|
13
|
-
if (schema.destinationRelativeToRoot) {
|
|
14
|
-
return schema.destination;
|
|
15
|
-
}
|
|
16
13
|
const projectType = project.projectType;
|
|
17
14
|
const workspaceLayout = (0, devkit_1.getWorkspaceLayout)(host);
|
|
18
15
|
let rootFolder = workspaceLayout.libsDir;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
2
|
import { Schema } from './schema';
|
|
3
3
|
export declare function moveGenerator(tree: Tree, rawSchema: Schema): Promise<void>;
|
|
4
|
+
export declare function moveGeneratorInternal(tree: Tree, rawSchema: Schema): Promise<void>;
|
|
4
5
|
export default moveGenerator;
|
|
5
6
|
export declare const moveSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.moveSchematic = exports.moveGenerator = void 0;
|
|
3
|
+
exports.moveSchematic = exports.moveGeneratorInternal = exports.moveGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const check_destination_1 = require("./lib/check-destination");
|
|
6
6
|
const create_project_configuration_in_new_destination_1 = require("./lib/create-project-configuration-in-new-destination");
|
|
7
7
|
const move_project_files_1 = require("./lib/move-project-files");
|
|
8
8
|
const normalize_schema_1 = require("./lib/normalize-schema");
|
|
9
|
+
const run_angular_plugin_1 = require("./lib/run-angular-plugin");
|
|
9
10
|
const update_build_targets_1 = require("./lib/update-build-targets");
|
|
10
11
|
const update_cypress_config_1 = require("./lib/update-cypress-config");
|
|
11
12
|
const update_default_project_1 = require("./lib/update-default-project");
|
|
@@ -19,9 +20,16 @@ const update_readme_1 = require("./lib/update-readme");
|
|
|
19
20
|
const update_storybook_config_1 = require("./lib/update-storybook-config");
|
|
20
21
|
const extract_base_configs_1 = require("./lib/extract-base-configs");
|
|
21
22
|
async function moveGenerator(tree, rawSchema) {
|
|
23
|
+
await moveGeneratorInternal(tree, {
|
|
24
|
+
projectNameAndRootFormat: 'derived',
|
|
25
|
+
...rawSchema,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.moveGenerator = moveGenerator;
|
|
29
|
+
async function moveGeneratorInternal(tree, rawSchema) {
|
|
22
30
|
let projectConfig = (0, devkit_1.readProjectConfiguration)(tree, rawSchema.projectName);
|
|
23
|
-
(0,
|
|
24
|
-
|
|
31
|
+
const schema = await (0, normalize_schema_1.normalizeSchema)(tree, rawSchema, projectConfig);
|
|
32
|
+
(0, check_destination_1.checkDestination)(tree, schema, rawSchema.destination);
|
|
25
33
|
if (projectConfig.root === '.') {
|
|
26
34
|
(0, extract_base_configs_1.maybeExtractTsConfigBase)(tree);
|
|
27
35
|
await (0, extract_base_configs_1.maybeExtractJestConfigBase)(tree);
|
|
@@ -43,10 +51,11 @@ async function moveGenerator(tree, rawSchema) {
|
|
|
43
51
|
(0, update_build_targets_1.updateBuildTargets)(tree, schema);
|
|
44
52
|
(0, update_default_project_1.updateDefaultProject)(tree, schema);
|
|
45
53
|
(0, update_implicit_dependencies_1.updateImplicitDependencies)(tree, schema);
|
|
54
|
+
await (0, run_angular_plugin_1.runAngularPlugin)(tree, schema);
|
|
46
55
|
if (!schema.skipFormat) {
|
|
47
56
|
await (0, devkit_1.formatFiles)(tree);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
exports.
|
|
59
|
+
exports.moveGeneratorInternal = moveGeneratorInternal;
|
|
51
60
|
exports.default = moveGenerator;
|
|
52
61
|
exports.moveSchematic = (0, devkit_1.convertNxGenerator)(moveGenerator);
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
|
+
|
|
1
3
|
export interface Schema {
|
|
2
4
|
projectName: string;
|
|
3
5
|
destination: string;
|
|
4
6
|
importPath?: string;
|
|
5
7
|
updateImportPath: boolean;
|
|
6
8
|
skipFormat?: boolean;
|
|
7
|
-
destinationRelativeToRoot?: boolean;
|
|
8
9
|
newProjectName?: string;
|
|
10
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export interface NormalizedSchema extends Schema {
|
|
12
|
-
importPath: string;
|
|
13
14
|
relativeToRootDestination: string;
|
|
14
15
|
}
|
|
@@ -18,6 +18,13 @@
|
|
|
18
18
|
"description": "The name of the project to move.",
|
|
19
19
|
"x-dropdown": "projects"
|
|
20
20
|
},
|
|
21
|
+
"newProjectName": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"alias": "project",
|
|
24
|
+
"description": "The new name of the project after the move.",
|
|
25
|
+
"pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$",
|
|
26
|
+
"x-priority": "important"
|
|
27
|
+
},
|
|
21
28
|
"destination": {
|
|
22
29
|
"type": "string",
|
|
23
30
|
"description": "The folder to move the project into.",
|
|
@@ -26,6 +33,11 @@
|
|
|
26
33
|
"index": 0
|
|
27
34
|
}
|
|
28
35
|
},
|
|
36
|
+
"projectNameAndRootFormat": {
|
|
37
|
+
"description": "Whether to generate the new project name and destination as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
|
|
38
|
+
"type": "string",
|
|
39
|
+
"enum": ["as-provided", "derived"]
|
|
40
|
+
},
|
|
29
41
|
"importPath": {
|
|
30
42
|
"type": "string",
|
|
31
43
|
"description": "The new import path to use in the `tsconfig.base.json`."
|
|
@@ -30,7 +30,6 @@ async function generateWorkspaceFiles(tree, options) {
|
|
|
30
30
|
}
|
|
31
31
|
setPresetProperty(tree, options);
|
|
32
32
|
addNpmScripts(tree, options);
|
|
33
|
-
createAppsAndLibsFolders(tree, options);
|
|
34
33
|
setUpWorkspacesInPackageJson(tree, options);
|
|
35
34
|
await (0, devkit_1.formatFiles)(tree);
|
|
36
35
|
}
|
|
@@ -41,7 +40,6 @@ function setPresetProperty(tree, options) {
|
|
|
41
40
|
addPropertyWithStableKeys(json, 'extends', 'nx/presets/npm.json');
|
|
42
41
|
delete json.implicitDependencies;
|
|
43
42
|
delete json.targetDefaults;
|
|
44
|
-
delete json.workspaceLayout;
|
|
45
43
|
}
|
|
46
44
|
return json;
|
|
47
45
|
});
|
|
@@ -164,7 +164,7 @@ async function createPreset(tree, options) {
|
|
|
164
164
|
const { libraryGenerator } = require('@nx' + '/js');
|
|
165
165
|
return libraryGenerator(tree, {
|
|
166
166
|
name: options.name,
|
|
167
|
-
directory:
|
|
167
|
+
directory: '.',
|
|
168
168
|
projectNameAndRootFormat: 'as-provided',
|
|
169
169
|
bundler: 'tsc',
|
|
170
170
|
unitTestRunner: 'vitest',
|
|
@@ -35,7 +35,7 @@ async function moveWorkspaceGeneratorsToLocalPlugin(tree) {
|
|
|
35
35
|
}));
|
|
36
36
|
project = (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
updateExistingPlugin(tree, project);
|
|
39
39
|
return tasks;
|
|
40
40
|
}
|
|
41
41
|
function hasWorkspaceGenerators(tree) {
|
|
@@ -129,7 +129,7 @@ async function createNewPlugin(tree) {
|
|
|
129
129
|
e2eTestRunner: 'none',
|
|
130
130
|
publishable: false,
|
|
131
131
|
});
|
|
132
|
-
getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
|
|
132
|
+
await getCreateGeneratorsJson()(tree, (0, devkit_1.readProjectConfiguration)(tree, PROJECT_NAME).root, PROJECT_NAME);
|
|
133
133
|
await moveGeneratedPlugin(tree, DESTINATION, importPath);
|
|
134
134
|
}
|
|
135
135
|
function moveGeneratedPlugin(tree, destination, importPath) {
|
|
@@ -140,8 +140,8 @@ function moveGeneratedPlugin(tree, destination, importPath) {
|
|
|
140
140
|
projectName: PROJECT_NAME,
|
|
141
141
|
newProjectName: PROJECT_NAME,
|
|
142
142
|
updateImportPath: true,
|
|
143
|
-
destinationRelativeToRoot: true,
|
|
144
143
|
importPath: importPath,
|
|
144
|
+
projectNameAndRootFormat: 'as-provided',
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getImportPath = void 0;
|
|
3
|
+
exports.getNpmScope = exports.getImportPath = void 0;
|
|
4
4
|
const nx_json_1 = require("nx/src/generators/utils/nx-json");
|
|
5
5
|
const json_1 = require("nx/src/generators/utils/json");
|
|
6
6
|
function getImportPath(tree, projectDirectory) {
|
|
@@ -23,3 +23,4 @@ function getNpmScope(tree) {
|
|
|
23
23
|
return name.split('/')[0].substring(1);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
exports.getNpmScope = getNpmScope;
|