@nx/devkit 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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 +1 -14
- package/package.json +5 -6
- package/src/executors/parse-target-string.d.ts +0 -4
- package/src/executors/read-target-options.js +3 -3
- package/src/generators/artifact-name-and-directory-utils.d.ts +23 -18
- package/src/generators/artifact-name-and-directory-utils.js +79 -205
- package/src/generators/format-files.d.ts +7 -1
- package/src/generators/format-files.js +17 -2
- package/src/generators/project-name-and-root-utils.d.ts +11 -16
- package/src/generators/project-name-and-root-utils.js +68 -230
- package/src/generators/prompt.d.ts +2 -0
- package/src/generators/prompt.js +14 -0
- package/src/generators/target-defaults-utils.js +1 -1
- package/src/generators/update-ts-configs-to-js.js +17 -22
- package/src/tasks/install-packages-task.js +1 -1
- package/src/utils/add-plugin.js +20 -8
- package/src/utils/async-iterable/create-async-iterable.d.ts +1 -0
- package/src/utils/async-iterable/create-async-iterable.js +10 -0
- package/src/utils/binary-extensions.js +1 -0
- package/src/utils/calculate-hash-for-create-nodes.d.ts +1 -0
- package/src/utils/calculate-hash-for-create-nodes.js +13 -0
- package/src/utils/config-utils.js +61 -33
- package/src/utils/package-json.js +12 -8
- package/src/utils/replace-package.js +1 -0
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +0 -3
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +0 -200
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/package/nx)
|
|
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,18 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"update-16-0-0-add-nx-packages": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "16.0.0-beta.1",
|
|
6
|
-
"description": "Replace @nrwl/devkit with @nx/devkit",
|
|
7
|
-
"implementation": "./src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages"
|
|
8
|
-
},
|
|
9
|
-
"update-16-9-0-migrate-mf-usage-to-webpack": {
|
|
10
|
-
"cli": "nx",
|
|
11
|
-
"version": "16.9.0-beta.1",
|
|
12
|
-
"description": "Replace imports of Module Federation utils frm @nx/devkit to @nx/webpack",
|
|
13
|
-
"implementation": "./src/migrations/update-16-9-0/migrate-mf-util-usage"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
2
|
+
"generators": {},
|
|
16
3
|
"packageJsonUpdates": {},
|
|
17
4
|
"version": "0.1"
|
|
18
5
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-31313-387cdca",
|
|
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,17 +29,16 @@
|
|
|
29
29
|
"homepage": "https://nx.dev",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"ejs": "^3.1.7",
|
|
32
|
-
"enquirer": "~2.3.6",
|
|
33
32
|
"ignore": "^5.0.4",
|
|
34
33
|
"tmp": "~0.2.1",
|
|
35
34
|
"tslib": "^2.3.0",
|
|
36
35
|
"semver": "^7.5.3",
|
|
37
36
|
"yargs-parser": "21.1.1",
|
|
38
37
|
"minimatch": "9.0.3",
|
|
39
|
-
"
|
|
38
|
+
"enquirer": "~2.3.6"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
|
-
"nx": "
|
|
41
|
+
"nx": "0.0.0-pr-31313-387cdca"
|
|
43
42
|
},
|
|
44
43
|
"publishConfig": {
|
|
45
44
|
"access": "public"
|
|
@@ -47,6 +46,6 @@
|
|
|
47
46
|
"nx-migrations": {
|
|
48
47
|
"migrations": "./migrations.json"
|
|
49
48
|
},
|
|
50
|
-
"
|
|
51
|
-
"
|
|
49
|
+
"types": "./index.d.ts",
|
|
50
|
+
"type": "commonjs"
|
|
52
51
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
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;
|
|
6
2
|
/**
|
|
7
3
|
* Parses a target string into {project, target, configuration}
|
|
8
4
|
*
|
|
@@ -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 =
|
|
12
|
+
const projectConfiguration = 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] = targetConfiguration.executor
|
|
21
|
-
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects
|
|
20
|
+
const [nodeModule, executorName] = (0, devkit_internals_1.parseExecutor)(targetConfiguration.executor);
|
|
21
|
+
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.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,20 @@
|
|
|
1
|
-
import { Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
export type NameAndDirectoryFormat = 'as-provided' | 'derived';
|
|
1
|
+
import { type Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
export type ArtifactGenerationOptions = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
3
|
+
path: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
fileExtension?: string;
|
|
16
6
|
suffix?: string;
|
|
17
|
-
|
|
7
|
+
allowedFileExtensions?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
10
|
+
*/
|
|
11
|
+
js?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
14
|
+
*/
|
|
15
|
+
jsOptionName?: string;
|
|
18
16
|
};
|
|
17
|
+
export type FileExtensionType = 'js' | 'ts' | 'other';
|
|
19
18
|
export type NameAndDirectoryOptions = {
|
|
20
19
|
/**
|
|
21
20
|
* Normalized artifact name.
|
|
@@ -29,6 +28,14 @@ export type NameAndDirectoryOptions = {
|
|
|
29
28
|
* Normalized file name of the artifact without the extension.
|
|
30
29
|
*/
|
|
31
30
|
fileName: string;
|
|
31
|
+
/**
|
|
32
|
+
* Normalized file extension.
|
|
33
|
+
*/
|
|
34
|
+
fileExtension: string;
|
|
35
|
+
/**
|
|
36
|
+
* Normalized file extension type.
|
|
37
|
+
*/
|
|
38
|
+
fileExtensionType: FileExtensionType;
|
|
32
39
|
/**
|
|
33
40
|
* Normalized full file path of the artifact.
|
|
34
41
|
*/
|
|
@@ -38,9 +45,7 @@ export type NameAndDirectoryOptions = {
|
|
|
38
45
|
*/
|
|
39
46
|
project: string;
|
|
40
47
|
};
|
|
41
|
-
export declare function determineArtifactNameAndDirectoryOptions(tree: Tree, options: ArtifactGenerationOptions): Promise<NameAndDirectoryOptions
|
|
42
|
-
nameAndDirectoryFormat: NameAndDirectoryFormat;
|
|
43
|
-
}>;
|
|
48
|
+
export declare function determineArtifactNameAndDirectoryOptions(tree: Tree, options: ArtifactGenerationOptions): Promise<NameAndDirectoryOptions>;
|
|
44
49
|
export declare function getRelativeCwd(): string;
|
|
45
50
|
/**
|
|
46
51
|
* Function for setting cwd during testing
|
|
@@ -3,210 +3,63 @@ 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");
|
|
9
6
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
10
7
|
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
|
+
];
|
|
11
16
|
async function determineArtifactNameAndDirectoryOptions(tree, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
};
|
|
17
|
+
const normalizedOptions = getNameAndDirectoryOptions(tree, options);
|
|
18
|
+
validateResolvedProject(normalizedOptions.project, normalizedOptions.directory);
|
|
19
|
+
return normalizedOptions;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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(/^\.?\//, ''))
|
|
21
|
+
function getNameAndDirectoryOptions(tree, options) {
|
|
22
|
+
const path = options.path
|
|
23
|
+
? (0, devkit_exports_1.normalizePath)(options.path.replace(/^\.?\//, ''))
|
|
67
24
|
: undefined;
|
|
68
|
-
|
|
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,
|
|
107
|
-
directory,
|
|
108
|
-
fileExtension,
|
|
109
|
-
name: extractedName,
|
|
110
|
-
}, asProvidedOptions, !options.disallowPathInNameForDerived && extractedDirectory
|
|
111
|
-
? extractedDirectory
|
|
112
|
-
: undefined);
|
|
113
|
-
return {
|
|
114
|
-
'as-provided': asProvidedOptions,
|
|
115
|
-
derived: derivedOptions,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
function getAsProvidedOptions(tree, options) {
|
|
25
|
+
let { name: extractedName, directory } = extractNameAndDirectoryFromPath(path);
|
|
119
26
|
const relativeCwd = getRelativeCwd();
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
27
|
+
// append the directory to the current working directory if it doesn't start with it
|
|
28
|
+
if (directory !== relativeCwd && !directory.startsWith(`${relativeCwd}/`)) {
|
|
29
|
+
directory = (0, devkit_exports_1.joinPathFragments)(relativeCwd, directory);
|
|
30
|
+
}
|
|
31
|
+
const project = findProjectFromPath(tree, directory);
|
|
32
|
+
let fileName = extractedName;
|
|
33
|
+
let fileExtension = options.fileExtension ?? 'ts';
|
|
34
|
+
const allowedFileExtensions = options.allowedFileExtensions ?? DEFAULT_ALLOWED_FILE_EXTENSIONS;
|
|
35
|
+
const fileExtensionRegex = new RegExp(`\\.(${allowedFileExtensions.join('|')})$`);
|
|
36
|
+
const fileExtensionMatch = fileName.match(fileExtensionRegex);
|
|
37
|
+
if (fileExtensionMatch) {
|
|
38
|
+
fileExtension = fileExtensionMatch[1];
|
|
39
|
+
fileName = fileName.replace(fileExtensionRegex, '');
|
|
40
|
+
extractedName = fileName;
|
|
41
|
+
}
|
|
42
|
+
else if (options.suffix) {
|
|
43
|
+
fileName = `${fileName}.${options.suffix}`;
|
|
44
|
+
}
|
|
45
|
+
const filePath = (0, devkit_exports_1.joinPathFragments)(directory, `${fileName}.${fileExtension}`);
|
|
46
|
+
const fileExtensionType = getFileExtensionType(fileExtension);
|
|
47
|
+
validateFileExtension(fileExtension, allowedFileExtensions, options.js, options.jsOptionName);
|
|
138
48
|
return {
|
|
139
|
-
artifactName: options.name,
|
|
140
|
-
directory
|
|
141
|
-
fileName
|
|
142
|
-
|
|
143
|
-
|
|
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,
|
|
49
|
+
artifactName: options.name ?? extractedName,
|
|
50
|
+
directory,
|
|
51
|
+
fileName,
|
|
52
|
+
fileExtension,
|
|
53
|
+
fileExtensionType,
|
|
54
|
+
filePath,
|
|
55
|
+
project,
|
|
199
56
|
};
|
|
200
57
|
}
|
|
201
|
-
function validateResolvedProject(
|
|
58
|
+
function validateResolvedProject(project, normalizedDirectory) {
|
|
202
59
|
if (project) {
|
|
203
60
|
return;
|
|
204
61
|
}
|
|
205
|
-
|
|
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. ` +
|
|
62
|
+
throw new Error(`The provided directory resolved relative to the current working directory "${normalizedDirectory}" does not exist under any project root. ` +
|
|
210
63
|
`Please make sure to navigate to a location or provide a directory that exists under a project root.`);
|
|
211
64
|
}
|
|
212
65
|
function findProjectFromPath(tree, path) {
|
|
@@ -218,15 +71,6 @@ function findProjectFromPath(tree, path) {
|
|
|
218
71
|
const projectRootMappings = (0, devkit_internals_1.createProjectRootMappingsFromProjectConfigurations)(projectConfigurations);
|
|
219
72
|
return (0, devkit_internals_1.findProjectForPath)(path, projectRootMappings);
|
|
220
73
|
}
|
|
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
|
-
}
|
|
230
74
|
function getRelativeCwd() {
|
|
231
75
|
return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd()));
|
|
232
76
|
}
|
|
@@ -241,9 +85,39 @@ function getCwd() {
|
|
|
241
85
|
? process.env.INIT_CWD
|
|
242
86
|
: process.cwd();
|
|
243
87
|
}
|
|
244
|
-
function
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const
|
|
88
|
+
function extractNameAndDirectoryFromPath(path) {
|
|
89
|
+
// Remove trailing slash
|
|
90
|
+
path = path.replace(/\/$/, '');
|
|
91
|
+
const parsedPath = (0, devkit_exports_1.normalizePath)(path).split('/');
|
|
92
|
+
const name = parsedPath.pop();
|
|
93
|
+
const directory = parsedPath.join('/');
|
|
248
94
|
return { name, directory };
|
|
249
95
|
}
|
|
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,4 +3,10 @@ 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
|
|
6
|
+
export declare function formatFiles(tree: Tree, options?: {
|
|
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>;
|
|
@@ -8,13 +8,28 @@ 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
|
|
11
|
+
async function formatFiles(tree, options = {
|
|
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
|
+
}) {
|
|
12
18
|
let prettier;
|
|
13
19
|
try {
|
|
14
20
|
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
|
+
}
|
|
15
28
|
}
|
|
16
29
|
catch { }
|
|
17
|
-
|
|
30
|
+
if (options.sortRootTsconfigPaths) {
|
|
31
|
+
sortTsConfig(tree);
|
|
32
|
+
}
|
|
18
33
|
if (!prettier)
|
|
19
34
|
return;
|
|
20
35
|
const files = new Set(tree.listChanges().filter((file) => file.type !== 'DELETE'));
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { ProjectType, Tree } from 'nx/src/devkit-exports';
|
|
2
|
-
export type ProjectNameAndRootFormat = 'as-provided' | 'derived';
|
|
1
|
+
import { type ProjectType, type Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
export type ProjectGenerationOptions = {
|
|
4
|
-
|
|
3
|
+
directory: string;
|
|
4
|
+
name?: string;
|
|
5
5
|
projectType: ProjectType;
|
|
6
|
-
callingGenerator: string | null;
|
|
7
|
-
directory?: string;
|
|
8
6
|
importPath?: string;
|
|
9
|
-
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
10
7
|
rootProject?: boolean;
|
|
11
8
|
};
|
|
12
9
|
export type ProjectNameAndRootOptions = {
|
|
13
10
|
/**
|
|
14
11
|
* Normalized full project name, including scope if name was provided with
|
|
15
|
-
* scope (e.g., `@scope/name
|
|
16
|
-
* is `as-provided`).
|
|
12
|
+
* scope (e.g., `@scope/name`)
|
|
17
13
|
*/
|
|
18
14
|
projectName: string;
|
|
19
15
|
/**
|
|
@@ -35,12 +31,11 @@ export type ProjectNameAndRootOptions = {
|
|
|
35
31
|
/**
|
|
36
32
|
* Normalized import path for the project.
|
|
37
33
|
*/
|
|
38
|
-
importPath
|
|
34
|
+
importPath: string;
|
|
39
35
|
};
|
|
40
|
-
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
export declare function setCwd(path: string): void;
|
|
36
|
+
export declare function determineProjectNameAndRootOptions(tree: Tree, options: ProjectGenerationOptions): Promise<ProjectNameAndRootOptions>;
|
|
37
|
+
export declare function resolveImportPath(tree: Tree, projectName: string, projectRoot: string): string;
|
|
38
|
+
export declare function ensureRootProjectName(options: {
|
|
39
|
+
directory: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
}, projectType: 'application' | 'library'): Promise<void>;
|