@nx/js 21.0.0-beta.1 → 21.0.0-beta.11
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/migrations.json +19 -73
- package/package.json +7 -8
- package/src/executors/node/node.impl.js +2 -2
- package/src/executors/release-publish/release-publish.impl.js +58 -17
- package/src/executors/verdaccio/schema.json +1 -0
- package/src/generators/init/files/ts-solution/tsconfig.base.json__tmpl__ +2 -1
- package/src/generators/init/init.js +1 -2
- package/src/generators/library/library.js +29 -135
- package/src/generators/library/utils/add-release-config.d.ts +11 -0
- package/src/generators/library/utils/add-release-config.js +150 -0
- package/src/generators/release-version/release-version.d.ts +1 -1
- package/src/generators/release-version/release-version.js +18 -15
- package/src/generators/release-version/schema.d.ts +1 -1
- package/src/generators/release-version/schema.json +23 -4
- package/src/generators/setup-build/generator.js +4 -0
- package/src/generators/typescript-sync/typescript-sync.js +0 -12
- package/src/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/plugin.js +447 -211
- package/src/plugins/typescript/util.d.ts +9 -0
- package/src/plugins/typescript/util.js +74 -0
- package/src/release/utils/update-lock-file.d.ts +10 -0
- package/src/{generators/release-version → release}/utils/update-lock-file.js +12 -9
- package/src/release/version-actions.d.ts +22 -0
- package/src/release/version-actions.js +202 -0
- package/src/utils/add-local-registry-scripts.js +1 -1
- package/src/utils/assets/copy-assets-handler.js +11 -5
- package/src/utils/buildable-libs-utils.d.ts +0 -2
- package/src/utils/buildable-libs-utils.js +12 -42
- package/src/utils/find-npm-dependencies.d.ts +1 -0
- package/src/utils/find-npm-dependencies.js +12 -2
- package/src/utils/npm-config.js +1 -4
- package/src/utils/package-json/update-package-json.d.ts +1 -0
- package/src/utils/package-json/update-package-json.js +42 -1
- package/src/utils/package-manager-workspaces.d.ts +1 -0
- package/src/utils/package-manager-workspaces.js +12 -7
- package/src/utils/swc/add-swc-config.d.ts +1 -1
- package/src/utils/swc/add-swc-config.js +3 -3
- package/src/utils/swc/compile-swc.js +1 -1
- package/src/utils/typescript/plugin.d.ts +1 -1
- package/src/utils/typescript/plugin.js +27 -16
- package/src/utils/typescript/ts-solution-setup.d.ts +3 -2
- package/src/utils/typescript/ts-solution-setup.js +32 -9
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/generators/release-version/utils/update-lock-file.d.ts +0 -5
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +0 -6
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +0 -30
- package/src/utils/typescript/tsnode-register.d.ts +0 -1
- package/src/utils/typescript/tsnode-register.js +0 -23
package/migrations.json
CHANGED
|
@@ -1,78 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
3
|
-
"update-17-0-0-remove-deprecated-build-options": {
|
|
4
|
-
"cli": "nx",
|
|
5
|
-
"version": "17.0.2",
|
|
6
|
-
"description": "Remove deprecated build options",
|
|
7
|
-
"implementation": "./src/migrations/update-17-0-0/remove-deprecated-build-options"
|
|
8
|
-
}
|
|
9
|
-
},
|
|
2
|
+
"generators": {},
|
|
10
3
|
"packageJsonUpdates": {
|
|
11
|
-
"17.0.0": {
|
|
12
|
-
"version": "17.0.0-rc.2",
|
|
13
|
-
"packages": {
|
|
14
|
-
"esbuild": {
|
|
15
|
-
"version": "^0.19.2",
|
|
16
|
-
"alwaysAddToPackageJson": false
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"17.1.0": {
|
|
21
|
-
"version": "17.1.0-beta.4",
|
|
22
|
-
"x-prompt": "Do you want to update to TypeScript v5.2?",
|
|
23
|
-
"requires": {
|
|
24
|
-
"typescript": ">=5.1.0 <5.2.0"
|
|
25
|
-
},
|
|
26
|
-
"packages": {
|
|
27
|
-
"typescript": {
|
|
28
|
-
"version": "~5.2.2"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"17.3.0": {
|
|
33
|
-
"version": "17.3.0-beta.3",
|
|
34
|
-
"packages": {
|
|
35
|
-
"@types/node": {
|
|
36
|
-
"version": "^18.16.9",
|
|
37
|
-
"alwaysAddToPackageJson": false
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"17.3.0-beta.10": {
|
|
42
|
-
"version": "17.3.0-beta.10",
|
|
43
|
-
"x-prompt": "Do you want to update to TypeScript v5.3?",
|
|
44
|
-
"requires": {
|
|
45
|
-
"typescript": ">=5.2.0 <5.3.0"
|
|
46
|
-
},
|
|
47
|
-
"packages": {
|
|
48
|
-
"typescript": {
|
|
49
|
-
"version": "~5.3.2",
|
|
50
|
-
"alwaysAddToPackageJson": false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"18.0.4": {
|
|
55
|
-
"version": "18.0.4-beta.0",
|
|
56
|
-
"packages": {
|
|
57
|
-
"@swc-node/register": {
|
|
58
|
-
"version": "~1.8.0",
|
|
59
|
-
"alwaysAddToPackageJson": false
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
"18.2.0": {
|
|
64
|
-
"version": "18.2.0-beta.0",
|
|
65
|
-
"x-prompt": "Do you want to update to TypeScript v5.4?",
|
|
66
|
-
"requires": {
|
|
67
|
-
"typescript": ">=5.3.0 <5.4.0"
|
|
68
|
-
},
|
|
69
|
-
"packages": {
|
|
70
|
-
"typescript": {
|
|
71
|
-
"version": "~5.4.2",
|
|
72
|
-
"alwaysAddToPackageJson": false
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
4
|
"19.0.0": {
|
|
77
5
|
"version": "19.0.0-beta.0",
|
|
78
6
|
"packages": {
|
|
@@ -137,6 +65,24 @@
|
|
|
137
65
|
"alwaysAddToPackageJson": false
|
|
138
66
|
}
|
|
139
67
|
}
|
|
68
|
+
},
|
|
69
|
+
"20.5.0": {
|
|
70
|
+
"version": "20.5.0-beta.3",
|
|
71
|
+
"packages": {
|
|
72
|
+
"verdaccio": {
|
|
73
|
+
"version": "^6.0.5",
|
|
74
|
+
"alwaysAddToPackageJson": false
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"20.7.1-beta.0": {
|
|
79
|
+
"version": "20.7.1-beta.0",
|
|
80
|
+
"packages": {
|
|
81
|
+
"@swc/cli": {
|
|
82
|
+
"version": "~0.6.0",
|
|
83
|
+
"alwaysAddToPackageJson": false
|
|
84
|
+
}
|
|
85
|
+
}
|
|
140
86
|
}
|
|
141
87
|
}
|
|
142
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "21.0.0-beta.
|
|
3
|
+
"version": "21.0.0-beta.11",
|
|
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": "21.0.0-beta.
|
|
43
|
-
"@nx/workspace": "21.0.0-beta.
|
|
42
|
+
"@nx/devkit": "21.0.0-beta.11",
|
|
43
|
+
"@nx/workspace": "21.0.0-beta.11",
|
|
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",
|
|
@@ -52,19 +52,18 @@
|
|
|
52
52
|
"ignore": "^5.0.4",
|
|
53
53
|
"js-tokens": "^4.0.0",
|
|
54
54
|
"jsonc-parser": "3.2.0",
|
|
55
|
-
"minimatch": "9.0.3",
|
|
56
55
|
"npm-package-arg": "11.0.1",
|
|
57
56
|
"npm-run-path": "^4.0.1",
|
|
58
57
|
"ora": "5.3.0",
|
|
58
|
+
"picocolors": "^1.1.0",
|
|
59
|
+
"picomatch": "4.0.2",
|
|
59
60
|
"semver": "^7.5.3",
|
|
60
61
|
"source-map-support": "0.5.19",
|
|
61
|
-
"tinyglobby": "^0.2.
|
|
62
|
-
"ts-node": "10.9.1",
|
|
63
|
-
"tsconfig-paths": "^4.1.2",
|
|
62
|
+
"tinyglobby": "^0.2.12",
|
|
64
63
|
"tslib": "^2.3.0"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
|
-
"verdaccio": "^
|
|
66
|
+
"verdaccio": "^6.0.5"
|
|
68
67
|
},
|
|
69
68
|
"peerDependenciesMeta": {
|
|
70
69
|
"verdaccio": {
|
|
@@ -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.success) {
|
|
91
|
+
if (result && !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) {
|
|
@@ -298,7 +298,7 @@ function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
|
|
|
298
298
|
const outputFilePath = (0, utils_1.interpolate)(outputPath, {
|
|
299
299
|
projectName: project.name,
|
|
300
300
|
projectRoot: project.data.root,
|
|
301
|
-
workspaceRoot:
|
|
301
|
+
workspaceRoot: context.root,
|
|
302
302
|
});
|
|
303
303
|
return path.join(outputFilePath, 'main.js');
|
|
304
304
|
}
|
|
@@ -34,19 +34,37 @@ async function runExecutor(options, context) {
|
|
|
34
34
|
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
35
35
|
const packageName = packageJson.name;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Whether or not dynamically replacing local dependency protocols (such as "workspace:*") is supported during `nx release publish` is
|
|
38
|
+
* dependent on the package manager the user is using.
|
|
39
|
+
*
|
|
40
|
+
* npm does not support the workspace protocol at all, and `npm publish` does not support dynamically updating locally linked packages
|
|
41
|
+
* during its packing phase, so we give the user a clear error message informing them of that.
|
|
42
|
+
*
|
|
43
|
+
* - `pnpm publish` provides ideal support, it has the possibility of providing JSON output consistent with npm
|
|
44
|
+
* - `bun publish`, provides very good support, including all the flags we need apart from the JSON output, so we just have to accept that
|
|
45
|
+
* it will look and feel different and print what it gives us and perform one bit of string manipulation for the dry-run case.
|
|
46
|
+
* - `yarn npm publish`, IS NOT YET SUPPORTED, and will be tricky because it does not support the majority of the flags we need. However, it
|
|
47
|
+
* does support replacing local dependency protocols with the correct version during its packing phase.
|
|
39
48
|
*/
|
|
40
|
-
if (pm
|
|
49
|
+
if (pm === 'npm' || pm === 'yarn') {
|
|
41
50
|
const depTypes = ['dependencies', 'devDependencies', 'peerDependencies'];
|
|
42
51
|
for (const depType of depTypes) {
|
|
43
52
|
const deps = packageJson[depType];
|
|
44
53
|
if (deps) {
|
|
45
54
|
for (const depName in deps) {
|
|
46
55
|
if ((0, is_locally_linked_package_version_1.isLocallyLinkedPackageVersion)(deps[depName])) {
|
|
47
|
-
|
|
56
|
+
if (pm === 'npm') {
|
|
57
|
+
console.error(`Error: Cannot publish package "${packageName}" because it contains a local dependency protocol in its "${depType}", and your package manager is npm.
|
|
58
|
+
|
|
59
|
+
Please update the local dependency on "${depName}" to be a valid semantic version (e.g. using \`nx release\`) before publishing, or switch to pnpm or bun as a package manager, which support dynamically replacing these protocols during publishing.`);
|
|
60
|
+
}
|
|
61
|
+
else if (pm === 'yarn') {
|
|
62
|
+
console.error(`Error: Cannot publish package "${packageName}" because it contains a local dependency protocol in its "${depType}", and your package manager is yarn.
|
|
63
|
+
|
|
64
|
+
Currently, yarn is not supported for this use case because its \`yarn npm publish\` command does not support the customization needed.
|
|
48
65
|
|
|
49
|
-
Please update the local dependency on "${depName}" to be a valid semantic version (e.g. using \`nx release\`) before publishing, or switch to pnpm as a package manager, which
|
|
66
|
+
Please update the local dependency on "${depName}" to be a valid semantic version (e.g. using \`nx release\`) before publishing, or switch to pnpm or bun as a package manager, which support dynamically replacing these protocols during publishing.`);
|
|
67
|
+
}
|
|
50
68
|
return {
|
|
51
69
|
success: false,
|
|
52
70
|
};
|
|
@@ -184,10 +202,13 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
184
202
|
* JSON output under the name of the package in that case (and it would need to be handled below).
|
|
185
203
|
*/
|
|
186
204
|
const publishCommandSegments = [
|
|
187
|
-
pm === '
|
|
188
|
-
? // Unlike npm,
|
|
189
|
-
`
|
|
190
|
-
:
|
|
205
|
+
pm === 'bun'
|
|
206
|
+
? // Unlike npm, bun publish does not support a custom registryConfigKey option
|
|
207
|
+
`bun publish --cwd="${packageRoot}" --json --registry="${registry}" --tag=${tag}`
|
|
208
|
+
: pm === 'pnpm'
|
|
209
|
+
? // Unlike npm, pnpm publish does not support a custom registryConfigKey option, and will error on uncommitted changes by default if --no-git-checks is not set
|
|
210
|
+
`pnpm publish "${packageRoot}" --json --registry="${registry}" --tag=${tag} --no-git-checks`
|
|
211
|
+
: `npm publish "${packageRoot}" --json --"${registryConfigKey}=${registry}" --tag=${tag}`,
|
|
191
212
|
];
|
|
192
213
|
if (options.otp) {
|
|
193
214
|
publishCommandSegments.push(`--otp=${options.otp}`);
|
|
@@ -206,6 +227,23 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
206
227
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
207
228
|
windowsHide: false,
|
|
208
229
|
});
|
|
230
|
+
// If in dry-run mode, the version on disk will not represent the version that would be published, so we scrub it from the output to avoid confusion.
|
|
231
|
+
const dryRunVersionPlaceholder = 'X.X.X-dry-run';
|
|
232
|
+
const publishSummaryMessage = isDryRun
|
|
233
|
+
? `Would publish to ${registry} with tag "${tag}", but ${chalk.keyword('orange')('[dry-run]')} was set`
|
|
234
|
+
: `Published to ${registry} with tag "${tag}"`;
|
|
235
|
+
// bun publish does not support outputting JSON, so we need to modify and print the output string directly
|
|
236
|
+
if (pm === 'bun') {
|
|
237
|
+
let outputStr = output.toString();
|
|
238
|
+
if (isDryRun) {
|
|
239
|
+
outputStr = outputStr.replace(new RegExp(`${packageJson.name}@${packageJson.version}`, 'g'), `${packageJson.name}@${dryRunVersionPlaceholder}`);
|
|
240
|
+
}
|
|
241
|
+
console.log(outputStr);
|
|
242
|
+
console.log(publishSummaryMessage);
|
|
243
|
+
return {
|
|
244
|
+
success: true,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
209
247
|
/**
|
|
210
248
|
* We cannot JSON.parse the output directly because if the user is using lifecycle scripts, npm/pnpm will mix its publish output with the JSON output all on stdout.
|
|
211
249
|
* Additionally, we want to capture and show the lifecycle script outputs as beforeJsonData and afterJsonData and print them accordingly below.
|
|
@@ -217,8 +255,6 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
217
255
|
success: false,
|
|
218
256
|
};
|
|
219
257
|
}
|
|
220
|
-
// If in dry-run mode, the version on disk will not represent the version that would be published, so we scrub it from the output to avoid confusion.
|
|
221
|
-
const dryRunVersionPlaceholder = 'X.X.X-dry-run';
|
|
222
258
|
if (isDryRun) {
|
|
223
259
|
for (const [key, val] of Object.entries(jsonData)) {
|
|
224
260
|
if (typeof val !== 'string') {
|
|
@@ -235,18 +271,23 @@ Please update the local dependency on "${depName}" to be a valid semantic versio
|
|
|
235
271
|
if (typeof afterJsonData === 'string' && afterJsonData.trim().length > 0) {
|
|
236
272
|
console.log(afterJsonData);
|
|
237
273
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
console.log(`Published to ${registry} with tag "${tag}"`);
|
|
243
|
-
}
|
|
274
|
+
// Print the summary message after the JSON data has been printed
|
|
275
|
+
console.log(publishSummaryMessage);
|
|
244
276
|
return {
|
|
245
277
|
success: true,
|
|
246
278
|
};
|
|
247
279
|
}
|
|
248
280
|
catch (err) {
|
|
249
281
|
try {
|
|
282
|
+
// bun publish does not support outputting JSON, so we cannot perform any further processing
|
|
283
|
+
if (pm === 'bun') {
|
|
284
|
+
console.error(`bun publish error:`);
|
|
285
|
+
console.error(err.stderr?.toString() || '');
|
|
286
|
+
console.error(err.stdout?.toString() || '');
|
|
287
|
+
return {
|
|
288
|
+
success: false,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
250
291
|
const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
|
|
251
292
|
console.error(`${pm} publish error:`);
|
|
252
293
|
if (stdoutData.error?.summary) {
|
|
@@ -54,8 +54,7 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
54
54
|
schema.addPlugin ??=
|
|
55
55
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
56
56
|
nxJson.useInferencePlugins !== false;
|
|
57
|
-
schema.addTsPlugin ??=
|
|
58
|
-
schema.addPlugin && process.env.NX_ADD_TS_PLUGIN !== 'false';
|
|
57
|
+
schema.addTsPlugin ??= schema.addPlugin;
|
|
59
58
|
if (schema.addTsPlugin) {
|
|
60
59
|
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/js/typescript', plugin_1.createNodesV2, {
|
|
61
60
|
typecheck: [
|
|
@@ -8,9 +8,10 @@ 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
|
|
11
|
+
const use_legacy_versioning_1 = require("nx/src/command-line/release/config/use-legacy-versioning");
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const generator_prompts_1 = require("../../utils/generator-prompts");
|
|
14
|
+
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
14
15
|
const update_package_json_1 = require("../../utils/package-json/update-package-json");
|
|
15
16
|
const add_swc_config_1 = require("../../utils/swc/add-swc-config");
|
|
16
17
|
const add_swc_dependencies_1 = require("../../utils/swc/add-swc-dependencies");
|
|
@@ -22,9 +23,7 @@ const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
|
22
23
|
const ts_solution_setup_1 = require("../../utils/typescript/ts-solution-setup");
|
|
23
24
|
const versions_1 = require("../../utils/versions");
|
|
24
25
|
const init_1 = require("../init/init");
|
|
25
|
-
const
|
|
26
|
-
const sort_fields_1 = require("../../utils/package-json/sort-fields");
|
|
27
|
-
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, {
|
|
@@ -44,18 +43,15 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
44
43
|
formatter: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree) ? 'none' : 'prettier',
|
|
45
44
|
}));
|
|
46
45
|
const options = await normalizeOptions(tree, schema);
|
|
47
|
-
// If we are using the new TS solution
|
|
48
|
-
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
49
|
-
if (options.isUsingTsSolutionConfig) {
|
|
50
|
-
(0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
|
|
51
|
-
}
|
|
52
46
|
createFiles(tree, options);
|
|
53
47
|
await configureProject(tree, options);
|
|
54
48
|
if (!options.skipPackageJson) {
|
|
55
49
|
tasks.push(addProjectDependencies(tree, options));
|
|
56
50
|
}
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
// If we are using the new TS solution
|
|
52
|
+
// We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
|
|
53
|
+
if (options.isUsingTsSolutionConfig) {
|
|
54
|
+
await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.projectRoot);
|
|
59
55
|
}
|
|
60
56
|
if (options.bundler === 'rollup') {
|
|
61
57
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
@@ -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) {
|
|
@@ -165,9 +159,9 @@ async function libraryGeneratorInternal(tree, schema) {
|
|
|
165
159
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
166
160
|
}
|
|
167
161
|
async function configureProject(tree, options) {
|
|
162
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
168
163
|
if (options.hasPlugin) {
|
|
169
|
-
|
|
170
|
-
(0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot);
|
|
164
|
+
(0, plugin_1.ensureProjectIsIncludedInPluginRegistrations)(nxJson, options.projectRoot, options.bundler === 'none' ? null : 'build');
|
|
171
165
|
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
172
166
|
}
|
|
173
167
|
const projectConfiguration = {
|
|
@@ -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)((0, use_legacy_versioning_1.shouldUseLegacyVersioning)(nxJson.release), 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
|
|
@@ -256,9 +236,7 @@ async function configureProject(tree, options) {
|
|
|
256
236
|
}
|
|
257
237
|
}
|
|
258
238
|
// empty targets are cleaned up automatically by `updateProjectConfiguration`
|
|
259
|
-
(0, devkit_1.updateProjectConfiguration)(tree, options.
|
|
260
|
-
? options.importPath ?? options.name
|
|
261
|
-
: options.name, projectConfiguration);
|
|
239
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.name, projectConfiguration);
|
|
262
240
|
}
|
|
263
241
|
else if (options.config === 'workspace' || options.config === 'project') {
|
|
264
242
|
(0, devkit_1.addProjectConfiguration)(tree, options.name, projectConfiguration);
|
|
@@ -448,6 +426,8 @@ function createFiles(tree, options) {
|
|
|
448
426
|
};
|
|
449
427
|
if (options.isUsingTsSolutionConfig &&
|
|
450
428
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
429
|
+
// the file must exist in the TS solution setup
|
|
430
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
451
431
|
return (0, update_package_json_1.getUpdatedPackageJsonContent)(updatedPackageJson, {
|
|
452
432
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
453
433
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -456,6 +436,7 @@ function createFiles(tree, options) {
|
|
|
456
436
|
generateExportsField: true,
|
|
457
437
|
packageJsonPath,
|
|
458
438
|
format: ['esm'],
|
|
439
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
459
440
|
});
|
|
460
441
|
}
|
|
461
442
|
return updatedPackageJson;
|
|
@@ -478,6 +459,7 @@ function createFiles(tree, options) {
|
|
|
478
459
|
}
|
|
479
460
|
if (options.isUsingTsSolutionConfig &&
|
|
480
461
|
!['none', 'rollup', 'vite'].includes(options.bundler)) {
|
|
462
|
+
const tsconfigBase = (0, devkit_1.readJson)(tree, 'tsconfig.base.json');
|
|
481
463
|
packageJson = (0, update_package_json_1.getUpdatedPackageJsonContent)(packageJson, {
|
|
482
464
|
main: (0, path_1.join)(options.projectRoot, 'src/index.ts'),
|
|
483
465
|
outputPath: (0, devkit_1.joinPathFragments)(options.projectRoot, 'dist'),
|
|
@@ -486,8 +468,14 @@ function createFiles(tree, options) {
|
|
|
486
468
|
generateExportsField: true,
|
|
487
469
|
packageJsonPath,
|
|
488
470
|
format: ['esm'],
|
|
471
|
+
skipDevelopmentExports: !tsconfigBase.compilerOptions?.customConditions?.includes('development'),
|
|
489
472
|
});
|
|
490
473
|
}
|
|
474
|
+
if (!options.useProjectJson && options.name !== options.importPath) {
|
|
475
|
+
packageJson.nx = {
|
|
476
|
+
name: options.name,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
491
479
|
(0, devkit_1.writeJson)(tree, packageJsonPath, packageJson);
|
|
492
480
|
}
|
|
493
481
|
if (options.config === 'npm-scripts') {
|
|
@@ -547,7 +535,7 @@ function replaceJestConfig(tree, options) {
|
|
|
547
535
|
});
|
|
548
536
|
}
|
|
549
537
|
async function normalizeOptions(tree, options) {
|
|
550
|
-
await (0, project_name_and_root_utils_1.
|
|
538
|
+
await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
|
|
551
539
|
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
552
540
|
options.addPlugin ??=
|
|
553
541
|
process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
@@ -649,9 +637,7 @@ async function normalizeOptions(tree, options) {
|
|
|
649
637
|
return {
|
|
650
638
|
...options,
|
|
651
639
|
fileName,
|
|
652
|
-
name: isUsingTsSolutionConfig
|
|
653
|
-
? (0, get_import_path_1.getImportPath)(tree, projectName)
|
|
654
|
-
: projectName,
|
|
640
|
+
name: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
|
|
655
641
|
projectNames,
|
|
656
642
|
projectRoot,
|
|
657
643
|
parsedTags,
|
|
@@ -739,9 +725,7 @@ function createProjectTsConfigs(tree, options) {
|
|
|
739
725
|
.map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`)
|
|
740
726
|
.join(',\n '),
|
|
741
727
|
tmpl: '',
|
|
742
|
-
outDir:
|
|
743
|
-
? 'dist'
|
|
744
|
-
: `out-tsc/${options.projectRoot.split('/').pop()}`,
|
|
728
|
+
outDir: 'dist',
|
|
745
729
|
emitDeclarationOnly: options.bundler === 'tsc' ? false : true,
|
|
746
730
|
});
|
|
747
731
|
// tsconfig.json
|
|
@@ -930,96 +914,6 @@ function determineEntryFields(options) {
|
|
|
930
914
|
}
|
|
931
915
|
}
|
|
932
916
|
}
|
|
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
917
|
function findRootJestPreset(tree) {
|
|
1024
918
|
const ext = ['js', 'cjs', 'mjs'].find((ext) => tree.exists(`jest.preset.${ext}`));
|
|
1025
919
|
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(useLegacyVersioning: boolean, tree: Tree, projectName: string, projectConfiguration: ProjectConfiguration, defaultOutputDirectory?: string): Promise<ProjectConfiguration>;
|
|
11
|
+
export declare function releaseTasks(tree: Tree): Promise<GeneratorCallback>;
|