@nx/devkit 0.0.0-pr-22179-271588f → 0.0.0-pr-26482-ebe2dba
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/package.json +5 -4
- package/public-api.d.ts +1 -1
- package/public-api.js +2 -1
- package/src/executors/parse-target-string.d.ts +1 -3
- package/src/executors/parse-target-string.js +5 -9
- package/src/executors/read-target-options.d.ts +1 -2
- package/src/executors/read-target-options.js +4 -17
- package/src/generators/add-build-target-defaults.d.ts +1 -1
- package/src/generators/add-build-target-defaults.js +3 -4
- package/src/generators/artifact-name-and-directory-utils.d.ts +1 -1
- package/src/generators/artifact-name-and-directory-utils.js +37 -26
- package/src/generators/executor-options-utils.d.ts +1 -2
- package/src/generators/executor-options-utils.js +3 -6
- package/src/generators/format-files.d.ts +1 -1
- package/src/generators/format-files.js +5 -8
- package/src/generators/generate-files.d.ts +20 -2
- package/src/generators/generate-files.js +27 -5
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +10 -0
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.js +286 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts +62 -0
- package/src/generators/plugin-migrations/plugin-migration-utils.js +143 -0
- package/src/generators/project-name-and-root-utils.d.ts +1 -2
- package/src/generators/project-name-and-root-utils.js +16 -17
- package/src/generators/run-tasks-in-serial.d.ts +1 -1
- package/src/generators/to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.d.ts +1 -1
- package/src/generators/update-ts-configs-to-js.js +3 -4
- package/src/generators/visit-not-ignored-files.d.ts +1 -1
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +1 -1
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +1 -2
- package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +2 -3
- package/src/tasks/install-packages-task.d.ts +1 -2
- package/src/tasks/install-packages-task.js +5 -6
- package/src/utils/add-plugin.d.ts +13 -0
- package/src/utils/add-plugin.js +258 -0
- package/src/utils/async-iterable/combine-async-iterables.js +4 -2
- package/src/utils/binary-extensions.js +4 -0
- package/src/utils/calculate-hash-for-create-nodes.d.ts +2 -2
- package/src/utils/calculate-hash-for-create-nodes.js +6 -6
- package/src/utils/config-utils.d.ts +1 -0
- package/src/utils/config-utils.js +23 -11
- package/src/utils/convert-nx-executor.d.ts +1 -1
- package/src/utils/convert-nx-executor.js +21 -17
- package/src/utils/get-named-inputs.d.ts +1 -1
- package/src/utils/get-named-inputs.js +3 -4
- package/src/utils/get-workspace-layout.d.ts +1 -1
- package/src/utils/get-workspace-layout.js +2 -3
- package/src/utils/invoke-nx-generator.d.ts +1 -1
- package/src/utils/invoke-nx-generator.js +3 -5
- package/src/utils/log-show-project-command.js +2 -3
- package/src/utils/move-dir.d.ts +1 -1
- package/src/utils/move-dir.js +3 -4
- package/src/utils/package-json.d.ts +1 -2
- package/src/utils/package-json.js +13 -13
- package/src/utils/replace-package.d.ts +1 -1
- package/src/utils/replace-package.js +8 -9
- package/src/utils/replace-project-configuration-with-plugin.d.ts +1 -2
- package/src/utils/replace-project-configuration-with-plugin.js +12 -11
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/nx.d.ts +0 -1
- package/nx.js +0 -19
- package/src/utils/update-package-scripts.d.ts +0 -3
- package/src/utils/update-package-scripts.js +0 -175
package/LICENSE
CHANGED
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-26482-ebe2dba",
|
|
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": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"Cypress",
|
|
20
20
|
"CLI"
|
|
21
21
|
],
|
|
22
|
-
"main": "./index
|
|
22
|
+
"main": "./index",
|
|
23
23
|
"typings": "./index.d.ts",
|
|
24
24
|
"author": "Victor Savkin",
|
|
25
25
|
"license": "MIT",
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
"tslib": "^2.3.0",
|
|
36
36
|
"semver": "^7.5.3",
|
|
37
37
|
"yargs-parser": "21.1.1",
|
|
38
|
-
"
|
|
38
|
+
"minimatch": "9.0.3",
|
|
39
|
+
"@nrwl/devkit": "0.0.0-pr-26482-ebe2dba"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"nx": ">=
|
|
42
|
+
"nx": ">= 17 <= 20"
|
|
42
43
|
},
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
package/public-api.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { formatFiles } from './src/generators/format-files';
|
|
|
14
14
|
/**
|
|
15
15
|
* @category Generators
|
|
16
16
|
*/
|
|
17
|
-
export { generateFiles } from './src/generators/generate-files';
|
|
17
|
+
export { generateFiles, OverwriteStrategy, } from './src/generators/generate-files';
|
|
18
18
|
/**
|
|
19
19
|
* @category Generators
|
|
20
20
|
*/
|
package/public-api.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* a. We might need to duplicate code instead of importing from nx until all supported versions of nx contain the file.
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.moveFilesToNewDirectory = exports.convertNxExecutor = exports.convertNxGenerator = exports.offsetFromRoot = exports.ChangeType = exports.applyChangesToString = exports.extractLayoutDirectory = exports.getWorkspaceLayout = exports.names = exports.installPackagesTask = exports.NX_VERSION = exports.removeDependenciesFromPackageJson = exports.ensurePackage = exports.addDependenciesToPackageJson = exports.readTargetOptions = exports.targetToTargetString = exports.parseTargetString = exports.visitNotIgnoredFiles = exports.runTasksInSerial = exports.updateTsConfigsToJs = exports.toJS = exports.generateFiles = exports.formatFiles = void 0;
|
|
12
|
+
exports.moveFilesToNewDirectory = exports.convertNxExecutor = exports.convertNxGenerator = exports.offsetFromRoot = exports.ChangeType = exports.applyChangesToString = exports.extractLayoutDirectory = exports.getWorkspaceLayout = exports.names = exports.installPackagesTask = exports.NX_VERSION = exports.removeDependenciesFromPackageJson = exports.ensurePackage = exports.addDependenciesToPackageJson = exports.readTargetOptions = exports.targetToTargetString = exports.parseTargetString = exports.visitNotIgnoredFiles = exports.runTasksInSerial = exports.updateTsConfigsToJs = exports.toJS = exports.OverwriteStrategy = exports.generateFiles = exports.formatFiles = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* @category Generators
|
|
15
15
|
*/
|
|
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "formatFiles", { enumerable: true, get: function
|
|
|
20
20
|
*/
|
|
21
21
|
var generate_files_1 = require("./src/generators/generate-files");
|
|
22
22
|
Object.defineProperty(exports, "generateFiles", { enumerable: true, get: function () { return generate_files_1.generateFiles; } });
|
|
23
|
+
Object.defineProperty(exports, "OverwriteStrategy", { enumerable: true, get: function () { return generate_files_1.OverwriteStrategy; } });
|
|
23
24
|
/**
|
|
24
25
|
* @category Generators
|
|
25
26
|
*/
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
3
|
-
import type { ExecutorContext } from 'nx/src/devkit-exports';
|
|
1
|
+
import { ExecutorContext, ProjectGraph, Target } from 'nx/src/devkit-exports';
|
|
4
2
|
/**
|
|
5
3
|
* @deprecated(v17) A project graph should be passed to parseTargetString for best accuracy.
|
|
6
4
|
*/
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.targetToTargetString = exports.parseTargetString = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
// TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
|
|
7
|
-
splitTarget = splitTarget ?? require('nx/src/utils/split-target').splitTarget;
|
|
8
|
-
splitByColons =
|
|
9
|
-
splitByColons ?? ((s) => s.split(':'));
|
|
4
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
5
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
10
6
|
function parseTargetString(targetString, projectGraphOrCtx) {
|
|
11
7
|
let projectGraph = projectGraphOrCtx && 'projectGraph' in projectGraphOrCtx
|
|
12
8
|
? projectGraphOrCtx.projectGraph
|
|
13
9
|
: projectGraphOrCtx;
|
|
14
10
|
if (!projectGraph) {
|
|
15
11
|
try {
|
|
16
|
-
projectGraph = readCachedProjectGraph();
|
|
12
|
+
projectGraph = (0, devkit_exports_1.readCachedProjectGraph)();
|
|
17
13
|
}
|
|
18
14
|
catch (e) {
|
|
19
15
|
projectGraph = { nodes: {} };
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
const [maybeProject] = splitByColons(targetString);
|
|
18
|
+
const [maybeProject] = (0, devkit_internals_1.splitByColons)(targetString);
|
|
23
19
|
if (!projectGraph.nodes[maybeProject] &&
|
|
24
20
|
projectGraphOrCtx &&
|
|
25
21
|
'projectName' in projectGraphOrCtx &&
|
|
26
22
|
maybeProject !== projectGraphOrCtx.projectName) {
|
|
27
23
|
targetString = `${projectGraphOrCtx.projectName}:${targetString}`;
|
|
28
24
|
}
|
|
29
|
-
const [project, target, configuration] = splitTarget(targetString, projectGraph);
|
|
25
|
+
const [project, target, configuration] = (0, devkit_internals_1.splitTarget)(targetString, projectGraph);
|
|
30
26
|
if (!project || !target) {
|
|
31
27
|
throw new Error(`Invalid Target String: ${targetString}`);
|
|
32
28
|
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readTargetOptions = void 0;
|
|
4
|
-
const nx_1 = require("../../nx");
|
|
5
4
|
const path_1 = require("path");
|
|
6
|
-
|
|
7
|
-
// TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
|
|
8
|
-
combineOptionsForExecutor =
|
|
9
|
-
combineOptionsForExecutor ??
|
|
10
|
-
require('nx/src/utils/params').combineOptionsForExecutor;
|
|
5
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
11
6
|
/**
|
|
12
7
|
* Reads and combines options for a given target.
|
|
13
8
|
*
|
|
@@ -22,17 +17,9 @@ function readTargetOptions({ project, target, configuration }, context) {
|
|
|
22
17
|
if (!targetConfiguration) {
|
|
23
18
|
throw new Error(`Unable to find target ${target} for project ${project}`);
|
|
24
19
|
}
|
|
25
|
-
// TODO(v19): remove Workspaces.
|
|
26
|
-
const ws = new Workspaces(context.root);
|
|
27
20
|
const [nodeModule, executorName] = targetConfiguration.executor.split(':');
|
|
28
|
-
const { schema } = getExecutorInformation
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ws.readExecutor(nodeModule, executorName);
|
|
32
|
-
const defaultProject = calculateDefaultProjectName
|
|
33
|
-
? calculateDefaultProjectName(context.cwd, context.root, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration)
|
|
34
|
-
: // TODO(v19): remove calculateDefaultProjectName. This is to be backwards compatible with Nx 16.5 and below.
|
|
35
|
-
ws.calculateDefaultProjectName(context.cwd, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration);
|
|
36
|
-
return combineOptionsForExecutor({}, configuration ?? targetConfiguration.defaultConfiguration ?? '', targetConfiguration, schema, defaultProject, (0, path_1.relative)(context.root, context.cwd));
|
|
21
|
+
const { schema } = (0, devkit_internals_1.getExecutorInformation)(nodeModule, executorName, context.root, context.projectsConfigurations?.projects ?? context.workspace.projects);
|
|
22
|
+
const defaultProject = (0, devkit_internals_1.calculateDefaultProjectName)(context.cwd, context.root, { version: 2, projects: context.projectsConfigurations.projects }, context.nxJsonConfiguration);
|
|
23
|
+
return (0, devkit_internals_1.combineOptionsForExecutor)({}, configuration ?? targetConfiguration.defaultConfiguration ?? '', targetConfiguration, schema, defaultProject, (0, path_1.relative)(context.root, context.cwd));
|
|
37
24
|
}
|
|
38
25
|
exports.readTargetOptions = readTargetOptions;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Tree } from 'nx/src/devkit-exports';
|
|
2
2
|
export declare function addBuildTargetDefaults(tree: Tree, executorName: string, buildTargetName?: string): void;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addBuildTargetDefaults = void 0;
|
|
4
|
-
const
|
|
5
|
-
const { readNxJson, updateNxJson } = (0, nx_1.requireNx)();
|
|
4
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
5
|
function addBuildTargetDefaults(tree, executorName, buildTargetName = 'build') {
|
|
7
|
-
const nxJson = readNxJson(tree);
|
|
6
|
+
const nxJson = (0, devkit_exports_1.readNxJson)(tree);
|
|
8
7
|
nxJson.targetDefaults ??= {};
|
|
9
8
|
nxJson.targetDefaults[executorName] ??= {
|
|
10
9
|
cache: true,
|
|
@@ -13,6 +12,6 @@ function addBuildTargetDefaults(tree, executorName, buildTargetName = 'build') {
|
|
|
13
12
|
? ['production', '^production']
|
|
14
13
|
: ['default', '^default'],
|
|
15
14
|
};
|
|
16
|
-
updateNxJson(tree, nxJson);
|
|
15
|
+
(0, devkit_exports_1.updateNxJson)(tree, nxJson);
|
|
17
16
|
}
|
|
18
17
|
exports.addBuildTargetDefaults = addBuildTargetDefaults;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setCwd = exports.getRelativeCwd = exports.determineArtifactNameAndDirectoryOptions = void 0;
|
|
4
4
|
const enquirer_1 = require("enquirer");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const nx_1 = require("../../nx");
|
|
7
6
|
const names_1 = require("../utils/names");
|
|
8
|
-
const
|
|
7
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
8
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
9
9
|
async function determineArtifactNameAndDirectoryOptions(tree, options) {
|
|
10
10
|
if (!options.nameAndDirectoryFormat &&
|
|
11
11
|
(process.env.NX_INTERACTIVE !== 'true' || !isTTY())) {
|
|
@@ -53,8 +53,8 @@ async function determineFormat(formats, options) {
|
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
55
55
|
function logDeprecationMessage(options, formats) {
|
|
56
|
-
logger.warn(`
|
|
57
|
-
In Nx
|
|
56
|
+
devkit_exports_1.logger.warn(`
|
|
57
|
+
In Nx 20, generating a ${options.artifactType} will no longer support providing a project and deriving the directory.
|
|
58
58
|
Please provide the exact directory in the future.
|
|
59
59
|
Example: nx g ${options.callingGenerator} ${formats['derived'].artifactName} --directory ${formats['derived'].directory}
|
|
60
60
|
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,7 +62,7 @@ NOTE: The example above assumes the command is being run from the workspace root
|
|
|
62
62
|
}
|
|
63
63
|
function getNameAndDirectoryOptionFormats(tree, options) {
|
|
64
64
|
const directory = options.directory
|
|
65
|
-
? normalizePath(options.directory.replace(/^\.?\//, ''))
|
|
65
|
+
? (0, devkit_exports_1.normalizePath)(options.directory.replace(/^\.?\//, ''))
|
|
66
66
|
: undefined;
|
|
67
67
|
const fileExtension = options.fileExtension ?? 'ts';
|
|
68
68
|
const { name: extractedName, directory: extractedDirectory } = extractNameAndDirectoryFromName(options.name);
|
|
@@ -87,7 +87,7 @@ function getNameAndDirectoryOptionFormats(tree, options) {
|
|
|
87
87
|
}
|
|
88
88
|
if (options.disallowPathInNameForDerived && options.name.includes('/')) {
|
|
89
89
|
if (!options.nameAndDirectoryFormat) {
|
|
90
|
-
output.warn({
|
|
90
|
+
devkit_exports_1.output.warn({
|
|
91
91
|
title: `The provided name "${options.name}" contains a path and this is not supported by the "${options.callingGenerator}" when using the "derived" format.`,
|
|
92
92
|
bodyLines: [
|
|
93
93
|
`The generator will try to generate the ${options.artifactType} using the "as-provided" format at "${asProvidedOptions.filePath}".`,
|
|
@@ -116,13 +116,24 @@ function getNameAndDirectoryOptionFormats(tree, options) {
|
|
|
116
116
|
}
|
|
117
117
|
function getAsProvidedOptions(tree, options) {
|
|
118
118
|
const relativeCwd = getRelativeCwd();
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
let asProvidedDirectory;
|
|
120
|
+
if (options.directory) {
|
|
121
|
+
// append the directory to the current working directory if it doesn't start with it
|
|
122
|
+
if (options.directory === relativeCwd ||
|
|
123
|
+
options.directory.startsWith(`${relativeCwd}/`)) {
|
|
124
|
+
asProvidedDirectory = options.directory;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
asProvidedDirectory = (0, devkit_exports_1.joinPathFragments)(relativeCwd, options.directory);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
asProvidedDirectory = relativeCwd;
|
|
132
|
+
}
|
|
122
133
|
const asProvidedProject = findProjectFromPath(tree, asProvidedDirectory);
|
|
123
134
|
const asProvidedFileName = options.fileName ??
|
|
124
135
|
(options.suffix ? `${options.name}.${options.suffix}` : options.name);
|
|
125
|
-
const asProvidedFilePath = joinPathFragments(asProvidedDirectory, `${asProvidedFileName}.${options.fileExtension}`);
|
|
136
|
+
const asProvidedFilePath = (0, devkit_exports_1.joinPathFragments)(asProvidedDirectory, `${asProvidedFileName}.${options.fileExtension}`);
|
|
126
137
|
return {
|
|
127
138
|
artifactName: options.name,
|
|
128
139
|
directory: asProvidedDirectory,
|
|
@@ -132,7 +143,7 @@ function getAsProvidedOptions(tree, options) {
|
|
|
132
143
|
};
|
|
133
144
|
}
|
|
134
145
|
function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory) {
|
|
135
|
-
const projects = getProjects(tree);
|
|
146
|
+
const projects = (0, devkit_exports_1.getProjects)(tree);
|
|
136
147
|
if (options.project && !projects.has(options.project)) {
|
|
137
148
|
throw new Error(`The provided project "${options.project}" does not exist! Please provide an existing project name.`);
|
|
138
149
|
}
|
|
@@ -141,22 +152,22 @@ function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory)
|
|
|
141
152
|
const derivedName = options.name;
|
|
142
153
|
const baseDirectory = options.directory
|
|
143
154
|
? (0, names_1.names)(options.directory).fileName
|
|
144
|
-
: joinPathFragments(project.sourceRoot ?? joinPathFragments(project.root, 'src'), project.projectType === 'application' ? 'app' : 'lib', extractedDirectory ?? '');
|
|
155
|
+
: (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? (0, devkit_exports_1.joinPathFragments)(project.root, 'src'), project.projectType === 'application' ? 'app' : 'lib', extractedDirectory ?? '');
|
|
145
156
|
const derivedDirectory = typeof options.derivedDirectory === 'string'
|
|
146
|
-
? joinPathFragments(project.sourceRoot ?? project.root, options.derivedDirectory, options.flat
|
|
157
|
+
? (0, devkit_exports_1.joinPathFragments)(project.sourceRoot ?? project.root, options.derivedDirectory, options.flat
|
|
147
158
|
? ''
|
|
148
159
|
: options.pascalCaseDirectory
|
|
149
160
|
? (0, names_1.names)(derivedName).className
|
|
150
161
|
: (0, names_1.names)(derivedName).fileName)
|
|
151
162
|
: options.flat
|
|
152
|
-
? normalizePath(baseDirectory)
|
|
153
|
-
: joinPathFragments(baseDirectory, options.pascalCaseDirectory
|
|
163
|
+
? (0, devkit_exports_1.normalizePath)(baseDirectory)
|
|
164
|
+
: (0, devkit_exports_1.joinPathFragments)(baseDirectory, options.pascalCaseDirectory
|
|
154
165
|
? (0, names_1.names)(derivedName).className
|
|
155
166
|
: (0, names_1.names)(derivedName).fileName);
|
|
156
167
|
if (options.directory &&
|
|
157
168
|
!isDirectoryUnderProjectRoot(derivedDirectory, project.root)) {
|
|
158
169
|
if (!options.nameAndDirectoryFormat) {
|
|
159
|
-
output.warn({
|
|
170
|
+
devkit_exports_1.output.warn({
|
|
160
171
|
title: `The provided directory "${options.directory}" is not under the provided project root "${project.root}".`,
|
|
161
172
|
bodyLines: [
|
|
162
173
|
`The generator will try to generate the ${options.artifactType} using the "as-provided" format.`,
|
|
@@ -177,7 +188,7 @@ function getDerivedOptions(tree, options, asProvidedOptions, extractedDirectory)
|
|
|
177
188
|
? (0, names_1.names)(derivedFileName).className
|
|
178
189
|
: (0, names_1.names)(derivedFileName).fileName;
|
|
179
190
|
}
|
|
180
|
-
const derivedFilePath = joinPathFragments(derivedDirectory, `${derivedFileName}.${options.fileExtension}`);
|
|
191
|
+
const derivedFilePath = (0, devkit_exports_1.joinPathFragments)(derivedDirectory, `${derivedFileName}.${options.fileExtension}`);
|
|
181
192
|
return {
|
|
182
193
|
artifactName: derivedName,
|
|
183
194
|
directory: derivedDirectory,
|
|
@@ -199,16 +210,16 @@ function validateResolvedProject(tree, project, options, normalizedDirectory) {
|
|
|
199
210
|
}
|
|
200
211
|
function findProjectFromPath(tree, path) {
|
|
201
212
|
const projectConfigurations = {};
|
|
202
|
-
const projects = getProjects(tree);
|
|
213
|
+
const projects = (0, devkit_exports_1.getProjects)(tree);
|
|
203
214
|
for (const [projectName, project] of projects) {
|
|
204
215
|
projectConfigurations[projectName] = project;
|
|
205
216
|
}
|
|
206
|
-
const projectRootMappings = createProjectRootMappingsFromProjectConfigurations(projectConfigurations);
|
|
207
|
-
return findProjectForPath(path, projectRootMappings);
|
|
217
|
+
const projectRootMappings = (0, devkit_internals_1.createProjectRootMappingsFromProjectConfigurations)(projectConfigurations);
|
|
218
|
+
return (0, devkit_internals_1.findProjectForPath)(path, projectRootMappings);
|
|
208
219
|
}
|
|
209
220
|
function isDirectoryUnderProjectRoot(directory, projectRoot) {
|
|
210
|
-
const normalizedDirectory = joinPathFragments(workspaceRoot, directory);
|
|
211
|
-
const normalizedProjectRoot = joinPathFragments(workspaceRoot, projectRoot).replace(/\/$/, '');
|
|
221
|
+
const normalizedDirectory = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, directory);
|
|
222
|
+
const normalizedProjectRoot = (0, devkit_exports_1.joinPathFragments)(devkit_exports_1.workspaceRoot, projectRoot).replace(/\/$/, '');
|
|
212
223
|
return (normalizedDirectory === normalizedProjectRoot ||
|
|
213
224
|
normalizedDirectory.startsWith(`${normalizedProjectRoot}/`));
|
|
214
225
|
}
|
|
@@ -216,23 +227,23 @@ function isTTY() {
|
|
|
216
227
|
return !!process.stdout.isTTY && process.env['CI'] !== 'true';
|
|
217
228
|
}
|
|
218
229
|
function getRelativeCwd() {
|
|
219
|
-
return normalizePath((0, path_1.relative)(workspaceRoot, getCwd()));
|
|
230
|
+
return (0, devkit_exports_1.normalizePath)((0, path_1.relative)(devkit_exports_1.workspaceRoot, getCwd()));
|
|
220
231
|
}
|
|
221
232
|
exports.getRelativeCwd = getRelativeCwd;
|
|
222
233
|
/**
|
|
223
234
|
* Function for setting cwd during testing
|
|
224
235
|
*/
|
|
225
236
|
function setCwd(path) {
|
|
226
|
-
process.env.INIT_CWD = (0, path_1.join)(workspaceRoot, path);
|
|
237
|
+
process.env.INIT_CWD = (0, path_1.join)(devkit_exports_1.workspaceRoot, path);
|
|
227
238
|
}
|
|
228
239
|
exports.setCwd = setCwd;
|
|
229
240
|
function getCwd() {
|
|
230
|
-
return process.env.INIT_CWD?.startsWith(workspaceRoot)
|
|
241
|
+
return process.env.INIT_CWD?.startsWith(devkit_exports_1.workspaceRoot)
|
|
231
242
|
? process.env.INIT_CWD
|
|
232
243
|
: process.cwd();
|
|
233
244
|
}
|
|
234
245
|
function extractNameAndDirectoryFromName(rawName) {
|
|
235
|
-
const parsedName = normalizePath(rawName).split('/');
|
|
246
|
+
const parsedName = (0, devkit_exports_1.normalizePath)(rawName).split('/');
|
|
236
247
|
const name = parsedName.pop();
|
|
237
248
|
const directory = parsedName.length ? parsedName.join('/') : undefined;
|
|
238
249
|
return { name, directory };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
1
|
+
import { ProjectGraph, Tree } from 'nx/src/devkit-exports';
|
|
3
2
|
type CallBack<T> = (currentValue: T, project: string, target: string, configuration?: string) => void;
|
|
4
3
|
/**
|
|
5
4
|
* Calls a function for each different options that an executor is configured with
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.forEachExecutorOptionsInGraph = exports.forEachExecutorOptions = void 0;
|
|
4
|
-
const
|
|
5
|
-
const { getProjects } = (0, nx_1.requireNx)();
|
|
4
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
5
|
/**
|
|
7
6
|
* Calls a function for each different options that an executor is configured with
|
|
8
7
|
*/
|
|
@@ -15,7 +14,7 @@ executorName,
|
|
|
15
14
|
* Callback that is called for each options configured for a builder
|
|
16
15
|
*/
|
|
17
16
|
callback) {
|
|
18
|
-
forEachProjectConfig(getProjects(tree), executorName, callback);
|
|
17
|
+
forEachProjectConfig((0, devkit_exports_1.getProjects)(tree), executorName, callback);
|
|
19
18
|
}
|
|
20
19
|
exports.forEachExecutorOptions = forEachExecutorOptions;
|
|
21
20
|
/**
|
|
@@ -34,9 +33,7 @@ function forEachProjectConfig(projects, executorName, callback) {
|
|
|
34
33
|
if (executorName !== target.executor) {
|
|
35
34
|
continue;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
callback(target.options, projectName, targetName);
|
|
39
|
-
}
|
|
36
|
+
callback(target.options ?? {}, projectName, targetName);
|
|
40
37
|
if (!target.configurations) {
|
|
41
38
|
continue;
|
|
42
39
|
}
|
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatFiles = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
// TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
|
|
8
|
-
sortObjectByKeys =
|
|
9
|
-
sortObjectByKeys ?? require('nx/src/utils/object-sort').sortObjectByKeys;
|
|
5
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
6
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
10
7
|
/**
|
|
11
8
|
* Formats all the created or updated files using Prettier
|
|
12
9
|
* @param tree - the file system tree
|
|
@@ -56,11 +53,11 @@ function sortTsConfig(tree) {
|
|
|
56
53
|
if (!tsConfigPath) {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
|
-
updateJson(tree, tsConfigPath, (tsconfig) => ({
|
|
56
|
+
(0, devkit_exports_1.updateJson)(tree, tsConfigPath, (tsconfig) => ({
|
|
60
57
|
...tsconfig,
|
|
61
58
|
compilerOptions: {
|
|
62
59
|
...tsconfig.compilerOptions,
|
|
63
|
-
paths: sortObjectByKeys(tsconfig.compilerOptions.paths),
|
|
60
|
+
paths: (0, devkit_internals_1.sortObjectByKeys)(tsconfig.compilerOptions.paths),
|
|
64
61
|
},
|
|
65
62
|
}));
|
|
66
63
|
}
|
|
@@ -79,7 +76,7 @@ function getRootTsConfigPath(tree) {
|
|
|
79
76
|
function getChangedPrettierConfigInTree(tree) {
|
|
80
77
|
if (tree.listChanges().find((file) => file.path === '.prettierrc')) {
|
|
81
78
|
try {
|
|
82
|
-
return readJson(tree, '.prettierrc');
|
|
79
|
+
return (0, devkit_exports_1.readJson)(tree, '.prettierrc');
|
|
83
80
|
}
|
|
84
81
|
catch {
|
|
85
82
|
return null;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Tree } from 'nx/src/devkit-exports';
|
|
2
|
+
/**
|
|
3
|
+
* Specify what should be done when a file is generated but already exists on the system
|
|
4
|
+
*/
|
|
5
|
+
export declare enum OverwriteStrategy {
|
|
6
|
+
Overwrite = "overwrite",
|
|
7
|
+
KeepExisting = "keepExisting",
|
|
8
|
+
ThrowIfExisting = "throwIfExisting"
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Options for the generateFiles function
|
|
12
|
+
*/
|
|
13
|
+
export interface GenerateFilesOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Specify what should be done when a file is generated but already exists on the system
|
|
16
|
+
*/
|
|
17
|
+
overwriteStrategy?: OverwriteStrategy;
|
|
18
|
+
}
|
|
2
19
|
/**
|
|
3
20
|
* Generates a folder of files based on provided templates.
|
|
4
21
|
*
|
|
@@ -20,7 +37,8 @@ import type { Tree } from 'nx/src/generators/tree';
|
|
|
20
37
|
* @param srcFolder - the source folder of files (absolute path)
|
|
21
38
|
* @param target - the target folder (relative to the tree root)
|
|
22
39
|
* @param substitutions - an object of key-value pairs
|
|
40
|
+
* @param options - See {@link GenerateFilesOptions}
|
|
23
41
|
*/
|
|
24
42
|
export declare function generateFiles(tree: Tree, srcFolder: string, target: string, substitutions: {
|
|
25
43
|
[k: string]: any;
|
|
26
|
-
}): void;
|
|
44
|
+
}, options?: GenerateFilesOptions): void;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFiles = void 0;
|
|
3
|
+
exports.generateFiles = exports.OverwriteStrategy = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const nx_1 = require("../../nx");
|
|
7
6
|
const binary_extensions_1 = require("../utils/binary-extensions");
|
|
8
|
-
const
|
|
7
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
8
|
+
/**
|
|
9
|
+
* Specify what should be done when a file is generated but already exists on the system
|
|
10
|
+
*/
|
|
11
|
+
var OverwriteStrategy;
|
|
12
|
+
(function (OverwriteStrategy) {
|
|
13
|
+
OverwriteStrategy["Overwrite"] = "overwrite";
|
|
14
|
+
OverwriteStrategy["KeepExisting"] = "keepExisting";
|
|
15
|
+
OverwriteStrategy["ThrowIfExisting"] = "throwIfExisting";
|
|
16
|
+
})(OverwriteStrategy || (exports.OverwriteStrategy = OverwriteStrategy = {}));
|
|
9
17
|
/**
|
|
10
18
|
* Generates a folder of files based on provided templates.
|
|
11
19
|
*
|
|
@@ -27,8 +35,13 @@ const { logger } = (0, nx_1.requireNx)();
|
|
|
27
35
|
* @param srcFolder - the source folder of files (absolute path)
|
|
28
36
|
* @param target - the target folder (relative to the tree root)
|
|
29
37
|
* @param substitutions - an object of key-value pairs
|
|
38
|
+
* @param options - See {@link GenerateFilesOptions}
|
|
30
39
|
*/
|
|
31
|
-
function generateFiles(tree, srcFolder, target, substitutions
|
|
40
|
+
function generateFiles(tree, srcFolder, target, substitutions, options = {
|
|
41
|
+
overwriteStrategy: OverwriteStrategy.Overwrite,
|
|
42
|
+
}) {
|
|
43
|
+
options ??= {};
|
|
44
|
+
options.overwriteStrategy ??= OverwriteStrategy.Overwrite;
|
|
32
45
|
const ejs = require('ejs');
|
|
33
46
|
const files = allFilesInDir(srcFolder);
|
|
34
47
|
if (files.length === 0) {
|
|
@@ -38,6 +51,15 @@ function generateFiles(tree, srcFolder, target, substitutions) {
|
|
|
38
51
|
files.forEach((filePath) => {
|
|
39
52
|
let newContent;
|
|
40
53
|
const computedPath = computePath(srcFolder, target, filePath, substitutions);
|
|
54
|
+
if (tree.exists(computedPath)) {
|
|
55
|
+
if (options.overwriteStrategy === OverwriteStrategy.KeepExisting) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
else if (options.overwriteStrategy === OverwriteStrategy.ThrowIfExisting) {
|
|
59
|
+
throw new Error(`Generated file already exists, not allowed by overwrite strategy in generator (${computedPath})`);
|
|
60
|
+
}
|
|
61
|
+
// else: file should be overwritten, so just fall through to file generation
|
|
62
|
+
}
|
|
41
63
|
if ((0, binary_extensions_1.isBinaryPath)(filePath)) {
|
|
42
64
|
newContent = (0, fs_1.readFileSync)(filePath);
|
|
43
65
|
}
|
|
@@ -49,7 +71,7 @@ function generateFiles(tree, srcFolder, target, substitutions) {
|
|
|
49
71
|
});
|
|
50
72
|
}
|
|
51
73
|
catch (e) {
|
|
52
|
-
logger.error(`Error in ${filePath.replace(`${tree.root}/`, '')}:`);
|
|
74
|
+
devkit_exports_1.logger.error(`Error in ${filePath.replace(`${tree.root}/`, '')}:`);
|
|
53
75
|
throw e;
|
|
54
76
|
}
|
|
55
77
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProjectGraph, TargetConfiguration, Tree, CreateNodes, CreateNodesV2 } from 'nx/src/devkit-exports';
|
|
2
|
+
type PluginOptionsBuilder<T> = (targetName: string) => T;
|
|
3
|
+
type PostTargetTransformer = (targetConfiguration: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration;
|
|
7
|
+
type SkipTargetFilter = (targetConfiguration: TargetConfiguration) => [boolean, string];
|
|
8
|
+
export declare function migrateExecutorToPlugin<T>(tree: Tree, projectGraph: ProjectGraph, executor: string, pluginPath: string, pluginOptionsBuilder: PluginOptionsBuilder<T>, postTargetTransformer: PostTargetTransformer, createNodes: CreateNodesV2<T>, specificProjectToMigrate?: string, skipTargetFilter?: SkipTargetFilter): Promise<Map<string, Set<string>>>;
|
|
9
|
+
export declare function migrateExecutorToPluginV1<T>(tree: Tree, projectGraph: ProjectGraph, executor: string, pluginPath: string, pluginOptionsBuilder: PluginOptionsBuilder<T>, postTargetTransformer: PostTargetTransformer, createNodes: CreateNodes<T>, specificProjectToMigrate?: string, skipTargetFilter?: SkipTargetFilter): Promise<Map<string, Set<string>>>;
|
|
10
|
+
export {};
|