@nx/devkit 16.7.2 → 16.8.0-beta.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "16.
|
|
3
|
+
"version": "16.8.0-beta.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.",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://nx.dev",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@nrwl/devkit": "16.
|
|
31
|
+
"@nrwl/devkit": "16.8.0-beta.1",
|
|
32
32
|
"ejs": "^3.1.7",
|
|
33
33
|
"enquirer": "~2.3.6",
|
|
34
34
|
"ignore": "^5.0.4",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"migrations": "./migrations.json"
|
|
47
47
|
},
|
|
48
48
|
"type": "commonjs",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "231a998e004c13e559c171ba6c164a9127886153"
|
|
50
50
|
}
|
|
@@ -38,7 +38,9 @@ function formatFiles(tree) {
|
|
|
38
38
|
if (support.ignored || !support.inferredParser) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
tree.write(file.path,
|
|
41
|
+
tree.write(file.path,
|
|
42
|
+
// In prettier v3 the format result is a promise
|
|
43
|
+
yield prettier.format(file.content.toString('utf-8'), options));
|
|
42
44
|
}
|
|
43
45
|
catch (e) {
|
|
44
46
|
console.warn(`Could not format ${file.path}. Error: "${e.message}"`);
|
|
@@ -4,6 +4,7 @@ export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
|
|
4
4
|
export type ProjectGenerationOptions = {
|
|
5
5
|
name: string;
|
|
6
6
|
projectType: ProjectType;
|
|
7
|
+
callingGenerator: string;
|
|
7
8
|
directory?: string;
|
|
8
9
|
importPath?: string;
|
|
9
10
|
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
@@ -37,4 +38,6 @@ export type ProjectNameAndRootOptions = {
|
|
|
37
38
|
*/
|
|
38
39
|
importPath?: string;
|
|
39
40
|
};
|
|
40
|
-
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions
|
|
41
|
+
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions & {
|
|
42
|
+
projectNameAndRootFormat: ProjectNameAndRootFormat;
|
|
43
|
+
}>;
|
|
@@ -6,14 +6,14 @@ const enquirer_1 = require("enquirer");
|
|
|
6
6
|
const nx_1 = require("../../nx");
|
|
7
7
|
const get_workspace_layout_1 = require("../utils/get-workspace-layout");
|
|
8
8
|
const names_1 = require("../utils/names");
|
|
9
|
-
const { joinPathFragments, readJson, readNxJson } = (0, nx_1.requireNx)();
|
|
9
|
+
const { joinPathFragments, normalizePath, logger, readJson, readNxJson, updateNxJson, } = (0, nx_1.requireNx)();
|
|
10
10
|
function determineProjectNameAndRootOptions(tree, options) {
|
|
11
11
|
var _a;
|
|
12
12
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
13
|
validateName(options.name, options.projectNameAndRootFormat);
|
|
14
14
|
const formats = getProjectNameAndRootFormats(tree, options);
|
|
15
|
-
const format = (_a = options.projectNameAndRootFormat) !== null && _a !== void 0 ? _a : (yield determineFormat(formats));
|
|
16
|
-
return formats[format];
|
|
15
|
+
const format = (_a = options.projectNameAndRootFormat) !== null && _a !== void 0 ? _a : (yield determineFormat(tree, formats, options.callingGenerator));
|
|
16
|
+
return Object.assign(Object.assign({}, formats[format]), { projectNameAndRootFormat: format });
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
exports.determineProjectNameAndRootOptions = determineProjectNameAndRootOptions;
|
|
@@ -37,7 +37,9 @@ function validateName(name, projectNameAndRootFormat) {
|
|
|
37
37
|
throw new Error(`The project name should match the pattern "${pattern}". The provided value "${name}" does not match.`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
function determineFormat(formats) {
|
|
40
|
+
function determineFormat(tree, formats, callingGenerator) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
var _c;
|
|
41
43
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
42
44
|
if (!formats.derived) {
|
|
43
45
|
return 'as-provided';
|
|
@@ -52,8 +54,8 @@ function determineFormat(formats) {
|
|
|
52
54
|
const derivedDescription = `Derived:
|
|
53
55
|
Name: ${formats['derived'].projectName}
|
|
54
56
|
Root: ${formats['derived'].projectRoot}`;
|
|
55
|
-
const derivedSelectedValue = `${formats['derived'].projectName} @ ${formats['derived'].projectRoot}
|
|
56
|
-
|
|
57
|
+
const derivedSelectedValue = `${formats['derived'].projectName} @ ${formats['derived'].projectRoot}`;
|
|
58
|
+
const result = yield (0, enquirer_1.prompt)({
|
|
57
59
|
type: 'select',
|
|
58
60
|
name: 'format',
|
|
59
61
|
message: 'What should be the project name and where should it be generated?',
|
|
@@ -69,12 +71,37 @@ function determineFormat(formats) {
|
|
|
69
71
|
],
|
|
70
72
|
initial: 'as-provided',
|
|
71
73
|
}).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived');
|
|
74
|
+
const deprecationWarning = 'In Nx 18, generating projects will no longer derive the name and root. Please provide the exact project name and root in the future.';
|
|
75
|
+
if (result === 'as-provided' && callingGenerator) {
|
|
76
|
+
const { saveDefault } = yield (0, enquirer_1.prompt)({
|
|
77
|
+
type: 'confirm',
|
|
78
|
+
message: `Would you like to configure Nx to always take project name and root as provided for ${callingGenerator}?`,
|
|
79
|
+
name: 'saveDefault',
|
|
80
|
+
initial: true,
|
|
81
|
+
});
|
|
82
|
+
if (saveDefault) {
|
|
83
|
+
const nxJson = readNxJson(tree);
|
|
84
|
+
(_a = nxJson.generators) !== null && _a !== void 0 ? _a : (nxJson.generators = {});
|
|
85
|
+
(_b = (_c = nxJson.generators)[callingGenerator]) !== null && _b !== void 0 ? _b : (_c[callingGenerator] = {});
|
|
86
|
+
nxJson.generators[callingGenerator].projectNameAndRootFormat = result;
|
|
87
|
+
updateNxJson(tree, nxJson);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
logger.warn(deprecationWarning);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
logger.warn(deprecationWarning);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
72
97
|
});
|
|
73
98
|
}
|
|
74
99
|
function getProjectNameAndRootFormats(tree, options) {
|
|
75
|
-
var _a, _b, _c
|
|
100
|
+
var _a, _b, _c;
|
|
76
101
|
const name = (0, names_1.names)(options.name).fileName;
|
|
77
|
-
const directory =
|
|
102
|
+
const directory = options.directory
|
|
103
|
+
? normalizePath(options.directory.replace(/^\.?\//, ''))
|
|
104
|
+
: undefined;
|
|
78
105
|
const asProvidedProjectName = name;
|
|
79
106
|
const asProvidedProjectDirectory = directory
|
|
80
107
|
? (0, names_1.names)(directory).fileName
|
|
@@ -90,7 +117,7 @@ function getProjectNameAndRootFormats(tree, options) {
|
|
|
90
117
|
projectSimpleName: nameWithoutScope,
|
|
91
118
|
projectFileName: nameWithoutScope,
|
|
92
119
|
},
|
|
93
|
-
importPath: (
|
|
120
|
+
importPath: (_a = options.importPath) !== null && _a !== void 0 ? _a : asProvidedProjectName,
|
|
94
121
|
projectRoot: asProvidedProjectDirectory,
|
|
95
122
|
},
|
|
96
123
|
};
|
|
@@ -103,7 +130,7 @@ function getProjectNameAndRootFormats(tree, options) {
|
|
|
103
130
|
npmScope = getNpmScope(tree);
|
|
104
131
|
asProvidedImportPath =
|
|
105
132
|
asProvidedProjectDirectory === '.'
|
|
106
|
-
? (
|
|
133
|
+
? (_b = readJson(tree, 'package.json').name) !== null && _b !== void 0 ? _b : getImportPath(npmScope, asProvidedProjectName)
|
|
107
134
|
: getImportPath(npmScope, asProvidedProjectName);
|
|
108
135
|
}
|
|
109
136
|
}
|
|
@@ -129,7 +156,7 @@ function getProjectNameAndRootFormats(tree, options) {
|
|
|
129
156
|
if (!derivedImportPath) {
|
|
130
157
|
derivedImportPath =
|
|
131
158
|
derivedProjectDirectory === '.'
|
|
132
|
-
? (
|
|
159
|
+
? (_c = readJson(tree, 'package.json').name) !== null && _c !== void 0 ? _c : getImportPath(npmScope, derivedProjectName)
|
|
133
160
|
: getImportPath(npmScope, derivedProjectDirectoryWithoutLayout);
|
|
134
161
|
}
|
|
135
162
|
}
|
|
@@ -29,9 +29,6 @@ function installPackagesTask(tree, alwaysRun = false, cwd = '', packageManager =
|
|
|
29
29
|
cwd: (0, path_1.join)(tree.root, cwd),
|
|
30
30
|
stdio: process.env.NX_GENERATE_QUIET === 'true' ? 'ignore' : 'inherit',
|
|
31
31
|
};
|
|
32
|
-
if (pmc.preInstall) {
|
|
33
|
-
(0, child_process_1.execSync)(pmc.preInstall, execSyncOptions);
|
|
34
|
-
}
|
|
35
32
|
(0, child_process_1.execSync)(pmc.install, execSyncOptions);
|
|
36
33
|
}
|
|
37
34
|
}
|