@nx/js 18.1.0-beta.2 → 18.1.0-beta.4
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 +157 -22
- package/src/generators/library/schema.json +1 -1
- package/src/generators/release-version/release-version.js +42 -24
- 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/generators/release-version/utils/update-lock-file.js +7 -0
- package/src/utils/add-local-registry-scripts.js +26 -6
- package/src/utils/buildable-libs-utils.js +1 -1
- package/src/utils/minimal-publish-script.d.ts +0 -2
- package/src/utils/minimal-publish-script.js +0 -74
- /package/src/generators/library/files/{lib → readme}/README.md +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "18.1.0-beta.
|
|
3
|
+
"version": "18.1.0-beta.4",
|
|
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.0-beta.
|
|
61
|
-
"@nx/workspace": "18.1.0-beta.
|
|
62
|
-
"@nrwl/js": "18.1.0-beta.
|
|
60
|
+
"@nx/devkit": "18.1.0-beta.4",
|
|
61
|
+
"@nx/workspace": "18.1.0-beta.4",
|
|
62
|
+
"@nrwl/js": "18.1.0-beta.4"
|
|
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,
|
|
@@ -25,7 +26,6 @@ async function libraryGenerator(tree, schema) {
|
|
|
25
26
|
}
|
|
26
27
|
exports.libraryGenerator = libraryGenerator;
|
|
27
28
|
async function libraryGeneratorInternal(tree, schema) {
|
|
28
|
-
const filesDir = (0, path_1.join)(__dirname, './files');
|
|
29
29
|
const tasks = [];
|
|
30
30
|
tasks.push(await (0, init_1.default)(tree, {
|
|
31
31
|
...schema,
|
|
@@ -33,8 +33,8 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
33
33
|
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
34
34
|
}));
|
|
35
35
|
const options = await normalizeOptions(tree, schema);
|
|
36
|
-
createFiles(tree, options
|
|
37
|
-
addProject(tree, options);
|
|
36
|
+
createFiles(tree, options);
|
|
37
|
+
await addProject(tree, options);
|
|
38
38
|
if (!options.skipPackageJson) {
|
|
39
39
|
tasks.push(addProjectDependencies(tree, options));
|
|
40
40
|
}
|
|
@@ -69,7 +69,7 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
69
69
|
const jestCallback = await addJest(tree, options);
|
|
70
70
|
tasks.push(jestCallback);
|
|
71
71
|
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
72
|
-
replaceJestConfig(tree, options
|
|
72
|
+
replaceJestConfig(tree, options);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
else if (options.unitTestRunner === 'vitest' &&
|
|
@@ -102,13 +102,18 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
102
102
|
if (!options.skipFormat) {
|
|
103
103
|
await (0, devkit_1.formatFiles)(tree);
|
|
104
104
|
}
|
|
105
|
+
if (options.publishable) {
|
|
106
|
+
tasks.push(() => {
|
|
107
|
+
logNxReleaseDocsInfo();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
105
110
|
tasks.push(() => {
|
|
106
111
|
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
107
112
|
});
|
|
108
113
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
109
114
|
}
|
|
110
115
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
111
|
-
function addProject(tree, options) {
|
|
116
|
+
async function addProject(tree, options) {
|
|
112
117
|
const projectConfiguration = {
|
|
113
118
|
root: options.projectRoot,
|
|
114
119
|
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
@@ -151,11 +156,24 @@ function addProject(tree, options) {
|
|
|
151
156
|
projectConfiguration.targets.build.options.assets.push((0, devkit_1.joinPathFragments)(options.projectRoot, '*.md'));
|
|
152
157
|
}
|
|
153
158
|
if (options.publishable) {
|
|
154
|
-
const
|
|
155
|
-
projectConfiguration.targets
|
|
156
|
-
|
|
157
|
-
|
|
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
|
+
},
|
|
158
175
|
};
|
|
176
|
+
await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
|
|
159
177
|
}
|
|
160
178
|
}
|
|
161
179
|
if (options.config === 'workspace' || options.config === 'project') {
|
|
@@ -284,10 +302,10 @@ function addBabelRc(tree, options) {
|
|
|
284
302
|
};
|
|
285
303
|
(0, devkit_1.writeJson)(tree, (0, path_1.join)(options.projectRoot, filename), babelrc);
|
|
286
304
|
}
|
|
287
|
-
function createFiles(tree, options
|
|
305
|
+
function createFiles(tree, options) {
|
|
288
306
|
const { className, name, propertyName } = (0, devkit_1.names)(options.projectNames.projectFileName);
|
|
289
307
|
createProjectTsConfigJson(tree, options);
|
|
290
|
-
(0, devkit_1.generateFiles)(tree,
|
|
308
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/lib'), options.projectRoot, {
|
|
291
309
|
...options,
|
|
292
310
|
dot: '.',
|
|
293
311
|
className,
|
|
@@ -301,6 +319,22 @@ function createFiles(tree, options, filesDir) {
|
|
|
301
319
|
buildable: options.bundler && options.bundler !== 'none',
|
|
302
320
|
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
303
321
|
});
|
|
322
|
+
if (!options.rootProject) {
|
|
323
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files/readme'), options.projectRoot, {
|
|
324
|
+
...options,
|
|
325
|
+
dot: '.',
|
|
326
|
+
className,
|
|
327
|
+
name,
|
|
328
|
+
propertyName,
|
|
329
|
+
js: !!options.js,
|
|
330
|
+
cliCommand: 'nx',
|
|
331
|
+
strict: undefined,
|
|
332
|
+
tmpl: '',
|
|
333
|
+
offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
|
|
334
|
+
buildable: options.bundler && options.bundler !== 'none',
|
|
335
|
+
hasUnitTestRunner: options.unitTestRunner !== 'none',
|
|
336
|
+
});
|
|
337
|
+
}
|
|
304
338
|
if (options.bundler === 'swc' || options.bundler === 'rollup') {
|
|
305
339
|
(0, add_swc_dependencies_1.addSwcDependencies)(tree);
|
|
306
340
|
(0, add_swc_config_1.addSwcConfig)(tree, options.projectRoot, options.bundler === 'swc' ? 'commonjs' : 'es6');
|
|
@@ -324,6 +358,9 @@ function createFiles(tree, options, filesDir) {
|
|
|
324
358
|
if (json.private && (options.publishable || options.rootProject)) {
|
|
325
359
|
delete json.private;
|
|
326
360
|
}
|
|
361
|
+
if (!options.publishable && !options.rootProject) {
|
|
362
|
+
json.private = true;
|
|
363
|
+
}
|
|
327
364
|
return {
|
|
328
365
|
...json,
|
|
329
366
|
dependencies: {
|
|
@@ -335,12 +372,16 @@ function createFiles(tree, options, filesDir) {
|
|
|
335
372
|
});
|
|
336
373
|
}
|
|
337
374
|
else {
|
|
338
|
-
|
|
375
|
+
const packageJson = {
|
|
339
376
|
name: options.importPath,
|
|
340
377
|
version: '0.0.1',
|
|
341
378
|
dependencies: determineDependencies(options),
|
|
342
379
|
...determineEntryFields(options),
|
|
343
|
-
}
|
|
380
|
+
};
|
|
381
|
+
if (!options.publishable && !options.rootProject) {
|
|
382
|
+
packageJson.private = true;
|
|
383
|
+
}
|
|
384
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
344
385
|
}
|
|
345
386
|
if (options.config === 'npm-scripts') {
|
|
346
387
|
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
@@ -377,7 +418,8 @@ async function addJest(tree, options) {
|
|
|
377
418
|
: undefined,
|
|
378
419
|
});
|
|
379
420
|
}
|
|
380
|
-
function replaceJestConfig(tree, options
|
|
421
|
+
function replaceJestConfig(tree, options) {
|
|
422
|
+
const filesDir = (0, path_1.join)(__dirname, './files/jest-config');
|
|
381
423
|
// the existing config has to be deleted otherwise the new config won't overwrite it
|
|
382
424
|
const existingJestConfig = (0, devkit_1.joinPathFragments)(filesDir, `jest.config.${options.js ? 'js' : 'ts'}`);
|
|
383
425
|
if (tree.exists(existingJestConfig)) {
|
|
@@ -394,7 +436,10 @@ function replaceJestConfig(tree, options, filesDir) {
|
|
|
394
436
|
});
|
|
395
437
|
}
|
|
396
438
|
async function normalizeOptions(tree, options) {
|
|
397
|
-
|
|
439
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
440
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
441
|
+
nxJson.useInferencePlugins !== false;
|
|
442
|
+
options.addPlugin ??= addPlugin;
|
|
398
443
|
/**
|
|
399
444
|
* We are deprecating the compiler and the buildable options.
|
|
400
445
|
* However, we want to keep the existing behavior for now.
|
|
@@ -429,7 +474,7 @@ async function normalizeOptions(tree, options) {
|
|
|
429
474
|
options.bundler = 'tsc';
|
|
430
475
|
}
|
|
431
476
|
}
|
|
432
|
-
// This is to preserve old
|
|
477
|
+
// This is to preserve old behavior, buildable: false
|
|
433
478
|
if (options.publishable === false && options.buildable === false) {
|
|
434
479
|
options.bundler = 'none';
|
|
435
480
|
}
|
|
@@ -521,7 +566,7 @@ function getBuildExecutor(bundler) {
|
|
|
521
566
|
}
|
|
522
567
|
}
|
|
523
568
|
function getOutputPath(options) {
|
|
524
|
-
const parts = [
|
|
569
|
+
const parts = [defaultOutputDirectory];
|
|
525
570
|
if (options.projectRoot === '.') {
|
|
526
571
|
parts.push(options.name);
|
|
527
572
|
}
|
|
@@ -613,4 +658,94 @@ function determineEntryFields(options) {
|
|
|
613
658
|
}
|
|
614
659
|
}
|
|
615
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
|
+
}
|
|
616
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
|
}
|
|
@@ -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[]>;
|
|
@@ -23,6 +23,13 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
23
23
|
}
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
26
|
+
const workspacesEnabled = (0, devkit_1.isWorkspacesEnabled)(packageManager, cwd);
|
|
27
|
+
if (!workspacesEnabled) {
|
|
28
|
+
if (verbose) {
|
|
29
|
+
console.log(`\nSkipped lock file update because ${packageManager} workspaces are not enabled.`);
|
|
30
|
+
}
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
26
33
|
const isDaemonEnabled = client_1.daemonClient.enabled();
|
|
27
34
|
if (!dryRun && isDaemonEnabled) {
|
|
28
35
|
// if not in dry-run temporarily stop the daemon, as it will error if the lock file is updated
|
|
@@ -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
|
}
|
|
@@ -127,7 +127,7 @@ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, proje
|
|
|
127
127
|
const depTask = taskGraph.tasks[taskName];
|
|
128
128
|
const depProjectNode = projectGraph.nodes?.[depTask.target.project];
|
|
129
129
|
if (depProjectNode?.type !== 'lib') {
|
|
130
|
-
|
|
130
|
+
continue;
|
|
131
131
|
}
|
|
132
132
|
let outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)(depTask.target, depTask.overrides, depProjectNode);
|
|
133
133
|
if (outputs.length === 0) {
|
|
@@ -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;
|
|
File without changes
|