@nx/js 20.4.3 → 20.5.0-beta.0

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",
3
+ "version": "20.5.0-beta.0",
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.3",
43
- "@nx/workspace": "20.4.3",
42
+ "@nx/devkit": "20.5.0-beta.0",
43
+ "@nx/workspace": "20.5.0-beta.0",
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,13 +54,15 @@ 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, {
59
63
  project: options.name,
60
64
  compiler: 'swc',
61
65
  format: options.isUsingTsSolutionConfig ? ['esm'] : ['cjs', 'esm'],
62
- skipFormat: true,
63
66
  });
64
67
  }
65
68
  if (options.bundler === 'vite') {
@@ -147,7 +150,9 @@ async function libraryGeneratorInternal(tree, schema) {
147
150
  await (0, devkit_1.formatFiles)(tree);
148
151
  }
149
152
  if (options.publishable) {
150
- tasks.push(await (0, add_release_config_1.releaseTasks)(tree));
153
+ tasks.push(() => {
154
+ logNxReleaseDocsInfo();
155
+ });
151
156
  }
152
157
  // Always run install to link packages.
153
158
  if (options.isUsingTsSolutionConfig) {
@@ -214,12 +219,26 @@ async function configureProject(tree, options) {
214
219
  }
215
220
  }
216
221
  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);
222
+ if (!options.isUsingTsSolutionConfig) {
223
+ const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
224
+ projectConfiguration.targets ??= {};
225
+ projectConfiguration.targets['nx-release-publish'] = {
226
+ options: {
227
+ packageRoot,
228
+ },
229
+ };
230
+ projectConfiguration.release = {
231
+ version: {
232
+ generatorOptions: {
233
+ packageRoot,
234
+ // using git tags to determine the current version is required here because
235
+ // the version in the package root is overridden with every build
236
+ currentVersionResolver: 'git-tag',
237
+ },
238
+ },
239
+ };
222
240
  }
241
+ await addProjectToNxReleaseConfig(tree, options, projectConfiguration);
223
242
  }
224
243
  if (!options.useProjectJson) {
225
244
  // we want the package.json as clean as possible, with the bare minimum
@@ -910,6 +929,96 @@ function determineEntryFields(options) {
910
929
  }
911
930
  }
912
931
  }
932
+ function projectsConfigMatchesProject(projectsConfig, project) {
933
+ if (!projectsConfig) {
934
+ return false;
935
+ }
936
+ if (typeof projectsConfig === 'string') {
937
+ projectsConfig = [projectsConfig];
938
+ }
939
+ const graph = {
940
+ [project.name]: project,
941
+ };
942
+ const matchingProjects = (0, find_matching_projects_1.findMatchingProjects)(projectsConfig, graph);
943
+ return matchingProjects.includes(project.name);
944
+ }
945
+ async function addProjectToNxReleaseConfig(tree, options, projectConfiguration) {
946
+ const nxJson = (0, devkit_1.readNxJson)(tree);
947
+ const addPreVersionCommand = () => {
948
+ const pmc = (0, devkit_1.getPackageManagerCommand)();
949
+ nxJson.release = {
950
+ ...nxJson.release,
951
+ version: {
952
+ preVersionCommand: `${pmc.dlx} nx run-many -t build`,
953
+ ...nxJson.release?.version,
954
+ },
955
+ };
956
+ };
957
+ if (!nxJson.release || (!nxJson.release.projects && !nxJson.release.groups)) {
958
+ // skip adding any projects configuration since the new project should be
959
+ // automatically included by nx release's default project detection logic
960
+ addPreVersionCommand();
961
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
962
+ return;
963
+ }
964
+ const project = {
965
+ name: options.name,
966
+ type: 'lib',
967
+ data: {
968
+ root: projectConfiguration.root,
969
+ tags: projectConfiguration.tags,
970
+ },
971
+ };
972
+ if (projectsConfigMatchesProject(nxJson.release.projects, project)) {
973
+ devkit_1.output.log({
974
+ title: `Project already included in existing release configuration`,
975
+ });
976
+ addPreVersionCommand();
977
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
978
+ return;
979
+ }
980
+ if (Array.isArray(nxJson.release.projects)) {
981
+ nxJson.release.projects.push(options.name);
982
+ addPreVersionCommand();
983
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
984
+ devkit_1.output.log({
985
+ title: `Added project to existing release configuration`,
986
+ });
987
+ }
988
+ if (nxJson.release.groups) {
989
+ const allGroups = Object.entries(nxJson.release.groups);
990
+ for (const [name, group] of allGroups) {
991
+ if (projectsConfigMatchesProject(group.projects, project)) {
992
+ addPreVersionCommand();
993
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
994
+ return `Project already included in existing release configuration for group ${name}`;
995
+ }
996
+ }
997
+ devkit_1.output.warn({
998
+ title: `Could not find a release group that includes ${options.name}`,
999
+ bodyLines: [
1000
+ `Ensure that ${options.name} is included in a release group's "projects" list in nx.json so it can be published with "nx release"`,
1001
+ ],
1002
+ });
1003
+ addPreVersionCommand();
1004
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
1005
+ return;
1006
+ }
1007
+ if (typeof nxJson.release.projects === 'string') {
1008
+ nxJson.release.projects = [nxJson.release.projects, options.name];
1009
+ addPreVersionCommand();
1010
+ (0, devkit_1.writeJson)(tree, 'nx.json', nxJson);
1011
+ devkit_1.output.log({
1012
+ title: `Added project to existing release configuration`,
1013
+ });
1014
+ return;
1015
+ }
1016
+ }
1017
+ function logNxReleaseDocsInfo() {
1018
+ devkit_1.output.log({
1019
+ title: `📦 To learn how to publish this library, see https://nx.dev/core-features/manage-releases.`,
1020
+ });
1021
+ }
913
1022
  function findRootJestPreset(tree) {
914
1023
  const ext = ['js', 'cjs', 'mjs'].find((ext) => tree.exists(`jest.preset.${ext}`));
915
1024
  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
  });
