@nx/devkit 0.0.0-pr-30715-a5f5e3b → 0.0.0-pr-31222-862e973
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/LICENSE +1 -1
- package/README.md +1 -1
- package/migrations.json +14 -1
- package/package.json +6 -5
- package/src/executors/parse-target-string.d.ts +4 -0
- package/src/executors/read-target-options.js +3 -3
- package/src/generators/artifact-name-and-directory-utils.d.ts +18 -24
- package/src/generators/artifact-name-and-directory-utils.js +205 -79
- package/src/generators/format-files.d.ts +1 -7
- package/src/generators/format-files.js +2 -17
- package/src/generators/project-name-and-root-utils.d.ts +16 -11
- package/src/generators/project-name-and-root-utils.js +230 -68
- package/src/generators/target-defaults-utils.js +1 -1
- package/src/generators/update-ts-configs-to-js.js +22 -17
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +3 -0
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +200 -0
- package/src/tasks/install-packages-task.js +1 -1
- package/src/utils/add-plugin.js +8 -20
- package/src/utils/async-iterable/create-async-iterable.d.ts +0 -1
- package/src/utils/async-iterable/create-async-iterable.js +0 -10
- package/src/utils/binary-extensions.js +0 -1
- package/src/utils/calculate-hash-for-create-nodes.d.ts +0 -1
- package/src/utils/calculate-hash-for-create-nodes.js +0 -13
- package/src/utils/config-utils.js +33 -61
- package/src/utils/package-json.js +8 -12
- package/src/utils/replace-package.js +0 -1
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/generators/prompt.d.ts +0 -2
- package/src/generators/prompt.js +0 -14
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
[](https://circleci.com/gh/nrwl/nx)
|
|
11
11
|
[]()
|
|
12
|
-
[](https://www.npmjs.com/@nx/workspace)
|
|
13
13
|
[]()
|
|
14
14
|
[](http://commitizen.github.io/cz-cli/)
|
|
15
15
|
[](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
package/migrations.json
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
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
|
+
},
|
|
3
16
|
"packageJsonUpdates": {},
|
|
4
17
|
"version": "0.1"
|
|
5
18
|
}
|
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-31222-862e973",
|
|
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": {
|
|
@@ -29,16 +29,17 @@
|
|
|
29
29
|
"homepage": "https://nx.dev",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"ejs": "^3.1.7",
|
|
32
|
+
"enquirer": "~2.3.6",
|
|
32
33
|
"ignore": "^5.0.4",
|
|
33
34
|
"tmp": "~0.2.1",
|
|
34
35
|
"tslib": "^2.3.0",
|
|
35
36
|
"semver": "^7.5.3",
|
|
36
37
|
"yargs-parser": "21.1.1",
|
|
37
38
|
"minimatch": "9.0.3",
|
|
38
|
-
"
|
|
39
|
+
"@nrwl/devkit": "0.0.0-pr-31222-862e973"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"nx": "
|
|
42
|
+
"nx": ">= 19 <= 21"
|
|
42
43
|
},
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
@@ -46,6 +47,6 @@
|
|
|
46
47
|
"nx-migrations": {
|
|
47
48
|
"migrations": "./migrations.json"
|
|
48
49
|
},
|
|
49
|
-
"
|
|
50
|
-
"
|
|
50
|
+
"type": "commonjs",
|
|
51
|
+
"types": "./index.d.ts"
|
|
51
52
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
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;
|
|
2
6
|
/**
|
|
3
7
|
* Parses a target string into {project, target, configuration}
|
|
4
8
|
*
|
|
@@ -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 = context.projectsConfigurations.projects[project];
|
|
12
|
+
const projectConfiguration = (context.workspace || context.projectsConfigurations).projects[project];
|
|
13
13
|
if (!projectConfiguration) {
|
|
14
14
|
throw new Error(`Unable to find project ${project}`);
|
|
15
15
|
}
|
|
@@ -17,8 +17,8 @@ function readTargetOptions({ project, target, configuration }, context) {
|
|
|
17
17
|
if (!targetConfiguration) {
|
|
18
18
|
throw new Error(`Unable to find target ${target} for project ${project}`);
|
|
19
19
|
}
|
|
20
|
-
const [nodeModule, executorName] =
|
|
21
|
-
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects);
|
|
20
|
+
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
|
|
21
|
+
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects ?? context.workspace.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
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tree } from 'nx/src/devkit-exports';
|
|
2
|
+
export type NameAndDirectoryFormat = 'as-provided' | 'derived';
|
|
2
3
|
export type ArtifactGenerationOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
artifactType: string;
|
|
5
|
+
callingGenerator: string | null;
|
|
6
|
+
name: string;
|
|
7
|
+
directory?: string;
|
|
8
|
+
disallowPathInNameForDerived?: boolean;
|
|
9
|
+
fileExtension?: 'js' | 'jsx' | 'ts' | 'tsx' | 'vue';
|
|
10
|
+
fileName?: string;
|
|
11
|
+
flat?: boolean;
|
|
12
|
+
nameAndDirectoryFormat?: NameAndDirectoryFormat;
|
|
13
|
+
pascalCaseDirectory?: boolean;
|
|
14
|
+
pascalCaseFile?: boolean;
|
|
15
|
+
project?: string;
|
|
6
16
|
suffix?: string;
|
|
7
|
-
|
|
8
|
-
allowedFileExtensions?: string[];
|
|
9
|
-
/**
|
|
10
|
-
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
11
|
-
*/
|
|
12
|
-
js?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
15
|
-
*/
|
|
16
|
-
jsOptionName?: string;
|
|
17
|
+
derivedDirectory?: string;
|
|
17
18
|
};
|
|
18
|
-
export type FileExtensionType = 'js' | 'ts' | 'other';
|
|
19
19
|
export type NameAndDirectoryOptions = {
|
|
20
20
|
/**
|
|
21
21
|
* Normalized artifact name.
|
|
@@ -29,14 +29,6 @@ export type NameAndDirectoryOptions = {
|
|
|
29
29
|
* Normalized file name of the artifact without the extension.
|
|
30
30
|
*/
|
|
31
31
|
fileName: string;
|
|
32
|
-
/**
|
|
33
|
-
* Normalized file extension.
|
|
34
|
-
*/
|
|
35
|
-
fileExtension: string;
|
|
36
|
-
/**
|
|
37
|
-
* Normalized file extension type.
|
|
38
|
-
*/
|
|
39
|
-
fileExtensionType: FileExtensionType;
|
|
40
32
|
/**
|
|
41
33
|
* Normalized full file path of the artifact.
|
|
42
34
|
*/
|
|
@@ -46,7 +38,9 @@ export type NameAndDirectoryOptions = {
|
|
|
46
38
|
*/
|
|
47
39
|
project: string;
|
|
48
40
|
};
|
|
49
|
-
export declare function determineArtifactNameAndDirectoryOptions(tree: Tree, options: ArtifactGenerationOptions): Promise<NameAndDirectoryOptions
|
|
41
|
+
export declare function determineArtifactNameAndDirectoryOptions(tree: Tree, options: ArtifactGenerationOptions): Promise<NameAndDirectoryOptions & {
|
|
42
|
+
nameAndDirectoryFormat: NameAndDirectoryFormat;
|
|
43
|
+
}>;
|
|
50
44
|
export declare function getRelativeCwd(): string;
|
|
51
45
|
/**
|
|
52
46
|
* Function for setting cwd during testing
|
|
@@ -3,63 +3,210 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.determineArtifactNameAndDirectoryOptions = determineArtifactNameAndDirectoryOptions;
|
|
4
4
|
exports.getRelativeCwd = getRelativeCwd;
|
|
5
5
|
exports.setCwd = setCwd;
|
|
6
|
+
const enquirer_1 = require("enquirer");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const names_1 = require("../utils/names");
|
|
6
9
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
7
10
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const DEFAULT_ALLOWED_JS_FILE_EXTENSIONS = ['js', 'cjs', 'mjs', 'jsx'];
|
|
10
|
-
const DEFAULT_ALLOWED_TS_FILE_EXTENSIONS = ['ts', 'cts', 'mts', 'tsx'];
|
|
11
|
-
const DEFAULT_ALLOWED_FILE_EXTENSIONS = [
|
|
12
|
-
...DEFAULT_ALLOWED_JS_FILE_EXTENSIONS,
|
|
13
|
-
...DEFAULT_ALLOWED_TS_FILE_EXTENSIONS,
|
|
14
|
-
'vue',
|
|
15
|
-
];
|
|
16
11
|
async function determineArtifactNameAndDirectoryOptions(tree, options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if (!options.nameAndDirectoryFormat &&
|
|
13
|
+
(process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
|
|
14
|
+
options.nameAndDirectoryFormat = 'derived';
|
|
15
|
+
}
|
|
16
|
+
const formats = getNameAndDirectoryOptionFormats(tree, options);
|
|
17
|
+
const format = options.nameAndDirectoryFormat ?? (await determineFormat(formats, options));
|
|
18
|
+
validateResolvedProject(tree, formats[format]?.project, options, formats[format]?.directory);
|
|
19
|
+
if (format === 'derived' && options.callingGenerator) {
|
|
20
|
+
logDeprecationMessage(options, formats);
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
...formats[format],
|
|
24
|
+
nameAndDirectoryFormat: format,
|
|
25
|
+
};
|
|
20
26
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
async function determineFormat(formats, options) {
|
|
28
|
+
if (!formats.derived) {
|
|
29
|
+
return 'as-provided';
|
|
30
|
+
}
|
|
31
|
+
const asProvidedDescription = `As provided: ${formats['as-provided'].filePath}`;
|
|
32
|
+
const asProvidedSelectedValue = formats['as-provided'].filePath;
|
|
33
|
+
const derivedDescription = `Derived: ${formats['derived'].filePath}`;
|
|
34
|
+
const derivedSelectedValue = formats['derived'].filePath;
|
|
35
|
+
if (asProvidedSelectedValue === derivedSelectedValue) {
|
|
36
|
+
return 'as-provided';
|
|
37
|
+
}
|
|
38
|
+
const result = await (0, enquirer_1.prompt)({
|
|
39
|
+
type: 'select',
|
|
40
|
+
name: 'format',
|
|
41
|
+
message: `Where should the ${options.artifactType} be generated?`,
|
|
42
|
+
choices: [
|
|
43
|
+
{
|
|
44
|
+
message: asProvidedDescription,
|
|
45
|
+
name: asProvidedSelectedValue,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
message: derivedDescription,
|
|
49
|
+
name: derivedSelectedValue,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
initial: 0,
|
|
53
|
+
}).then(({ format }) => format === asProvidedSelectedValue ? 'as-provided' : 'derived');
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function logDeprecationMessage(options, formats) {
|
|
57
|
+
devkit_exports_1.logger.warn(`
|
|
58
|
+
In Nx 20, generating a ${options.artifactType} will no longer support providing a project and deriving the directory.
|
|
59
|
+
Please provide the exact directory in the future.
|
|
60
|
+
Example: nx g ${options.callingGenerator} ${formats['derived'].artifactName} --directory ${formats['derived'].directory}
|
|
61
|
+
NOTE: The example above assumes the command is being run from the workspace root. If the command is being run from a subdirectory, the directory option should be adjusted accordingly.
|
|
62
|
+
`);
|
|
63
|
+
}
|
|
64
|
+
function getNameAndDirectoryOptionFormats(tree, options) {
|
|
65
|
+
const directory = options.directory
|
|
66
|
+
? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
|
|
24
67
|
: undefined;
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
68
|
+
const fileExtension = options.fileExtension ?? 'ts';
|
|
69
|
+
const { name: extractedName, directory: extractedDirectory } = extractNameAndDirectoryFromName(options.name);
|
|
70
|
+
if (extractedDirectory && directory) {
|
|
71
|
+
throw new Error(`You can't specify both a directory (${options.directory}) and a name with a directory path (${options.name}). ` +
|
|
72
|
+
`Please specify either a directory or a name with a directory path.`);
|
|
73
|
+
}
|
|
74
|
+
const asProvidedOptions = getAsProvidedOptions(tree, {
|
|
75
|
+
...options,
|
|
76
|
+
directory: directory ?? extractedDirectory,
|
|
77
|
+
fileExtension,
|
|
78
|
+
name: extractedName,
|
|
79
|
+
});
|
|
80
|
+
if (!options.project) {
|
|
81
|
+
validateResolvedProject(tree, asProvidedOptions.project, options, asProvidedOptions.directory);
|
|
82
|
+
}
|
|
83
|
+
if (options.nameAndDirectoryFormat === 'as-provided') {
|
|
84
|
+
return {
|
|
85
|
+
'as-provided': asProvidedOptions,
|
|
86
|
+
derived: undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (options.disallowPathInNameForDerived && options.name.includes('/')) {
|
|
90
|
+
if (!options.nameAndDirectoryFormat) {
|
|
91
|
+
devkit_exports_1.output.warn({
|
|
92
|
+
title: `The provided name "${options.name}" contains a path and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
|
|
93
|
+
bodyLines: [
|
|
94
|
+
`The generator will try to generate the ${options.artifactType} using the "as-provided" format at "${asProvidedOptions.filePath}".`,
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
'as-provided': asProvidedOptions,
|
|
99
|
+
derived: undefined,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
throw new Error(`The provided name "${options.name}" contains a path and this is not supported by the "${options.callingGenerator}" when using the "derived" format. ` +
|
|
103
|
+
`Please provide a name without a path or use the "as-provided" format.`);
|
|
104
|
+
}
|
|
105
|
+
const derivedOptions = getDerivedOptions(tree, {
|
|
106
|
+
...options,
|
|
50
107
|
directory,
|
|
51
|
-
fileName,
|
|
52
108
|
fileExtension,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
109
|
+
name: extractedName,
|
|
110
|
+
}, asProvidedOptions, !options.disallowPathInNameForDerived && extractedDirectory
|
|
111
|
+
? extractedDirectory
|
|
112
|
+
: undefined);
|
|
113
|
+
return {
|
|
114
|
+
'as-provided': asProvidedOptions,
|
|
115
|
+
derived: derivedOptions,
|
|
56
116
|
};
|
|
57
117
|
}
|
|
58
|
-
function
|
|
118
|
+
function getAsProvidedOptions(tree, options) {
|
|
119
|
+
const relativeCwd = getRelativeCwd();
|
|
120
|
+
let asProvidedDirectory;
|
|
121
|
+
if (options.directory) {
|
|
122
|
+
// append the directory to the current working directory if it doesn't start with it
|
|
123
|
+
if (options.directory === relativeCwd ||
|
|
124
|
+
options.directory.startsWith(`${relativeCwd}/`)) {
|
|
125
|
+
asProvidedDirectory = options.directory;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
asProvidedDirectory = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
asProvidedDirectory = relativeCwd;
|
|
133
|
+
}
|
|
134
|
+
const asProvidedProject = findProjectFromPath(tree, asProvidedDirectory);
|
|
135
|
+
const asProvidedFileName = options.fileName ??
|
|
136
|
+
(options.suffix ? `${options.name}.${options.suffix}` : options.name);
|
|
137
|
+
const asProvidedFilePath = (0, devkit_exports_1.joinPathFragments)(asProvidedDirectory, `${asProvidedFileName}.${options.fileExtension}`);
|
|
138
|
+
return {
|
|
139
|
+
artifactName: options.name,
|
|
140
|
+
directory: asProvidedDirectory,
|
|
141
|
+
fileName: asProvidedFileName,
|
|
142
|
+
filePath: asProvidedFilePath,
|
|
143
|
+
project: asProvidedProject,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory) {
|
|
147
|
+
const projects = (0, devkit_exports_1.getProjects)(tree);
|
|
148
|
+
if (options.project && !projects.has(options.project)) {
|
|
149
|
+
throw new Error(`The provided project "${options.project}" does not exist! Please provide an existing project name.`);
|
|
150
|
+
}
|
|
151
|
+
const projectName = options.project ?? asProvidedOptions.project;
|
|
152
|
+
const project = projects.get(projectName);
|
|
153
|
+
const derivedName = options.name;
|
|
154
|
+
const baseDirectory = options.directory
|
|
155
|
+
? (0, names_1.names)(options.directory).fileName
|
|
156
|
+
: (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? (0, devkit_exports_1.joinPathFragments)(project.root, 'src'), project.projectType === 'application' ? 'app' : 'lib', extractedDirectory ?? '');
|
|
157
|
+
const derivedDirectory = typeof options.derivedDirectory === 'string'
|
|
158
|
+
? (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? project.root, options.derivedDirectory, options.flat
|
|
159
|
+
? ''
|
|
160
|
+
: options.pascalCaseDirectory
|
|
161
|
+
? (0, names_1.names)(derivedName).className
|
|
162
|
+
: (0, names_1.names)(derivedName).fileName)
|
|
163
|
+
: options.flat
|
|
164
|
+
? (0, devkit_exports_1.normalizePath)(baseDirectory)
|
|
165
|
+
: (0, devkit_exports_1.joinPathFragments)(baseDirectory, options.pascalCaseDirectory
|
|
166
|
+
? (0, names_1.names)(derivedName).className
|
|
167
|
+
: (0, names_1.names)(derivedName).fileName);
|
|
168
|
+
if (options.directory &&
|
|
169
|
+
!isDirectoryUnderProjectRoot(derivedDirectory, project.root)) {
|
|
170
|
+
if (!options.nameAndDirectoryFormat) {
|
|
171
|
+
devkit_exports_1.output.warn({
|
|
172
|
+
title: `The provided directory "${options.directory}" is not under the provided project root "${project.root}".`,
|
|
173
|
+
bodyLines: [
|
|
174
|
+
`The generator will try to generate the ${options.artifactType} using the "as-provided" format.`,
|
|
175
|
+
`With the "as-provided" format, the "project" option is ignored and the ${options.artifactType} will be generated at "${asProvidedOptions.filePath}" (<cwd>/<provided directory>).`,
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
throw new Error(`The provided directory "${options.directory}" is not under the provided project root "${project.root}". ` +
|
|
181
|
+
`Please provide a directory that is under the provided project root or use the "as-provided" format and only provide the directory.`);
|
|
182
|
+
}
|
|
183
|
+
let derivedFileName = options.fileName;
|
|
184
|
+
if (!derivedFileName) {
|
|
185
|
+
derivedFileName = options.suffix
|
|
186
|
+
? `${derivedName}.${options.suffix}`
|
|
187
|
+
: derivedName;
|
|
188
|
+
derivedFileName = options.pascalCaseFile
|
|
189
|
+
? (0, names_1.names)(derivedFileName).className
|
|
190
|
+
: (0, names_1.names)(derivedFileName).fileName;
|
|
191
|
+
}
|
|
192
|
+
const derivedFilePath = (0, devkit_exports_1.joinPathFragments)(derivedDirectory, `${derivedFileName}.${options.fileExtension}`);
|
|
193
|
+
return {
|
|
194
|
+
artifactName: derivedName,
|
|
195
|
+
directory: derivedDirectory,
|
|
196
|
+
fileName: derivedFileName,
|
|
197
|
+
filePath: derivedFilePath,
|
|
198
|
+
project: projectName,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function validateResolvedProject(tree, project, options, normalizedDirectory) {
|
|
59
202
|
if (project) {
|
|
60
203
|
return;
|
|
61
204
|
}
|
|
62
|
-
|
|
205
|
+
if (options.directory) {
|
|
206
|
+
throw new Error(`The provided directory resolved relative to the current working directory "${normalizedDirectory}" does not exist under any project root. ` +
|
|
207
|
+
`Please make sure to navigate to a location or provide a directory that exists under a project root.`);
|
|
208
|
+
}
|
|
209
|
+
throw new Error(`The current working directory "${getRelativeCwd() || '.'}" does not exist under any project root. ` +
|
|
63
210
|
`Please make sure to navigate to a location or provide a directory that exists under a project root.`);
|
|
64
211
|
}
|
|
65
212
|
function findProjectFromPath(tree, path) {
|
|
@@ -71,6 +218,15 @@ function findProjectFromPath(tree, path) {
|
|
|
71
218
|
const projectRootMappings = (0, devkit_internals_1.createProjectRootMappingsFromProjectConfigurations)(projectConfigurations);
|
|
72
219
|
return (0, devkit_internals_1.findProjectForPath)(path, projectRootMappings);
|
|
73
220
|
}
|
|
221
|
+
function isDirectoryUnderProjectRoot(directory, projectRoot) {
|
|
222
|
+
const normalizedDirectory = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, directory);
|
|
223
|
+
const normalizedProjectRoot = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, projectRoot).replace(/\/$/, '');
|
|
224
|
+
return (normalizedDirectory === normalizedProjectRoot ||
|
|
225
|
+
normalizedDirectory.startsWith(`${normalizedProjectRoot}/`));
|
|
226
|
+
}
|
|
227
|
+
function isTTY() {
|
|
228
|
+
return !!process.stdout.isTTY && process.env['CI'] !== 'true';
|
|
229
|
+
}
|
|
74
230
|
function getRelativeCwd() {
|
|
75
231
|
return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd()));
|
|
76
232
|
}
|
|
@@ -85,39 +241,9 @@ function getCwd() {
|
|
|
85
241
|
? process.env.INIT_CWD
|
|
86
242
|
: process.cwd();
|
|
87
243
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
const name = parsedPath.pop();
|
|
93
|
-
const directory = parsedPath.join('/');
|
|
244
|
+
function extractNameAndDirectoryFromName(rawName) {
|
|
245
|
+
const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
|
|
246
|
+
const name = parsedName.pop();
|
|
247
|
+
const directory = parsedName.length ? parsedName.join('/') : undefined;
|
|
94
248
|
return { name, directory };
|
|
95
249
|
}
|
|
96
|
-
function getFileExtensionType(fileExtension) {
|
|
97
|
-
if (DEFAULT_ALLOWED_JS_FILE_EXTENSIONS.includes(fileExtension)) {
|
|
98
|
-
return 'js';
|
|
99
|
-
}
|
|
100
|
-
if (DEFAULT_ALLOWED_TS_FILE_EXTENSIONS.includes(fileExtension)) {
|
|
101
|
-
return 'ts';
|
|
102
|
-
}
|
|
103
|
-
return 'other';
|
|
104
|
-
}
|
|
105
|
-
function validateFileExtension(fileExtension, allowedFileExtensions, js, jsOptionName) {
|
|
106
|
-
const fileExtensionType = getFileExtensionType(fileExtension);
|
|
107
|
-
if (!allowedFileExtensions.includes(fileExtension)) {
|
|
108
|
-
throw new Error(`The provided file path has an extension (.${fileExtension}) that is not supported by this generator.
|
|
109
|
-
The supported extensions are: ${allowedFileExtensions
|
|
110
|
-
.map((ext) => `.${ext}`)
|
|
111
|
-
.join(', ')}.`);
|
|
112
|
-
}
|
|
113
|
-
if (js !== undefined) {
|
|
114
|
-
jsOptionName = jsOptionName ?? 'js';
|
|
115
|
-
if (js && fileExtensionType === 'ts') {
|
|
116
|
-
throw new Error(`The provided file path has an extension (.${fileExtension}) that conflicts with the provided "--${jsOptionName}" option.`);
|
|
117
|
-
}
|
|
118
|
-
if (!js && fileExtensionType === 'js') {
|
|
119
|
-
throw new Error(`The provided file path has an extension (.${fileExtension}) that conflicts with the provided "--${jsOptionName}" option.`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return fileExtensionType;
|
|
123
|
-
}
|
|
@@ -3,10 +3,4 @@ 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
|
|
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;
|
|
12
|
-
}): Promise<void>;
|
|
6
|
+
export declare function formatFiles(tree: Tree): Promise<void>;
|
|
@@ -8,28 +8,13 @@ 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
|
|
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,
|
|
17
|
-
}) {
|
|
11
|
+
async function formatFiles(tree) {
|
|
18
12
|
let prettier;
|
|
19
13
|
try {
|
|
20
14
|
prettier = await Promise.resolve().then(() => require('prettier'));
|
|
21
|
-
/**
|
|
22
|
-
* Even after we discovered prettier in node_modules, we need to be sure that the user is intentionally using prettier
|
|
23
|
-
* before proceeding to format with it.
|
|
24
|
-
*/
|
|
25
|
-
if (!(0, devkit_internals_1.isUsingPrettierInTree)(tree)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
15
|
}
|
|
29
16
|
catch { }
|
|
30
|
-
|
|
31
|
-
sortTsConfig(tree);
|
|
32
|
-
}
|
|
17
|
+
sortTsConfig(tree);
|
|
33
18
|
if (!prettier)
|
|
34
19
|
return;
|
|
35
20
|
const files = new Set(tree.listChanges().filter((file) => file.type !== 'DELETE'));
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProjectType, Tree } from 'nx/src/devkit-exports';
|
|
2
|
+
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
|
2
3
|
export type ProjectGenerationOptions = {
|
|
3
|
-
|
|
4
|
-
name?: string;
|
|
4
|
+
name: string;
|
|
5
5
|
projectType: ProjectType;
|
|
6
|
+
callingGenerator: string | null;
|
|
7
|
+
directory?: string;
|
|
6
8
|
importPath?: string;
|
|
9
|
+
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
7
10
|
rootProject?: boolean;
|
|
8
11
|
};
|
|
9
12
|
export type ProjectNameAndRootOptions = {
|
|
10
13
|
/**
|
|
11
14
|
* Normalized full project name, including scope if name was provided with
|
|
12
|
-
* scope (e.g., `@scope/name`
|
|
15
|
+
* scope (e.g., `@scope/name`, only available when `projectNameAndRootFormat`
|
|
16
|
+
* is `as-provided`).
|
|
13
17
|
*/
|
|
14
18
|
projectName: string;
|
|
15
19
|
/**
|
|
@@ -31,11 +35,12 @@ export type ProjectNameAndRootOptions = {
|
|
|
31
35
|
/**
|
|
32
36
|
* Normalized import path for the project.
|
|
33
37
|
*/
|
|
34
|
-
importPath
|
|
38
|
+
importPath?: string;
|
|
35
39
|
};
|
|
36
|
-
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions & {
|
|
41
|
+
projectNameAndRootFormat: ProjectNameAndRootFormat;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Function for setting cwd during testing
|
|
45
|
+
*/
|
|
46
|
+
export declare function setCwd(path: string): void;
|