@nx/js 0.0.0-pr-30516-4c8bfff → 0.0.0-pr-30457-d91a68c
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/migrations.json +9 -0
- package/package.json +3 -3
- package/src/generators/library/library.js +4 -15
- package/src/generators/library/utils/add-release-config.d.ts +1 -1
- package/src/generators/library/utils/add-release-config.js +21 -7
- package/src/generators/release-version/release-version.d.ts +1 -1
- package/src/generators/release-version/release-version.js +12 -11
- package/src/generators/release-version/schema.d.ts +1 -1
- package/src/generators/release-version/schema.json +23 -4
- package/src/plugins/typescript/plugin.js +136 -42
- package/src/plugins/typescript/util.d.ts +5 -4
- package/src/release/utils/update-lock-file.d.ts +10 -0
- package/src/{generators/release-version → release}/utils/update-lock-file.js +12 -9
- package/src/release/version-actions.d.ts +22 -0
- package/src/release/version-actions.js +189 -0
- package/src/utils/buildable-libs-utils.d.ts +0 -2
- package/src/utils/buildable-libs-utils.js +2 -34
- package/src/utils/typescript/ts-solution-setup.js +1 -1
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/src/generators/release-version/utils/update-lock-file.d.ts +0 -5
package/migrations.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-30457-d91a68c",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "0.0.0-pr-
|
|
43
|
-
"@nx/workspace": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-30457-d91a68c",
|
|
43
|
+
"@nx/workspace": "0.0.0-pr-30457-d91a68c",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -8,8 +8,10 @@ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project
|
|
|
8
8
|
const prompt_1 = require("@nx/devkit/src/generators/prompt");
|
|
9
9
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
10
10
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
11
|
+
const use_legacy_versioning_1 = require("nx/src/command-line/release/config/use-legacy-versioning");
|
|
11
12
|
const path_1 = require("path");
|
|
12
13
|
const generator_prompts_1 = require("../../utils/generator-prompts");
|
|
14
|
+
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
13
15
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
14
16
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
15
17
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
@@ -21,7 +23,6 @@ const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
|
21
23
|
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
22
24
|
const versions_1 = require("../../utils/versions");
|
|
23
25
|
const init_1 = require("../init/init");
|
|
24
|
-
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
25
26
|
const add_release_config_1 = require("./utils/add-release-config");
|
|
26
27
|
const defaultOutputDirectory = 'dist';
|
|
27
28
|
async function libraryGenerator(tree, schema) {
|
|
@@ -158,8 +159,8 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
158
159
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
159
160
|
}
|
|
160
161
|
async function configureProject(tree, options) {
|
|
162
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
161
163
|
if (options.hasPlugin) {
|
|
162
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
163
164
|
(0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot, options.bundler === 'none' ? null : 'build');
|
|
164
165
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
165
166
|
}
|
|
@@ -217,7 +218,7 @@ async function configureProject(tree, options) {
|
|
|
217
218
|
await (0, add_release_config_1.addReleaseConfigForTsSolution)(tree, options.name, projectConfiguration);
|
|
218
219
|
}
|
|
219
220
|
else {
|
|
220
|
-
await (0, add_release_config_1.addReleaseConfigForNonTsSolution)(tree, options.name, projectConfiguration, defaultOutputDirectory);
|
|
221
|
+
await (0, add_release_config_1.addReleaseConfigForNonTsSolution)((0, use_legacy_versioning_1.shouldUseLegacyVersioning)(nxJson.release), tree, options.name, projectConfiguration, defaultOutputDirectory);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
if (!options.useProjectJson) {
|
|
@@ -737,12 +738,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
737
738
|
json.references.push({
|
|
738
739
|
path: './tsconfig.lib.json',
|
|
739
740
|
});
|
|
740
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
741
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
742
|
-
if (options.bundler === 'tsc') {
|
|
743
|
-
json['nx'] ??= {};
|
|
744
|
-
json['nx'].addTypecheckTarget = false;
|
|
745
|
-
}
|
|
746
741
|
return json;
|
|
747
742
|
});
|
|
748
743
|
}
|
|
@@ -754,12 +749,6 @@ function createProjectTsConfigs(tree, options) {
|
|
|
754
749
|
include: [],
|
|
755
750
|
references: [{ path: './tsconfig.lib.json' }],
|
|
756
751
|
};
|
|
757
|
-
// If using `tsc` to build, then we do not want a typecheck target that duplicates the work, since both run `tsc`.
|
|
758
|
-
// This applies to `@nx/js/typescript` plugin only.
|
|
759
|
-
if (options.bundler === 'tsc') {
|
|
760
|
-
tsconfig['nx'] ??= {};
|
|
761
|
-
tsconfig['nx'].addTypecheckTarget = false;
|
|
762
|
-
}
|
|
763
752
|
(0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), tsconfig);
|
|
764
753
|
// update root project tsconfig.json references with the new lib tsconfig
|
|
765
754
|
(0, devkit_1.updateJson)(tree, 'tsconfig.json', (json) => {
|
|
@@ -7,5 +7,5 @@ export declare function addReleaseConfigForTsSolution(tree: Tree, projectName: s
|
|
|
7
7
|
* Add release configuration for non-ts solution projects
|
|
8
8
|
* Add release option in project.json and add packageRoot to nx-release-publish target
|
|
9
9
|
*/
|
|
10
|
-
export declare function addReleaseConfigForNonTsSolution(tree: Tree, projectName: string, projectConfiguration: ProjectConfiguration, defaultOutputDirectory?: string): Promise<ProjectConfiguration>;
|
|
10
|
+
export declare function addReleaseConfigForNonTsSolution(useLegacyVersioning: boolean, tree: Tree, projectName: string, projectConfiguration: ProjectConfiguration, defaultOutputDirectory?: string): Promise<ProjectConfiguration>;
|
|
11
11
|
export declare function releaseTasks(tree: Tree): Promise<GeneratorCallback>;
|
|
@@ -91,7 +91,7 @@ async function addReleaseConfigForTsSolution(tree, projectName, projectConfigura
|
|
|
91
91
|
* Add release configuration for non-ts solution projects
|
|
92
92
|
* Add release option in project.json and add packageRoot to nx-release-publish target
|
|
93
93
|
*/
|
|
94
|
-
async function addReleaseConfigForNonTsSolution(tree, projectName, projectConfiguration, defaultOutputDirectory = 'dist') {
|
|
94
|
+
async function addReleaseConfigForNonTsSolution(useLegacyVersioning, tree, projectName, projectConfiguration, defaultOutputDirectory = 'dist') {
|
|
95
95
|
const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
|
|
96
96
|
projectConfiguration.targets ??= {};
|
|
97
97
|
projectConfiguration.targets['nx-release-publish'] = {
|
|
@@ -99,17 +99,31 @@ async function addReleaseConfigForNonTsSolution(tree, projectName, projectConfig
|
|
|
99
99
|
packageRoot,
|
|
100
100
|
},
|
|
101
101
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
if (useLegacyVersioning) {
|
|
103
|
+
projectConfiguration.release = {
|
|
104
|
+
version: {
|
|
105
|
+
generatorOptions: {
|
|
106
|
+
packageRoot,
|
|
107
|
+
// using git tags to determine the current version is required here because
|
|
108
|
+
// the version in the package root is overridden with every build
|
|
109
|
+
currentVersionResolver: 'git-tag',
|
|
110
|
+
fallbackCurrentVersionResolver: 'disk',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// TODO: re-evaluate this config in new versions
|
|
117
|
+
projectConfiguration.release = {
|
|
118
|
+
version: {
|
|
119
|
+
manifestRootsToUpdate: [packageRoot],
|
|
106
120
|
// using git tags to determine the current version is required here because
|
|
107
121
|
// the version in the package root is overridden with every build
|
|
108
122
|
currentVersionResolver: 'git-tag',
|
|
109
123
|
fallbackCurrentVersionResolver: 'disk',
|
|
110
124
|
},
|
|
111
|
-
}
|
|
112
|
-
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
113
127
|
await addReleaseConfigForTsSolution(tree, projectName, projectConfiguration);
|
|
114
128
|
return projectConfiguration;
|
|
115
129
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
-
import { ReleaseVersionGeneratorResult } from 'nx/src/command-line/release/version';
|
|
2
|
+
import { ReleaseVersionGeneratorResult } from 'nx/src/command-line/release/version-legacy';
|
|
3
3
|
import { ReleaseVersionGeneratorSchema } from './schema';
|
|
4
4
|
export declare function releaseVersionGenerator(tree: Tree, options: ReleaseVersionGeneratorSchema): Promise<ReleaseVersionGeneratorResult>;
|
|
5
5
|
export default releaseVersionGenerator;
|
|
@@ -11,15 +11,15 @@ const config_1 = require("nx/src/command-line/release/config/config");
|
|
|
11
11
|
const git_1 = require("nx/src/command-line/release/utils/git");
|
|
12
12
|
const resolve_semver_specifier_1 = require("nx/src/command-line/release/utils/resolve-semver-specifier");
|
|
13
13
|
const semver_1 = require("nx/src/command-line/release/utils/semver");
|
|
14
|
-
const
|
|
14
|
+
const version_legacy_1 = require("nx/src/command-line/release/version-legacy");
|
|
15
15
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
16
16
|
const ora = require("ora");
|
|
17
17
|
const semver_2 = require("semver");
|
|
18
|
+
const update_lock_file_1 = require("../../release/utils/update-lock-file");
|
|
18
19
|
const is_locally_linked_package_version_1 = require("../../utils/is-locally-linked-package-version");
|
|
19
20
|
const npm_config_1 = require("../../utils/npm-config");
|
|
20
21
|
const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
|
|
21
22
|
const sort_projects_topologically_1 = require("./utils/sort-projects-topologically");
|
|
22
|
-
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
23
23
|
function resolvePreIdSpecifier(currentSpecifier, preid) {
|
|
24
24
|
if (!currentSpecifier.startsWith('pre') && preid) {
|
|
25
25
|
return `pre${currentSpecifier}`;
|
|
@@ -39,10 +39,10 @@ async function releaseVersionGenerator(tree, options) {
|
|
|
39
39
|
options.specifier = options.specifier.replace(/^v/, '');
|
|
40
40
|
}
|
|
41
41
|
if (options.versionPrefix &&
|
|
42
|
-
|
|
42
|
+
version_legacy_1.validReleaseVersionPrefixes.indexOf(options.versionPrefix) === -1) {
|
|
43
43
|
throw new Error(`Invalid value for version.generatorOptions.versionPrefix: "${options.versionPrefix}"
|
|
44
44
|
|
|
45
|
-
Valid values are: ${
|
|
45
|
+
Valid values are: ${version_legacy_1.validReleaseVersionPrefixes
|
|
46
46
|
.map((s) => `"${s}"`)
|
|
47
47
|
.join(', ')}`);
|
|
48
48
|
}
|
|
@@ -54,7 +54,6 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
|
|
|
54
54
|
const updateDependents = options.updateDependents ?? 'auto';
|
|
55
55
|
const updateDependentsBump = resolvePreIdSpecifier('patch', options.preid);
|
|
56
56
|
// Sort the projects topologically if update dependents is enabled
|
|
57
|
-
// TODO: maybe move this sorting to the command level?
|
|
58
57
|
const projects = updateDependents === 'never' ||
|
|
59
58
|
options.releaseGroup.projectsRelationship !== 'independent'
|
|
60
59
|
? options.projects
|
|
@@ -287,8 +286,6 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
287
286
|
logger.buffer(`🚫 No changes were detected using git history and the conventional commits standard.`);
|
|
288
287
|
break;
|
|
289
288
|
}
|
|
290
|
-
// TODO: reevaluate this prerelease logic/workflow for independent projects
|
|
291
|
-
//
|
|
292
289
|
// Always assume that if the current version is a prerelease, then the next version should be a prerelease.
|
|
293
290
|
// Users must manually graduate from a prerelease to a release by providing an explicit specifier.
|
|
294
291
|
if ((0, semver_2.prerelease)(currentVersion ?? '')) {
|
|
@@ -490,7 +487,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
490
487
|
}
|
|
491
488
|
continue;
|
|
492
489
|
}
|
|
493
|
-
const newVersion = (0,
|
|
490
|
+
const newVersion = (0, version_legacy_1.deriveNewSemverVersion)(currentVersion, specifier, options.preid);
|
|
494
491
|
versionData[projectName].newVersion = newVersion;
|
|
495
492
|
(0, devkit_1.writeJson)(tree, packageJsonPath, {
|
|
496
493
|
...packageJson,
|
|
@@ -556,7 +553,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
556
553
|
}
|
|
557
554
|
// Bump the dependent's version if applicable and record it in the version data
|
|
558
555
|
if (forceVersionBump) {
|
|
559
|
-
const newPackageVersion = (0,
|
|
556
|
+
const newPackageVersion = (0, version_legacy_1.deriveNewSemverVersion)(currentPackageVersion, forceVersionBump, options.preid);
|
|
560
557
|
json.version = newPackageVersion;
|
|
561
558
|
// Look up any dependent projects from the transitiveLocalPackageDependents list
|
|
562
559
|
const transitiveDependentProjects = transitiveLocalPackageDependents.filter((localPackageDependency) => localPackageDependency.target === dependentProject.source);
|
|
@@ -666,7 +663,10 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
666
663
|
deletedFiles.push(...(await cb(opts.dryRun)));
|
|
667
664
|
}
|
|
668
665
|
const cwd = tree.root;
|
|
669
|
-
changedFiles.push(...(await (0, update_lock_file_1.updateLockFile)(cwd,
|
|
666
|
+
changedFiles.push(...(await (0, update_lock_file_1.updateLockFile)(cwd, {
|
|
667
|
+
...opts,
|
|
668
|
+
useLegacyVersioning: true,
|
|
669
|
+
})));
|
|
670
670
|
return { changedFiles, deletedFiles };
|
|
671
671
|
},
|
|
672
672
|
};
|
|
@@ -697,7 +697,8 @@ function createResolvePackageRoot(customPackageRoot) {
|
|
|
697
697
|
return projectNode.data.root;
|
|
698
698
|
}
|
|
699
699
|
if (projectNode.data.root === '.') {
|
|
700
|
-
//
|
|
700
|
+
// This is a temporary workaround to fix NXC-574 until NXC-573 is resolved.
|
|
701
|
+
// This has been fixed in "versioning v2"
|
|
701
702
|
return projectNode.data.root;
|
|
702
703
|
}
|
|
703
704
|
return (0, utils_1.interpolate)(customPackageRoot, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ReleaseVersionGeneratorSchema } from 'nx/src/command-line/release/version';
|
|
1
|
+
export { ReleaseVersionGeneratorSchema } from 'nx/src/command-line/release/version-legacy';
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
"properties": {
|
|
9
9
|
"projects": {
|
|
10
10
|
"type": "array",
|
|
11
|
+
"hidden": true,
|
|
12
|
+
"$comment": "This is not configured/passed by the user. It is provided by the version command.",
|
|
11
13
|
"description": "The ProjectGraphProjectNodes being versioned in the current execution.",
|
|
12
14
|
"items": {
|
|
13
15
|
"type": "object"
|
|
@@ -15,16 +17,33 @@
|
|
|
15
17
|
},
|
|
16
18
|
"projectGraph": {
|
|
17
19
|
"type": "object",
|
|
20
|
+
"hidden": true,
|
|
21
|
+
"$comment": "This is not configured/passed by the user. It is provided by the version command.",
|
|
18
22
|
"description": "ProjectGraph instance"
|
|
19
23
|
},
|
|
20
|
-
"specifier": {
|
|
21
|
-
"type": "string",
|
|
22
|
-
"description": "Exact version or semver keyword to apply to the selected release group. Overrides specifierSource."
|
|
23
|
-
},
|
|
24
24
|
"releaseGroup": {
|
|
25
25
|
"type": "object",
|
|
26
|
+
"hidden": true,
|
|
27
|
+
"$comment": "This is not configured/passed by the user. It is provided by the version command.",
|
|
26
28
|
"description": "The resolved release group configuration, including name, relevant to all projects in the current execution."
|
|
27
29
|
},
|
|
30
|
+
"conventionalCommitsConfig": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"hidden": true,
|
|
33
|
+
"$comment": "This is not configured/passed by the user. It is provided by the version command.",
|
|
34
|
+
"description": "The conventional commits configuration to use when determining the next version of the project.",
|
|
35
|
+
"default": {}
|
|
36
|
+
},
|
|
37
|
+
"firstRelease": {
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"hidden": true,
|
|
40
|
+
"$comment": "This is not configured/passed by the user. It is provided by the version command.",
|
|
41
|
+
"description": "Whether this is the first release of the project (which skips some validation within the generator)."
|
|
42
|
+
},
|
|
43
|
+
"specifier": {
|
|
44
|
+
"type": "string",
|
|
45
|
+
"description": "Exact version or semver keyword to apply to the selected release group. Overrides specifierSource."
|
|
46
|
+
},
|
|
28
47
|
"specifierSource": {
|
|
29
48
|
"type": "string",
|
|
30
49
|
"default": "prompt",
|
|
@@ -3,15 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createNodes = exports.createNodesV2 = exports.PLUGIN_NAME = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
6
|
-
const picomatch = require("picomatch");
|
|
7
6
|
const node_fs_1 = require("node:fs");
|
|
8
7
|
const node_path_1 = require("node:path");
|
|
9
8
|
const posix = require("node:path/posix");
|
|
10
9
|
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
10
|
+
const picomatch = require("picomatch");
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
12
12
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
13
13
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
14
14
|
const util_1 = require("./util");
|
|
15
|
+
let ts;
|
|
15
16
|
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
17
|
let tsConfigCache;
|
|
17
18
|
const tsConfigCachePath = (0, node_path_1.join)(cache_directory_1.workspaceDataDirectory, 'tsconfig-files.hash');
|
|
@@ -144,6 +145,9 @@ async function getConfigFileHash(configFilePath, workspaceRoot, projectRoot, opt
|
|
|
144
145
|
lockFileHash,
|
|
145
146
|
optionsHash,
|
|
146
147
|
...(packageJson ? [(0, file_hasher_1.hashObject)(packageJson)] : []),
|
|
148
|
+
// change this to bust the cache when making changes that would yield
|
|
149
|
+
// different results for the same hash
|
|
150
|
+
(0, file_hasher_1.hashObject)({ bust: 2 }),
|
|
147
151
|
]);
|
|
148
152
|
}
|
|
149
153
|
function checkIfConfigFileShouldBeProject(configFilePath, projectRoot, context) {
|
|
@@ -192,13 +196,27 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
192
196
|
// `tsc --build` does not work with `noEmit: true`
|
|
193
197
|
command = `echo "The 'typecheck' target is disabled because one or more project references set 'noEmit: true' in their tsconfig. Remove this property to resolve this issue."`;
|
|
194
198
|
}
|
|
199
|
+
const dependsOn = [`^${targetName}`];
|
|
200
|
+
if (options.build && targets[options.build.targetName]) {
|
|
201
|
+
// we already processed and have a build target
|
|
202
|
+
dependsOn.unshift(options.build.targetName);
|
|
203
|
+
}
|
|
204
|
+
else if (options.build) {
|
|
205
|
+
// check if the project will have a build target
|
|
206
|
+
const buildConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, options.build.configName);
|
|
207
|
+
if (context.configFiles.some((f) => f === buildConfigPath) &&
|
|
208
|
+
(0, util_1.isValidPackageJsonBuildConfig)(retrieveTsConfigFromCache(buildConfigPath, context.workspaceRoot), context.workspaceRoot, projectRoot)) {
|
|
209
|
+
dependsOn.unshift(options.build.targetName);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
195
212
|
targets[targetName] = {
|
|
196
|
-
dependsOn
|
|
213
|
+
dependsOn,
|
|
197
214
|
command,
|
|
198
215
|
options: { cwd: projectRoot },
|
|
199
216
|
cache: true,
|
|
200
217
|
inputs: getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot),
|
|
201
|
-
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot
|
|
218
|
+
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot,
|
|
219
|
+
/* emitDeclarationOnly */ true),
|
|
202
220
|
syncGenerators: ['@nx/js:typescript-sync'],
|
|
203
221
|
metadata: {
|
|
204
222
|
technologies: ['typescript'],
|
|
@@ -225,7 +243,9 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
|
|
|
225
243
|
options: { cwd: projectRoot },
|
|
226
244
|
cache: true,
|
|
227
245
|
inputs: getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot),
|
|
228
|
-
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot
|
|
246
|
+
outputs: getOutputs(configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot,
|
|
247
|
+
// should be false for build target, but providing it just in case is set to true
|
|
248
|
+
tsConfig.options.emitDeclarationOnly),
|
|
229
249
|
syncGenerators: ['@nx/js:typescript-sync'],
|
|
230
250
|
metadata: {
|
|
231
251
|
technologies: ['typescript'],
|
|
@@ -260,10 +280,57 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
260
280
|
...Object.entries(internalProjectReferences),
|
|
261
281
|
];
|
|
262
282
|
const absoluteProjectRoot = (0, node_path_1.join)(workspaceRoot, projectRoot);
|
|
283
|
+
if (!ts) {
|
|
284
|
+
ts = require('typescript');
|
|
285
|
+
}
|
|
286
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9869
|
|
287
|
+
const supportedTSExtensions = [
|
|
288
|
+
ts.Extension.Ts,
|
|
289
|
+
ts.Extension.Tsx,
|
|
290
|
+
ts.Extension.Dts,
|
|
291
|
+
ts.Extension.Cts,
|
|
292
|
+
ts.Extension.Dcts,
|
|
293
|
+
ts.Extension.Mts,
|
|
294
|
+
ts.Extension.Dmts,
|
|
295
|
+
];
|
|
296
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9878
|
|
297
|
+
const allSupportedExtensions = [
|
|
298
|
+
ts.Extension.Ts,
|
|
299
|
+
ts.Extension.Tsx,
|
|
300
|
+
ts.Extension.Dts,
|
|
301
|
+
ts.Extension.Js,
|
|
302
|
+
ts.Extension.Jsx,
|
|
303
|
+
ts.Extension.Cts,
|
|
304
|
+
ts.Extension.Dcts,
|
|
305
|
+
ts.Extension.Cjs,
|
|
306
|
+
ts.Extension.Mts,
|
|
307
|
+
ts.Extension.Dmts,
|
|
308
|
+
ts.Extension.Mjs,
|
|
309
|
+
];
|
|
310
|
+
const normalizeInput = (input, config) => {
|
|
311
|
+
const extensions = config.options.allowJs
|
|
312
|
+
? [...allSupportedExtensions]
|
|
313
|
+
: [...supportedTSExtensions];
|
|
314
|
+
if (config.options.resolveJsonModule) {
|
|
315
|
+
extensions.push(ts.Extension.Json);
|
|
316
|
+
}
|
|
317
|
+
const segments = input.split('/');
|
|
318
|
+
// An "includes" path "foo" is implicitly a glob "foo/**/*" if its last
|
|
319
|
+
// segment has no extension, and does not contain any glob characters
|
|
320
|
+
// itself.
|
|
321
|
+
// https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9577-L9585
|
|
322
|
+
if (!/[.*?]/.test(segments.at(-1))) {
|
|
323
|
+
return extensions.map((ext) => `${segments.join('/')}/**/*${ext}`);
|
|
324
|
+
}
|
|
325
|
+
return [input];
|
|
326
|
+
};
|
|
263
327
|
projectTsConfigFiles.forEach(([configPath, config]) => {
|
|
264
328
|
configFiles.add(configPath);
|
|
265
329
|
const offset = (0, node_path_1.relative)(absoluteProjectRoot, (0, node_path_1.dirname)(configPath));
|
|
266
|
-
(config.raw?.include ?? []).forEach((p) =>
|
|
330
|
+
(config.raw?.include ?? []).forEach((p) => {
|
|
331
|
+
const normalized = normalizeInput((0, node_path_1.join)(offset, p), config);
|
|
332
|
+
normalized.forEach((input) => includePaths.add(input));
|
|
333
|
+
});
|
|
267
334
|
if (config.raw?.exclude) {
|
|
268
335
|
/**
|
|
269
336
|
* We need to filter out the exclude paths that are already included in
|
|
@@ -311,7 +378,7 @@ function getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferen
|
|
|
311
378
|
inputs.push({ externalDependencies });
|
|
312
379
|
return inputs;
|
|
313
380
|
}
|
|
314
|
-
function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot) {
|
|
381
|
+
function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspaceRoot, projectRoot, emitDeclarationOnly) {
|
|
315
382
|
const outputs = new Set();
|
|
316
383
|
// We could have more surgical outputs based on the tsconfig options, but the
|
|
317
384
|
// user could override them through the command line and that wouldn't be
|
|
@@ -333,9 +400,18 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
|
|
|
333
400
|
: pathToInputOrOutput((0, devkit_1.joinPathFragments)(outDir, `${outFileName}.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
334
401
|
}
|
|
335
402
|
else if (config.options.outDir) {
|
|
336
|
-
|
|
403
|
+
if (emitDeclarationOnly) {
|
|
404
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, '**/*.d.ts'), workspaceRoot, projectRoot));
|
|
405
|
+
if (tsConfig.options.declarationMap) {
|
|
406
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, '**/*.d.ts.map'), workspaceRoot, projectRoot));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
outputs.add(pathToInputOrOutput(config.options.outDir, workspaceRoot, projectRoot));
|
|
411
|
+
}
|
|
337
412
|
if (config.options.tsBuildInfoFile) {
|
|
338
|
-
if (
|
|
413
|
+
if (emitDeclarationOnly ||
|
|
414
|
+
!(0, node_path_1.normalize)(config.options.tsBuildInfoFile).startsWith(`${(0, node_path_1.normalize)(config.options.outDir)}${node_path_1.sep}`)) {
|
|
339
415
|
// https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
|
|
340
416
|
outputs.add(pathToInputOrOutput(config.options.tsBuildInfoFile, workspaceRoot, projectRoot));
|
|
341
417
|
}
|
|
@@ -345,6 +421,11 @@ function getOutputs(configFilePath, tsConfig, internalProjectReferences, workspa
|
|
|
345
421
|
const relativeRootDir = (0, node_path_1.relative)(config.options.rootDir, (0, node_path_1.join)(workspaceRoot, projectRoot));
|
|
346
422
|
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, relativeRootDir, `*.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
347
423
|
}
|
|
424
|
+
else if (emitDeclarationOnly) {
|
|
425
|
+
// https://www.typescriptlang.org/tsconfig#tsBuildInfoFile
|
|
426
|
+
const name = (0, node_path_1.basename)(configFilePath, '.json');
|
|
427
|
+
outputs.add(pathToInputOrOutput((0, devkit_1.joinPathFragments)(config.options.outDir, `${name}.tsbuildinfo`), workspaceRoot, projectRoot));
|
|
428
|
+
}
|
|
348
429
|
}
|
|
349
430
|
else if (config.raw?.include?.length ||
|
|
350
431
|
config.raw?.files?.length ||
|
|
@@ -380,17 +461,15 @@ function pathToInputOrOutput(path, workspaceRoot, projectRoot) {
|
|
|
380
461
|
}
|
|
381
462
|
return (0, devkit_1.joinPathFragments)('{projectRoot}', pathRelativeToProjectRoot);
|
|
382
463
|
}
|
|
383
|
-
function getExtendedConfigFiles(tsConfig, workspaceRoot) {
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
extendedConfigFiles.add(currentExtendedConfigFile.filePath);
|
|
393
|
-
currentExtendedConfigFile = retrieveTsConfigFromCache(currentExtendedConfigFile.filePath, workspaceRoot).extendedConfigFile;
|
|
464
|
+
function getExtendedConfigFiles(tsConfig, workspaceRoot, extendedConfigFiles = new Set(), extendedExternalPackages = new Set()) {
|
|
465
|
+
for (const extendedConfigFile of tsConfig.extendedConfigFiles) {
|
|
466
|
+
if (extendedConfigFile.externalPackage) {
|
|
467
|
+
extendedExternalPackages.add(extendedConfigFile.externalPackage);
|
|
468
|
+
}
|
|
469
|
+
else if (extendedConfigFile.filePath) {
|
|
470
|
+
extendedConfigFiles.add(extendedConfigFile.filePath);
|
|
471
|
+
getExtendedConfigFiles(retrieveTsConfigFromCache(extendedConfigFile.filePath, workspaceRoot), workspaceRoot, extendedConfigFiles, extendedExternalPackages);
|
|
472
|
+
}
|
|
394
473
|
}
|
|
395
474
|
return {
|
|
396
475
|
files: Array.from(extendedConfigFiles),
|
|
@@ -526,44 +605,54 @@ function readTsConfigAndCache(tsConfigPath, workspaceRoot) {
|
|
|
526
605
|
let extendedFilesHash;
|
|
527
606
|
if (tsConfigCache[relativePath] &&
|
|
528
607
|
tsConfigCache[relativePath].hash === hash) {
|
|
529
|
-
extendedFilesHash = getExtendedFilesHash(tsConfigCache[relativePath].data.
|
|
608
|
+
extendedFilesHash = getExtendedFilesHash(tsConfigCache[relativePath].data.extendedConfigFiles, workspaceRoot);
|
|
530
609
|
if (tsConfigCache[relativePath].extendedFilesHash === extendedFilesHash) {
|
|
531
610
|
return tsConfigCache[relativePath].data;
|
|
532
611
|
}
|
|
533
612
|
}
|
|
534
613
|
const tsConfig = readTsConfig(tsConfigPath, workspaceRoot);
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
614
|
+
const extendedConfigFiles = [];
|
|
615
|
+
if (tsConfig.raw?.extends) {
|
|
616
|
+
const extendsArray = typeof tsConfig.raw.extends === 'string'
|
|
617
|
+
? [tsConfig.raw.extends]
|
|
618
|
+
: tsConfig.raw.extends;
|
|
619
|
+
for (const extendsPath of extendsArray) {
|
|
620
|
+
const extendedConfigFile = resolveExtendedTsConfigPath(extendsPath, (0, node_path_1.dirname)(tsConfigPath));
|
|
621
|
+
if (extendedConfigFile) {
|
|
622
|
+
extendedConfigFiles.push(extendedConfigFile);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
extendedFilesHash ??= getExtendedFilesHash(extendedConfigFiles, workspaceRoot);
|
|
539
627
|
tsConfigCache[relativePath] = {
|
|
540
628
|
data: {
|
|
541
629
|
options: tsConfig.options,
|
|
542
630
|
projectReferences: tsConfig.projectReferences,
|
|
543
631
|
raw: tsConfig.raw,
|
|
544
|
-
|
|
632
|
+
extendedConfigFiles,
|
|
545
633
|
},
|
|
546
634
|
hash,
|
|
547
635
|
extendedFilesHash,
|
|
548
636
|
};
|
|
549
637
|
return tsConfigCache[relativePath].data;
|
|
550
638
|
}
|
|
551
|
-
function getExtendedFilesHash(
|
|
639
|
+
function getExtendedFilesHash(extendedConfigFiles, workspaceRoot) {
|
|
552
640
|
const hashes = [];
|
|
553
|
-
if (!
|
|
641
|
+
if (!extendedConfigFiles.length) {
|
|
554
642
|
return '';
|
|
555
643
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
.extendedConfigFile, workspaceRoot)
|
|
644
|
+
for (const extendedConfigFile of extendedConfigFiles) {
|
|
645
|
+
if (extendedConfigFile.externalPackage) {
|
|
646
|
+
hashes.push(extendedConfigFile.externalPackage);
|
|
647
|
+
}
|
|
648
|
+
else if (extendedConfigFile.filePath) {
|
|
649
|
+
hashes.push(getFileHash(extendedConfigFile.filePath, workspaceRoot));
|
|
650
|
+
hashes.push(getExtendedFilesHash(readTsConfigAndCache(extendedConfigFile.filePath, workspaceRoot)
|
|
651
|
+
.extendedConfigFiles, workspaceRoot));
|
|
652
|
+
}
|
|
563
653
|
}
|
|
564
654
|
return hashes.join('|');
|
|
565
655
|
}
|
|
566
|
-
let ts;
|
|
567
656
|
function readTsConfig(tsConfigPath, workspaceRoot) {
|
|
568
657
|
if (!ts) {
|
|
569
658
|
ts = require('typescript');
|
|
@@ -623,7 +712,8 @@ function resolveExtendedTsConfigPath(tsConfigPath, directory) {
|
|
|
623
712
|
const resolvedPath = require.resolve(tsConfigPath, {
|
|
624
713
|
paths: directory ? [directory] : undefined,
|
|
625
714
|
});
|
|
626
|
-
if (tsConfigPath.startsWith('.')
|
|
715
|
+
if (tsConfigPath.startsWith('.') ||
|
|
716
|
+
!resolvedPath.includes('/node_modules/')) {
|
|
627
717
|
return { filePath: resolvedPath };
|
|
628
718
|
}
|
|
629
719
|
// parse the package from the tsconfig path
|
|
@@ -661,7 +751,7 @@ function toAbsolutePaths(cache, workspaceRoot) {
|
|
|
661
751
|
raw: {
|
|
662
752
|
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
663
753
|
},
|
|
664
|
-
|
|
754
|
+
extendedConfigFiles: data.extendedConfigFiles,
|
|
665
755
|
},
|
|
666
756
|
extendedFilesHash,
|
|
667
757
|
hash,
|
|
@@ -678,8 +768,10 @@ function toAbsolutePaths(cache, workspaceRoot) {
|
|
|
678
768
|
if (data.options.tsBuildInfoFile) {
|
|
679
769
|
updatedCache[key].data.options.tsBuildInfoFile = (0, node_path_1.join)(workspaceRoot, data.options.tsBuildInfoFile);
|
|
680
770
|
}
|
|
681
|
-
if (data.
|
|
682
|
-
updatedCache[key].data.
|
|
771
|
+
if (data.extendedConfigFiles.length) {
|
|
772
|
+
updatedCache[key].data.extendedConfigFiles.forEach((file) => {
|
|
773
|
+
file.filePath = (0, node_path_1.join)(workspaceRoot, file.filePath);
|
|
774
|
+
});
|
|
683
775
|
}
|
|
684
776
|
if (data.projectReferences) {
|
|
685
777
|
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({ ...ref, path: (0, node_path_1.join)(workspaceRoot, ref.path) }));
|
|
@@ -696,7 +788,7 @@ function toRelativePaths(cache, workspaceRoot) {
|
|
|
696
788
|
raw: {
|
|
697
789
|
nx: { addTypecheckTarget: data.raw?.['nx']?.addTypecheckTarget },
|
|
698
790
|
},
|
|
699
|
-
|
|
791
|
+
extendedConfigFiles: data.extendedConfigFiles,
|
|
700
792
|
},
|
|
701
793
|
extendedFilesHash,
|
|
702
794
|
hash,
|
|
@@ -713,8 +805,10 @@ function toRelativePaths(cache, workspaceRoot) {
|
|
|
713
805
|
if (data.options.tsBuildInfoFile) {
|
|
714
806
|
updatedCache[key].data.options.tsBuildInfoFile = posixRelative(workspaceRoot, data.options.tsBuildInfoFile);
|
|
715
807
|
}
|
|
716
|
-
if (data.
|
|
717
|
-
updatedCache[key].data.
|
|
808
|
+
if (data.extendedConfigFiles.length) {
|
|
809
|
+
updatedCache[key].data.extendedConfigFiles.forEach((file) => {
|
|
810
|
+
file.filePath = posixRelative(workspaceRoot, file.filePath);
|
|
811
|
+
});
|
|
718
812
|
}
|
|
719
813
|
if (data.projectReferences) {
|
|
720
814
|
updatedCache[key].data.projectReferences = data.projectReferences.map((ref) => ({
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type TargetConfiguration } from '@nx/devkit';
|
|
2
2
|
import { type PackageManagerCommands } from 'nx/src/utils/package-manager';
|
|
3
3
|
import { type ParsedCommandLine } from 'typescript';
|
|
4
|
+
export type ExtendedConfigFile = {
|
|
5
|
+
filePath: string;
|
|
6
|
+
externalPackage?: string;
|
|
7
|
+
};
|
|
4
8
|
export type ParsedTsconfigData = Pick<ParsedCommandLine, 'options' | 'projectReferences' | 'raw'> & {
|
|
5
|
-
|
|
6
|
-
filePath: string;
|
|
7
|
-
externalPackage?: string;
|
|
8
|
-
} | null;
|
|
9
|
+
extendedConfigFiles: ExtendedConfigFile[];
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function updateLockFile(cwd: string, { dryRun, verbose, useLegacyVersioning, options, }: {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
verbose?: boolean;
|
|
4
|
+
useLegacyVersioning?: boolean;
|
|
5
|
+
options?: {
|
|
6
|
+
skipLockFileUpdate?: boolean;
|
|
7
|
+
installArgs?: string;
|
|
8
|
+
installIgnoreScripts?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}): Promise<string[]>;
|
|
@@ -7,8 +7,8 @@ const client_1 = require("nx/src/daemon/client/client");
|
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
8
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
9
9
|
const semver_1 = require("semver");
|
|
10
|
-
async function updateLockFile(cwd, { dryRun, verbose,
|
|
11
|
-
if (
|
|
10
|
+
async function updateLockFile(cwd, { dryRun, verbose, useLegacyVersioning, options, }) {
|
|
11
|
+
if (options?.skipLockFileUpdate) {
|
|
12
12
|
if (verbose) {
|
|
13
13
|
console.log('\nSkipped lock file update because skipLockFileUpdate was set.');
|
|
14
14
|
}
|
|
@@ -36,10 +36,10 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
36
36
|
await client_1.daemonClient.stop();
|
|
37
37
|
}
|
|
38
38
|
const packageManagerCommands = (0, devkit_1.getPackageManagerCommand)(packageManager);
|
|
39
|
-
let installArgs =
|
|
39
|
+
let installArgs = options?.installArgs || '';
|
|
40
40
|
devkit_1.output.logSingleLine(`Updating ${packageManager} lock file`);
|
|
41
41
|
let env = {};
|
|
42
|
-
if (
|
|
42
|
+
if (options?.installIgnoreScripts) {
|
|
43
43
|
if (packageManager === 'yarn') {
|
|
44
44
|
env = { YARN_ENABLE_SCRIPTS: 'false' };
|
|
45
45
|
}
|
|
@@ -62,7 +62,7 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
62
62
|
if (dryRun) {
|
|
63
63
|
return [];
|
|
64
64
|
}
|
|
65
|
-
execLockFileUpdate(command, cwd, env);
|
|
65
|
+
execLockFileUpdate(command, cwd, env, useLegacyVersioning);
|
|
66
66
|
if (isDaemonEnabled) {
|
|
67
67
|
try {
|
|
68
68
|
await client_1.daemonClient.startInBackground();
|
|
@@ -79,7 +79,7 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
79
79
|
}
|
|
80
80
|
return [lockFile];
|
|
81
81
|
}
|
|
82
|
-
function execLockFileUpdate(command, cwd, env
|
|
82
|
+
function execLockFileUpdate(command, cwd, env, useLegacyVersioning) {
|
|
83
83
|
try {
|
|
84
84
|
const LARGE_BUFFER = 1024 * 1000000;
|
|
85
85
|
(0, child_process_1.execSync)(command, {
|
|
@@ -93,13 +93,16 @@ function execLockFileUpdate(command, cwd, env = {}) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
catch (e) {
|
|
96
|
+
const configPathStart = useLegacyVersioning
|
|
97
|
+
? 'release.version.generatorOptions'
|
|
98
|
+
: 'release.version.versionActionsOptions';
|
|
96
99
|
devkit_1.output.error({
|
|
97
100
|
title: `Error updating lock file with command '${command}'`,
|
|
98
101
|
bodyLines: [
|
|
99
102
|
`Verify that '${command}' succeeds when run from the workspace root.`,
|
|
100
|
-
`To configure a string of arguments to be passed to this command, set the '
|
|
101
|
-
`To ignore install lifecycle scripts, set '
|
|
102
|
-
`To disable this step entirely, set '
|
|
103
|
+
`To configure a string of arguments to be passed to this command, set the '${configPathStart}.installArgs' property in nx.json.`,
|
|
104
|
+
`To ignore install lifecycle scripts, set '${configPathStart}.installIgnoreScripts' to true in nx.json.`,
|
|
105
|
+
`To disable this step entirely, set '${configPathStart}.skipLockFileUpdate' to true in nx.json.`,
|
|
103
106
|
],
|
|
104
107
|
});
|
|
105
108
|
throw e;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ProjectGraph, Tree } from '@nx/devkit';
|
|
2
|
+
import { AfterAllProjectsVersioned, VersionActions } from 'nx/release';
|
|
3
|
+
import type { NxReleaseVersionV2Configuration } from 'nx/src/config/nx-json';
|
|
4
|
+
export declare const afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
5
|
+
export default class JsVersionActions extends VersionActions {
|
|
6
|
+
validManifestFilenames: string[];
|
|
7
|
+
readCurrentVersionFromSourceManifest(tree: Tree): Promise<{
|
|
8
|
+
currentVersion: string;
|
|
9
|
+
manifestPath: string;
|
|
10
|
+
}>;
|
|
11
|
+
readCurrentVersionFromRegistry(tree: Tree, currentVersionResolverMetadata: NxReleaseVersionV2Configuration['currentVersionResolverMetadata']): Promise<{
|
|
12
|
+
currentVersion: string;
|
|
13
|
+
logText: string;
|
|
14
|
+
}>;
|
|
15
|
+
readCurrentVersionOfDependency(tree: Tree, projectGraph: ProjectGraph, dependencyProjectName: string): Promise<{
|
|
16
|
+
currentVersion: string | null;
|
|
17
|
+
dependencyCollection: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
isLocalDependencyProtocol(versionSpecifier: string): Promise<boolean>;
|
|
20
|
+
updateProjectVersion(tree: Tree, newVersion: string): Promise<string[]>;
|
|
21
|
+
updateProjectDependencies(tree: Tree, projectGraph: ProjectGraph, dependenciesToUpdate: Record<string, string>): Promise<string[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.afterAllProjectsVersioned = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const release_1 = require("nx/release");
|
|
8
|
+
const npm_config_1 = require("../utils/npm-config");
|
|
9
|
+
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
10
|
+
const chalk = require("chalk");
|
|
11
|
+
const afterAllProjectsVersioned = async (cwd, opts) => {
|
|
12
|
+
return {
|
|
13
|
+
changedFiles: await (0, update_lock_file_1.updateLockFile)(cwd, {
|
|
14
|
+
...opts,
|
|
15
|
+
useLegacyVersioning: false,
|
|
16
|
+
}),
|
|
17
|
+
deletedFiles: [],
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
21
|
+
// Cache at the module level to avoid re-detecting the package manager for each instance
|
|
22
|
+
let pm;
|
|
23
|
+
class JsVersionActions extends release_1.VersionActions {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.validManifestFilenames = ['package.json'];
|
|
27
|
+
}
|
|
28
|
+
async readCurrentVersionFromSourceManifest(tree) {
|
|
29
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
30
|
+
try {
|
|
31
|
+
const packageJson = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
32
|
+
return {
|
|
33
|
+
manifestPath: sourcePackageJsonPath,
|
|
34
|
+
currentVersion: packageJson.version,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`Unable to determine the current version for project "${this.projectGraphNode.name}" from ${sourcePackageJsonPath}, please ensure that the "version" field is set within the package.json file`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async readCurrentVersionFromRegistry(tree, currentVersionResolverMetadata) {
|
|
42
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
43
|
+
const packageJson = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
44
|
+
const packageName = packageJson.name;
|
|
45
|
+
const metadata = currentVersionResolverMetadata;
|
|
46
|
+
const registryArg = typeof metadata?.registry === 'string' ? metadata.registry : undefined;
|
|
47
|
+
const tagArg = typeof metadata?.tag === 'string' ? metadata.tag : undefined;
|
|
48
|
+
const warnFn = (message) => {
|
|
49
|
+
console.log(chalk.keyword('orange')(message));
|
|
50
|
+
};
|
|
51
|
+
const { registry, tag, registryConfigKey } = await (0, npm_config_1.parseRegistryOptions)(devkit_1.workspaceRoot, {
|
|
52
|
+
packageRoot: this.projectGraphNode.data.root,
|
|
53
|
+
packageJson,
|
|
54
|
+
}, {
|
|
55
|
+
registry: registryArg,
|
|
56
|
+
tag: tagArg,
|
|
57
|
+
}, warnFn);
|
|
58
|
+
let currentVersion = null;
|
|
59
|
+
try {
|
|
60
|
+
// Must be non-blocking async to allow spinner to render
|
|
61
|
+
currentVersion = await new Promise((resolve, reject) => {
|
|
62
|
+
(0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, {
|
|
63
|
+
windowsHide: false,
|
|
64
|
+
}, (error, stdout, stderr) => {
|
|
65
|
+
if (error) {
|
|
66
|
+
return reject(error);
|
|
67
|
+
}
|
|
68
|
+
if (stderr) {
|
|
69
|
+
return reject(stderr);
|
|
70
|
+
}
|
|
71
|
+
return resolve(stdout.trim());
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
return {
|
|
77
|
+
currentVersion,
|
|
78
|
+
// Make troubleshooting easier by including the registry and tag data in the log text
|
|
79
|
+
logText: `"${registryConfigKey}=${registry}" tag=${tag}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async readCurrentVersionOfDependency(tree, projectGraph, dependencyProjectName) {
|
|
83
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
84
|
+
const json = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
85
|
+
// Resolve the package name from the project graph metadata, as it may not match the project name
|
|
86
|
+
const dependencyPackageName = projectGraph.nodes[dependencyProjectName].data.metadata?.js?.packageName;
|
|
87
|
+
const dependencyTypes = [
|
|
88
|
+
'dependencies',
|
|
89
|
+
'devDependencies',
|
|
90
|
+
'peerDependencies',
|
|
91
|
+
'optionalDependencies',
|
|
92
|
+
];
|
|
93
|
+
let currentVersion = null;
|
|
94
|
+
let dependencyCollection = null;
|
|
95
|
+
for (const depType of dependencyTypes) {
|
|
96
|
+
if (json[depType] && json[depType][dependencyPackageName]) {
|
|
97
|
+
currentVersion = json[depType][dependencyPackageName];
|
|
98
|
+
dependencyCollection = depType;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
currentVersion,
|
|
104
|
+
dependencyCollection,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// NOTE: The TODOs were carried over from the original implementation, they are not yet implemented
|
|
108
|
+
async isLocalDependencyProtocol(versionSpecifier) {
|
|
109
|
+
const localPackageProtocols = [
|
|
110
|
+
'file:', // all package managers
|
|
111
|
+
'workspace:', // not npm
|
|
112
|
+
// TODO: Support portal protocol at the project graph level before enabling here
|
|
113
|
+
// 'portal:', // modern yarn only
|
|
114
|
+
];
|
|
115
|
+
// Not using a supported local protocol
|
|
116
|
+
if (!localPackageProtocols.some((protocol) => versionSpecifier.startsWith(protocol))) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
// Supported by all package managers
|
|
120
|
+
if (versionSpecifier.startsWith('file:')) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
// Determine specific package manager in use
|
|
124
|
+
if (!pm) {
|
|
125
|
+
pm = (0, devkit_1.detectPackageManager)();
|
|
126
|
+
// pmVersion = getPackageManagerVersion(pm);
|
|
127
|
+
}
|
|
128
|
+
if (pm === 'npm' && versionSpecifier.startsWith('workspace:')) {
|
|
129
|
+
throw new Error(`The "workspace:" protocol is not yet supported by npm (https://github.com/npm/rfcs/issues/765). Please ensure you have a valid setup according to your package manager before attempting to release packages.`);
|
|
130
|
+
}
|
|
131
|
+
// TODO: Support portal protocol at the project graph level before enabling here
|
|
132
|
+
// if (
|
|
133
|
+
// version.startsWith('portal:') &&
|
|
134
|
+
// (pm !== 'yarn' || lt(pmVersion, '2.0.0'))
|
|
135
|
+
// ) {
|
|
136
|
+
// throw new Error(
|
|
137
|
+
// `The "portal:" protocol is only supported by yarn@2.0.0 and above. Please ensure you have a valid setup according to your package manager before attempting to release packages.`
|
|
138
|
+
// );
|
|
139
|
+
// }
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
async updateProjectVersion(tree, newVersion) {
|
|
143
|
+
const logMessages = [];
|
|
144
|
+
for (const manifestPath of this.manifestsToUpdate) {
|
|
145
|
+
(0, devkit_1.updateJson)(tree, manifestPath, (json) => {
|
|
146
|
+
json.version = newVersion;
|
|
147
|
+
return json;
|
|
148
|
+
});
|
|
149
|
+
logMessages.push(`✍️ New version ${newVersion} written to manifest: ${manifestPath}`);
|
|
150
|
+
}
|
|
151
|
+
return logMessages;
|
|
152
|
+
}
|
|
153
|
+
async updateProjectDependencies(tree, projectGraph, dependenciesToUpdate) {
|
|
154
|
+
const numDependenciesToUpdate = Object.keys(dependenciesToUpdate).length;
|
|
155
|
+
const depText = numDependenciesToUpdate === 1 ? 'dependency' : 'dependencies';
|
|
156
|
+
if (numDependenciesToUpdate === 0) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const logMessages = [];
|
|
160
|
+
for (const manifestPath of this.manifestsToUpdate) {
|
|
161
|
+
(0, devkit_1.updateJson)(tree, manifestPath, (json) => {
|
|
162
|
+
const dependencyTypes = [
|
|
163
|
+
'dependencies',
|
|
164
|
+
'devDependencies',
|
|
165
|
+
'peerDependencies',
|
|
166
|
+
'optionalDependencies',
|
|
167
|
+
];
|
|
168
|
+
for (const depType of dependencyTypes) {
|
|
169
|
+
if (json[depType]) {
|
|
170
|
+
for (const [dep, version] of Object.entries(dependenciesToUpdate)) {
|
|
171
|
+
// Resolve the package name from the project graph metadata, as it may not match the project name
|
|
172
|
+
const packageName = projectGraph.nodes[dep].data.metadata?.js?.packageName;
|
|
173
|
+
if (!packageName) {
|
|
174
|
+
throw new Error(`Unable to determine the package name for project "${dep}" from the project graph metadata, please ensure that the "@nx/js" plugin is installed and the project graph has been built. If the issue persists, please report this issue on https://github.com/nrwl/nx/issues`);
|
|
175
|
+
}
|
|
176
|
+
if (json[depType][packageName]) {
|
|
177
|
+
json[depType][packageName] = version;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return json;
|
|
183
|
+
});
|
|
184
|
+
logMessages.push(`✍️ Updated ${numDependenciesToUpdate} ${depText} in manifest: ${manifestPath}`);
|
|
185
|
+
}
|
|
186
|
+
return logMessages;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.default = JsVersionActions;
|
|
@@ -33,8 +33,6 @@ export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph,
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function computeCompilerOptionsPaths(tsConfig: string | ts.ParsedCommandLine, dependencies: DependentBuildableProjectNode[]): ts.MapLike<string[]>;
|
|
35
35
|
export declare function createTmpTsConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, dependencies: DependentBuildableProjectNode[], useWorkspaceAsBaseUrl?: boolean): string;
|
|
36
|
-
export declare function checkDependentProjectsHaveBeenBuilt(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): boolean;
|
|
37
|
-
export declare function findMissingBuildDependencies(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): DependentBuildableProjectNode[];
|
|
38
36
|
export declare function updatePaths(dependencies: DependentBuildableProjectNode[], paths: Record<string, string[]>): void;
|
|
39
37
|
/**
|
|
40
38
|
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
@@ -5,8 +5,6 @@ exports.calculateProjectDependencies = calculateProjectDependencies;
|
|
|
5
5
|
exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
|
|
6
6
|
exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
|
|
7
7
|
exports.createTmpTsConfig = createTmpTsConfig;
|
|
8
|
-
exports.checkDependentProjectsHaveBeenBuilt = checkDependentProjectsHaveBeenBuilt;
|
|
9
|
-
exports.findMissingBuildDependencies = findMissingBuildDependencies;
|
|
10
8
|
exports.updatePaths = updatePaths;
|
|
11
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
12
10
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -116,7 +114,7 @@ function readTsConfigWithRemappedPaths(originalTsconfigPath, generatedTsconfigPa
|
|
|
116
114
|
const normalizedTsConfig = (0, path_1.resolve)(workspaceRoot, originalTsconfigPath);
|
|
117
115
|
const normalizedGeneratedTsConfigDir = (0, path_1.resolve)(workspaceRoot, (0, path_1.dirname)(generatedTsconfigPath));
|
|
118
116
|
generatedTsConfig.extends = (0, path_1.relative)(normalizedGeneratedTsConfigDir, normalizedTsConfig);
|
|
119
|
-
generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths(
|
|
117
|
+
generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths(normalizedTsConfig, dependencies);
|
|
120
118
|
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
121
119
|
output_1.output.log({
|
|
122
120
|
title: 'TypeScript path mappings have been rewritten.',
|
|
@@ -252,36 +250,6 @@ function cleanupTmpTsConfigFile(tmpTsConfigPath) {
|
|
|
252
250
|
}
|
|
253
251
|
catch (e) { }
|
|
254
252
|
}
|
|
255
|
-
function checkDependentProjectsHaveBeenBuilt(root, projectName, targetName, projectDependencies) {
|
|
256
|
-
const missing = findMissingBuildDependencies(root, projectName, targetName, projectDependencies);
|
|
257
|
-
if (missing.length > 0) {
|
|
258
|
-
console.error((0, devkit_1.stripIndents) `
|
|
259
|
-
It looks like all of ${projectName}'s dependencies have not been built yet:
|
|
260
|
-
${missing.map((x) => ` - ${x.node.name}`).join('\n')}
|
|
261
|
-
|
|
262
|
-
You might be missing a "targetDefaults" configuration in your root nx.json (https://nx.dev/reference/project-configuration#target-defaults),
|
|
263
|
-
or "dependsOn" configured in ${projectName}'s project.json (https://nx.dev/reference/project-configuration#dependson)
|
|
264
|
-
`);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function findMissingBuildDependencies(root, projectName, targetName, projectDependencies) {
|
|
272
|
-
const depLibsToBuildFirst = [];
|
|
273
|
-
// verify whether all dependent libraries have been built
|
|
274
|
-
projectDependencies.forEach((dep) => {
|
|
275
|
-
if (dep.node.type !== 'lib') {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
const paths = dep.outputs.map((p) => (0, path_1.join)(root, p));
|
|
279
|
-
if (!paths.some(fileutils_1.directoryExists)) {
|
|
280
|
-
depLibsToBuildFirst.push(dep);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
return depLibsToBuildFirst;
|
|
284
|
-
}
|
|
285
253
|
function updatePaths(dependencies, paths) {
|
|
286
254
|
const pathsKeys = Object.keys(paths);
|
|
287
255
|
// For each registered dependency
|
|
@@ -291,7 +259,7 @@ function updatePaths(dependencies, paths) {
|
|
|
291
259
|
// If there are outputs
|
|
292
260
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
293
261
|
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
294
|
-
paths[dep.name] = dep.outputs;
|
|
262
|
+
paths[dep.name] = dep.outputs.map((output) => output.replace(/(\*|\/[^\/]*\*).*$/, ''));
|
|
295
263
|
// check for secondary entrypoints
|
|
296
264
|
// For each registered path
|
|
297
265
|
for (const path of pathsKeys) {
|
|
@@ -158,7 +158,7 @@ async function addProjectToTsSolutionWorkspace(tree, projectDir) {
|
|
|
158
158
|
let pattern = projectDir;
|
|
159
159
|
if (baseDir !== '.') {
|
|
160
160
|
const patterns = (0, package_manager_workspaces_1.getPackageManagerWorkspacesPatterns)(tree);
|
|
161
|
-
const projectsBefore = await (0, devkit_1.globAsync)(tree, patterns);
|
|
161
|
+
const projectsBefore = patterns.length > 0 ? await (0, devkit_1.globAsync)(tree, patterns) : [];
|
|
162
162
|
patterns.push(`${baseDir}/*/package.json`);
|
|
163
163
|
const projectsAfter = await (0, devkit_1.globAsync)(tree, patterns);
|
|
164
164
|
if (projectsBefore.length + 1 === projectsAfter.length) {
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
2
|
export declare const esbuildVersion = "^0.19.2";
|
|
3
3
|
export declare const prettierVersion = "^2.6.2";
|
|
4
|
-
export declare const swcCliVersion = "~0.
|
|
4
|
+
export declare const swcCliVersion = "~0.6.0";
|
|
5
5
|
export declare const swcCoreVersion = "~1.5.7";
|
|
6
6
|
export declare const swcHelpersVersion = "~0.5.11";
|
|
7
7
|
export declare const swcNodeVersion = "~1.9.1";
|
package/src/utils/versions.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.supportedTypescriptVersions = exports.typescriptVersion = exports.verdac
|
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
5
|
exports.esbuildVersion = '^0.19.2';
|
|
6
6
|
exports.prettierVersion = '^2.6.2';
|
|
7
|
-
exports.swcCliVersion = '~0.
|
|
7
|
+
exports.swcCliVersion = '~0.6.0';
|
|
8
8
|
exports.swcCoreVersion = '~1.5.7';
|
|
9
9
|
exports.swcHelpersVersion = '~0.5.11';
|
|
10
10
|
exports.swcNodeVersion = '~1.9.1';
|