@nx/devkit 23.0.0-beta.2 → 23.0.0-beta.20
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/{index.d.ts → dist/index.d.ts} +0 -1
- package/dist/internal.d.ts +24 -0
- package/dist/internal.js +84 -0
- package/{ngcli-adapter.d.ts → dist/ngcli-adapter.d.ts} +0 -1
- package/{public-api.d.ts → dist/public-api.d.ts} +0 -1
- package/{src → dist/src}/executors/parse-target-string.d.ts +0 -1
- package/{src → dist/src}/executors/read-target-options.d.ts +0 -1
- package/{src → dist/src}/generators/artifact-name-and-directory-utils.d.ts +0 -1
- package/{src → dist/src}/generators/e2e-web-server-info-utils.d.ts +0 -1
- package/{src → dist/src}/generators/e2e-web-server-info-utils.js +8 -12
- package/{src → dist/src}/generators/executor-options-utils.d.ts +0 -1
- package/{src → dist/src}/generators/format-files.d.ts +0 -1
- package/{src → dist/src}/generators/format-files.js +1 -1
- package/{src → dist/src}/generators/generate-files.d.ts +0 -1
- package/{src → dist/src}/generators/plugin-migrations/aggregate-log-util.d.ts +0 -1
- package/{src → dist/src}/generators/plugin-migrations/executor-to-plugin-migrator.d.ts +2 -2
- package/{src → dist/src}/generators/plugin-migrations/executor-to-plugin-migrator.js +19 -1
- package/{src → dist/src}/generators/plugin-migrations/plugin-migration-utils.d.ts +0 -1
- package/{src → dist/src}/generators/project-name-and-root-utils.d.ts +0 -1
- package/{src → dist/src}/generators/prompt.d.ts +0 -1
- package/{src → dist/src}/generators/run-tasks-in-serial.d.ts +0 -1
- package/dist/src/generators/target-defaults-utils.d.ts +31 -0
- package/dist/src/generators/target-defaults-utils.js +216 -0
- package/{src → dist/src}/generators/to-js.d.ts +0 -1
- package/{src → dist/src}/generators/to-js.js +9 -4
- package/{src → dist/src}/generators/typescript/insert-import.d.ts +0 -1
- package/{src → dist/src}/generators/typescript/insert-statement.d.ts +0 -1
- package/{src → dist/src}/generators/update-ts-configs-to-js.d.ts +0 -1
- package/{src → dist/src}/generators/visit-not-ignored-files.d.ts +0 -1
- package/dist/src/migrations/update-23-0-0/update-deep-imports.d.ts +4 -0
- package/dist/src/migrations/update-23-0-0/update-deep-imports.js +323 -0
- package/dist/src/migrations/update-23-0-0/update-deep-imports.md +43 -0
- package/{src → dist/src}/tasks/install-packages-task.d.ts +0 -1
- package/{src → dist/src}/utils/add-plugin.d.ts +0 -1
- package/{src → dist/src}/utils/async-iterable/combine-async-iterables.d.ts +0 -1
- package/{src → dist/src}/utils/async-iterable/create-async-iterable.d.ts +0 -1
- package/{src → dist/src}/utils/async-iterable/index.d.ts +0 -1
- package/{src → dist/src}/utils/async-iterable/map-async-iteratable.d.ts +0 -1
- package/{src → dist/src}/utils/async-iterable/tap-async-iteratable.d.ts +0 -1
- package/{src → dist/src}/utils/binary-extensions.d.ts +0 -1
- package/{src → dist/src}/utils/calculate-hash-for-create-nodes.d.ts +5 -1
- package/{src → dist/src}/utils/calculate-hash-for-create-nodes.js +12 -5
- package/{src → dist/src}/utils/catalog/index.d.ts +0 -1
- package/{src → dist/src}/utils/catalog/manager-factory.d.ts +0 -1
- package/{src → dist/src}/utils/catalog/manager.d.ts +0 -1
- package/{src → dist/src}/utils/catalog/pnpm-manager.d.ts +0 -1
- package/{src → dist/src}/utils/catalog/types.d.ts +0 -1
- package/{src → dist/src}/utils/catalog/yarn-manager.d.ts +0 -1
- package/{src → dist/src}/utils/config-utils.d.ts +0 -1
- package/{src → dist/src}/utils/config-utils.js +59 -4
- package/{src → dist/src}/utils/convert-nx-executor.d.ts +0 -1
- package/{src → dist/src}/utils/find-plugin-for-config-file.d.ts +0 -1
- package/dist/src/utils/find-plugin-for-config-file.js +28 -0
- package/{src → dist/src}/utils/get-named-inputs.d.ts +0 -1
- package/{src → dist/src}/utils/get-workspace-layout.d.ts +0 -1
- package/dist/src/utils/installed-version.d.ts +29 -0
- package/dist/src/utils/installed-version.js +57 -0
- package/{src → dist/src}/utils/invoke-nx-generator.d.ts +0 -1
- package/{src → dist/src}/utils/log-show-project-command.d.ts +0 -1
- package/{src → dist/src}/utils/move-dir.d.ts +0 -1
- package/{src → dist/src}/utils/names.d.ts +0 -1
- package/dist/src/utils/normalize-target-defaults.d.ts +32 -0
- package/dist/src/utils/normalize-target-defaults.js +84 -0
- package/{src → dist/src}/utils/offset-from-root.d.ts +0 -1
- package/{src → dist/src}/utils/package-json.d.ts +0 -1
- package/{src → dist/src}/utils/replace-project-configuration-with-plugin.d.ts +0 -1
- package/{src → dist/src}/utils/rxjs-for-await.d.ts +0 -1
- package/{src → dist/src}/utils/semver.d.ts +0 -1
- package/{src → dist/src}/utils/string-change.d.ts +0 -1
- package/{src → dist/src}/utils/string-utils.d.ts +0 -1
- package/dist/src/utils/version-floor.d.ts +25 -0
- package/dist/src/utils/version-floor.js +45 -0
- package/{src → dist/src}/utils/versions.d.ts +0 -1
- package/{testing.d.ts → dist/testing.d.ts} +0 -1
- package/migrations.json +9 -3
- package/package.json +57 -7
- package/assets.json +0 -15
- package/index.d.ts.map +0 -1
- package/internal.d.ts +0 -2
- package/internal.d.ts.map +0 -1
- package/internal.js +0 -8
- package/ngcli-adapter.d.ts.map +0 -1
- package/project.json +0 -14
- package/public-api.d.ts.map +0 -1
- package/src/executors/parse-target-string.d.ts.map +0 -1
- package/src/executors/read-target-options.d.ts.map +0 -1
- package/src/generators/artifact-name-and-directory-utils.d.ts.map +0 -1
- package/src/generators/e2e-web-server-info-utils.d.ts.map +0 -1
- package/src/generators/executor-options-utils.d.ts.map +0 -1
- package/src/generators/format-files.d.ts.map +0 -1
- package/src/generators/generate-files.d.ts.map +0 -1
- package/src/generators/plugin-migrations/aggregate-log-util.d.ts.map +0 -1
- package/src/generators/plugin-migrations/executor-to-plugin-migrator.d.ts.map +0 -1
- package/src/generators/plugin-migrations/plugin-migration-utils.d.ts.map +0 -1
- package/src/generators/project-name-and-root-utils.d.ts.map +0 -1
- package/src/generators/prompt.d.ts.map +0 -1
- package/src/generators/run-tasks-in-serial.d.ts.map +0 -1
- package/src/generators/target-defaults-utils.d.ts +0 -4
- package/src/generators/target-defaults-utils.d.ts.map +0 -1
- package/src/generators/target-defaults-utils.js +0 -100
- package/src/generators/to-js.d.ts.map +0 -1
- package/src/generators/typescript/insert-import.d.ts.map +0 -1
- package/src/generators/typescript/insert-statement.d.ts.map +0 -1
- package/src/generators/update-ts-configs-to-js.d.ts.map +0 -1
- package/src/generators/visit-not-ignored-files.d.ts.map +0 -1
- package/src/tasks/install-packages-task.d.ts.map +0 -1
- package/src/utils/add-plugin.d.ts.map +0 -1
- package/src/utils/async-iterable/combine-async-iterables.d.ts.map +0 -1
- package/src/utils/async-iterable/create-async-iterable.d.ts.map +0 -1
- package/src/utils/async-iterable/index.d.ts.map +0 -1
- package/src/utils/async-iterable/map-async-iteratable.d.ts.map +0 -1
- package/src/utils/async-iterable/tap-async-iteratable.d.ts.map +0 -1
- package/src/utils/binary-extensions.d.ts.map +0 -1
- package/src/utils/calculate-hash-for-create-nodes.d.ts.map +0 -1
- package/src/utils/catalog/index.d.ts.map +0 -1
- package/src/utils/catalog/manager-factory.d.ts.map +0 -1
- package/src/utils/catalog/manager.d.ts.map +0 -1
- package/src/utils/catalog/pnpm-manager.d.ts.map +0 -1
- package/src/utils/catalog/types.d.ts.map +0 -1
- package/src/utils/catalog/yarn-manager.d.ts.map +0 -1
- package/src/utils/config-utils.d.ts.map +0 -1
- package/src/utils/convert-nx-executor.d.ts.map +0 -1
- package/src/utils/find-plugin-for-config-file.d.ts.map +0 -1
- package/src/utils/find-plugin-for-config-file.js +0 -61
- package/src/utils/get-named-inputs.d.ts.map +0 -1
- package/src/utils/get-workspace-layout.d.ts.map +0 -1
- package/src/utils/invoke-nx-generator.d.ts.map +0 -1
- package/src/utils/log-show-project-command.d.ts.map +0 -1
- package/src/utils/move-dir.d.ts.map +0 -1
- package/src/utils/names.d.ts.map +0 -1
- package/src/utils/offset-from-root.d.ts.map +0 -1
- package/src/utils/package-json.d.ts.map +0 -1
- package/src/utils/replace-package.d.ts +0 -3
- package/src/utils/replace-package.d.ts.map +0 -1
- package/src/utils/replace-package.js +0 -124
- package/src/utils/replace-project-configuration-with-plugin.d.ts.map +0 -1
- package/src/utils/rxjs-for-await.d.ts.map +0 -1
- package/src/utils/semver.d.ts.map +0 -1
- package/src/utils/string-change.d.ts.map +0 -1
- package/src/utils/string-utils.d.ts.map +0 -1
- package/src/utils/versions.d.ts.map +0 -1
- package/testing.d.ts.map +0 -1
- /package/{LICENSE → dist/LICENSE} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{ngcli-adapter.js → dist/ngcli-adapter.js} +0 -0
- /package/{public-api.js → dist/public-api.js} +0 -0
- /package/{src → dist/src}/executors/parse-target-string.js +0 -0
- /package/{src → dist/src}/executors/read-target-options.js +0 -0
- /package/{src → dist/src}/generators/artifact-name-and-directory-utils.js +0 -0
- /package/{src → dist/src}/generators/executor-options-utils.js +0 -0
- /package/{src → dist/src}/generators/generate-files.js +0 -0
- /package/{src → dist/src}/generators/plugin-migrations/aggregate-log-util.js +0 -0
- /package/{src → dist/src}/generators/plugin-migrations/plugin-migration-utils.js +0 -0
- /package/{src → dist/src}/generators/project-name-and-root-utils.js +0 -0
- /package/{src → dist/src}/generators/prompt.js +0 -0
- /package/{src → dist/src}/generators/run-tasks-in-serial.js +0 -0
- /package/{src → dist/src}/generators/typescript/insert-import.js +0 -0
- /package/{src → dist/src}/generators/typescript/insert-statement.js +0 -0
- /package/{src → dist/src}/generators/update-ts-configs-to-js.js +0 -0
- /package/{src → dist/src}/generators/visit-not-ignored-files.js +0 -0
- /package/{src → dist/src}/tasks/install-packages-task.js +0 -0
- /package/{src → dist/src}/utils/add-plugin.js +0 -0
- /package/{src → dist/src}/utils/async-iterable/combine-async-iterables.js +0 -0
- /package/{src → dist/src}/utils/async-iterable/create-async-iterable.js +0 -0
- /package/{src → dist/src}/utils/async-iterable/index.js +0 -0
- /package/{src → dist/src}/utils/async-iterable/map-async-iteratable.js +0 -0
- /package/{src → dist/src}/utils/async-iterable/tap-async-iteratable.js +0 -0
- /package/{src → dist/src}/utils/binary-extensions.js +0 -0
- /package/{src → dist/src}/utils/catalog/index.js +0 -0
- /package/{src → dist/src}/utils/catalog/manager-factory.js +0 -0
- /package/{src → dist/src}/utils/catalog/manager.js +0 -0
- /package/{src → dist/src}/utils/catalog/pnpm-manager.js +0 -0
- /package/{src → dist/src}/utils/catalog/types.js +0 -0
- /package/{src → dist/src}/utils/catalog/yarn-manager.js +0 -0
- /package/{src → dist/src}/utils/convert-nx-executor.js +0 -0
- /package/{src → dist/src}/utils/get-named-inputs.js +0 -0
- /package/{src → dist/src}/utils/get-workspace-layout.js +0 -0
- /package/{src → dist/src}/utils/invoke-nx-generator.js +0 -0
- /package/{src → dist/src}/utils/log-show-project-command.js +0 -0
- /package/{src → dist/src}/utils/move-dir.js +0 -0
- /package/{src → dist/src}/utils/names.js +0 -0
- /package/{src → dist/src}/utils/offset-from-root.js +0 -0
- /package/{src → dist/src}/utils/package-json.js +0 -0
- /package/{src → dist/src}/utils/replace-project-configuration-with-plugin.js +0 -0
- /package/{src → dist/src}/utils/rxjs-for-await.js +0 -0
- /package/{src → dist/src}/utils/semver.js +0 -0
- /package/{src → dist/src}/utils/string-change.js +0 -0
- /package/{src → dist/src}/utils/string-utils.js +0 -0
- /package/{src → dist/src}/utils/versions.js +0 -0
- /package/{testing.js → dist/testing.js} +0 -0
|
@@ -3,4 +3,3 @@ import type { Tree } from 'nx/src/devkit-exports';
|
|
|
3
3
|
* Utility to act on all files in a tree that are not ignored by git.
|
|
4
4
|
*/
|
|
5
5
|
export declare function visitNotIgnoredFiles(tree: Tree, dirPath: string, visitor: (path: string) => void): void;
|
|
6
|
-
//# sourceMappingURL=visit-not-ignored-files.d.ts.map
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEVKIT_INTERNAL_SYMBOLS = void 0;
|
|
4
|
+
exports.default = updateDevkitDeepImports;
|
|
5
|
+
exports.rewriteDevkitDeepImports = rewriteDevkitDeepImports;
|
|
6
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
7
|
+
const format_files_1 = require("../../generators/format-files");
|
|
8
|
+
const visit_not_ignored_files_1 = require("../../generators/visit-not-ignored-files");
|
|
9
|
+
const package_json_1 = require("../../utils/package-json");
|
|
10
|
+
const string_change_1 = require("../../utils/string-change");
|
|
11
|
+
const versions_1 = require("../../utils/versions");
|
|
12
|
+
const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
|
|
13
|
+
const DEEP_IMPORT_PREFIX = '@nx/devkit/src/';
|
|
14
|
+
const PUBLIC_SPECIFIER = '@nx/devkit';
|
|
15
|
+
const INTERNAL_SPECIFIER = '@nx/devkit/internal';
|
|
16
|
+
// Names re-exported from `@nx/devkit/internal` (see packages/devkit/internal.ts
|
|
17
|
+
// at the time this migration was authored). Anything imported from a
|
|
18
|
+
// `@nx/devkit/src/...` path whose name is NOT in this set is assumed to be
|
|
19
|
+
// part of the stable public `@nx/devkit` API.
|
|
20
|
+
exports.DEVKIT_INTERNAL_SYMBOLS = new Set([
|
|
21
|
+
'signalToCode',
|
|
22
|
+
'createProjectRootMappingsFromProjectConfigurations',
|
|
23
|
+
'PluginCache',
|
|
24
|
+
'safeWriteFileCache',
|
|
25
|
+
'determineArtifactNameAndDirectoryOptions',
|
|
26
|
+
'getRelativeCwd',
|
|
27
|
+
'FileExtensionType',
|
|
28
|
+
'getE2EWebServerInfo',
|
|
29
|
+
'E2EWebServerDetails',
|
|
30
|
+
'forEachExecutorOptions',
|
|
31
|
+
'AggregatedLog',
|
|
32
|
+
'migrateProjectExecutorsToPlugin',
|
|
33
|
+
'migrateProjectExecutorsToPluginV1',
|
|
34
|
+
'NoTargetsToMigrateError',
|
|
35
|
+
'InferredTargetConfiguration',
|
|
36
|
+
'processTargetOutputs',
|
|
37
|
+
'deleteMatchingProperties',
|
|
38
|
+
'toProjectRelativePath',
|
|
39
|
+
'determineProjectNameAndRootOptions',
|
|
40
|
+
'ensureRootProjectName',
|
|
41
|
+
'resolveImportPath',
|
|
42
|
+
'promptWhenInteractive',
|
|
43
|
+
'addBuildTargetDefaults',
|
|
44
|
+
'addE2eCiTargetDefaults',
|
|
45
|
+
'addPlugin',
|
|
46
|
+
'createAsyncIterable',
|
|
47
|
+
'combineAsyncIterables',
|
|
48
|
+
'mapAsyncIterable',
|
|
49
|
+
'calculateHashForCreateNodes',
|
|
50
|
+
'calculateHashesForCreateNodes',
|
|
51
|
+
'getCatalogManager',
|
|
52
|
+
'loadConfigFile',
|
|
53
|
+
'clearRequireCache',
|
|
54
|
+
'findPluginForConfigFile',
|
|
55
|
+
'getNamedInputs',
|
|
56
|
+
'logShowProjectCommand',
|
|
57
|
+
'eachValueFrom',
|
|
58
|
+
'checkAndCleanWithSemver',
|
|
59
|
+
'camelize',
|
|
60
|
+
'capitalize',
|
|
61
|
+
'classify',
|
|
62
|
+
'dasherize',
|
|
63
|
+
'emitPluginWorkerLog',
|
|
64
|
+
'throwForUnsupportedVersion',
|
|
65
|
+
]);
|
|
66
|
+
// Methods on `jest` and `vi` that take a module specifier as their first
|
|
67
|
+
// argument. Calls like `jest.mock('@nx/devkit/src/...')` are rewritten so the
|
|
68
|
+
// mock target lines up with the rewritten import.
|
|
69
|
+
const MOCK_HELPER_METHODS = new Set([
|
|
70
|
+
'mock',
|
|
71
|
+
'unmock',
|
|
72
|
+
'doMock',
|
|
73
|
+
'dontMock',
|
|
74
|
+
'requireActual',
|
|
75
|
+
'requireMock',
|
|
76
|
+
'importActual',
|
|
77
|
+
'importMock',
|
|
78
|
+
]);
|
|
79
|
+
let ts;
|
|
80
|
+
async function updateDevkitDeepImports(tree) {
|
|
81
|
+
let touchedCount = 0;
|
|
82
|
+
(0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
|
|
83
|
+
if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const original = tree.read(filePath, 'utf-8');
|
|
87
|
+
if (!original || !original.includes(DEEP_IMPORT_PREFIX)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const updated = rewriteDevkitDeepImports(original);
|
|
91
|
+
if (updated !== original) {
|
|
92
|
+
tree.write(filePath, updated);
|
|
93
|
+
touchedCount += 1;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (touchedCount > 0) {
|
|
97
|
+
devkit_exports_1.logger.info(`Rewrote @nx/devkit deep imports in ${touchedCount} file(s).`);
|
|
98
|
+
}
|
|
99
|
+
await (0, format_files_1.formatFiles)(tree);
|
|
100
|
+
}
|
|
101
|
+
function rewriteDevkitDeepImports(source) {
|
|
102
|
+
ts ??= (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
|
|
103
|
+
const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
|
|
104
|
+
/* setParentNodes */ true, ts.ScriptKind.TSX);
|
|
105
|
+
const changes = [];
|
|
106
|
+
for (const stmt of sourceFile.statements) {
|
|
107
|
+
if (!ts.isImportDeclaration(stmt))
|
|
108
|
+
continue;
|
|
109
|
+
if (!ts.isStringLiteral(stmt.moduleSpecifier))
|
|
110
|
+
continue;
|
|
111
|
+
if (!stmt.moduleSpecifier.text.startsWith(DEEP_IMPORT_PREFIX))
|
|
112
|
+
continue;
|
|
113
|
+
const replacement = buildReplacement(stmt, sourceFile);
|
|
114
|
+
changes.push({
|
|
115
|
+
type: string_change_1.ChangeType.Delete,
|
|
116
|
+
start: stmt.getStart(sourceFile),
|
|
117
|
+
length: stmt.getEnd() - stmt.getStart(sourceFile),
|
|
118
|
+
}, {
|
|
119
|
+
type: string_change_1.ChangeType.Insert,
|
|
120
|
+
index: stmt.getStart(sourceFile),
|
|
121
|
+
text: replacement,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
// Pass 2: rewrite `require('@nx/devkit/src/...')`, dynamic
|
|
125
|
+
// `import('@nx/devkit/src/...')`, and `jest.mock(...)` / `vi.mock(...)`-style
|
|
126
|
+
// calls. We can't bucket these by symbol (no named binding to inspect), so
|
|
127
|
+
// we route them at `/internal` as a best guess. Walking the AST instead of
|
|
128
|
+
// string-replacing keeps us out of unrelated string literals — template
|
|
129
|
+
// strings, `typeof import('...')` type queries, comments, etc.
|
|
130
|
+
collectCallExpressionRewrites(sourceFile, changes);
|
|
131
|
+
let updated = changes.length > 0 ? (0, string_change_1.applyChangesToString)(source, changes) : source;
|
|
132
|
+
// Final pass: collapse any duplicate `@nx/devkit` and `@nx/devkit/internal`
|
|
133
|
+
// named-only imports into a single declaration. This handles both the
|
|
134
|
+
// imports we just emitted AND any that the user already had, so we never
|
|
135
|
+
// leave the file with two `from '@nx/devkit'` lines.
|
|
136
|
+
updated = collapseDevkitImports(updated);
|
|
137
|
+
return updated;
|
|
138
|
+
}
|
|
139
|
+
function collapseDevkitImports(source) {
|
|
140
|
+
const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
|
|
141
|
+
/* setParentNodes */ true, ts.ScriptKind.TSX);
|
|
142
|
+
const groups = new Map();
|
|
143
|
+
for (const stmt of sourceFile.statements) {
|
|
144
|
+
if (!ts.isImportDeclaration(stmt))
|
|
145
|
+
continue;
|
|
146
|
+
if (!ts.isStringLiteral(stmt.moduleSpecifier))
|
|
147
|
+
continue;
|
|
148
|
+
const specifier = stmt.moduleSpecifier.text;
|
|
149
|
+
if (specifier !== PUBLIC_SPECIFIER && specifier !== INTERNAL_SPECIFIER) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const importClause = stmt.importClause;
|
|
153
|
+
if (!importClause)
|
|
154
|
+
continue; // skip side-effect imports
|
|
155
|
+
if (importClause.name)
|
|
156
|
+
continue; // skip default imports
|
|
157
|
+
const namedBindings = importClause.namedBindings;
|
|
158
|
+
if (!namedBindings || !ts.isNamedImports(namedBindings))
|
|
159
|
+
continue;
|
|
160
|
+
const typeOnly = !!importClause.isTypeOnly;
|
|
161
|
+
const key = `${specifier}\x00${typeOnly ? 'type' : 'value'}`;
|
|
162
|
+
if (!groups.has(key)) {
|
|
163
|
+
groups.set(key, { decls: [], specifier, typeOnly });
|
|
164
|
+
}
|
|
165
|
+
groups.get(key).decls.push(stmt);
|
|
166
|
+
}
|
|
167
|
+
const changes = [];
|
|
168
|
+
for (const { decls, specifier, typeOnly } of groups.values()) {
|
|
169
|
+
if (decls.length < 2)
|
|
170
|
+
continue;
|
|
171
|
+
const seen = new Set();
|
|
172
|
+
const merged = [];
|
|
173
|
+
for (const decl of decls) {
|
|
174
|
+
const named = decl.importClause.namedBindings;
|
|
175
|
+
for (const el of named.elements) {
|
|
176
|
+
const text = renderSpecifierFromNode(el, typeOnly);
|
|
177
|
+
if (!seen.has(text)) {
|
|
178
|
+
seen.add(text);
|
|
179
|
+
merged.push(text);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Replace the first declaration with the merged one in place.
|
|
184
|
+
const first = decls[0];
|
|
185
|
+
changes.push({
|
|
186
|
+
type: string_change_1.ChangeType.Delete,
|
|
187
|
+
start: first.getStart(sourceFile),
|
|
188
|
+
length: first.getEnd() - first.getStart(sourceFile),
|
|
189
|
+
}, {
|
|
190
|
+
type: string_change_1.ChangeType.Insert,
|
|
191
|
+
index: first.getStart(sourceFile),
|
|
192
|
+
text: renderImport(merged, specifier, typeOnly),
|
|
193
|
+
});
|
|
194
|
+
// Delete every other declaration in this group (and consume one trailing
|
|
195
|
+
// newline so we don't leave behind a blank line that prettier has to clean
|
|
196
|
+
// up later).
|
|
197
|
+
for (let i = 1; i < decls.length; i++) {
|
|
198
|
+
const decl = decls[i];
|
|
199
|
+
const start = decl.getStart(sourceFile);
|
|
200
|
+
let end = decl.getEnd();
|
|
201
|
+
if (source[end] === '\n') {
|
|
202
|
+
end += 1;
|
|
203
|
+
}
|
|
204
|
+
else if (source[end] === '\r' && source[end + 1] === '\n') {
|
|
205
|
+
end += 2;
|
|
206
|
+
}
|
|
207
|
+
changes.push({
|
|
208
|
+
type: string_change_1.ChangeType.Delete,
|
|
209
|
+
start,
|
|
210
|
+
length: end - start,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return changes.length > 0 ? (0, string_change_1.applyChangesToString)(source, changes) : source;
|
|
215
|
+
}
|
|
216
|
+
function renderSpecifierFromNode(el, parentIsTypeOnly) {
|
|
217
|
+
const aliasText = el.propertyName ? ` as ${el.name.text}` : '';
|
|
218
|
+
const typePrefix = !parentIsTypeOnly && el.isTypeOnly ? 'type ' : '';
|
|
219
|
+
return `${typePrefix}${(el.propertyName ?? el.name).text}${aliasText}`;
|
|
220
|
+
}
|
|
221
|
+
function buildReplacement(decl, sourceFile) {
|
|
222
|
+
const importClause = decl.importClause;
|
|
223
|
+
// `import '@nx/devkit/src/...';` (side-effect) — no clause to bucket.
|
|
224
|
+
if (!importClause) {
|
|
225
|
+
return `import '${INTERNAL_SPECIFIER}';`;
|
|
226
|
+
}
|
|
227
|
+
const namedBindings = importClause.namedBindings;
|
|
228
|
+
const isNamedImport = namedBindings && ts.isNamedImports(namedBindings) && !importClause.name;
|
|
229
|
+
// Default / namespace / mixed-default-and-named — can't bucket reliably.
|
|
230
|
+
// Preserve the import shape, swap the specifier.
|
|
231
|
+
if (!isNamedImport) {
|
|
232
|
+
const before = source(decl, sourceFile).slice(0, decl.moduleSpecifier.getStart(sourceFile) - decl.getStart(sourceFile));
|
|
233
|
+
const after = source(decl, sourceFile).slice(decl.moduleSpecifier.getEnd() - decl.getStart(sourceFile));
|
|
234
|
+
return `${before}'${INTERNAL_SPECIFIER}'${after}`;
|
|
235
|
+
}
|
|
236
|
+
const isTypeOnlyImport = importClause.isTypeOnly;
|
|
237
|
+
const elements = namedBindings.elements;
|
|
238
|
+
const publik = [];
|
|
239
|
+
const internal = [];
|
|
240
|
+
for (const el of elements) {
|
|
241
|
+
bucketSpecifier(el, isTypeOnlyImport, publik, internal);
|
|
242
|
+
}
|
|
243
|
+
const lines = [];
|
|
244
|
+
if (publik.length > 0) {
|
|
245
|
+
lines.push(renderImport(publik, PUBLIC_SPECIFIER, isTypeOnlyImport));
|
|
246
|
+
}
|
|
247
|
+
if (internal.length > 0) {
|
|
248
|
+
lines.push(renderImport(internal, INTERNAL_SPECIFIER, isTypeOnlyImport));
|
|
249
|
+
}
|
|
250
|
+
if (lines.length === 0) {
|
|
251
|
+
// Defensive: empty `import {} from '...'` — point at /internal.
|
|
252
|
+
lines.push(`import {} from '${INTERNAL_SPECIFIER}';`);
|
|
253
|
+
}
|
|
254
|
+
return lines.join('\n');
|
|
255
|
+
}
|
|
256
|
+
function bucketSpecifier(el, parentIsTypeOnly, publik, internal) {
|
|
257
|
+
const lookupName = (el.propertyName ?? el.name).text;
|
|
258
|
+
const elementIsTypeOnly = el.isTypeOnly;
|
|
259
|
+
const aliasText = el.propertyName ? ` as ${el.name.text}` : '';
|
|
260
|
+
// Inline `type` is illegal when the parent import is already `import type`.
|
|
261
|
+
const typePrefix = !parentIsTypeOnly && elementIsTypeOnly ? 'type ' : '';
|
|
262
|
+
const text = `${typePrefix}${(el.propertyName ?? el.name).text}${aliasText}`;
|
|
263
|
+
if (exports.DEVKIT_INTERNAL_SYMBOLS.has(lookupName)) {
|
|
264
|
+
internal.push(text);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
publik.push(text);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function renderImport(specifiers, from, typeOnly) {
|
|
271
|
+
const prefix = typeOnly ? 'import type' : 'import';
|
|
272
|
+
return `${prefix} { ${specifiers.join(', ')} } from '${from}';`;
|
|
273
|
+
}
|
|
274
|
+
function source(decl, sourceFile) {
|
|
275
|
+
return sourceFile.text.slice(decl.getStart(sourceFile), decl.getEnd());
|
|
276
|
+
}
|
|
277
|
+
function collectCallExpressionRewrites(sourceFile, changes) {
|
|
278
|
+
const visit = (node) => {
|
|
279
|
+
if (ts.isCallExpression(node) &&
|
|
280
|
+
shouldRewriteCallExpression(node) &&
|
|
281
|
+
node.arguments.length >= 1 &&
|
|
282
|
+
ts.isStringLiteral(node.arguments[0]) &&
|
|
283
|
+
node.arguments[0].text.startsWith(DEEP_IMPORT_PREFIX)) {
|
|
284
|
+
const arg = node.arguments[0];
|
|
285
|
+
const start = arg.getStart(sourceFile);
|
|
286
|
+
const end = arg.getEnd();
|
|
287
|
+
const quote = sourceFile.text.charAt(start);
|
|
288
|
+
changes.push({
|
|
289
|
+
type: string_change_1.ChangeType.Delete,
|
|
290
|
+
start,
|
|
291
|
+
length: end - start,
|
|
292
|
+
}, {
|
|
293
|
+
type: string_change_1.ChangeType.Insert,
|
|
294
|
+
index: start,
|
|
295
|
+
text: `${quote}${INTERNAL_SPECIFIER}${quote}`,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
ts.forEachChild(node, visit);
|
|
299
|
+
};
|
|
300
|
+
visit(sourceFile);
|
|
301
|
+
}
|
|
302
|
+
function shouldRewriteCallExpression(call) {
|
|
303
|
+
const callee = call.expression;
|
|
304
|
+
// `require('...')`
|
|
305
|
+
if (ts.isIdentifier(callee) && callee.text === 'require')
|
|
306
|
+
return true;
|
|
307
|
+
// dynamic `import('...')` — the runtime form parses as a CallExpression
|
|
308
|
+
// whose callee is the `import` keyword. The type-position form
|
|
309
|
+
// (`typeof import('...')`) parses as `ImportTypeNode`, not a CallExpression,
|
|
310
|
+
// so we don't touch it.
|
|
311
|
+
if (callee.kind === ts.SyntaxKind.ImportKeyword)
|
|
312
|
+
return true;
|
|
313
|
+
// `jest.mock(...)` / `vi.mock(...)` and friends.
|
|
314
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
315
|
+
const obj = callee.expression;
|
|
316
|
+
if (ts.isIdentifier(obj) &&
|
|
317
|
+
(obj.text === 'jest' || obj.text === 'vi') &&
|
|
318
|
+
MOCK_HELPER_METHODS.has(callee.name.text)) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#### Update `@nx/devkit` deep imports
|
|
2
|
+
|
|
3
|
+
`@nx/devkit` now ships a strict `exports` map, so deep imports like `@nx/devkit/src/utils/...` and `@nx/devkit/src/generators/...` are no longer reachable through Node module resolution.
|
|
4
|
+
|
|
5
|
+
This migration scans every `.ts`, `.tsx`, `.cts`, and `.mts` file in your workspace and rewrites those deep imports to one of the supported entry points:
|
|
6
|
+
|
|
7
|
+
- Symbols that are part of the stable `@nx/devkit` public API are routed to `@nx/devkit`.
|
|
8
|
+
- Symbols that were previously only reachable through deep imports are routed to `@nx/devkit/internal`.
|
|
9
|
+
|
|
10
|
+
After rewriting, the migration **collapses duplicate imports** so a file never ends up with two `import ... from '@nx/devkit'` (or `@nx/devkit/internal`) lines — including merging into any matching import you already had.
|
|
11
|
+
|
|
12
|
+
#### Sample Code Changes
|
|
13
|
+
|
|
14
|
+
##### Before
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { Tree } from '@nx/devkit';
|
|
18
|
+
import { dasherize, names } from '@nx/devkit/src/utils/string-utils';
|
|
19
|
+
import { addPlugin } from '@nx/devkit/src/utils/add-plugin';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
##### After
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Tree, names } from '@nx/devkit';
|
|
26
|
+
import { dasherize, addPlugin } from '@nx/devkit/internal';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`names` was already in the public API, so it joins the existing `@nx/devkit` import. `dasherize` and `addPlugin` move to `@nx/devkit/internal`, and the two `/internal` imports are collapsed into one.
|
|
30
|
+
|
|
31
|
+
#### Fallback for non-named imports
|
|
32
|
+
|
|
33
|
+
For deep-import shapes that can't be split by symbol — default imports, namespace imports, side-effect imports, `require(...)` calls, dynamic `import(...)`, and `jest.mock(...)` / `vi.mock(...)`-style mock-helper calls — the migration rewrites the specifier to `@nx/devkit/internal` as a best guess, since most symbols that previously lived under `@nx/devkit/src/...` ended up there.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Before
|
|
37
|
+
const { dasherize } = require('@nx/devkit/src/utils/string-utils');
|
|
38
|
+
|
|
39
|
+
// After
|
|
40
|
+
const { dasherize } = require('@nx/devkit/internal');
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If the symbol you're after is part of the stable public API instead, the rewritten import will fail to resolve against `@nx/devkit/internal` — switch it to `@nx/devkit` by hand. The migration also leaves `typeof import('@nx/devkit/src/...')` type queries and any deep-import strings inside template literals or comments untouched, so you'll need to update those by hand.
|
|
@@ -8,4 +8,3 @@ import { PackageManager, Tree } from 'nx/src/devkit-exports';
|
|
|
8
8
|
* unless install already ran this generator cycle.
|
|
9
9
|
*/
|
|
10
10
|
export declare function installPackagesTask(tree: Tree, ensureInstall?: boolean, cwd?: string, packageManager?: PackageManager): void;
|
|
11
|
-
//# sourceMappingURL=install-packages-task.d.ts.map
|
|
@@ -11,4 +11,3 @@ export declare function addPlugin<PluginOptions>(tree: Tree, graph: ProjectGraph
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function addPluginV1<PluginOptions>(tree: Tree, graph: ProjectGraph, pluginName: string, createNodesTuple: CreateNodesV2<PluginOptions>, options: Partial<Record<keyof PluginOptions, PluginOptions[keyof PluginOptions][]>>, shouldUpdatePackageJsonScripts: boolean): Promise<void>;
|
|
13
13
|
export declare function generateCombinations<T>(input: Record<string, T[]>): Record<string, T>[];
|
|
14
|
-
//# sourceMappingURL=add-plugin.d.ts.map
|
|
@@ -5,4 +5,3 @@ export interface AsyncPushCallbacks<T> {
|
|
|
5
5
|
registerCleanup?: (cb: () => void | Promise<void>) => void;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAsyncIterable<T = unknown>(listener: (ls: AsyncPushCallbacks<T>) => void): AsyncIterable<T>;
|
|
8
|
-
//# sourceMappingURL=create-async-iterable.d.ts.map
|
|
@@ -1,2 +1 @@
|
|
|
1
1
|
export declare function mapAsyncIterable<T = any, I = any, O = any>(data: AsyncIterable<T> | AsyncIterableIterator<T>, transform: (input: I, index?: number, data?: AsyncIterable<T> | AsyncIterableIterator<T>) => O): AsyncIterable<O> | AsyncIterableIterator<O>;
|
|
2
|
-
//# sourceMappingURL=map-async-iteratable.d.ts.map
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { CreateNodesContextV2 } from 'nx/src/devkit-exports';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Use {@link calculateHashesForCreateNodes} instead, which batches
|
|
4
|
+
* workspace-context hashing across multiple project roots in a single call.
|
|
5
|
+
* This will be removed in Nx 24.
|
|
6
|
+
*/
|
|
2
7
|
export declare function calculateHashForCreateNodes(projectRoot: string, options: object, context: CreateNodesContextV2, additionalGlobs?: string[]): Promise<string>;
|
|
3
8
|
export declare function calculateHashesForCreateNodes(projectRoots: string[], options: object, context: CreateNodesContextV2, additionalGlobs?: string[][]): Promise<string[]>;
|
|
4
|
-
//# sourceMappingURL=calculate-hash-for-create-nodes.d.ts.map
|
|
@@ -5,6 +5,11 @@ exports.calculateHashesForCreateNodes = calculateHashesForCreateNodes;
|
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
7
7
|
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use {@link calculateHashesForCreateNodes} instead, which batches
|
|
10
|
+
* workspace-context hashing across multiple project roots in a single call.
|
|
11
|
+
* This will be removed in Nx 24.
|
|
12
|
+
*/
|
|
8
13
|
async function calculateHashForCreateNodes(projectRoot, options, context, additionalGlobs = []) {
|
|
9
14
|
return (0, devkit_exports_1.hashArray)([
|
|
10
15
|
await (0, devkit_internals_1.hashWithWorkspaceContext)(context.workspaceRoot, [
|
|
@@ -15,14 +20,16 @@ async function calculateHashForCreateNodes(projectRoot, options, context, additi
|
|
|
15
20
|
]);
|
|
16
21
|
}
|
|
17
22
|
async function calculateHashesForCreateNodes(projectRoots, options, context, additionalGlobs = []) {
|
|
23
|
+
if (projectRoots.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
18
26
|
if (additionalGlobs.length &&
|
|
19
27
|
additionalGlobs.length !== projectRoots.length) {
|
|
20
|
-
throw new Error(
|
|
28
|
+
throw new Error(`calculateHashesForCreateNodes: projectRoots.length (${projectRoots.length}) !== additionalGlobs.length (${additionalGlobs.length})`);
|
|
21
29
|
}
|
|
22
|
-
|
|
30
|
+
const hashes = await (0, devkit_internals_1.hashMultiGlobWithWorkspaceContext)(context.workspaceRoot, projectRoots.map((projectRoot, idx) => [
|
|
23
31
|
(0, path_1.join)(projectRoot, '**/*'),
|
|
24
32
|
...(additionalGlobs.length ? additionalGlobs[idx] : []),
|
|
25
|
-
]))
|
|
26
|
-
|
|
27
|
-
});
|
|
33
|
+
]));
|
|
34
|
+
return hashes.map((hash) => (0, devkit_exports_1.hashArray)([hash, (0, devkit_internals_1.hashObject)(options)]));
|
|
28
35
|
}
|
|
@@ -7,4 +7,3 @@ export { type CatalogManager, getCatalogManager };
|
|
|
7
7
|
* Returns Map of package name -> catalog name (undefined for default catalog)
|
|
8
8
|
*/
|
|
9
9
|
export declare function getCatalogDependenciesFromPackageJson(tree: Tree, packageJsonPath: string, manager: CatalogManager): Map<string, string | undefined>;
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,4 +3,3 @@ import type { CatalogManager } from './manager';
|
|
|
3
3
|
* Factory function to get the appropriate catalog manager based on the package manager
|
|
4
4
|
*/
|
|
5
5
|
export declare function getCatalogManager(workspaceRoot: string): CatalogManager | null;
|
|
6
|
-
//# sourceMappingURL=manager-factory.d.ts.map
|
|
@@ -3,4 +3,3 @@ export declare function loadConfigFile<T extends object = any>(configFilePath: s
|
|
|
3
3
|
export declare function getRootTsConfigPath(): string | null;
|
|
4
4
|
export declare function getRootTsConfigFileName(): string | null;
|
|
5
5
|
export declare function clearRequireCache(): void;
|
|
6
|
-
//# sourceMappingURL=config-utils.d.ts.map
|
|
@@ -27,16 +27,71 @@ function isTypeScriptFile(extension) {
|
|
|
27
27
|
}
|
|
28
28
|
async function loadTypeScriptModule(path, extension, tsconfigFileNames) {
|
|
29
29
|
const tsConfigPath = getTypeScriptConfigPath(path, tsconfigFileNames);
|
|
30
|
-
if (tsConfigPath) {
|
|
31
|
-
|
|
30
|
+
if (!tsConfigPath) {
|
|
31
|
+
return await loadModuleByExtension(path, extension);
|
|
32
|
+
}
|
|
33
|
+
// loadTsFile was added in nx@23. @nx/devkit's peer range supports older
|
|
34
|
+
// nx majors, so fall back to the legacy registerTsProject + require path
|
|
35
|
+
// when loadTsFile isn't available on the host nx.
|
|
36
|
+
if (typeof devkit_internals_1.loadTsFile !== 'function') {
|
|
37
|
+
const cleanup = (0, devkit_internals_1.registerTsProject)(tsConfigPath);
|
|
32
38
|
try {
|
|
33
39
|
return await loadModuleByExtension(path, extension);
|
|
34
40
|
}
|
|
35
41
|
finally {
|
|
36
|
-
|
|
42
|
+
cleanup();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Both .ts and .mts go through loadTsFile first. Node 22.12+ supports
|
|
46
|
+
// require() of synchronous ESM by default, and loadTsFile's lazy fallback
|
|
47
|
+
// covers swc/ts-node + tsconfig-paths registration when needed (swc-node
|
|
48
|
+
// hooks .cts/.mts/.ts via Module._extensions). Async-only ESM modules
|
|
49
|
+
// (top-level await) throw ERR_REQUIRE_ASYNC_MODULE and fall through to
|
|
50
|
+
// dynamic import(). ERR_REQUIRE_ESM is the legacy code for the same case
|
|
51
|
+
// - kept for older Node lines.
|
|
52
|
+
try {
|
|
53
|
+
return (0, devkit_internals_1.loadTsFile)(path, tsConfigPath);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
if (e?.code !== 'ERR_REQUIRE_ESM' &&
|
|
57
|
+
e?.code !== 'ERR_REQUIRE_ASYNC_MODULE') {
|
|
58
|
+
throw e;
|
|
59
|
+
}
|
|
60
|
+
// The module must be loaded via dynamic import(). Register
|
|
61
|
+
// tsconfig-paths first so workspace alias imports resolve, then try a
|
|
62
|
+
// native dynamic import. Node 22.18+ LTS strips TS types on the ESM
|
|
63
|
+
// path natively, so pure-ESM TLA configs load without any swc/ts-node
|
|
64
|
+
// ESM loader. Only escalate to forceRegisterEsmLoader (which throws
|
|
65
|
+
// when neither @swc-node/register nor ts-node is installed) if the
|
|
66
|
+
// native attempt hits unsupported TS syntax.
|
|
67
|
+
const cleanup = (0, devkit_internals_1.registerTsProject)(tsConfigPath);
|
|
68
|
+
try {
|
|
69
|
+
return await loadESM(path);
|
|
70
|
+
}
|
|
71
|
+
catch (esmErr) {
|
|
72
|
+
if (esmErr?.code !== 'ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX' ||
|
|
73
|
+
typeof devkit_internals_1.forceRegisterEsmLoader !== 'function') {
|
|
74
|
+
throw esmErr;
|
|
75
|
+
}
|
|
76
|
+
// Module.register is global and one-shot per process. After this
|
|
77
|
+
// runs, every subsequent ESM import in the process is routed
|
|
78
|
+
// through the registered loader, forfeiting Node's native TS
|
|
79
|
+
// stripping for the dynamic-import path. If neither swc-node nor
|
|
80
|
+
// ts-node is installed, forceRegisterEsmLoader throws - surface the
|
|
81
|
+
// original ESM error in that case so the user sees the real
|
|
82
|
+
// problem, not a misleading "loader missing" message.
|
|
83
|
+
try {
|
|
84
|
+
(0, devkit_internals_1.forceRegisterEsmLoader)();
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw esmErr;
|
|
88
|
+
}
|
|
89
|
+
return await loadESM(path);
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
cleanup();
|
|
37
93
|
}
|
|
38
94
|
}
|
|
39
|
-
return await loadModuleByExtension(path, extension);
|
|
40
95
|
}
|
|
41
96
|
function getTypeScriptConfigPath(path, tsconfigFileNames) {
|
|
42
97
|
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.dirname)(path));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findPluginForConfigFile = findPluginForConfigFile;
|
|
4
|
+
const devkit_exports_1 = require("nx/src/devkit-exports");
|
|
5
|
+
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
6
|
+
async function findPluginForConfigFile(tree, pluginName, pathToConfigFile) {
|
|
7
|
+
const nxJson = (0, devkit_exports_1.readNxJson)(tree);
|
|
8
|
+
if (!nxJson.plugins) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const pluginRegistrations = nxJson.plugins.filter((p) => (typeof p === 'string' ? p === pluginName : p.plugin === pluginName));
|
|
12
|
+
for (const plugin of pluginRegistrations) {
|
|
13
|
+
if (typeof plugin === 'string') {
|
|
14
|
+
return plugin;
|
|
15
|
+
}
|
|
16
|
+
if (!plugin.include && !plugin.exclude) {
|
|
17
|
+
return plugin;
|
|
18
|
+
}
|
|
19
|
+
if (plugin.include || plugin.exclude) {
|
|
20
|
+
const resolvedPlugin = await import(pluginName);
|
|
21
|
+
const pluginGlob = resolvedPlugin.createNodesV2?.[0] ?? resolvedPlugin.createNodes?.[0];
|
|
22
|
+
const matchingConfigFile = (0, devkit_internals_1.findMatchingConfigFiles)([pathToConfigFile], pluginGlob, plugin.include, plugin.exclude);
|
|
23
|
+
if (matchingConfigFile.length) {
|
|
24
|
+
return plugin;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|