@nx/js 18.1.0 → 18.1.2
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/package.json +4 -4
- package/src/generators/library/library.js +131 -15
- package/src/generators/library/schema.json +1 -1
- package/src/generators/release-version/release-version.js +43 -25
- package/src/generators/release-version/schema.json +12 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +6 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +1 -0
- package/src/utils/add-local-registry-scripts.js +26 -6
- package/src/utils/minimal-publish-script.d.ts +0 -2
- package/src/utils/minimal-publish-script.js +0 -74
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "18.1.
|
|
3
|
+
"version": "18.1.2",
|
|
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": {
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"semver": "^7.5.3",
|
|
58
58
|
"source-map-support": "0.5.19",
|
|
59
59
|
"tslib": "^2.3.0",
|
|
60
|
-
"@nx/devkit": "18.1.
|
|
61
|
-
"@nx/workspace": "18.1.
|
|
62
|
-
"@nrwl/js": "18.1.
|
|
60
|
+
"@nx/devkit": "18.1.2",
|
|
61
|
+
"@nx/workspace": "18.1.2",
|
|
62
|
+
"@nrwl/js": "18.1.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"verdaccio": "^5.0.4"
|
|
@@ -3,17 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addLint = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
|
-
const
|
|
6
|
+
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
8
|
+
const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
7
9
|
const path_1 = require("path");
|
|
8
|
-
const minimal_publish_script_1 = require("../../utils/minimal-publish-script");
|
|
9
10
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
10
11
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
12
|
+
const create_ts_config_1 = require("../../utils/typescript/create-ts-config");
|
|
13
|
+
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
11
14
|
const versions_1 = require("../../utils/versions");
|
|
12
15
|
const init_1 = require("../init/init");
|
|
13
16
|
const generator_1 = require("../setup-verdaccio/generator");
|
|
14
|
-
const
|
|
15
|
-
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
16
|
-
const add_build_target_defaults_1 = require("@nx/devkit/src/generators/add-build-target-defaults");
|
|
17
|
+
const defaultOutputDirectory = 'dist';
|
|
17
18
|
async function libraryGenerator(tree, schema) {
|
|
18
19
|
return await libraryGeneratorInternal(tree, {
|
|
19
20
|
addPlugin: false,
|
|
@@ -33,7 +34,7 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
33
34
|
}));
|
|
34
35
|
const options = await normalizeOptions(tree, schema);
|
|
35
36
|
createFiles(tree, options);
|
|
36
|
-
addProject(tree, options);
|
|
37
|
+
await addProject(tree, options);
|
|
37
38
|
if (!options.skipPackageJson) {
|
|
38
39
|
tasks.push(addProjectDependencies(tree, options));
|
|
39
40
|
}
|
|
@@ -101,13 +102,18 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
101
102
|
if (!options.skipFormat) {
|
|
102
103
|
await (0, devkit_1.formatFiles)(tree);
|
|
103
104
|
}
|
|
105
|
+
if (options.publishable) {
|
|
106
|
+
tasks.push(() => {
|
|
107
|
+
logNxReleaseDocsInfo();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
104
110
|
tasks.push(() => {
|
|
105
111
|
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
106
112
|
});
|
|
107
113
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
108
114
|
}
|
|
109
115
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
110
|
-
function addProject(tree, options) {
|
|
116
|
+
async function addProject(tree, options) {
|
|
111
117
|
const projectConfiguration = {
|
|
112
118
|
root: options.projectRoot,
|
|
113
119
|
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
@@ -150,11 +156,24 @@ function addProject(tree, options) {
|
|
|
150
156
|
projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
|
|
151
157
|
}
|
|
152
158
|
if (options.publishable) {
|
|
153
|
-
const
|
|
154
|
-
projectConfiguration.targets
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
const packageRoot = (0, path_1.join)(defaultOutputDirectory, '{projectRoot}');
|
|
160
|
+
projectConfiguration.targets ??= {};
|
|
161
|
+
projectConfiguration.targets['nx-release-publish'] = {
|
|
162
|
+
options: {
|
|
163
|
+
packageRoot,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
projectConfiguration.release = {
|
|
167
|
+
version: {
|
|
168
|
+
generatorOptions: {
|
|
169
|
+
packageRoot,
|
|
170
|
+
// using git tags to determine the current version is required here because
|
|
171
|
+
// the version in the package root is overridden with every build
|
|
172
|
+
currentVersionResolver: 'git-tag',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
157
175
|
};
|
|
176
|
+
await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
|
|
158
177
|
}
|
|
159
178
|
}
|
|
160
179
|
if (options.config === 'workspace' || options.config === 'project') {
|
|
@@ -339,6 +358,9 @@ function createFiles(tree, options) {
|
|
|
339
358
|
if (json.private && (options.publishable || options.rootProject)) {
|
|
340
359
|
delete json.private;
|
|
341
360
|
}
|
|
361
|
+
if (!options.publishable && !options.rootProject) {
|
|
362
|
+
json.private = true;
|
|
363
|
+
}
|
|
342
364
|
return {
|
|
343
365
|
...json,
|
|
344
366
|
dependencies: {
|
|
@@ -350,12 +372,16 @@ function createFiles(tree, options) {
|
|
|
350
372
|
});
|
|
351
373
|
}
|
|
352
374
|
else {
|
|
353
|
-
|
|
375
|
+
const packageJson = {
|
|
354
376
|
name: options.importPath,
|
|
355
377
|
version: '0.0.1',
|
|
356
378
|
dependencies: determineDependencies(options),
|
|
357
379
|
...determineEntryFields(options),
|
|
358
|
-
}
|
|
380
|
+
};
|
|
381
|
+
if (!options.publishable && !options.rootProject) {
|
|
382
|
+
packageJson.private = true;
|
|
383
|
+
}
|
|
384
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
359
385
|
}
|
|
360
386
|
if (options.config === 'npm-scripts') {
|
|
361
387
|
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
@@ -448,7 +474,7 @@ async function normalizeOptions(tree, options) {
|
|
|
448
474
|
options.bundler = 'tsc';
|
|
449
475
|
}
|
|
450
476
|
}
|
|
451
|
-
// This is to preserve old
|
|
477
|
+
// This is to preserve old behavior, buildable: false
|
|
452
478
|
if (options.publishable === false && options.buildable === false) {
|
|
453
479
|
options.bundler = 'none';
|
|
454
480
|
}
|
|
@@ -540,7 +566,7 @@ function getBuildExecutor(bundler) {
|
|
|
540
566
|
}
|
|
541
567
|
}
|
|
542
568
|
function getOutputPath(options) {
|
|
543
|
-
const parts = [
|
|
569
|
+
const parts = [defaultOutputDirectory];
|
|
544
570
|
if (options.projectRoot === '.') {
|
|
545
571
|
parts.push(options.name);
|
|
546
572
|
}
|
|
@@ -632,4 +658,94 @@ function determineEntryFields(options) {
|
|
|
632
658
|
}
|
|
633
659
|
}
|
|
634
660
|
}
|
|
661
|
+
function projectsConfigMatchesProject(projectsConfig, project) {
|
|
662
|
+
if (!projectsConfig) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
if (typeof projectsConfig === 'string') {
|
|
666
|
+
projectsConfig = [projectsConfig];
|
|
667
|
+
}
|
|
668
|
+
const graph = {
|
|
669
|
+
[project.name]: project,
|
|
670
|
+
};
|
|
671
|
+
const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
|
|
672
|
+
return matchingProjects.includes(project.name);
|
|
673
|
+
}
|
|
674
|
+
async function addProjectToNxReleaseConfig(tree, options, projectConfiguration) {
|
|
675
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
676
|
+
const addPreVersionCommand = () => {
|
|
677
|
+
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
678
|
+
nxJson.release = {
|
|
679
|
+
...nxJson.release,
|
|
680
|
+
version: {
|
|
681
|
+
preVersionCommand: `${pmc.dlx} nx run-many -t build`,
|
|
682
|
+
...nxJson.release?.version,
|
|
683
|
+
},
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
|
|
687
|
+
// skip adding any projects configuration since the new project should be
|
|
688
|
+
// automatically included by nx release's default project detection logic
|
|
689
|
+
addPreVersionCommand();
|
|
690
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const project = {
|
|
694
|
+
name: options.name,
|
|
695
|
+
type: 'lib',
|
|
696
|
+
data: {
|
|
697
|
+
root: projectConfiguration.root,
|
|
698
|
+
tags: projectConfiguration.tags,
|
|
699
|
+
},
|
|
700
|
+
};
|
|
701
|
+
if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
|
|
702
|
+
devkit_1.output.log({
|
|
703
|
+
title: `Project already included in existing release configuration`,
|
|
704
|
+
});
|
|
705
|
+
addPreVersionCommand();
|
|
706
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (Array.isArray(nxJson.release.projects)) {
|
|
710
|
+
nxJson.release.projects.push(options.name);
|
|
711
|
+
addPreVersionCommand();
|
|
712
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
713
|
+
devkit_1.output.log({
|
|
714
|
+
title: `Added project to existing release configuration`,
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
if (nxJson.release.groups) {
|
|
718
|
+
const allGroups = Object.entries(nxJson.release.groups);
|
|
719
|
+
for (const [name, group] of allGroups) {
|
|
720
|
+
if (projectsConfigMatchesProject(group.projects, project)) {
|
|
721
|
+
addPreVersionCommand();
|
|
722
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
723
|
+
return `Project already included in existing release configuration for group ${name}`;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
devkit_1.output.warn({
|
|
727
|
+
title: `Could not find a release group that includes ${options.name}`,
|
|
728
|
+
bodyLines: [
|
|
729
|
+
`Ensure that ${options.name} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
|
|
730
|
+
],
|
|
731
|
+
});
|
|
732
|
+
addPreVersionCommand();
|
|
733
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (typeof nxJson.release.projects === 'string') {
|
|
737
|
+
nxJson.release.projects = [nxJson.release.projects, options.name];
|
|
738
|
+
addPreVersionCommand();
|
|
739
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
740
|
+
devkit_1.output.log({
|
|
741
|
+
title: `Added project to existing release configuration`,
|
|
742
|
+
});
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function logNxReleaseDocsInfo() {
|
|
747
|
+
devkit_1.output.log({
|
|
748
|
+
title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
|
|
749
|
+
});
|
|
750
|
+
}
|
|
635
751
|
exports.default = libraryGenerator;
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"publishable": {
|
|
90
90
|
"type": "boolean",
|
|
91
91
|
"default": false,
|
|
92
|
-
"description": "
|
|
92
|
+
"description": "Configure the library ready for use with `nx release` (https://nx.dev/core-features/manage-releases).",
|
|
93
93
|
"x-priority": "important"
|
|
94
94
|
},
|
|
95
95
|
"importPath": {
|
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.releaseVersionGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const chalk = require("chalk");
|
|
6
|
-
const
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
7
8
|
const config_1 = require("nx/src/command-line/release/config/config");
|
|
8
9
|
const git_1 = require("nx/src/command-line/release/utils/git");
|
|
9
10
|
const resolve_semver_specifier_1 = require("nx/src/command-line/release/utils/resolve-semver-specifier");
|
|
@@ -11,7 +12,6 @@ const semver_1 = require("nx/src/command-line/release/utils/semver");
|
|
|
11
12
|
const version_1 = require("nx/src/command-line/release/version");
|
|
12
13
|
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
13
14
|
const ora = require("ora");
|
|
14
|
-
const path_1 = require("path");
|
|
15
15
|
const semver_2 = require("semver");
|
|
16
16
|
const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
|
|
17
17
|
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
@@ -39,36 +39,30 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
|
|
|
39
39
|
options.fallbackCurrentVersionResolver = 'disk';
|
|
40
40
|
}
|
|
41
41
|
const projects = options.projects;
|
|
42
|
-
const createResolvePackageRoot = (customPackageRoot) => (projectNode) => {
|
|
43
|
-
// Default to the project root if no custom packageRoot
|
|
44
|
-
if (!customPackageRoot) {
|
|
45
|
-
return projectNode.data.root;
|
|
46
|
-
}
|
|
47
|
-
return (0, utils_1.interpolate)(customPackageRoot, {
|
|
48
|
-
workspaceRoot: '',
|
|
49
|
-
projectRoot: projectNode.data.root,
|
|
50
|
-
projectName: projectNode.name,
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
42
|
const resolvePackageRoot = createResolvePackageRoot(options.packageRoot);
|
|
54
43
|
// Resolve any custom package roots for each project upfront as they will need to be reused during dependency resolution
|
|
55
44
|
const projectNameToPackageRootMap = new Map();
|
|
56
45
|
for (const project of projects) {
|
|
57
46
|
projectNameToPackageRootMap.set(project.name, resolvePackageRoot(project));
|
|
58
47
|
}
|
|
59
|
-
let currentVersion;
|
|
48
|
+
let currentVersion = undefined;
|
|
60
49
|
let currentVersionResolvedFromFallback = false;
|
|
61
50
|
// only used for options.currentVersionResolver === 'git-tag', but
|
|
62
51
|
// must be declared here in order to reuse it for additional projects
|
|
63
|
-
let latestMatchingGitTag;
|
|
52
|
+
let latestMatchingGitTag = undefined;
|
|
64
53
|
// if specifier is undefined, then we haven't resolved it yet
|
|
65
54
|
// if specifier is null, then it has been resolved and no changes are necessary
|
|
66
|
-
let specifier = options.specifier
|
|
55
|
+
let specifier = options.specifier
|
|
56
|
+
? options.specifier
|
|
57
|
+
: undefined;
|
|
67
58
|
for (const project of projects) {
|
|
68
59
|
const projectName = project.name;
|
|
69
60
|
const packageRoot = projectNameToPackageRootMap.get(projectName);
|
|
61
|
+
if (!packageRoot) {
|
|
62
|
+
throw new Error(`The project "${projectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
|
|
63
|
+
}
|
|
70
64
|
const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
|
|
71
|
-
const workspaceRelativePackageJsonPath = (0,
|
|
65
|
+
const workspaceRelativePackageJsonPath = (0, node_path_1.relative)(devkit_1.workspaceRoot, packageJsonPath);
|
|
72
66
|
const color = getColor(projectName);
|
|
73
67
|
const log = (msg) => {
|
|
74
68
|
console.log(color.instance.bold(projectName) + ' ' + msg);
|
|
@@ -102,7 +96,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
102
96
|
try {
|
|
103
97
|
// Must be non-blocking async to allow spinner to render
|
|
104
98
|
currentVersion = await new Promise((resolve, reject) => {
|
|
105
|
-
(0,
|
|
99
|
+
(0, node_child_process_1.exec)(`npm view ${packageName} version --registry=${registry} --tag=${tag}`, (error, stdout, stderr) => {
|
|
106
100
|
if (error) {
|
|
107
101
|
return reject(error);
|
|
108
102
|
}
|
|
@@ -169,7 +163,9 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
169
163
|
log(`📄 Using the current version ${currentVersion} already resolved from disk fallback.`);
|
|
170
164
|
}
|
|
171
165
|
else {
|
|
172
|
-
log(
|
|
166
|
+
log(
|
|
167
|
+
// In this code path we know that latestMatchingGitTag is defined, because we are not relying on the fallbackCurrentVersionResolver, so we can safely use the non-null assertion operator
|
|
168
|
+
`📄 Using the current version ${currentVersion} already resolved from git tag "${latestMatchingGitTag.tag}".`);
|
|
173
169
|
}
|
|
174
170
|
}
|
|
175
171
|
break;
|
|
@@ -195,7 +191,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
195
191
|
!options.specifier)) {
|
|
196
192
|
const specifierSource = options.specifierSource;
|
|
197
193
|
switch (specifierSource) {
|
|
198
|
-
case 'conventional-commits':
|
|
194
|
+
case 'conventional-commits': {
|
|
199
195
|
if (options.currentVersionResolver !== 'git-tag') {
|
|
200
196
|
throw new Error(`Invalid currentVersionResolver "${options.currentVersionResolver}" provided for release group "${options.releaseGroup.name}". Must be "git-tag" when "specifierSource" is "conventional-commits"`);
|
|
201
197
|
}
|
|
@@ -213,7 +209,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
213
209
|
// This should never happen since the checks above should catch if the current version couldn't be resolved
|
|
214
210
|
throw new Error(`Unable to determine previous version ref for the projects ${affectedProjects.join(', ')}. This is likely a bug in Nx.`);
|
|
215
211
|
}
|
|
216
|
-
specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromConventionalCommits)(previousVersionRef, options.projectGraph, affectedProjects);
|
|
212
|
+
specifier = await (0, resolve_semver_specifier_1.resolveSemverSpecifierFromConventionalCommits)(previousVersionRef, options.projectGraph, affectedProjects, options.conventionalCommitsConfig);
|
|
217
213
|
if (!specifier) {
|
|
218
214
|
log(`🚫 No changes were detected using git history and the conventional commits standard.`);
|
|
219
215
|
break;
|
|
@@ -222,7 +218,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
222
218
|
//
|
|
223
219
|
// Always assume that if the current version is a prerelease, then the next version should be a prerelease.
|
|
224
220
|
// Users must manually graduate from a prerelease to a release by providing an explicit specifier.
|
|
225
|
-
if ((0, semver_2.prerelease)(currentVersion)) {
|
|
221
|
+
if ((0, semver_2.prerelease)(currentVersion ?? '')) {
|
|
226
222
|
specifier = 'prerelease';
|
|
227
223
|
log(`📄 Resolved the specifier as "${specifier}" since the current version is a prerelease.`);
|
|
228
224
|
}
|
|
@@ -230,6 +226,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
230
226
|
log(`📄 Resolved the specifier as "${specifier}" using git history and the conventional commits standard.`);
|
|
231
227
|
}
|
|
232
228
|
break;
|
|
229
|
+
}
|
|
233
230
|
case 'prompt': {
|
|
234
231
|
// Only add the release group name to the log if it is one set by the user, otherwise it is useless noise
|
|
235
232
|
const maybeLogReleaseGroup = (log) => {
|
|
@@ -259,9 +256,13 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
259
256
|
.filter((localPackageDependency) => {
|
|
260
257
|
return localPackageDependency.target === project.name;
|
|
261
258
|
});
|
|
259
|
+
if (!currentVersion) {
|
|
260
|
+
throw new Error(`The current version for project "${project.name}" could not be resolved. Please report this on https://github.com/nrwl/nx`);
|
|
261
|
+
}
|
|
262
262
|
versionData[projectName] = {
|
|
263
263
|
currentVersion,
|
|
264
264
|
dependentProjects,
|
|
265
|
+
// @ts-ignore: The types will be updated in a future version of Nx
|
|
265
266
|
newVersion: null, // will stay as null in the final result in the case that no changes are detected
|
|
266
267
|
};
|
|
267
268
|
if (!specifier) {
|
|
@@ -281,7 +282,11 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
281
282
|
: 'package which depends'} on ${project.name}`);
|
|
282
283
|
}
|
|
283
284
|
for (const dependentProject of dependentProjects) {
|
|
284
|
-
|
|
285
|
+
const dependentPackageRoot = projectNameToPackageRootMap.get(dependentProject.source);
|
|
286
|
+
if (!dependentPackageRoot) {
|
|
287
|
+
throw new Error(`The dependent project "${dependentProject.source}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
|
|
288
|
+
}
|
|
289
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(dependentPackageRoot, 'package.json'), (json) => {
|
|
285
290
|
// Auto (i.e.infer existing) by default
|
|
286
291
|
let versionPrefix = options.versionPrefix ?? 'auto';
|
|
287
292
|
// For auto, we infer the prefix based on the current version of the dependent
|
|
@@ -304,7 +309,7 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
304
309
|
}
|
|
305
310
|
}
|
|
306
311
|
/**
|
|
307
|
-
* Ensure that formatting is applied so that version bump diffs are as
|
|
312
|
+
* Ensure that formatting is applied so that version bump diffs are as minimal as possible
|
|
308
313
|
* within the context of the user's workspace.
|
|
309
314
|
*/
|
|
310
315
|
await (0, devkit_1.formatFiles)(tree);
|
|
@@ -336,6 +341,19 @@ To fix this you will either need to add a package.json file at that location, or
|
|
|
336
341
|
}
|
|
337
342
|
exports.releaseVersionGenerator = releaseVersionGenerator;
|
|
338
343
|
exports.default = releaseVersionGenerator;
|
|
344
|
+
function createResolvePackageRoot(customPackageRoot) {
|
|
345
|
+
return (projectNode) => {
|
|
346
|
+
// Default to the project root if no custom packageRoot
|
|
347
|
+
if (!customPackageRoot) {
|
|
348
|
+
return projectNode.data.root;
|
|
349
|
+
}
|
|
350
|
+
return (0, utils_1.interpolate)(customPackageRoot, {
|
|
351
|
+
workspaceRoot: '',
|
|
352
|
+
projectRoot: projectNode.data.root,
|
|
353
|
+
projectName: projectNode.name,
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
}
|
|
339
357
|
const colors = [
|
|
340
358
|
{ instance: chalk.green, spinnerColor: 'green' },
|
|
341
359
|
{ instance: chalk.greenBright, spinnerColor: 'green' },
|
|
@@ -359,7 +377,7 @@ function getColor(projectName) {
|
|
|
359
377
|
async function getNpmRegistry() {
|
|
360
378
|
// Must be non-blocking async to allow spinner to render
|
|
361
379
|
return await new Promise((resolve, reject) => {
|
|
362
|
-
(0,
|
|
380
|
+
(0, node_child_process_1.exec)('npm config get registry', (error, stdout, stderr) => {
|
|
363
381
|
if (error) {
|
|
364
382
|
return reject(error);
|
|
365
383
|
}
|
|
@@ -49,6 +49,18 @@
|
|
|
49
49
|
"type": "object",
|
|
50
50
|
"description": "Additional metadata to pass to the current version resolver.",
|
|
51
51
|
"default": {}
|
|
52
|
+
},
|
|
53
|
+
"skipLockFileUpdate": {
|
|
54
|
+
"type": "boolean",
|
|
55
|
+
"description": "Whether to skip updating the lock file after updating the version."
|
|
56
|
+
},
|
|
57
|
+
"installArgs": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "Additional arguments to pass to the package manager when updating the lock file with an install command."
|
|
60
|
+
},
|
|
61
|
+
"installIgnoreScripts": {
|
|
62
|
+
"type": "boolean",
|
|
63
|
+
"description": "Whether to ignore install lifecycle scripts when updating the lock file with an install command."
|
|
52
64
|
}
|
|
53
65
|
},
|
|
54
66
|
"required": ["projects", "projectGraph", "releaseGroup"]
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ProjectGraph, ProjectGraphDependency, ProjectGraphProjectNode, Tree } from '@nx/devkit';
|
|
2
2
|
interface LocalPackageDependency extends ProjectGraphDependency {
|
|
3
|
+
/**
|
|
4
|
+
* The rawVersionSpec contains the value of the version spec as it was defined in the package.json
|
|
5
|
+
* of the dependent project. This can be useful in cases where the version spec is a range, path or
|
|
6
|
+
* workspace reference, and it needs to be be reverted to that original value as part of the release.
|
|
7
|
+
*/
|
|
8
|
+
rawVersionSpec: string;
|
|
3
9
|
dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
4
10
|
}
|
|
5
11
|
export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, filteredProjects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>, resolvePackageRoot: (projectNode: ProjectGraphProjectNode) => string, includeAll?: boolean): Record<string, LocalPackageDependency[]>;
|
|
@@ -9,6 +9,7 @@ const startLocalRegistryScript = (localRegistryTarget) => `
|
|
|
9
9
|
*/
|
|
10
10
|
import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry';
|
|
11
11
|
import { execFileSync } from 'child_process';
|
|
12
|
+
import { releasePublish, releaseVersion } from 'nx/release';
|
|
12
13
|
|
|
13
14
|
export default async () => {
|
|
14
15
|
// local registry target to run
|
|
@@ -21,12 +22,21 @@ export default async () => {
|
|
|
21
22
|
storage,
|
|
22
23
|
verbose: false,
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
|
|
26
|
+
await releaseVersion({
|
|
27
|
+
specifier: '0.0.0-e2e',
|
|
28
|
+
stageChanges: false,
|
|
29
|
+
gitCommit: false,
|
|
30
|
+
gitTag: false,
|
|
31
|
+
firstRelease: true,
|
|
32
|
+
generatorOptionsOverrides: {
|
|
33
|
+
skipLockFileUpdate: true
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
await releasePublish({
|
|
37
|
+
tag: 'e2e',
|
|
38
|
+
firstRelease: true
|
|
39
|
+
});
|
|
30
40
|
};
|
|
31
41
|
`;
|
|
32
42
|
const stopLocalRegistryScript = `
|
|
@@ -49,6 +59,16 @@ function addLocalRegistryScripts(tree) {
|
|
|
49
59
|
if (!tree.exists(startLocalRegistryPath)) {
|
|
50
60
|
tree.write(startLocalRegistryPath, startLocalRegistryScript(localRegistryTarget));
|
|
51
61
|
}
|
|
62
|
+
else {
|
|
63
|
+
const existingStartLocalRegistryScript = tree
|
|
64
|
+
.read(startLocalRegistryPath)
|
|
65
|
+
.toString();
|
|
66
|
+
if (!existingStartLocalRegistryScript.includes('nx/release')) {
|
|
67
|
+
devkit_1.output.warn({
|
|
68
|
+
title: 'Your `start-local-registry.ts` script may be outdated. To ensure that newly generated packages are published appropriately when running end to end tests, update this script to use Nx Release. See https://nx.dev/recipes/nx-release/update-local-registry-setup for details.',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
52
72
|
if (!tree.exists(stopLocalRegistryPath)) {
|
|
53
73
|
tree.write(stopLocalRegistryPath, stopLocalRegistryScript);
|
|
54
74
|
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addMinimalPublishScript = void 0;
|
|
4
|
-
const publishScriptContent = `
|
|
5
|
-
/**
|
|
6
|
-
* This is a minimal script to publish your package to "npm".
|
|
7
|
-
* This is meant to be used as-is or customize as you see fit.
|
|
8
|
-
*
|
|
9
|
-
* This script is executed on "dist/path/to/library" as "cwd" by default.
|
|
10
|
-
*
|
|
11
|
-
* You might need to authenticate with NPM before running this script.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { execSync } from 'child_process';
|
|
15
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
16
|
-
|
|
17
|
-
import devkit from '@nx/devkit';
|
|
18
|
-
const { readCachedProjectGraph } = devkit;
|
|
19
|
-
|
|
20
|
-
function invariant(condition, message) {
|
|
21
|
-
if (!condition) {
|
|
22
|
-
console.error(message);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
|
|
28
|
-
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
|
|
29
|
-
const [, , name, version, tag = 'next'] = process.argv;
|
|
30
|
-
|
|
31
|
-
// A simple SemVer validation to validate the version
|
|
32
|
-
const validVersion = /^\\d+\\.\\d+\\.\\d+(-\\w+\\.\\d+)?/;
|
|
33
|
-
invariant(
|
|
34
|
-
version && validVersion.test(version),
|
|
35
|
-
\`No version provided or version did not match Semantic Versioning, expected: #.#.#-tag.# or #.#.#, got \${version}.\`
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const graph = readCachedProjectGraph();
|
|
40
|
-
const project = graph.nodes[name];
|
|
41
|
-
|
|
42
|
-
invariant(
|
|
43
|
-
project,
|
|
44
|
-
\`Could not find project "\${name}" in the workspace. Is the project.json configured correctly?\`
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const outputPath = project.data?.targets?.build?.options?.outputPath;
|
|
48
|
-
invariant(
|
|
49
|
-
outputPath,
|
|
50
|
-
\`Could not find "build.options.outputPath" of project "\${name}". Is project.json configured correctly?\`
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
process.chdir(outputPath);
|
|
54
|
-
|
|
55
|
-
// Updating the version in "package.json" before publishing
|
|
56
|
-
try {
|
|
57
|
-
const json = JSON.parse(readFileSync(\`package.json\`).toString());
|
|
58
|
-
json.version = version;
|
|
59
|
-
writeFileSync(\`package.json\`, JSON.stringify(json, null, 2));
|
|
60
|
-
} catch (e) {
|
|
61
|
-
console.error(\`Error reading package.json file from library build output.\`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Execute "npm publish" to publish
|
|
65
|
-
execSync(\`npm publish --access public --tag \${tag}\`);
|
|
66
|
-
`;
|
|
67
|
-
function addMinimalPublishScript(tree) {
|
|
68
|
-
const publishScriptPath = 'tools/scripts/publish.mjs';
|
|
69
|
-
if (!tree.exists(publishScriptPath)) {
|
|
70
|
-
tree.write(publishScriptPath, publishScriptContent);
|
|
71
|
-
}
|
|
72
|
-
return publishScriptPath;
|
|
73
|
-
}
|
|
74
|
-
exports.addMinimalPublishScript = addMinimalPublishScript;
|