@nx/devkit 0.0.0-pr-22179-271588f

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.
Files changed (98) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/index.d.ts +14 -0
  4. package/index.js +18 -0
  5. package/migrations.json +18 -0
  6. package/ngcli-adapter.d.ts +4 -0
  7. package/ngcli-adapter.js +11 -0
  8. package/nx.d.ts +1 -0
  9. package/nx.js +19 -0
  10. package/package.json +50 -0
  11. package/public-api.d.ts +78 -0
  12. package/public-api.js +100 -0
  13. package/src/executors/parse-target-string.d.ts +44 -0
  14. package/src/executors/parse-target-string.js +55 -0
  15. package/src/executors/read-target-options.d.ts +8 -0
  16. package/src/executors/read-target-options.js +38 -0
  17. package/src/generators/add-build-target-defaults.d.ts +2 -0
  18. package/src/generators/add-build-target-defaults.js +18 -0
  19. package/src/generators/artifact-name-and-directory-utils.d.ts +48 -0
  20. package/src/generators/artifact-name-and-directory-utils.js +239 -0
  21. package/src/generators/executor-options-utils.d.ts +21 -0
  22. package/src/generators/executor-options-utils.js +49 -0
  23. package/src/generators/format-files.d.ts +6 -0
  24. package/src/generators/format-files.js +91 -0
  25. package/src/generators/generate-files.d.ts +26 -0
  26. package/src/generators/generate-files.js +91 -0
  27. package/src/generators/project-name-and-root-utils.d.ts +47 -0
  28. package/src/generators/project-name-and-root-utils.js +298 -0
  29. package/src/generators/run-tasks-in-serial.d.ts +7 -0
  30. package/src/generators/run-tasks-in-serial.js +16 -0
  31. package/src/generators/to-js.d.ts +11 -0
  32. package/src/generators/to-js.js +24 -0
  33. package/src/generators/typescript/insert-import.d.ts +1 -0
  34. package/src/generators/typescript/insert-import.js +5 -0
  35. package/src/generators/typescript/insert-statement.d.ts +1 -0
  36. package/src/generators/typescript/insert-statement.js +5 -0
  37. package/src/generators/update-ts-configs-to-js.d.ts +4 -0
  38. package/src/generators/update-ts-configs-to-js.js +49 -0
  39. package/src/generators/visit-not-ignored-files.d.ts +5 -0
  40. package/src/generators/visit-not-ignored-files.js +41 -0
  41. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  42. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  43. package/src/migrations/update-16-9-0/migrate-mf-util-usage.d.ts +4 -0
  44. package/src/migrations/update-16-9-0/migrate-mf-util-usage.js +201 -0
  45. package/src/tasks/install-packages-task.d.ts +10 -0
  46. package/src/tasks/install-packages-task.js +41 -0
  47. package/src/utils/async-iterable/combine-async-iterables.d.ts +3 -0
  48. package/src/utils/async-iterable/combine-async-iterables.js +58 -0
  49. package/src/utils/async-iterable/create-async-iterable.d.ts +6 -0
  50. package/src/utils/async-iterable/create-async-iterable.js +58 -0
  51. package/src/utils/async-iterable/index.d.ts +4 -0
  52. package/src/utils/async-iterable/index.js +7 -0
  53. package/src/utils/async-iterable/map-async-iteratable.d.ts +1 -0
  54. package/src/utils/async-iterable/map-async-iteratable.js +18 -0
  55. package/src/utils/async-iterable/tap-async-iteratable.d.ts +1 -0
  56. package/src/utils/async-iterable/tap-async-iteratable.js +11 -0
  57. package/src/utils/binary-extensions.d.ts +1 -0
  58. package/src/utils/binary-extensions.js +275 -0
  59. package/src/utils/calculate-hash-for-create-nodes.d.ts +2 -0
  60. package/src/utils/calculate-hash-for-create-nodes.js +16 -0
  61. package/src/utils/config-utils.d.ts +4 -0
  62. package/src/utils/config-utils.js +75 -0
  63. package/src/utils/convert-nx-executor.d.ts +7 -0
  64. package/src/utils/convert-nx-executor.js +89 -0
  65. package/src/utils/get-named-inputs.d.ts +8 -0
  66. package/src/utils/get-named-inputs.js +26 -0
  67. package/src/utils/get-workspace-layout.d.ts +24 -0
  68. package/src/utils/get-workspace-layout.js +52 -0
  69. package/src/utils/invoke-nx-generator.d.ts +6 -0
  70. package/src/utils/invoke-nx-generator.js +172 -0
  71. package/src/utils/log-show-project-command.d.ts +1 -0
  72. package/src/utils/log-show-project-command.js +14 -0
  73. package/src/utils/move-dir.d.ts +5 -0
  74. package/src/utils/move-dir.js +28 -0
  75. package/src/utils/names.d.ts +18 -0
  76. package/src/utils/names.js +63 -0
  77. package/src/utils/offset-from-root.d.ts +13 -0
  78. package/src/utils/offset-from-root.js +29 -0
  79. package/src/utils/package-json.d.ts +78 -0
  80. package/src/utils/package-json.js +375 -0
  81. package/src/utils/replace-package.d.ts +2 -0
  82. package/src/utils/replace-package.js +125 -0
  83. package/src/utils/replace-project-configuration-with-plugin.d.ts +3 -0
  84. package/src/utils/replace-project-configuration-with-plugin.js +136 -0
  85. package/src/utils/rxjs-for-await.d.ts +109 -0
  86. package/src/utils/rxjs-for-await.js +363 -0
  87. package/src/utils/semver.d.ts +1 -0
  88. package/src/utils/semver.js +18 -0
  89. package/src/utils/string-change.d.ts +62 -0
  90. package/src/utils/string-change.js +109 -0
  91. package/src/utils/string-utils.d.ts +95 -0
  92. package/src/utils/string-utils.js +147 -0
  93. package/src/utils/update-package-scripts.d.ts +3 -0
  94. package/src/utils/update-package-scripts.js +175 -0
  95. package/src/utils/versions.d.ts +1 -0
  96. package/src/utils/versions.js +4 -0
  97. package/testing.d.ts +1 -0
  98. package/testing.js +5 -0
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertNxGenerator = void 0;
4
+ const path_1 = require("path");
5
+ const nx_1 = require("../../nx");
6
+ let { logger, stripIndent } = (0, nx_1.requireNx)();
7
+ // TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
8
+ stripIndent = stripIndent ?? require('nx/src/utils/logger').stripIndent;
9
+ class RunCallbackTask {
10
+ constructor(callback) {
11
+ this.callback = callback;
12
+ }
13
+ toConfiguration() {
14
+ return {
15
+ name: 'RunCallback',
16
+ options: {
17
+ callback: this.callback,
18
+ },
19
+ };
20
+ }
21
+ }
22
+ function createRunCallbackTask() {
23
+ return {
24
+ name: 'RunCallback',
25
+ create: () => {
26
+ return Promise.resolve(async ({ callback }) => {
27
+ await callback();
28
+ });
29
+ },
30
+ };
31
+ }
32
+ /**
33
+ * Convert an Nx Generator into an Angular Devkit Schematic.
34
+ * @param generator The Nx generator to convert to an Angular Devkit Schematic.
35
+ */
36
+ function convertNxGenerator(generator, skipWritingConfigInOldFormat = false) {
37
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
38
+ return (generatorOptions) => invokeNxGenerator(generator, generatorOptions);
39
+ }
40
+ exports.convertNxGenerator = convertNxGenerator;
41
+ /**
42
+ * Create a Rule to invoke an Nx Generator
43
+ */
44
+ function invokeNxGenerator(generator, options, skipWritingConfigInOldFormat) {
45
+ return async (tree, context) => {
46
+ if (context.engine.workflow) {
47
+ const engineHost = context.engine.workflow.engineHost;
48
+ engineHost.registerTaskExecutor(createRunCallbackTask());
49
+ }
50
+ const root = context.engine.workflow && context.engine.workflow.engineHost.paths
51
+ ? context.engine.workflow.engineHost.paths[1]
52
+ : tree.root.path;
53
+ const adapterTree = new DevkitTreeFromAngularDevkitTree(tree, root, skipWritingConfigInOldFormat);
54
+ const result = await generator(adapterTree, options);
55
+ if (!result) {
56
+ return adapterTree['tree'];
57
+ }
58
+ if (typeof result === 'function') {
59
+ if (context.engine.workflow) {
60
+ context.addTask(new RunCallbackTask(result));
61
+ }
62
+ }
63
+ };
64
+ }
65
+ const actionToFileChangeMap = {
66
+ c: 'CREATE',
67
+ o: 'UPDATE',
68
+ d: 'DELETE',
69
+ };
70
+ class DevkitTreeFromAngularDevkitTree {
71
+ constructor(tree, _root, skipWritingConfigInOldFormat) {
72
+ this.tree = tree;
73
+ this._root = _root;
74
+ this.skipWritingConfigInOldFormat = skipWritingConfigInOldFormat;
75
+ /**
76
+ * When using the UnitTestTree from @angular-devkit/schematics/testing, the root is just `/`.
77
+ * This causes a massive issue if `getProjects()` is used in the underlying generator because it
78
+ * causes fast-glob to be set to work on the user's entire file system.
79
+ *
80
+ * Therefore, in this case, patch the root to match what Nx Devkit does and use /virtual instead.
81
+ */
82
+ try {
83
+ const { UnitTestTree } = require('@angular-devkit/schematics/testing');
84
+ if (tree instanceof UnitTestTree && _root === '/') {
85
+ this._root = '/virtual';
86
+ }
87
+ }
88
+ catch { }
89
+ }
90
+ get root() {
91
+ return this._root;
92
+ }
93
+ children(dirPath) {
94
+ const { subdirs, subfiles } = this.tree.getDir(dirPath);
95
+ return [...subdirs, ...subfiles];
96
+ }
97
+ delete(filePath) {
98
+ this.tree.delete(filePath);
99
+ }
100
+ exists(filePath) {
101
+ if (this.isFile(filePath)) {
102
+ return this.tree.exists(filePath);
103
+ }
104
+ else {
105
+ return this.children(filePath).length > 0;
106
+ }
107
+ }
108
+ isFile(filePath) {
109
+ return this.tree.exists(filePath) && !!this.tree.read(filePath);
110
+ }
111
+ listChanges() {
112
+ const fileChanges = [];
113
+ for (const action of this.tree.actions) {
114
+ if (action.kind === 'r') {
115
+ fileChanges.push({
116
+ path: this.normalize(action.to),
117
+ type: 'CREATE',
118
+ content: this.read(action.to),
119
+ });
120
+ fileChanges.push({
121
+ path: this.normalize(action.path),
122
+ type: 'DELETE',
123
+ content: null,
124
+ });
125
+ }
126
+ else if (action.kind === 'c' || action.kind === 'o') {
127
+ fileChanges.push({
128
+ path: this.normalize(action.path),
129
+ type: actionToFileChangeMap[action.kind],
130
+ content: action.content,
131
+ });
132
+ }
133
+ else {
134
+ fileChanges.push({
135
+ path: this.normalize(action.path),
136
+ type: 'DELETE',
137
+ content: null,
138
+ });
139
+ }
140
+ }
141
+ return fileChanges;
142
+ }
143
+ normalize(path) {
144
+ return (0, path_1.relative)(this.root, (0, path_1.join)(this.root, path));
145
+ }
146
+ read(filePath, encoding) {
147
+ return encoding
148
+ ? this.tree.read(filePath).toString(encoding)
149
+ : this.tree.read(filePath);
150
+ }
151
+ rename(from, to) {
152
+ this.tree.rename(from, to);
153
+ }
154
+ write(filePath, content, options) {
155
+ if (options?.mode) {
156
+ this.warnUnsupportedFilePermissionsChange(filePath, options.mode);
157
+ }
158
+ if (this.tree.exists(filePath)) {
159
+ this.tree.overwrite(filePath, content);
160
+ }
161
+ else {
162
+ this.tree.create(filePath, content);
163
+ }
164
+ }
165
+ changePermissions(filePath, mode) {
166
+ this.warnUnsupportedFilePermissionsChange(filePath, mode);
167
+ }
168
+ warnUnsupportedFilePermissionsChange(filePath, mode) {
169
+ logger.warn(stripIndent(`The Angular DevKit tree does not support changing a file permissions.
170
+ Ignoring changing ${filePath} permissions to ${mode}.`));
171
+ }
172
+ }
@@ -0,0 +1 @@
1
+ export declare function logShowProjectCommand(projectName: string): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logShowProjectCommand = void 0;
4
+ const nx_1 = require("../../nx");
5
+ function logShowProjectCommand(projectName) {
6
+ const { output } = (0, nx_1.requireNx)();
7
+ output.log({
8
+ title: `👀 View Details of ${projectName}`,
9
+ bodyLines: [
10
+ `Run "nx show project ${projectName} --web" to view details about this project.`,
11
+ ],
12
+ });
13
+ }
14
+ exports.logShowProjectCommand = logShowProjectCommand;
@@ -0,0 +1,5 @@
1
+ import type { Tree } from 'nx/src/generators/tree';
2
+ /**
3
+ * Analogous to cp -r oldDir newDir
4
+ */
5
+ export declare function moveFilesToNewDirectory(tree: Tree, oldDir: string, newDir: string): void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.moveFilesToNewDirectory = void 0;
4
+ const path_1 = require("path");
5
+ const visit_not_ignored_files_1 = require("../generators/visit-not-ignored-files");
6
+ const nx_1 = require("../../nx");
7
+ const { normalizePath } = (0, nx_1.requireNx)();
8
+ /**
9
+ * Analogous to cp -r oldDir newDir
10
+ */
11
+ function moveFilesToNewDirectory(tree, oldDir, newDir) {
12
+ oldDir = normalizePath(oldDir);
13
+ newDir = normalizePath(newDir);
14
+ (0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, oldDir, (file) => {
15
+ try {
16
+ tree.rename(file, `${newDir}/${(0, path_1.relative)(oldDir, file)}`);
17
+ }
18
+ catch (e) {
19
+ if (!tree.exists(oldDir)) {
20
+ console.warn(`Path ${oldDir} does not exist`);
21
+ }
22
+ else if (!tree.exists(newDir)) {
23
+ console.warn(`Path ${newDir} does not exist`);
24
+ }
25
+ }
26
+ });
27
+ }
28
+ exports.moveFilesToNewDirectory = moveFilesToNewDirectory;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Util function to generate different strings based off the provided name.
3
+ *
4
+ * Examples:
5
+ *
6
+ * ```typescript
7
+ * names("my-name") // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
8
+ * names("myName") // {name: 'myName', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
9
+ * ```
10
+ * @param name
11
+ */
12
+ export declare function names(name: string): {
13
+ name: string;
14
+ className: string;
15
+ propertyName: string;
16
+ constantName: string;
17
+ fileName: string;
18
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.names = void 0;
4
+ /**
5
+ * Util function to generate different strings based off the provided name.
6
+ *
7
+ * Examples:
8
+ *
9
+ * ```typescript
10
+ * names("my-name") // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
11
+ * names("myName") // {name: 'myName', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
12
+ * ```
13
+ * @param name
14
+ */
15
+ function names(name) {
16
+ return {
17
+ name,
18
+ className: toClassName(name),
19
+ propertyName: toPropertyName(name),
20
+ constantName: toConstantName(name),
21
+ fileName: toFileName(name),
22
+ };
23
+ }
24
+ exports.names = names;
25
+ /**
26
+ * Hyphenated to UpperCamelCase
27
+ */
28
+ function toClassName(str) {
29
+ return toCapitalCase(toPropertyName(str));
30
+ }
31
+ /**
32
+ * Hyphenated to lowerCamelCase
33
+ */
34
+ function toPropertyName(s) {
35
+ return s
36
+ .replace(/([^a-zA-Z0-9])+(.)?/g, (_, __, chr) => chr ? chr.toUpperCase() : '')
37
+ .replace(/[^a-zA-Z\d]/g, '')
38
+ .replace(/^([A-Z])/, (m) => m.toLowerCase());
39
+ }
40
+ /**
41
+ * Hyphenated to CONSTANT_CASE
42
+ */
43
+ function toConstantName(s) {
44
+ const normalizedS = s.toUpperCase() === s ? s.toLowerCase() : s;
45
+ return toFileName(toPropertyName(normalizedS))
46
+ .replace(/([^a-zA-Z0-9])/g, '_')
47
+ .toUpperCase();
48
+ }
49
+ /**
50
+ * Upper camelCase to lowercase, hyphenated
51
+ */
52
+ function toFileName(s) {
53
+ return s
54
+ .replace(/([a-z\d])([A-Z])/g, '$1_$2')
55
+ .toLowerCase()
56
+ .replace(/(?!^[_])[ _]/g, '-');
57
+ }
58
+ /**
59
+ * Capitalizes the first letter of a string
60
+ */
61
+ function toCapitalCase(s) {
62
+ return s.charAt(0).toUpperCase() + s.slice(1);
63
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Calculates an offset from the root of the workspace, which is useful for
3
+ * constructing relative URLs.
4
+ *
5
+ * Examples:
6
+ *
7
+ * ```typescript
8
+ * offsetFromRoot("apps/mydir/myapp/") // returns "../../../"
9
+ * ```
10
+ *
11
+ * @param fullPathToDir - directory path
12
+ */
13
+ export declare function offsetFromRoot(fullPathToDir: string): string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.offsetFromRoot = void 0;
4
+ const path_1 = require("path");
5
+ /**
6
+ * Calculates an offset from the root of the workspace, which is useful for
7
+ * constructing relative URLs.
8
+ *
9
+ * Examples:
10
+ *
11
+ * ```typescript
12
+ * offsetFromRoot("apps/mydir/myapp/") // returns "../../../"
13
+ * ```
14
+ *
15
+ * @param fullPathToDir - directory path
16
+ */
17
+ function offsetFromRoot(fullPathToDir) {
18
+ if (fullPathToDir === '.')
19
+ return './';
20
+ const parts = (0, path_1.normalize)(fullPathToDir).split(path_1.sep);
21
+ let offset = '';
22
+ for (let i = 0; i < parts.length; ++i) {
23
+ if (parts[i].length > 0) {
24
+ offset += '../';
25
+ }
26
+ }
27
+ return offset;
28
+ }
29
+ exports.offsetFromRoot = offsetFromRoot;
@@ -0,0 +1,78 @@
1
+ import type { Tree } from 'nx/src/generators/tree';
2
+ import type { GeneratorCallback } from 'nx/src/config/misc-interfaces';
3
+ /**
4
+ * Add Dependencies and Dev Dependencies to package.json
5
+ *
6
+ * For example:
7
+ * ```typescript
8
+ * addDependenciesToPackageJson(tree, { react: 'latest' }, { jest: 'latest' })
9
+ * ```
10
+ * This will **add** `react` and `jest` to the dependencies and devDependencies sections of package.json respectively.
11
+ *
12
+ * @param tree Tree representing file system to modify
13
+ * @param dependencies Dependencies to be added to the dependencies section of package.json
14
+ * @param devDependencies Dependencies to be added to the devDependencies section of package.json
15
+ * @param packageJsonPath Path to package.json
16
+ * @param keepExistingVersions If true, prevents existing dependencies from being bumped to newer versions
17
+ * @returns Callback to install dependencies only if necessary, no-op otherwise
18
+ */
19
+ export declare function addDependenciesToPackageJson(tree: Tree, dependencies: Record<string, string>, devDependencies: Record<string, string>, packageJsonPath?: string, keepExistingVersions?: boolean): GeneratorCallback;
20
+ /**
21
+ * Remove Dependencies and Dev Dependencies from package.json
22
+ *
23
+ * For example:
24
+ * ```typescript
25
+ * removeDependenciesFromPackageJson(tree, ['react'], ['jest'])
26
+ * ```
27
+ * This will **remove** `react` and `jest` from the dependencies and devDependencies sections of package.json respectively.
28
+ *
29
+ * @param dependencies Dependencies to be removed from the dependencies section of package.json
30
+ * @param devDependencies Dependencies to be removed from the devDependencies section of package.json
31
+ * @returns Callback to uninstall dependencies only if necessary. undefined is returned if changes are not necessary.
32
+ */
33
+ export declare function removeDependenciesFromPackageJson(tree: Tree, dependencies: string[], devDependencies: string[], packageJsonPath?: string): GeneratorCallback;
34
+ /**
35
+ * @typedef EnsurePackageOptions
36
+ * @type {object}
37
+ * @property {boolean} dev indicate if the package is a dev dependency
38
+ * @property {throwOnMissing} boolean throws an error when the package is missing
39
+ */
40
+ /**
41
+ * @deprecated Use the other function signature without a Tree
42
+ *
43
+ * Use a package that has not been installed as a dependency.
44
+ *
45
+ * For example:
46
+ * ```typescript
47
+ * ensurePackage(tree, '@nx/jest', nxVersion)
48
+ * ```
49
+ * This install the @nx/jest@<nxVersion> and return the module
50
+ * When running with --dryRun, the function will throw when dependencies are missing.
51
+ * Returns null for ESM dependencies. Import them with a dynamic import instead.
52
+ *
53
+ * @param tree the file system tree
54
+ * @param pkg the package to check (e.g. @nx/jest)
55
+ * @param requiredVersion the version or semver range to check (e.g. ~1.0.0, >=1.0.0 <2.0.0)
56
+ * @param {EnsurePackageOptions} options?
57
+ */
58
+ export declare function ensurePackage(tree: Tree, pkg: string, requiredVersion: string, options?: {
59
+ dev?: boolean;
60
+ throwOnMissing?: boolean;
61
+ }): void;
62
+ /**
63
+ * Ensure that dependencies and devDependencies from package.json are installed at the required versions.
64
+ * Returns null for ESM dependencies. Import them with a dynamic import instead.
65
+ *
66
+ * For example:
67
+ * ```typescript
68
+ * ensurePackage('@nx/jest', nxVersion)
69
+ * ```
70
+ *
71
+ * @param pkg the package to install and require
72
+ * @param version the version to install if the package doesn't exist already
73
+ */
74
+ export declare function ensurePackage<T extends any = any>(pkg: string, version: string): T;
75
+ /**
76
+ * @description The version of Nx used by the workspace. Returns null if no version is found.
77
+ */
78
+ export declare const NX_VERSION: string;