@nx/js 20.4.4 → 20.5.0-beta.1

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.4",
3
+ "version": "20.5.0-beta.1",
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.4",
43
- "@nx/workspace": "20.4.4",
42
+ "@nx/devkit": "20.5.0-beta.1",
43
+ "@nx/workspace": "20.5.0-beta.1",
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",
@@ -88,7 +88,7 @@ async function* nodeExecutor(options, context) {
88
88
  start: async () => {
89
89
  // Wait for build to finish.
90
90
  const result = await buildResult;
91
- if (result && !result.success) {
91
+ if (!result.success) {
92
92
  // If in watch-mode, don't throw or else the process exits.
93
93
  if (options.watch) {
94
94
  if (!task.killed) {
@@ -8,6 +8,7 @@ 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");
11
12
  const path_1 = require("path");
12
13
  const generator_prompts_1 = require("../../utils/generator-prompts");
13
14
  const update_package_json_1 = require("../../utils/package-json/update-package-json");
@@ -21,9 +22,9 @@ const ts_config_1 = require("../../utils/typescript/ts-config");
21
22
  const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
22
23
  const versions_1 = require("../../utils/versions");
23
24
  const init_1 = require("../init/init");
25
+ const generator_1 = require("../setup-verdaccio/generator");
24
26
  const sort_fields_1 = require("../../utils/package-json/sort-fields");
25
27
  const get_import_path_1 = require("../../utils/get-import-path");
26
- const add_release_config_1 = require("./utils/add-release-config");
27
28
  const defaultOutputDirectory = 'dist';
28
29
  async function libraryGenerator(tree, schema) {
29
30
  return await libraryGeneratorInternal(tree, {
@@ -53,6 +54,9 @@ async function libraryGeneratorInternal(tree, schema) {
53
54
  if (!options.skipPackageJson) {
54
55
  tasks.push(addProjectDependencies(tree, options));
55
56
  }
57
+ if (options.publishable) {
58
+ tasks.push(await (0, generator_1.default)(tree, { ...options, skipFormat: true }));
59
+ }
56
60
  if (options.bundler === 'rollup') {
57
61
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
58
62
  await configurationGenerator(tree, {
@@ -147,7 +151,9 @@ async function libraryGeneratorInternal(tree, schema) {
147
151
  await (0, devkit_1.formatFiles)(tree);
148
152
  }
149
153
  if (options.publishable) {
150
- tasks.push(await (0, add_release_config_1.releaseTasks)(tree));
154
+ tasks.push(() => {
155
+ logNxReleaseDocsInfo();
156
+ });
151
157
  }
152
158
  // Always run install to link packages.
153
159
  if (options.isUsingTsSolutionConfig) {
@@ -214,12 +220,26 @@ async function configureProject(tree, options) {
214
220
  }
215
221
  }
216
222
  if (options.publishable) {
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);
223
+ if (!options.isUsingTsSolutionConfig) {
224
+ const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
225
+ projectConfiguration.targets ??= {};
226
+ projectConfiguration.targets['nx-release-publish'] = {
227
+ options: {
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
+ };
222
241
  }
242
+ await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
223
243
  }
224
244
  if (!options.useProjectJson) {
225
245
  // we want the package.json as clean as possible, with the bare minimum
@@ -910,6 +930,96 @@ function determineEntryFields(options) {
910
930
  }
911
931
  }
912
932
  }
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
+ }
913
1023
  function findRootJestPreset(tree) {
914
1024
  const ext = ['js', 'cjs', 'mjs'].find((ext) => tree.exists(`jest.preset.${ext}`));
915
1025
  return ext ? `jest.preset.${ext}` : null;
@@ -31,7 +31,7 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
31
31
  const registry = `http://${listenAddress}:${port}`;
32
32
  console.log(`Local registry started on ${registry}`);
33
33
  process.env.npm_config_registry = registry;
34
- (0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken" --ws=false`, {
34
+ (0, child_process_1.execSync)(`npm config set //${listenAddress}:${port}/:_authToken "secretVerdaccioToken"`, {
35
35
  windowsHide: false,
36
36
  });
37
37
  // yarnv1
@@ -42,7 +42,7 @@ function startLocalRegistry({ localRegistryTarget, storage, verbose, clearStorag
42
42
  console.log('Set npm and yarn config registry to ' + registry);
43
43
  resolve(() => {
44
44
  childProcess.kill();
45
- (0, child_process_1.execSync)(`npm config delete //${listenAddress}:${port}/:_authToken --ws=false`, {
45
+ (0, child_process_1.execSync)(`npm config delete //${listenAddress}:${port}/:_authToken`, {
46
46
  windowsHide: false,
47
47
  });
48
48
  });
@@ -78,7 +78,10 @@ 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((stderr ? `${stderr}\n` : '') + error);
81
+ return reject(error);
82
+ }
83
+ if (stderr) {
84
+ return reject(stderr);
82
85
  }
83
86
  return resolve(stdout.trim());
84
87
  });
@@ -1,4 +1,4 @@
1
1
  import { type Tree } from '@nx/devkit';
2
2
  export declare const defaultExclude: string[];
3
- export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean, swcName?: string, additionalExcludes?: string[]): void;
3
+ export declare function addSwcConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
4
4
  export declare function addSwcTestConfig(tree: Tree, projectDir: string, type?: 'commonjs' | 'es6', supportTsx?: boolean): void;
@@ -43,11 +43,11 @@ const swcOptionsString = (type = 'commonjs', exclude, supportTsx) => `{
43
43
  "exclude": ${JSON.stringify(exclude)}
44
44
  }
45
45
  `;
46
- function addSwcConfig(tree, projectDir, type = 'commonjs', supportTsx = false, swcName = '.swcrc', additionalExcludes = []) {
47
- const swcrcPath = (0, path_1.join)(projectDir, swcName);
46
+ function addSwcConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
47
+ const swcrcPath = (0, path_1.join)(projectDir, '.swcrc');
48
48
  if (tree.exists(swcrcPath))
49
49
  return;
50
- tree.write(swcrcPath, swcOptionsString(type, [...exports.defaultExclude, ...additionalExcludes], supportTsx));
50
+ tree.write(swcrcPath, swcOptionsString(type, exports.defaultExclude, supportTsx));
51
51
  }
52
52
  function addSwcTestConfig(tree, projectDir, type = 'commonjs', supportTsx = false) {
53
53
  const swcrcPath = (0, path_1.join)(projectDir, '.spec.swcrc');
@@ -1,11 +0,0 @@
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>;
@@ -1,136 +0,0 @@
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
- }