@nx/devkit 16.8.0-beta.4 → 16.8.0-beta.5
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/nx.js +8 -4
- package/package.json +3 -3
- package/src/executors/parse-target-string.js +1 -1
- package/src/executors/read-target-options.js +3 -3
- package/src/generators/format-files.js +43 -36
- package/src/generators/generate-files.js +2 -2
- package/src/generators/project-name-and-root-utils.js +64 -67
- package/src/generators/run-tasks-in-serial.js +3 -4
- package/src/generators/visit-not-ignored-files.js +3 -3
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/utils/async-iterable/combine-async-iterables.js +37 -55
- package/src/utils/async-iterable/create-async-iterable.js +3 -6
- package/src/utils/async-iterable/map-async-iteratable.js +12 -17
- package/src/utils/async-iterable/tap-async-iteratable.js +4 -7
- package/src/utils/convert-nx-executor.js +3 -4
- package/src/utils/get-workspace-layout.js +5 -4
- package/src/utils/invoke-nx-generator.js +9 -10
- package/src/utils/module-federation/dependencies.js +1 -2
- package/src/utils/module-federation/secondary-entry-points.js +6 -5
- package/src/utils/module-federation/share.js +10 -10
- package/src/utils/module-federation/typescript.js +3 -5
- package/src/utils/package-json.js +30 -18
- package/src/utils/replace-package.js +9 -12
- package/src/utils/rxjs-for-await.js +217 -226
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tapAsyncIterable = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const map_async_iteratable_1 = require("./map-async-iteratable");
|
|
6
|
-
function tapAsyncIterable(data, fn) {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return x;
|
|
11
|
-
})))));
|
|
5
|
+
async function* tapAsyncIterable(data, fn) {
|
|
6
|
+
return yield* (0, map_async_iteratable_1.mapAsyncIterable)(data, (x) => {
|
|
7
|
+
fn(x);
|
|
8
|
+
return x;
|
|
12
9
|
});
|
|
13
10
|
}
|
|
14
11
|
exports.tapAsyncIterable = tapAsyncIterable;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertNxExecutor = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const nx_1 = require("../../nx");
|
|
6
5
|
const { Workspaces, readNxJsonFromDisk, retrieveProjectConfigurationsWithAngularProjects, } = (0, nx_1.requireNx)();
|
|
7
6
|
/**
|
|
@@ -17,11 +16,11 @@ function convertNxExecutor(executor) {
|
|
|
17
16
|
? readNxJsonFromDisk(builderContext.workspaceRoot)
|
|
18
17
|
: // TODO(v18): remove readNxJson. This is to be backwards compatible with Nx 16.5 and below.
|
|
19
18
|
workspaces.readNxJson();
|
|
20
|
-
const promise = () =>
|
|
19
|
+
const promise = async () => {
|
|
21
20
|
const projectsConfigurations = retrieveProjectConfigurationsWithAngularProjects
|
|
22
21
|
? {
|
|
23
22
|
version: 2,
|
|
24
|
-
projects:
|
|
23
|
+
projects: await retrieveProjectConfigurationsWithAngularProjects(builderContext.workspaceRoot, nxJsonConfiguration).then((p) => p.projectNodes),
|
|
25
24
|
}
|
|
26
25
|
: // TODO(v18): remove retrieveProjectConfigurations. This is to be backwards compatible with Nx 16.5 and below.
|
|
27
26
|
workspaces.readProjectsConfigurations({
|
|
@@ -41,7 +40,7 @@ function convertNxExecutor(executor) {
|
|
|
41
40
|
isVerbose: false,
|
|
42
41
|
};
|
|
43
42
|
return executor(options, context);
|
|
44
|
-
}
|
|
43
|
+
};
|
|
45
44
|
return toObservable(promise());
|
|
46
45
|
};
|
|
47
46
|
return require('@angular-devkit/architect').createBuilder(builderFunction);
|
|
@@ -15,12 +15,13 @@ const { readNxJson } = (0, nx_1.requireNx)();
|
|
|
15
15
|
* @param tree - file system tree
|
|
16
16
|
*/
|
|
17
17
|
function getWorkspaceLayout(tree) {
|
|
18
|
-
var _a, _b, _c, _d;
|
|
19
18
|
const nxJson = readNxJson(tree);
|
|
20
19
|
return {
|
|
21
|
-
appsDir:
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
appsDir: nxJson?.workspaceLayout?.appsDir ??
|
|
21
|
+
inOrderOfPreference(tree, ['apps', 'packages'], '.'),
|
|
22
|
+
libsDir: nxJson?.workspaceLayout?.libsDir ??
|
|
23
|
+
inOrderOfPreference(tree, ['libs', 'packages'], '.'),
|
|
24
|
+
npmScope: nxJson?.npmScope,
|
|
24
25
|
standaloneAsDefault: true,
|
|
25
26
|
};
|
|
26
27
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertNxGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const path_1 = require("path");
|
|
6
5
|
const nx_1 = require("../../nx");
|
|
7
6
|
let { logger, stripIndent } = (0, nx_1.requireNx)();
|
|
8
7
|
// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
|
|
9
|
-
stripIndent = stripIndent
|
|
8
|
+
stripIndent = stripIndent ?? require('nx/src/utils/logger').stripIndent;
|
|
10
9
|
class RunCallbackTask {
|
|
11
10
|
constructor(callback) {
|
|
12
11
|
this.callback = callback;
|
|
@@ -24,9 +23,9 @@ function createRunCallbackTask() {
|
|
|
24
23
|
return {
|
|
25
24
|
name: 'RunCallback',
|
|
26
25
|
create: () => {
|
|
27
|
-
return Promise.resolve(({ callback }) =>
|
|
28
|
-
|
|
29
|
-
})
|
|
26
|
+
return Promise.resolve(async ({ callback }) => {
|
|
27
|
+
await callback();
|
|
28
|
+
});
|
|
30
29
|
},
|
|
31
30
|
};
|
|
32
31
|
}
|
|
@@ -43,7 +42,7 @@ exports.convertNxGenerator = convertNxGenerator;
|
|
|
43
42
|
* Create a Rule to invoke an Nx Generator
|
|
44
43
|
*/
|
|
45
44
|
function invokeNxGenerator(generator, options, skipWritingConfigInOldFormat) {
|
|
46
|
-
return (tree, context) =>
|
|
45
|
+
return async (tree, context) => {
|
|
47
46
|
if (context.engine.workflow) {
|
|
48
47
|
const engineHost = context.engine.workflow.engineHost;
|
|
49
48
|
engineHost.registerTaskExecutor(createRunCallbackTask());
|
|
@@ -52,7 +51,7 @@ function invokeNxGenerator(generator, options, skipWritingConfigInOldFormat) {
|
|
|
52
51
|
? context.engine.workflow.engineHost.paths[1]
|
|
53
52
|
: tree.root.path;
|
|
54
53
|
const adapterTree = new DevkitTreeFromAngularDevkitTree(tree, root, skipWritingConfigInOldFormat);
|
|
55
|
-
const result =
|
|
54
|
+
const result = await generator(adapterTree, options);
|
|
56
55
|
if (!result) {
|
|
57
56
|
return adapterTree['tree'];
|
|
58
57
|
}
|
|
@@ -61,7 +60,7 @@ function invokeNxGenerator(generator, options, skipWritingConfigInOldFormat) {
|
|
|
61
60
|
context.addTask(new RunCallbackTask(result));
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
}
|
|
63
|
+
};
|
|
65
64
|
}
|
|
66
65
|
const actionToFileChangeMap = {
|
|
67
66
|
c: 'CREATE',
|
|
@@ -86,7 +85,7 @@ class DevkitTreeFromAngularDevkitTree {
|
|
|
86
85
|
this._root = '/virtual';
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
|
-
catch
|
|
88
|
+
catch { }
|
|
90
89
|
}
|
|
91
90
|
get root() {
|
|
92
91
|
return this._root;
|
|
@@ -153,7 +152,7 @@ class DevkitTreeFromAngularDevkitTree {
|
|
|
153
152
|
this.tree.rename(from, to);
|
|
154
153
|
}
|
|
155
154
|
write(filePath, content, options) {
|
|
156
|
-
if (options
|
|
155
|
+
if (options?.mode) {
|
|
157
156
|
this.warnUnsupportedFilePermissionsChange(filePath, options.mode);
|
|
158
157
|
}
|
|
159
158
|
if (this.tree.exists(filePath)) {
|
|
@@ -14,12 +14,11 @@ function collectDependencies(projectGraph, name, dependencies = {
|
|
|
14
14
|
workspaceLibraries: new Map(),
|
|
15
15
|
npmPackages: new Set(),
|
|
16
16
|
}, seen = new Set()) {
|
|
17
|
-
var _a;
|
|
18
17
|
if (seen.has(name)) {
|
|
19
18
|
return dependencies;
|
|
20
19
|
}
|
|
21
20
|
seen.add(name);
|
|
22
|
-
(
|
|
21
|
+
(projectGraph.dependencies[name] ?? []).forEach((dependency) => {
|
|
23
22
|
if (dependency.target.startsWith('npm:')) {
|
|
24
23
|
dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
|
|
25
24
|
}
|
|
@@ -7,7 +7,8 @@ const nx_1 = require("../../../nx");
|
|
|
7
7
|
let { readJsonFile, joinPathFragments, workspaceRoot, readModulePackageJson } = (0, nx_1.requireNx)();
|
|
8
8
|
// TODO: Remove this in Nx 18 when Nx 16.7.0 is no longer supported
|
|
9
9
|
readModulePackageJson =
|
|
10
|
-
readModulePackageJson
|
|
10
|
+
readModulePackageJson ??
|
|
11
|
+
require('nx/src/utils/package-json').readModulePackageJson;
|
|
11
12
|
function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliases) {
|
|
12
13
|
const libraryRoot = (0, path_1.join)(workspaceRoot, library.root);
|
|
13
14
|
const needsSecondaryEntryPointsCollected = (0, fs_1.existsSync)((0, path_1.join)(libraryRoot, 'ng-package.json'));
|
|
@@ -15,10 +16,10 @@ function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliase
|
|
|
15
16
|
if (needsSecondaryEntryPointsCollected) {
|
|
16
17
|
const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
|
|
17
18
|
if (!tsKey.startsWith(library.importKey)) {
|
|
18
|
-
return
|
|
19
|
+
return { ...acc };
|
|
19
20
|
}
|
|
20
21
|
if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
|
|
21
|
-
acc =
|
|
22
|
+
acc = { ...acc, [tsKey]: tsPaths };
|
|
22
23
|
}
|
|
23
24
|
return acc;
|
|
24
25
|
}, {});
|
|
@@ -60,7 +61,7 @@ function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion
|
|
|
60
61
|
collectedPackages.push({ name, version: pkgVersion });
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
catch
|
|
64
|
+
catch { }
|
|
64
65
|
}
|
|
65
66
|
else if (mainEntryPointExports) {
|
|
66
67
|
// if the package.json doesn't exist, check if the directory is
|
|
@@ -87,7 +88,7 @@ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackag
|
|
|
87
88
|
({ path: packageJsonPath, packageJson } = readModulePackageJson(pkgName));
|
|
88
89
|
pathToPackage = (0, path_1.dirname)(packageJsonPath);
|
|
89
90
|
}
|
|
90
|
-
catch
|
|
91
|
+
catch {
|
|
91
92
|
// the package.json might not resolve if the package has the "exports"
|
|
92
93
|
// entry and is not exporting the package.json file, fall back to trying
|
|
93
94
|
// to find it from the top-level node_modules
|
|
@@ -14,9 +14,7 @@ const { workspaceRoot, logger } = (0, nx_1.requireNx)();
|
|
|
14
14
|
* @param libraries - The Nx Workspace Libraries to share
|
|
15
15
|
* @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
|
|
16
16
|
*/
|
|
17
|
-
function shareWorkspaceLibraries(libraries, tsConfigPath) {
|
|
18
|
-
var _a;
|
|
19
|
-
if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : (0, typescript_1.getRootTsConfigPath)(); }
|
|
17
|
+
function shareWorkspaceLibraries(libraries, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
|
|
20
18
|
if (!libraries) {
|
|
21
19
|
return getEmptySharedLibrariesConfig();
|
|
22
20
|
}
|
|
@@ -43,8 +41,11 @@ function shareWorkspaceLibraries(libraries, tsConfigPath) {
|
|
|
43
41
|
}
|
|
44
42
|
const webpack = require('webpack');
|
|
45
43
|
return {
|
|
46
|
-
getAliases: () => pathMappings.reduce((aliases, library) => (
|
|
47
|
-
getLibraries: (eager) => pathMappings.reduce((libraries, library) => (
|
|
44
|
+
getAliases: () => pathMappings.reduce((aliases, library) => ({ ...aliases, [library.name]: library.path }), {}),
|
|
45
|
+
getLibraries: (eager) => pathMappings.reduce((libraries, library) => ({
|
|
46
|
+
...libraries,
|
|
47
|
+
[library.name]: { requiredVersion: false, eager },
|
|
48
|
+
}), {}),
|
|
48
49
|
getReplacementPlugin: () => new webpack.NormalModuleReplacementPlugin(/./, (req) => {
|
|
49
50
|
if (!req.request.startsWith('.')) {
|
|
50
51
|
return;
|
|
@@ -89,8 +90,7 @@ function sharePackages(packages) {
|
|
|
89
90
|
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
90
91
|
const allPackages = [];
|
|
91
92
|
packages.forEach((pkg) => {
|
|
92
|
-
|
|
93
|
-
const pkgVersion = (_b = (_a = pkgJson.dependencies) === null || _a === void 0 ? void 0 : _a[pkg]) !== null && _b !== void 0 ? _b : (_c = pkgJson.devDependencies) === null || _c === void 0 ? void 0 : _c[pkg];
|
|
93
|
+
const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
|
|
94
94
|
allPackages.push({ name: pkg, version: pkgVersion });
|
|
95
95
|
(0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
|
|
96
96
|
});
|
|
@@ -157,13 +157,13 @@ function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
|
|
|
157
157
|
}
|
|
158
158
|
exports.applyAdditionalShared = applyAdditionalShared;
|
|
159
159
|
function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
|
|
160
|
-
var _a, _b, _c, _d;
|
|
161
160
|
if (projectGraph.nodes[dependency]) {
|
|
162
161
|
sharedConfig[dependency] = { requiredVersion: false };
|
|
163
162
|
}
|
|
164
|
-
else if (
|
|
163
|
+
else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
|
|
165
164
|
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
166
|
-
const config = getNpmPackageSharedConfig(dependency,
|
|
165
|
+
const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
|
|
166
|
+
pkgJson.devDependencies?.[dependency]);
|
|
167
167
|
if (!config) {
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
@@ -7,15 +7,13 @@ const nx_1 = require("../../../nx");
|
|
|
7
7
|
const { workspaceRoot } = (0, nx_1.requireNx)();
|
|
8
8
|
let tsConfig;
|
|
9
9
|
let tsPathMappings;
|
|
10
|
-
function readTsPathMappings(tsConfigPath) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
|
-
if (tsConfigPath === void 0) { tsConfigPath = (_a = process.env.NX_TSCONFIG_PATH) !== null && _a !== void 0 ? _a : getRootTsConfigPath(); }
|
|
10
|
+
function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
|
|
13
11
|
if (tsPathMappings) {
|
|
14
12
|
return tsPathMappings;
|
|
15
13
|
}
|
|
16
|
-
tsConfig
|
|
14
|
+
tsConfig ??= readTsConfiguration(tsConfigPath);
|
|
17
15
|
tsPathMappings = {};
|
|
18
|
-
Object.entries(
|
|
16
|
+
Object.entries(tsConfig.options?.paths ?? {}).forEach(([alias, paths]) => {
|
|
19
17
|
tsPathMappings[alias] = paths.map((path) => path.replace(/^\.\//, ''));
|
|
20
18
|
});
|
|
21
19
|
return tsPathMappings;
|
|
@@ -23,23 +23,21 @@ function filterExistingDependencies(dependencies, existingAltDependencies) {
|
|
|
23
23
|
if (!existingAltDependencies) {
|
|
24
24
|
return dependencies;
|
|
25
25
|
}
|
|
26
|
-
return Object.keys(dependencies
|
|
26
|
+
return Object.keys(dependencies ?? {})
|
|
27
27
|
.filter((d) => !existingAltDependencies[d])
|
|
28
|
-
.reduce((acc, d) => (
|
|
28
|
+
.reduce((acc, d) => ({ ...acc, [d]: dependencies[d] }), {});
|
|
29
29
|
}
|
|
30
30
|
function cleanSemver(version) {
|
|
31
|
-
|
|
32
|
-
return (_a = (0, semver_1.clean)(version)) !== null && _a !== void 0 ? _a : (0, semver_1.coerce)(version);
|
|
31
|
+
return (0, semver_1.clean)(version) ?? (0, semver_1.coerce)(version);
|
|
33
32
|
}
|
|
34
33
|
function isIncomingVersionGreater(incomingVersion, existingVersion) {
|
|
35
|
-
var _a, _b, _c, _d;
|
|
36
34
|
// if version is in the format of "latest", "next" or similar - keep it, otherwise try to parse it
|
|
37
35
|
const incomingVersionCompareBy = incomingVersion in NON_SEMVER_TAGS
|
|
38
36
|
? incomingVersion
|
|
39
|
-
:
|
|
37
|
+
: cleanSemver(incomingVersion)?.toString() ?? UNIDENTIFIED_VERSION;
|
|
40
38
|
const existingVersionCompareBy = existingVersion in NON_SEMVER_TAGS
|
|
41
39
|
? existingVersion
|
|
42
|
-
:
|
|
40
|
+
: cleanSemver(existingVersion)?.toString() ?? UNIDENTIFIED_VERSION;
|
|
43
41
|
if (incomingVersionCompareBy in NON_SEMVER_TAGS &&
|
|
44
42
|
existingVersionCompareBy in NON_SEMVER_TAGS) {
|
|
45
43
|
return (NON_SEMVER_TAGS[incomingVersionCompareBy] >
|
|
@@ -61,7 +59,7 @@ function updateExistingAltDependenciesVersion(dependencies, existingAltDependenc
|
|
|
61
59
|
const existingVersion = existingAltDependencies[d];
|
|
62
60
|
return isIncomingVersionGreater(incomingVersion, existingVersion);
|
|
63
61
|
})
|
|
64
|
-
.reduce((acc, d) => (
|
|
62
|
+
.reduce((acc, d) => ({ ...acc, [d]: dependencies[d] }), {});
|
|
65
63
|
}
|
|
66
64
|
function updateExistingDependenciesVersion(dependencies, existingDependencies = {}) {
|
|
67
65
|
return Object.keys(dependencies)
|
|
@@ -73,7 +71,7 @@ function updateExistingDependenciesVersion(dependencies, existingDependencies =
|
|
|
73
71
|
const existingVersion = existingDependencies[d];
|
|
74
72
|
return isIncomingVersionGreater(incomingVersion, existingVersion);
|
|
75
73
|
})
|
|
76
|
-
.reduce((acc, d) => (
|
|
74
|
+
.reduce((acc, d) => ({ ...acc, [d]: dependencies[d] }), {});
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
77
|
* Add Dependencies and Dev Dependencies to package.json
|
|
@@ -100,14 +98,26 @@ function addDependenciesToPackageJson(tree, dependencies, devDependencies, packa
|
|
|
100
98
|
// - dependencies of the same type that are not present
|
|
101
99
|
// - dependencies of the same type that have greater version
|
|
102
100
|
// - specified dependencies of the other type that have greater version and are already installed as current type
|
|
103
|
-
filteredDependencies =
|
|
104
|
-
|
|
101
|
+
filteredDependencies = {
|
|
102
|
+
...updateExistingDependenciesVersion(filteredDependencies, currentPackageJson.dependencies),
|
|
103
|
+
...updateExistingAltDependenciesVersion(devDependencies, currentPackageJson.dependencies),
|
|
104
|
+
};
|
|
105
|
+
filteredDevDependencies = {
|
|
106
|
+
...updateExistingDependenciesVersion(filteredDevDependencies, currentPackageJson.devDependencies),
|
|
107
|
+
...updateExistingAltDependenciesVersion(dependencies, currentPackageJson.devDependencies),
|
|
108
|
+
};
|
|
105
109
|
filteredDependencies = removeLowerVersions(filteredDependencies, currentPackageJson.dependencies);
|
|
106
110
|
filteredDevDependencies = removeLowerVersions(filteredDevDependencies, currentPackageJson.devDependencies);
|
|
107
111
|
if (requiresAddingOfPackages(currentPackageJson, filteredDependencies, filteredDevDependencies)) {
|
|
108
112
|
updateJson(tree, packageJsonPath, (json) => {
|
|
109
|
-
json.dependencies =
|
|
110
|
-
|
|
113
|
+
json.dependencies = {
|
|
114
|
+
...(json.dependencies || {}),
|
|
115
|
+
...filteredDependencies,
|
|
116
|
+
};
|
|
117
|
+
json.devDependencies = {
|
|
118
|
+
...(json.devDependencies || {}),
|
|
119
|
+
...filteredDevDependencies,
|
|
120
|
+
};
|
|
111
121
|
json.dependencies = sortObjectByKeys(json.dependencies);
|
|
112
122
|
json.devDependencies = sortObjectByKeys(json.devDependencies);
|
|
113
123
|
return json;
|
|
@@ -124,11 +134,11 @@ exports.addDependenciesToPackageJson = addDependenciesToPackageJson;
|
|
|
124
134
|
**/
|
|
125
135
|
function removeLowerVersions(incomingDeps, existingDeps) {
|
|
126
136
|
return Object.keys(incomingDeps).reduce((acc, d) => {
|
|
127
|
-
if (
|
|
137
|
+
if (existingDeps?.[d] &&
|
|
128
138
|
!isIncomingVersionGreater(incomingDeps[d], existingDeps[d])) {
|
|
129
139
|
return acc;
|
|
130
140
|
}
|
|
131
|
-
return
|
|
141
|
+
return { ...acc, [d]: incomingDeps[d] };
|
|
132
142
|
}, {});
|
|
133
143
|
}
|
|
134
144
|
/**
|
|
@@ -171,7 +181,10 @@ function sortObjectByKeys(obj) {
|
|
|
171
181
|
return Object.keys(obj)
|
|
172
182
|
.sort()
|
|
173
183
|
.reduce((result, key) => {
|
|
174
|
-
return
|
|
184
|
+
return {
|
|
185
|
+
...result,
|
|
186
|
+
[key]: obj[key],
|
|
187
|
+
};
|
|
175
188
|
}, {});
|
|
176
189
|
}
|
|
177
190
|
/**
|
|
@@ -232,7 +245,6 @@ function requiresRemovingOfPackages(packageJsonFile, deps, devDeps) {
|
|
|
232
245
|
}
|
|
233
246
|
const packageMapCache = new Map();
|
|
234
247
|
function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion, _) {
|
|
235
|
-
var _a;
|
|
236
248
|
let pkg;
|
|
237
249
|
let requiredVersion;
|
|
238
250
|
if (typeof pkgOrTree === 'string') {
|
|
@@ -263,7 +275,7 @@ function ensurePackage(pkgOrTree, requiredVersionOrPackage, maybeRequiredVersion
|
|
|
263
275
|
if (process.env.NX_DRY_RUN && process.env.NX_DRY_RUN !== 'false') {
|
|
264
276
|
throw new Error('NOTE: This generator does not support --dry-run. If you are running this in Nx Console, it should execute fine once you hit the "Run" button.\n');
|
|
265
277
|
}
|
|
266
|
-
const { dir: tempDir } =
|
|
278
|
+
const { dir: tempDir } = createTempNpmDirectory?.() ?? {
|
|
267
279
|
dir: (0, tmp_1.dirSync)().name,
|
|
268
280
|
};
|
|
269
281
|
console.log(`Fetching ${pkg}...`);
|
|
@@ -21,12 +21,11 @@ function replacePackageInDependencies(tree, oldPackageName, newPackageName) {
|
|
|
21
21
|
}
|
|
22
22
|
try {
|
|
23
23
|
updateJson(tree, path, (packageJson) => {
|
|
24
|
-
var _a, _b, _c, _d;
|
|
25
24
|
for (const deps of [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
packageJson.dependencies ?? {},
|
|
26
|
+
packageJson.devDependencies ?? {},
|
|
27
|
+
packageJson.peerDependencies ?? {},
|
|
28
|
+
packageJson.optionalDependencies ?? {},
|
|
30
29
|
]) {
|
|
31
30
|
if (oldPackageName in deps) {
|
|
32
31
|
deps[newPackageName] = deps[oldPackageName];
|
|
@@ -42,11 +41,10 @@ function replacePackageInDependencies(tree, oldPackageName, newPackageName) {
|
|
|
42
41
|
});
|
|
43
42
|
}
|
|
44
43
|
function replacePackageInProjectConfigurations(tree, oldPackageName, newPackageName) {
|
|
45
|
-
var _a, _b;
|
|
46
44
|
const projects = getProjects(tree);
|
|
47
45
|
for (const [projectName, projectConfiguration] of projects) {
|
|
48
46
|
let needsUpdate = false;
|
|
49
|
-
for (const [targetName, targetConfig] of Object.entries(
|
|
47
|
+
for (const [targetName, targetConfig] of Object.entries(projectConfiguration.targets ?? {})) {
|
|
50
48
|
if (!targetConfig.executor) {
|
|
51
49
|
continue;
|
|
52
50
|
}
|
|
@@ -57,7 +55,7 @@ function replacePackageInProjectConfigurations(tree, oldPackageName, newPackageN
|
|
|
57
55
|
newPackageName + ':' + executorName;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
for (const [collection, collectionDefaults] of Object.entries(
|
|
58
|
+
for (const [collection, collectionDefaults] of Object.entries(projectConfiguration.generators ?? {})) {
|
|
61
59
|
if (collection === oldPackageName) {
|
|
62
60
|
needsUpdate = true;
|
|
63
61
|
projectConfiguration.generators[newPackageName] = collectionDefaults;
|
|
@@ -70,13 +68,12 @@ function replacePackageInProjectConfigurations(tree, oldPackageName, newPackageN
|
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
function replacePackageInNxJson(tree, oldPackageName, newPackageName) {
|
|
73
|
-
var _a, _b;
|
|
74
71
|
if (!tree.exists('nx.json')) {
|
|
75
72
|
return;
|
|
76
73
|
}
|
|
77
74
|
const nxJson = readNxJson(tree);
|
|
78
75
|
let needsUpdate = false;
|
|
79
|
-
for (const [targetName, targetConfig] of Object.entries(
|
|
76
|
+
for (const [targetName, targetConfig] of Object.entries(nxJson.targetDefaults ?? {})) {
|
|
80
77
|
if (!targetConfig.executor) {
|
|
81
78
|
continue;
|
|
82
79
|
}
|
|
@@ -87,7 +84,7 @@ function replacePackageInNxJson(tree, oldPackageName, newPackageName) {
|
|
|
87
84
|
newPackageName + ':' + executorName;
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
|
-
for (const [collection, collectionDefaults] of Object.entries(
|
|
87
|
+
for (const [collection, collectionDefaults] of Object.entries(nxJson.generators ?? {})) {
|
|
91
88
|
if (collection === oldPackageName) {
|
|
92
89
|
needsUpdate = true;
|
|
93
90
|
nxJson.generators[newPackageName] = collectionDefaults;
|
|
@@ -119,7 +116,7 @@ function replaceMentions(tree, oldPackageName, newPackageName) {
|
|
|
119
116
|
}
|
|
120
117
|
tree.write(path, contents.replace(new RegExp(oldPackageName, 'g'), newPackageName));
|
|
121
118
|
}
|
|
122
|
-
catch
|
|
119
|
+
catch {
|
|
123
120
|
// Its **probably** ok, contents can be null if the file is too large or
|
|
124
121
|
// there was an access exception.
|
|
125
122
|
logger.warn(`An error was thrown when trying to update ${path}. If you believe the migration should have updated it, be sure to review the file and open an issue.`);
|