@nx/js 20.4.2 → 20.4.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "20.4.
|
|
3
|
+
"version": "20.4.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": {
|
|
@@ -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": "20.4.
|
|
43
|
-
"@nx/workspace": "20.4.
|
|
42
|
+
"@nx/devkit": "20.4.4",
|
|
43
|
+
"@nx/workspace": "20.4.4",
|
|
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,7 +8,6 @@ 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 find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
12
11
|
const path_1 = require("path");
|
|
13
12
|
const generator_prompts_1 = require("../../utils/generator-prompts");
|
|
14
13
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
@@ -22,9 +21,9 @@ const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
|
22
21
|
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
23
22
|
const versions_1 = require("../../utils/versions");
|
|
24
23
|
const init_1 = require("../init/init");
|
|
25
|
-
const generator_1 = require("../setup-verdaccio/generator");
|
|
26
24
|
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
27
25
|
const get_import_path_1 = require("../../utils/get-import-path");
|
|
26
|
+
const add_release_config_1 = require("./utils/add-release-config");
|
|
28
27
|
const defaultOutputDirectory = 'dist';
|
|
29
28
|
async function libraryGenerator(tree, schema) {
|
|
30
29
|
return await libraryGeneratorInternal(tree, {
|
|
@@ -54,9 +53,6 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
54
53
|
if (!options.skipPackageJson) {
|
|
55
54
|
tasks.push(addProjectDependencies(tree, options));
|
|
56
55
|
}
|
|
57
|
-
if (options.publishable) {
|
|
58
|
-
tasks.push(await (0, generator_1.default)(tree, { ...options, skipFormat: true }));
|
|
59
|
-
}
|
|
60
56
|
if (options.bundler === 'rollup') {
|
|
61
57
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
62
58
|
await configurationGenerator(tree, {
|
|
@@ -151,9 +147,7 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
151
147
|
await (0, devkit_1.formatFiles)(tree);
|
|
152
148
|
}
|
|
153
149
|
if (options.publishable) {
|
|
154
|
-
tasks.push(()
|
|
155
|
-
logNxReleaseDocsInfo();
|
|
156
|
-
});
|
|
150
|
+
tasks.push(await (0, add_release_config_1.releaseTasks)(tree));
|
|
157
151
|
}
|
|
158
152
|
// Always run install to link packages.
|
|
159
153
|
if (options.isUsingTsSolutionConfig) {
|
|
@@ -220,26 +214,12 @@ async function configureProject(tree, options) {
|
|
|
220
214
|
}
|
|
221
215
|
}
|
|
222
216
|
if (options.publishable) {
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
packageRoot,
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
projectConfiguration.release = {
|
|
232
|
-
version: {
|
|
233
|
-
generatorOptions: {
|
|
234
|
-
packageRoot,
|
|
235
|
-
// using git tags to determine the current version is required here because
|
|
236
|
-
// the version in the package root is overridden with every build
|
|
237
|
-
currentVersionResolver: 'git-tag',
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
};
|
|
217
|
+
if (options.isUsingTsSolutionConfig) {
|
|
218
|
+
await (0, add_release_config_1.addReleaseConfigForTsSolution)(tree, options.name, projectConfiguration);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
await (0, add_release_config_1.addReleaseConfigForNonTsSolution)(tree, options.name, projectConfiguration, defaultOutputDirectory);
|
|
241
222
|
}
|
|
242
|
-
await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
|
|
243
223
|
}
|
|
244
224
|
if (!options.useProjectJson) {
|
|
245
225
|
// we want the package.json as clean as possible, with the bare minimum
|
|
@@ -930,96 +910,6 @@ function determineEntryFields(options) {
|
|
|
930
910
|
}
|
|
931
911
|
}
|
|
932
912
|
}
|
|
933
|
-
function projectsConfigMatchesProject(projectsConfig, project) {
|
|
934
|
-
if (!projectsConfig) {
|
|
935
|
-
return false;
|
|
936
|
-
}
|
|
937
|
-
if (typeof projectsConfig === 'string') {
|
|
938
|
-
projectsConfig = [projectsConfig];
|
|
939
|
-
}
|
|
940
|
-
const graph = {
|
|
941
|
-
[project.name]: project,
|
|
942
|
-
};
|
|
943
|
-
const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
|
|
944
|
-
return matchingProjects.includes(project.name);
|
|
945
|
-
}
|
|
946
|
-
async function addProjectToNxReleaseConfig(tree, options, projectConfiguration) {
|
|
947
|
-
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
948
|
-
const addPreVersionCommand = () => {
|
|
949
|
-
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
950
|
-
nxJson.release = {
|
|
951
|
-
...nxJson.release,
|
|
952
|
-
version: {
|
|
953
|
-
preVersionCommand: `${pmc.dlx} nx run-many -t build`,
|
|
954
|
-
...nxJson.release?.version,
|
|
955
|
-
},
|
|
956
|
-
};
|
|
957
|
-
};
|
|
958
|
-
if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
|
|
959
|
-
// skip adding any projects configuration since the new project should be
|
|
960
|
-
// automatically included by nx release's default project detection logic
|
|
961
|
-
addPreVersionCommand();
|
|
962
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
const project = {
|
|
966
|
-
name: options.name,
|
|
967
|
-
type: 'lib',
|
|
968
|
-
data: {
|
|
969
|
-
root: projectConfiguration.root,
|
|
970
|
-
tags: projectConfiguration.tags,
|
|
971
|
-
},
|
|
972
|
-
};
|
|
973
|
-
if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
|
|
974
|
-
devkit_1.output.log({
|
|
975
|
-
title: `Project already included in existing release configuration`,
|
|
976
|
-
});
|
|
977
|
-
addPreVersionCommand();
|
|
978
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
if (Array.isArray(nxJson.release.projects)) {
|
|
982
|
-
nxJson.release.projects.push(options.name);
|
|
983
|
-
addPreVersionCommand();
|
|
984
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
985
|
-
devkit_1.output.log({
|
|
986
|
-
title: `Added project to existing release configuration`,
|
|
987
|
-
});
|
|
988
|
-
}
|
|
989
|
-
if (nxJson.release.groups) {
|
|
990
|
-
const allGroups = Object.entries(nxJson.release.groups);
|
|
991
|
-
for (const [name, group] of allGroups) {
|
|
992
|
-
if (projectsConfigMatchesProject(group.projects, project)) {
|
|
993
|
-
addPreVersionCommand();
|
|
994
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
995
|
-
return `Project already included in existing release configuration for group ${name}`;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
devkit_1.output.warn({
|
|
999
|
-
title: `Could not find a release group that includes ${options.name}`,
|
|
1000
|
-
bodyLines: [
|
|
1001
|
-
`Ensure that ${options.name} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
|
|
1002
|
-
],
|
|
1003
|
-
});
|
|
1004
|
-
addPreVersionCommand();
|
|
1005
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
1006
|
-
return;
|
|
1007
|
-
}
|
|
1008
|
-
if (typeof nxJson.release.projects === 'string') {
|
|
1009
|
-
nxJson.release.projects = [nxJson.release.projects, options.name];
|
|
1010
|
-
addPreVersionCommand();
|
|
1011
|
-
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
1012
|
-
devkit_1.output.log({
|
|
1013
|
-
title: `Added project to existing release configuration`,
|
|
1014
|
-
});
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
function logNxReleaseDocsInfo() {
|
|
1019
|
-
devkit_1.output.log({
|
|
1020
|
-
title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
|
|
1021
|
-
});
|
|
1022
|
-
}
|
|
1023
913
|
function findRootJestPreset(tree) {
|
|
1024
914
|
const ext = ['js', 'cjs', 'mjs'].find((ext) => tree.exists(`jest.preset.${ext}`));
|
|
1025
915
|
return ext ? `jest.preset.${ext}` : null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GeneratorCallback, ProjectConfiguration, Tree } from '@nx/devkit';
|
|
2
|
+
/**
|
|
3
|
+
* Adds release option in nx.json to build the project before versioning
|
|
4
|
+
*/
|
|
5
|
+
export declare function addReleaseConfigForTsSolution(tree: Tree, projectName: string, projectConfiguration: ProjectConfiguration): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Add release configuration for non-ts solution projects
|
|
8
|
+
* Add release option in project.json and add packageRoot to nx-release-publish target
|
|
9
|
+
*/
|
|
10
|
+
export declare function addReleaseConfigForNonTsSolution(tree: Tree, projectName: string, projectConfiguration: ProjectConfiguration, defaultOutputDirectory?: string): Promise<ProjectConfiguration>;
|
|
11
|
+
export declare function releaseTasks(tree: Tree): Promise<GeneratorCallback>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addReleaseConfigForTsSolution = addReleaseConfigForTsSolution;
|
|
4
|
+
exports.addReleaseConfigForNonTsSolution = addReleaseConfigForNonTsSolution;
|
|
5
|
+
exports.releaseTasks = releaseTasks;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
8
|
+
const generator_1 = require("../../setup-verdaccio/generator");
|
|
9
|
+
/**
|
|
10
|
+
* Adds release option in nx.json to build the project before versioning
|
|
11
|
+
*/
|
|
12
|
+
async function addReleaseConfigForTsSolution(tree, projectName, projectConfiguration) {
|
|
13
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
14
|
+
const addPreVersionCommand = () => {
|
|
15
|
+
const pmc = (0, devkit_1.getPackageManagerCommand)();
|
|
16
|
+
nxJson.release = {
|
|
17
|
+
...nxJson.release,
|
|
18
|
+
version: {
|
|
19
|
+
preVersionCommand: `${pmc.dlx} nx run-many -t build`,
|
|
20
|
+
...nxJson.release?.version,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
// if the release configuration does not exist, it will be created
|
|
25
|
+
if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
|
|
26
|
+
// skip adding any projects configuration since the new project should be
|
|
27
|
+
// automatically included by nx release's default project detection logic
|
|
28
|
+
addPreVersionCommand();
|
|
29
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const project = {
|
|
33
|
+
name: projectName,
|
|
34
|
+
type: 'lib',
|
|
35
|
+
data: {
|
|
36
|
+
root: projectConfiguration.root,
|
|
37
|
+
tags: projectConfiguration.tags,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
// if the project is already included in the release configuration, it will not be added again
|
|
41
|
+
if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
|
|
42
|
+
devkit_1.output.log({
|
|
43
|
+
title: `Project already included in existing release configuration`,
|
|
44
|
+
});
|
|
45
|
+
addPreVersionCommand();
|
|
46
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// if the release configuration is a string, it will be converted to an array and added to it
|
|
50
|
+
if (Array.isArray(nxJson.release.projects)) {
|
|
51
|
+
nxJson.release.projects.push(projectName);
|
|
52
|
+
addPreVersionCommand();
|
|
53
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
54
|
+
devkit_1.output.log({
|
|
55
|
+
title: `Added project to existing release configuration`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (nxJson.release.groups) {
|
|
59
|
+
const allGroups = Object.entries(nxJson.release.groups);
|
|
60
|
+
for (const [name, group] of allGroups) {
|
|
61
|
+
if (projectsConfigMatchesProject(group.projects, project)) {
|
|
62
|
+
addPreVersionCommand();
|
|
63
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
64
|
+
devkit_1.output.log({
|
|
65
|
+
title: `Project already included in existing release configuration for group ${name}`,
|
|
66
|
+
});
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
devkit_1.output.warn({
|
|
71
|
+
title: `Could not find a release group that includes ${projectName}`,
|
|
72
|
+
bodyLines: [
|
|
73
|
+
`Ensure that ${projectName} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
|
|
74
|
+
],
|
|
75
|
+
});
|
|
76
|
+
addPreVersionCommand();
|
|
77
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (typeof nxJson.release.projects === 'string') {
|
|
81
|
+
nxJson.release.projects = [nxJson.release.projects, projectName];
|
|
82
|
+
addPreVersionCommand();
|
|
83
|
+
(0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
|
|
84
|
+
devkit_1.output.log({
|
|
85
|
+
title: `Added project to existing release configuration`,
|
|
86
|
+
});
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Add release configuration for non-ts solution projects
|
|
92
|
+
* Add release option in project.json and add packageRoot to nx-release-publish target
|
|
93
|
+
*/
|
|
94
|
+
async function addReleaseConfigForNonTsSolution(tree, projectName, projectConfiguration, defaultOutputDirectory = 'dist') {
|
|
95
|
+
const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
|
|
96
|
+
projectConfiguration.targets ??= {};
|
|
97
|
+
projectConfiguration.targets['nx-release-publish'] = {
|
|
98
|
+
options: {
|
|
99
|
+
packageRoot,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
projectConfiguration.release = {
|
|
103
|
+
version: {
|
|
104
|
+
generatorOptions: {
|
|
105
|
+
packageRoot,
|
|
106
|
+
// using git tags to determine the current version is required here because
|
|
107
|
+
// the version in the package root is overridden with every build
|
|
108
|
+
currentVersionResolver: 'git-tag',
|
|
109
|
+
fallbackCurrentVersionResolver: 'disk',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
await addReleaseConfigForTsSolution(tree, projectName, projectConfiguration);
|
|
114
|
+
return projectConfiguration;
|
|
115
|
+
}
|
|
116
|
+
function projectsConfigMatchesProject(projectsConfig, project) {
|
|
117
|
+
if (!projectsConfig) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (typeof projectsConfig === 'string') {
|
|
121
|
+
projectsConfig = [projectsConfig];
|
|
122
|
+
}
|
|
123
|
+
const graph = {
|
|
124
|
+
[project.name]: project,
|
|
125
|
+
};
|
|
126
|
+
const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
|
|
127
|
+
return matchingProjects.includes(project.name);
|
|
128
|
+
}
|
|
129
|
+
async function releaseTasks(tree) {
|
|
130
|
+
return (0, devkit_1.runTasksInSerial)(await (0, generator_1.default)(tree, { skipFormat: true }), () => logNxReleaseDocsInfo());
|
|
131
|
+
}
|
|
132
|
+
function logNxReleaseDocsInfo() {
|
|
133
|
+
devkit_1.output.log({
|
|
134
|
+
title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
|
|
135
|
+
});
|
|
136
|
+
}
|
package/src/utils/npm-config.js
CHANGED
|
@@ -78,10 +78,7 @@ async function execAsync(command, cwd) {
|
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
79
79
|
(0, child_process_1.exec)(command, { cwd, windowsHide: false }, (error, stdout, stderr) => {
|
|
80
80
|
if (error) {
|
|
81
|
-
return reject(error);
|
|
82
|
-
}
|
|
83
|
-
if (stderr) {
|
|
84
|
-
return reject(stderr);
|
|
81
|
+
return reject((stderr ? `${stderr}\n` : '') + error);
|
|
85
82
|
}
|
|
86
83
|
return resolve(stdout.trim());
|
|
87
84
|
});
|