@@ -9,7 +9,6 @@ export interface TscPluginOptions {
9
9
  buildDepsName?: string;
10
10
  watchDepsName?: string;
11
11
  };
12
- verboseOutput?: boolean;
13
12
  }
14
13
  /**
15
14
  * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
@@ -126,6 +126,11 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
126
126
  const targets = {};
127
127
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
128
128
  const tsConfig = readCachedTsConfig(configFilePath);
129
+ // TODO: check whether we want to always run with --pretty --verbose, it makes replacing scripts harder
130
+ // `--verbose` conflicts with `tsc -b --clean`, might be another reason for not using it, it would
131
+ // prevent users from running the task with `--clean` flag.
132
+ // Should we consider creating a different optional target for `--clean`?
133
+ // Should we consider having a plugin option to disable `--pretty` and `--verbose`?
129
134
  let internalProjectReferences;
130
135
  // Typecheck target
131
136
  if ((0, node_path_1.basename)(configFilePath) === 'tsconfig.json' && options.typecheck) {
@@ -133,7 +138,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
133
138
  const externalProjectReferences = resolveShallowExternalProjectReferences(tsConfig, context.workspaceRoot, projectRoot);
134
139
  const targetName = options.typecheck.targetName;
135
140
  if (!targets[targetName]) {
136
- let command = `tsc --build --emitDeclarationOnly${options.verboseOutput ? ' --verbose' : ''}`;
141
+ let command = `tsc --build --emitDeclarationOnly --pretty --verbose`;
137
142
  if (tsConfig.options.noEmit ||
138
143
  Object.values(internalProjectReferences).some((ref) => ref.options.noEmit) ||
139
144
  Object.values(externalProjectReferences).some((ref) => ref.options.noEmit)) {
@@ -169,7 +174,7 @@ function buildTscTargets(configFilePath, projectRoot, options, context) {
169
174
  const targetName = options.build.targetName;
170
175
  targets[targetName] = {
171
176
  dependsOn: [`^${targetName}`],
172
- command: `tsc --build ${options.build.configName}${options.verboseOutput ? ' --verbose' : ''}`,
177
+ command: `tsc --build ${options.build.configName} --pretty --verbose`,
173
178
  options: { cwd: projectRoot },
174
179
  cache: true,
175
180
  inputs: getInputs(namedInputs, configFilePath, tsConfig, internalProjectReferences, context.workspaceRoot, projectRoot),
@@ -579,7 +584,6 @@ function normalizePluginOptions(pluginOptions = {}) {
579
584
  return {
580
585
  typecheck,
581
586
  build,
582
- verboseOutput: pluginOptions.verboseOutput ?? false,
583
587
  };
584
588
  }
585
589
  function resolveExtendedTsConfigPath(tsConfigPath, directory) {
@@ -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
- }