@nx/js 16.9.0-beta.0 → 16.9.0-beta.2
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/executors.json +6 -0
- package/generators.json +6 -0
- package/package.json +9 -5
- package/src/executors/release-publish/format-bytes.d.ts +1 -0
- package/src/executors/release-publish/format-bytes.js +28 -0
- package/src/executors/release-publish/log-tar.d.ts +1 -0
- package/src/executors/release-publish/log-tar.js +68 -0
- package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
- package/src/executors/release-publish/release-publish.impl.js +86 -0
- package/src/executors/release-publish/schema.d.ts +5 -0
- package/src/executors/release-publish/schema.json +22 -0
- package/src/executors/tsc/tsc.batch-impl.js +3 -2
- package/src/executors/tsc/tsc.impl.d.ts +0 -3
- package/src/executors/tsc/tsc.impl.js +4 -12
- package/src/generators/release-version/release-version.d.ts +4 -0
- package/src/generators/release-version/release-version.js +131 -0
- package/src/generators/release-version/schema.d.ts +1 -0
- package/src/generators/release-version/schema.json +45 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
- package/src/generators/release-version/utils/package.d.ts +12 -0
- package/src/generators/release-version/utils/package.js +34 -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 +68 -0
- package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
- package/src/generators/release-version/utils/resolve-version-spec.js +26 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/utils/package-json/create-entry-points.d.ts +1 -0
- package/src/utils/package-json/create-entry-points.js +23 -0
- package/src/utils/package-json/update-package-json.js +9 -4
package/executors.json
CHANGED
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"schema": "./src/executors/node/schema.json",
|
|
18
18
|
"description": "Execute a Node application."
|
|
19
19
|
},
|
|
20
|
+
"release-publish": {
|
|
21
|
+
"implementation": "./src/executors/release-publish/release-publish.impl",
|
|
22
|
+
"schema": "./src/executors/release-publish/schema.json",
|
|
23
|
+
"description": "DO NOT INVOKE DIRECTLY WITH `nx run`. Use `nx release publish` instead.",
|
|
24
|
+
"hidden": true
|
|
25
|
+
},
|
|
20
26
|
"verdaccio": {
|
|
21
27
|
"implementation": "./src/executors/verdaccio/verdaccio.impl",
|
|
22
28
|
"schema": "./src/executors/verdaccio/schema.json",
|
package/generators.json
CHANGED
|
@@ -59,6 +59,12 @@
|
|
|
59
59
|
"x-type": "library",
|
|
60
60
|
"description": "Convert a TypeScript library to compile with SWC."
|
|
61
61
|
},
|
|
62
|
+
"release-version": {
|
|
63
|
+
"factory": "./src/generators/release-version/release-version#releaseVersionGenerator",
|
|
64
|
+
"schema": "./src/generators/release-version/schema.json",
|
|
65
|
+
"description": "DO NOT INVOKE DIRECTLY WITH `nx generate`. Use `nx release version` instead.",
|
|
66
|
+
"hidden": true
|
|
67
|
+
},
|
|
62
68
|
"setup-verdaccio": {
|
|
63
69
|
"factory": "./src/generators/setup-verdaccio/generator#setupVerdaccio",
|
|
64
70
|
"schema": "./src/generators/setup-verdaccio/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "16.9.0-beta.
|
|
3
|
+
"version": "16.9.0-beta.2",
|
|
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,20 +39,24 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.22.9",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nrwl/js": "16.9.0-beta.
|
|
43
|
-
"@nx/devkit": "16.9.0-beta.
|
|
44
|
-
"@nx/workspace": "16.9.0-beta.
|
|
42
|
+
"@nrwl/js": "16.9.0-beta.2",
|
|
43
|
+
"@nx/devkit": "16.9.0-beta.2",
|
|
44
|
+
"@nx/workspace": "16.9.0-beta.2",
|
|
45
45
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
46
46
|
"babel-plugin-const-enum": "^1.0.1",
|
|
47
47
|
"babel-plugin-macros": "^2.8.0",
|
|
48
48
|
"babel-plugin-transform-typescript-metadata": "^0.3.1",
|
|
49
49
|
"chalk": "^4.1.0",
|
|
50
|
+
"columnify": "^1.6.0",
|
|
50
51
|
"detect-port": "^1.5.1",
|
|
51
52
|
"fast-glob": "3.2.7",
|
|
52
53
|
"fs-extra": "^11.1.0",
|
|
53
54
|
"ignore": "^5.0.4",
|
|
54
55
|
"js-tokens": "^4.0.0",
|
|
55
56
|
"minimatch": "3.0.5",
|
|
57
|
+
"npm-package-arg": "11.0.1",
|
|
58
|
+
"npm-run-path": "^4.0.1",
|
|
59
|
+
"ora": "5.3.0",
|
|
56
60
|
"semver": "7.5.3",
|
|
57
61
|
"source-map-support": "0.5.19",
|
|
58
62
|
"ts-node": "10.9.1",
|
|
@@ -71,5 +75,5 @@
|
|
|
71
75
|
"access": "public"
|
|
72
76
|
},
|
|
73
77
|
"type": "commonjs",
|
|
74
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "e11d538fa2c7266066d554d9405abab8e0a65040"
|
|
75
79
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatBytes: (bytes: any, space?: boolean) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Taken from https://github.com/npm/cli/blob/c736b622b8504b07f5a19f631ade42dd40063269/lib/utils/format-bytes.js
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.formatBytes = void 0;
|
|
5
|
+
// Convert bytes to printable output, for file reporting in tarballs
|
|
6
|
+
// Only supports up to GB because that's way larger than anything the registry
|
|
7
|
+
// supports anyways.
|
|
8
|
+
const formatBytes = (bytes, space = true) => {
|
|
9
|
+
let spacer = '';
|
|
10
|
+
if (space) {
|
|
11
|
+
spacer = ' ';
|
|
12
|
+
}
|
|
13
|
+
if (bytes < 1000) {
|
|
14
|
+
// B
|
|
15
|
+
return `${bytes}${spacer}B`;
|
|
16
|
+
}
|
|
17
|
+
if (bytes < 1000000) {
|
|
18
|
+
// kB
|
|
19
|
+
return `${(bytes / 1000).toFixed(1)}${spacer}kB`;
|
|
20
|
+
}
|
|
21
|
+
if (bytes < 1000000000) {
|
|
22
|
+
// MB
|
|
23
|
+
return `${(bytes / 1000000).toFixed(1)}${spacer}MB`;
|
|
24
|
+
}
|
|
25
|
+
// GB
|
|
26
|
+
return `${(bytes / 1000000000).toFixed(1)}${spacer}GB`;
|
|
27
|
+
};
|
|
28
|
+
exports.formatBytes = formatBytes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const logTar: (tarball: any, opts?: {}) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logTar = void 0;
|
|
4
|
+
// Adapted from https://github.com/npm/cli/blob/c736b622b8504b07f5a19f631ade42dd40063269/lib/utils/tar.js
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const columnify = require("columnify");
|
|
7
|
+
const format_bytes_1 = require("./format-bytes");
|
|
8
|
+
const logTar = (tarball, opts = {}) => {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const { unicode = true } = opts;
|
|
11
|
+
console.log('');
|
|
12
|
+
console.log(`${unicode ? '📦 ' : 'package:'} ${tarball.name}@${tarball.version}`);
|
|
13
|
+
console.log(chalk.magenta('=== Tarball Contents ==='));
|
|
14
|
+
if (tarball.files.length) {
|
|
15
|
+
console.log('');
|
|
16
|
+
const columnData = columnify(tarball.files
|
|
17
|
+
.map((f) => {
|
|
18
|
+
const bytes = (0, format_bytes_1.formatBytes)(f.size, false);
|
|
19
|
+
return /^node_modules\//.test(f.path)
|
|
20
|
+
? null
|
|
21
|
+
: { path: f.path, size: `${bytes}` };
|
|
22
|
+
})
|
|
23
|
+
.filter((f) => f), {
|
|
24
|
+
include: ['size', 'path'],
|
|
25
|
+
showHeaders: false,
|
|
26
|
+
});
|
|
27
|
+
columnData.split('\n').forEach((line) => {
|
|
28
|
+
console.log(line);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (tarball.bundled.length) {
|
|
32
|
+
console.log(chalk.magenta('=== Bundled Dependencies ==='));
|
|
33
|
+
tarball.bundled.forEach((name) => console.log('', name));
|
|
34
|
+
}
|
|
35
|
+
console.log(chalk.magenta('=== Tarball Details ==='));
|
|
36
|
+
console.log(columnify([
|
|
37
|
+
{ name: 'name:', value: tarball.name },
|
|
38
|
+
{ name: 'version:', value: tarball.version },
|
|
39
|
+
tarball.filename && { name: 'filename:', value: tarball.filename },
|
|
40
|
+
{ name: 'package size:', value: (0, format_bytes_1.formatBytes)(tarball.size) },
|
|
41
|
+
{ name: 'unpacked size:', value: (0, format_bytes_1.formatBytes)(tarball.unpackedSize) },
|
|
42
|
+
{ name: 'shasum:', value: tarball.shasum },
|
|
43
|
+
{
|
|
44
|
+
name: 'integrity:',
|
|
45
|
+
value: tarball.integrity.toString().slice(0, 20) +
|
|
46
|
+
'[...]' +
|
|
47
|
+
tarball.integrity.toString().slice(80),
|
|
48
|
+
},
|
|
49
|
+
tarball.bundled.length && {
|
|
50
|
+
name: 'bundled deps:',
|
|
51
|
+
value: tarball.bundled.length,
|
|
52
|
+
},
|
|
53
|
+
tarball.bundled.length && {
|
|
54
|
+
name: 'bundled files:',
|
|
55
|
+
value: tarball.entryCount - tarball.files.length,
|
|
56
|
+
},
|
|
57
|
+
tarball.bundled.length && {
|
|
58
|
+
name: 'own files:',
|
|
59
|
+
value: tarball.files.length,
|
|
60
|
+
},
|
|
61
|
+
{ name: 'total files:', value: tarball.entryCount },
|
|
62
|
+
].filter((x) => x), {
|
|
63
|
+
include: ['name', 'value'],
|
|
64
|
+
showHeaders: false,
|
|
65
|
+
}));
|
|
66
|
+
console.log('', '');
|
|
67
|
+
};
|
|
68
|
+
exports.logTar = logTar;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const devkit_1 = require("@nx/devkit");
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const npm_run_path_1 = require("npm-run-path");
|
|
6
|
+
const log_tar_1 = require("./log-tar");
|
|
7
|
+
const LARGE_BUFFER = 1024 * 1000000;
|
|
8
|
+
function processEnv(color) {
|
|
9
|
+
const env = {
|
|
10
|
+
...process.env,
|
|
11
|
+
...(0, npm_run_path_1.env)(),
|
|
12
|
+
};
|
|
13
|
+
if (color) {
|
|
14
|
+
env.FORCE_COLOR = `${color}`;
|
|
15
|
+
}
|
|
16
|
+
return env;
|
|
17
|
+
}
|
|
18
|
+
async function runExecutor(options, context) {
|
|
19
|
+
const projectConfig = context.projectsConfigurations.projects[context.projectName];
|
|
20
|
+
const packageRoot = (0, devkit_1.joinPathFragments)(context.root, options.packageRoot ?? projectConfig.root);
|
|
21
|
+
const npmPublishCommandSegments = [`npm publish --json`];
|
|
22
|
+
if (options.registry) {
|
|
23
|
+
npmPublishCommandSegments.push(`--registry=${options.registry}`);
|
|
24
|
+
}
|
|
25
|
+
if (options.tag) {
|
|
26
|
+
npmPublishCommandSegments.push(`--tag=${options.tag}`);
|
|
27
|
+
}
|
|
28
|
+
// Resolve values using the `npm config` command so that things like environment variables and `publishConfig`s are accounted for
|
|
29
|
+
const registry = options.registry ?? (0, child_process_1.execSync)(`npm config get registry`).toString().trim();
|
|
30
|
+
const tag = options.tag ?? (0, child_process_1.execSync)(`npm config get tag`).toString().trim();
|
|
31
|
+
try {
|
|
32
|
+
const output = (0, child_process_1.execSync)(npmPublishCommandSegments.join(' '), {
|
|
33
|
+
maxBuffer: LARGE_BUFFER,
|
|
34
|
+
env: processEnv(true),
|
|
35
|
+
cwd: packageRoot,
|
|
36
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
37
|
+
});
|
|
38
|
+
const stdoutData = JSON.parse(output.toString());
|
|
39
|
+
// If npm workspaces are in use, the publish output will nest the data under the package name, so we normalize it first
|
|
40
|
+
const normalizedStdoutData = stdoutData[context.projectName] ?? stdoutData;
|
|
41
|
+
(0, log_tar_1.logTar)(normalizedStdoutData);
|
|
42
|
+
console.log(`Published to ${registry} with tag "${tag}"`);
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
try {
|
|
49
|
+
const projectPackageJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(packageRoot, 'package.json'));
|
|
50
|
+
const name = projectPackageJson.name;
|
|
51
|
+
const currentVersion = projectPackageJson.version;
|
|
52
|
+
const stdoutData = JSON.parse(err.stdout?.toString() || '{}');
|
|
53
|
+
if (stdoutData.error?.code === 'EPUBLISHCONFLICT' ||
|
|
54
|
+
(stdoutData.error?.code === 'E403' &&
|
|
55
|
+
stdoutData.error?.body?.error?.includes('You cannot publish over the previously published versions'))) {
|
|
56
|
+
// If package and project name match, make it terser
|
|
57
|
+
let packageTxt = name === context.projectName
|
|
58
|
+
? `package "${name}"`
|
|
59
|
+
: `package "${name}" from project "${context.projectName}"`;
|
|
60
|
+
console.warn(`Skipping ${packageTxt}, as v${currentVersion} has already been published to ${registry} with tag "${tag}"`);
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
console.error('npm publish error:');
|
|
66
|
+
if (stdoutData.error.summary) {
|
|
67
|
+
console.error(stdoutData.error.summary);
|
|
68
|
+
}
|
|
69
|
+
if (stdoutData.error.detail) {
|
|
70
|
+
console.error(stdoutData.error.detail);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
success: false,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
// npm v9 onwards seems to guarantee stdout will be well formed JSON when --json is used, so maybe we need to
|
|
78
|
+
// specify that as minimum supported version? (comes with node 18 and 20 by default)
|
|
79
|
+
console.error('Something unexpected went wrong when processing the npm publish output\n', err);
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.default = runExecutor;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Implementation details of `nx release publish`",
|
|
5
|
+
"description": "DO NOT INVOKE DIRECTLY WITH `nx run`. Use `nx release publish` instead.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"packageRoot": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The root directory of the directory (containing a manifest file at its root) to publish. Defaults to the project root."
|
|
11
|
+
},
|
|
12
|
+
"registry": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "The registry to publish the package to."
|
|
15
|
+
},
|
|
16
|
+
"tag": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "The distribution tag to apply to the published package."
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": []
|
|
22
|
+
}
|
|
@@ -8,6 +8,7 @@ const update_package_json_1 = require("../../utils/package-json/update-package-j
|
|
|
8
8
|
const tsc_impl_1 = require("./tsc.impl");
|
|
9
9
|
const lib_1 = require("./lib");
|
|
10
10
|
const batch_1 = require("./lib/batch");
|
|
11
|
+
const create_entry_points_1 = require("../../utils/package-json/create-entry-points");
|
|
11
12
|
async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
12
13
|
const tasksOptions = (0, batch_1.normalizeTasksOptions)(inputs, context);
|
|
13
14
|
let shouldWatch = false;
|
|
@@ -48,7 +49,7 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
48
49
|
taskInfo.assetsHandler.processAllAssetsOnceSync();
|
|
49
50
|
(0, update_package_json_1.updatePackageJson)({
|
|
50
51
|
...taskInfo.options,
|
|
51
|
-
additionalEntryPoints: (0,
|
|
52
|
+
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(taskInfo.options.additionalEntryPoints, context.root),
|
|
52
53
|
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(tsConfig)],
|
|
53
54
|
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
54
55
|
// TSC can match them correctly based on file names.
|
|
@@ -72,7 +73,7 @@ async function* tscBatchExecutor(taskGraph, inputs, overrides, context) {
|
|
|
72
73
|
for (const t of changedTaskInfos) {
|
|
73
74
|
(0, update_package_json_1.updatePackageJson)({
|
|
74
75
|
...t.options,
|
|
75
|
-
additionalEntryPoints: (0,
|
|
76
|
+
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(t.options.additionalEntryPoints, context.root),
|
|
76
77
|
format: [(0, tsc_impl_1.determineModuleFormatFromTsConfig)(t.options.tsConfig)],
|
|
77
78
|
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
78
79
|
// TSC can match them correctly based on file names.
|
|
@@ -4,7 +4,4 @@ import { ExecutorOptions, NormalizedExecutorOptions } from '../../utils/schema';
|
|
|
4
4
|
export declare function determineModuleFormatFromTsConfig(absolutePathToTsConfig: string): 'cjs' | 'esm';
|
|
5
5
|
export declare function createTypeScriptCompilationOptions(normalizedOptions: NormalizedExecutorOptions, context: ExecutorContext): TypeScriptCompilationOptions;
|
|
6
6
|
export declare function tscExecutor(_options: ExecutorOptions, context: ExecutorContext): AsyncGenerator<import("../../utils/typescript/compile-typescript-files").TypescriptCompilationResult, any, undefined>;
|
|
7
|
-
export declare function createEntryPoints(options: {
|
|
8
|
-
additionalEntryPoints?: string[];
|
|
9
|
-
}, context: ExecutorContext): string[];
|
|
10
7
|
export default tscExecutor;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.tscExecutor = exports.createTypeScriptCompilationOptions = exports.determineModuleFormatFromTsConfig = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
|
-
const fast_glob_1 = require("fast-glob");
|
|
6
5
|
const copy_assets_handler_1 = require("../../utils/assets/copy-assets-handler");
|
|
7
6
|
const check_dependencies_1 = require("../../utils/check-dependencies");
|
|
8
7
|
const compiler_helper_dependency_1 = require("../../utils/compiler-helper-dependency");
|
|
@@ -12,6 +11,7 @@ const compile_typescript_files_1 = require("../../utils/typescript/compile-types
|
|
|
12
11
|
const watch_for_single_file_changes_1 = require("../../utils/watch-for-single-file-changes");
|
|
13
12
|
const lib_1 = require("./lib");
|
|
14
13
|
const ts_config_1 = require("../../utils/typescript/ts-config");
|
|
14
|
+
const create_entry_points_1 = require("../../utils/package-json/create-entry-points");
|
|
15
15
|
function determineModuleFormatFromTsConfig(absolutePathToTsConfig) {
|
|
16
16
|
const tsConfig = (0, ts_config_1.readTsConfig)(absolutePathToTsConfig);
|
|
17
17
|
if (tsConfig.options.module === ts.ModuleKind.ES2015 ||
|
|
@@ -64,7 +64,7 @@ async function* tscExecutor(_options, context) {
|
|
|
64
64
|
await assetHandler.processAllAssetsOnce();
|
|
65
65
|
(0, update_package_json_1.updatePackageJson)({
|
|
66
66
|
...options,
|
|
67
|
-
additionalEntryPoints: createEntryPoints(options, context),
|
|
67
|
+
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
|
|
68
68
|
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
|
69
69
|
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
70
70
|
// TSC can match them correctly based on file names.
|
|
@@ -76,7 +76,7 @@ async function* tscExecutor(_options, context) {
|
|
|
76
76
|
const disposeWatchAssetChanges = await assetHandler.watchAndProcessOnAssetChange();
|
|
77
77
|
const disposePackageJsonChanges = await (0, watch_for_single_file_changes_1.watchForSingleFileChanges)(context.projectName, options.projectRoot, 'package.json', () => (0, update_package_json_1.updatePackageJson)({
|
|
78
78
|
...options,
|
|
79
|
-
additionalEntryPoints: createEntryPoints(options, context),
|
|
79
|
+
additionalEntryPoints: (0, create_entry_points_1.createEntryPoints)(options.additionalEntryPoints, context.root),
|
|
80
80
|
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
|
81
81
|
// TSC can match them correctly based on file names.
|
|
82
82
|
skipTypings: true,
|
|
@@ -94,12 +94,4 @@ async function* tscExecutor(_options, context) {
|
|
|
94
94
|
return yield* typescriptCompilation.iterator;
|
|
95
95
|
}
|
|
96
96
|
exports.tscExecutor = tscExecutor;
|
|
97
|
-
function createEntryPoints(options, context) {
|
|
98
|
-
if (!options.additionalEntryPoints?.length)
|
|
99
|
-
return [];
|
|
100
|
-
return (0, fast_glob_1.sync)(options.additionalEntryPoints, {
|
|
101
|
-
cwd: context.root,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
exports.createEntryPoints = createEntryPoints;
|
|
105
97
|
exports.default = tscExecutor;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseVersionGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const version_1 = require("nx/src/command-line/release/version");
|
|
8
|
+
const utils_1 = require("nx/src/tasks-runner/utils");
|
|
9
|
+
const ora = require("ora");
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const resolve_local_package_dependencies_1 = require("./utils/resolve-local-package-dependencies");
|
|
12
|
+
async function releaseVersionGenerator(tree, options) {
|
|
13
|
+
const projects = options.projects;
|
|
14
|
+
// Resolve any custom package roots for each project upfront as they will need to be reused during dependency resolution
|
|
15
|
+
const projectNameToPackageRootMap = new Map();
|
|
16
|
+
for (const project of projects) {
|
|
17
|
+
projectNameToPackageRootMap.set(project.name,
|
|
18
|
+
// Default to the project root if no custom packageRoot
|
|
19
|
+
!options.packageRoot
|
|
20
|
+
? project.data.root
|
|
21
|
+
: (0, utils_1.interpolate)(options.packageRoot, {
|
|
22
|
+
workspaceRoot: '',
|
|
23
|
+
projectRoot: project.data.root,
|
|
24
|
+
projectName: project.name,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
let currentVersion;
|
|
28
|
+
for (const project of projects) {
|
|
29
|
+
const projectName = project.name;
|
|
30
|
+
const packageRoot = projectNameToPackageRootMap.get(projectName);
|
|
31
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
|
|
32
|
+
const workspaceRelativePackageJsonPath = (0, path_1.relative)(devkit_1.workspaceRoot, packageJsonPath);
|
|
33
|
+
const color = getColor(projectName);
|
|
34
|
+
const log = (msg) => {
|
|
35
|
+
console.log(color.instance.bold(projectName) + ' ' + msg);
|
|
36
|
+
};
|
|
37
|
+
if (!tree.exists(packageJsonPath)) {
|
|
38
|
+
throw new Error(`The project "${projectName}" does not have a package.json available at ${workspaceRelativePackageJsonPath}.
|
|
39
|
+
|
|
40
|
+
To fix this you will either need to add a package.json file at that location, or configure "release" within your nx.json to exclude "${projectName}" from the current release group, or amend the packageRoot configuration to point to where the package.json should be.`);
|
|
41
|
+
}
|
|
42
|
+
devkit_1.output.logSingleLine(`Running release version for project: ${color.instance.bold(project.name)}`);
|
|
43
|
+
const projectPackageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
|
|
44
|
+
log(`🔍 Reading data for package "${projectPackageJson.name}" from ${workspaceRelativePackageJsonPath}`);
|
|
45
|
+
const { name: packageName, version: currentVersionFromDisk } = projectPackageJson;
|
|
46
|
+
switch (options.currentVersionResolver) {
|
|
47
|
+
case 'registry': {
|
|
48
|
+
const metadata = options.currentVersionResolverMetadata;
|
|
49
|
+
const registry = metadata?.registry ?? 'https://registry.npmjs.org';
|
|
50
|
+
const tag = metadata?.tag ?? 'latest';
|
|
51
|
+
// If the currentVersionResolver is set to registry, we only want to make the request once for the whole batch of projects
|
|
52
|
+
if (!currentVersion) {
|
|
53
|
+
const spinner = ora(`${Array.from(new Array(projectName.length + 3)).join(' ')}Resolving the current version for tag "${tag}" on ${registry}`);
|
|
54
|
+
spinner.color =
|
|
55
|
+
color.spinnerColor;
|
|
56
|
+
spinner.start();
|
|
57
|
+
// Must be non-blocking async to allow spinner to render
|
|
58
|
+
currentVersion = await new Promise((resolve, reject) => {
|
|
59
|
+
(0, child_process_1.exec)(`npm view ${packageName} version --registry=${registry} --tag=${tag}`, (error, stdout, stderr) => {
|
|
60
|
+
if (error) {
|
|
61
|
+
return reject(error);
|
|
62
|
+
}
|
|
63
|
+
if (stderr) {
|
|
64
|
+
return reject(stderr);
|
|
65
|
+
}
|
|
66
|
+
return resolve(stdout.trim());
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
spinner.stop();
|
|
70
|
+
log(`📄 Resolved the current version as ${currentVersion} for tag "${tag}" from registry ${registry}`);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
log(`📄 Using the current version ${currentVersion} already resolved from the registry ${registry}`);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'disk':
|
|
78
|
+
currentVersion = currentVersionFromDisk;
|
|
79
|
+
log(`📄 Resolved the current version as ${currentVersion} from ${packageJsonPath}`);
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
throw new Error(`Invalid value for options.currentVersionResolver: ${options.currentVersionResolver}`);
|
|
83
|
+
}
|
|
84
|
+
// Resolve any local package dependencies for this project (before applying the new version)
|
|
85
|
+
const localPackageDependencies = (0, resolve_local_package_dependencies_1.resolveLocalPackageDependencies)(tree, options.projectGraph, projects, projectNameToPackageRootMap);
|
|
86
|
+
const newVersion = (0, version_1.deriveNewSemverVersion)(currentVersion, options.specifier, options.preid);
|
|
87
|
+
(0, devkit_1.writeJson)(tree, packageJsonPath, {
|
|
88
|
+
...projectPackageJson,
|
|
89
|
+
version: newVersion,
|
|
90
|
+
});
|
|
91
|
+
log(`✍️ New version ${newVersion} written to ${workspaceRelativePackageJsonPath}`);
|
|
92
|
+
const dependentProjects = Object.values(localPackageDependencies)
|
|
93
|
+
.filter((localPackageDependencies) => {
|
|
94
|
+
return localPackageDependencies.some((localPackageDependency) => localPackageDependency.target === project.name);
|
|
95
|
+
})
|
|
96
|
+
.flat();
|
|
97
|
+
if (dependentProjects.length > 0) {
|
|
98
|
+
log(`✍️ Applying new version ${newVersion} to ${dependentProjects.length} ${dependentProjects.length > 1
|
|
99
|
+
? 'packages which depend'
|
|
100
|
+
: 'package which depends'} on ${project.name}`);
|
|
101
|
+
}
|
|
102
|
+
for (const dependentProject of dependentProjects) {
|
|
103
|
+
(0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(projectNameToPackageRootMap.get(dependentProject.source), 'package.json'), (json) => {
|
|
104
|
+
json[dependentProject.dependencyCollection][packageName] = newVersion;
|
|
105
|
+
return json;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.releaseVersionGenerator = releaseVersionGenerator;
|
|
111
|
+
exports.default = releaseVersionGenerator;
|
|
112
|
+
const colors = [
|
|
113
|
+
{ instance: chalk.green, spinnerColor: 'green' },
|
|
114
|
+
{ instance: chalk.greenBright, spinnerColor: 'green' },
|
|
115
|
+
{ instance: chalk.red, spinnerColor: 'red' },
|
|
116
|
+
{ instance: chalk.redBright, spinnerColor: 'red' },
|
|
117
|
+
{ instance: chalk.cyan, spinnerColor: 'cyan' },
|
|
118
|
+
{ instance: chalk.cyanBright, spinnerColor: 'cyan' },
|
|
119
|
+
{ instance: chalk.yellow, spinnerColor: 'yellow' },
|
|
120
|
+
{ instance: chalk.yellowBright, spinnerColor: 'yellow' },
|
|
121
|
+
{ instance: chalk.magenta, spinnerColor: 'magenta' },
|
|
122
|
+
{ instance: chalk.magentaBright, spinnerColor: 'magenta' },
|
|
123
|
+
];
|
|
124
|
+
function getColor(projectName) {
|
|
125
|
+
let code = 0;
|
|
126
|
+
for (let i = 0; i < projectName.length; ++i) {
|
|
127
|
+
code += projectName.charCodeAt(i);
|
|
128
|
+
}
|
|
129
|
+
const colorIndex = code % colors.length;
|
|
130
|
+
return colors[colorIndex];
|
|
131
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ReleaseVersionGeneratorSchema } from 'nx/src/command-line/release/version';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "NxJSReleaseVersionGenerator",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Implementation details of `nx release version`",
|
|
6
|
+
"description": "DO NOT INVOKE DIRECTLY WITH `nx generate`. Use `nx release version` instead.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"projects": {
|
|
10
|
+
"type": "array",
|
|
11
|
+
"description": "The ProjectGraphProjectNodes being versioned in the current execution.",
|
|
12
|
+
"items": {
|
|
13
|
+
"type": "object"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"projectGraph": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"description": "ProjectGraph instance"
|
|
19
|
+
},
|
|
20
|
+
"specifier": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Exact version or semver keyword to apply to the selected release group. NOTE: This should be set on the release group level, not the project level."
|
|
23
|
+
},
|
|
24
|
+
"preid": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "The optional prerelease identifier to apply to the version, in the case that specifier has been set to prerelease."
|
|
27
|
+
},
|
|
28
|
+
"packageRoot": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"description": "The root directory of the directory (containing a manifest file at its root) to publish. Defaults to the project root"
|
|
31
|
+
},
|
|
32
|
+
"currentVersionResolver": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"default": "disk",
|
|
35
|
+
"description": "Which approach to use to determine the current version of the project.",
|
|
36
|
+
"enum": ["registry", "disk"]
|
|
37
|
+
},
|
|
38
|
+
"currentVersionResolverMetadata": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"description": "Additional metadata to pass to the current version resolver.",
|
|
41
|
+
"default": {}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"required": ["projects", "projectGraph", "specifier"]
|
|
45
|
+
}
|
package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ProjectGraph, Tree } from '@nx/devkit';
|
|
2
|
+
interface ProjectAndPackageData {
|
|
3
|
+
[projectName: string]: {
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
packageName: string;
|
|
6
|
+
version: string;
|
|
7
|
+
packageJsonPath: string;
|
|
8
|
+
localDependencies: {
|
|
9
|
+
projectName: string;
|
|
10
|
+
dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
11
|
+
version: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare function createWorkspaceWithPackageDependencies(tree: Tree, projectAndPackageData: ProjectAndPackageData): ProjectGraph;
|
|
16
|
+
export {};
|
package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkspaceWithPackageDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function createWorkspaceWithPackageDependencies(tree, projectAndPackageData) {
|
|
6
|
+
const projectGraph = {
|
|
7
|
+
nodes: {},
|
|
8
|
+
dependencies: {},
|
|
9
|
+
};
|
|
10
|
+
for (const [projectName, data] of Object.entries(projectAndPackageData)) {
|
|
11
|
+
const packageJsonContents = {
|
|
12
|
+
name: data.packageName,
|
|
13
|
+
version: data.version,
|
|
14
|
+
};
|
|
15
|
+
for (const dependency of data.localDependencies) {
|
|
16
|
+
const dependencyPackageName = projectAndPackageData[dependency.projectName].packageName;
|
|
17
|
+
packageJsonContents[dependency.dependencyCollection] = {
|
|
18
|
+
...packageJsonContents[dependency.dependencyCollection],
|
|
19
|
+
[dependencyPackageName]: dependency.version,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
// add the project and its nx project level dependencies to the projectGraph
|
|
23
|
+
projectGraph.nodes[projectName] = {
|
|
24
|
+
name: projectName,
|
|
25
|
+
type: 'lib',
|
|
26
|
+
data: {
|
|
27
|
+
root: data.projectRoot,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
projectGraph.dependencies[projectName] = data.localDependencies.map((dependency) => ({
|
|
31
|
+
source: projectName,
|
|
32
|
+
target: dependency.projectName,
|
|
33
|
+
type: 'static',
|
|
34
|
+
}));
|
|
35
|
+
// create the package.json in the tree
|
|
36
|
+
(0, devkit_1.writeJson)(tree, data.packageJsonPath, packageJsonContents);
|
|
37
|
+
}
|
|
38
|
+
return projectGraph;
|
|
39
|
+
}
|
|
40
|
+
exports.createWorkspaceWithPackageDependencies = createWorkspaceWithPackageDependencies;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PackageJson } from 'nx/src/utils/package-json';
|
|
2
|
+
export declare class Package {
|
|
3
|
+
private packageJson;
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
location: string;
|
|
7
|
+
constructor(packageJson: PackageJson, workspaceRoot: string, workspaceRelativeLocation: string);
|
|
8
|
+
getLocalDependency(depName: string): {
|
|
9
|
+
collection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
10
|
+
spec: string;
|
|
11
|
+
} | null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Package = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
class Package {
|
|
6
|
+
constructor(packageJson, workspaceRoot, workspaceRelativeLocation) {
|
|
7
|
+
this.packageJson = packageJson;
|
|
8
|
+
this.name = packageJson.name;
|
|
9
|
+
this.version = packageJson.version;
|
|
10
|
+
this.location = (0, devkit_1.joinPathFragments)(workspaceRoot, workspaceRelativeLocation);
|
|
11
|
+
}
|
|
12
|
+
getLocalDependency(depName) {
|
|
13
|
+
if (this.packageJson.dependencies?.[depName]) {
|
|
14
|
+
return {
|
|
15
|
+
collection: 'dependencies',
|
|
16
|
+
spec: this.packageJson.dependencies[depName],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (this.packageJson.devDependencies?.[depName]) {
|
|
20
|
+
return {
|
|
21
|
+
collection: 'devDependencies',
|
|
22
|
+
spec: this.packageJson.devDependencies[depName],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
if (this.packageJson.optionalDependencies?.[depName]) {
|
|
26
|
+
return {
|
|
27
|
+
collection: 'optionalDependencies',
|
|
28
|
+
spec: this.packageJson.optionalDependencies[depName],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Package = Package;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProjectGraph, ProjectGraphDependency, ProjectGraphProjectNode, Tree } from '@nx/devkit';
|
|
2
|
+
interface LocalPackageDependency extends ProjectGraphDependency {
|
|
3
|
+
dependencyCollection: 'dependencies' | 'devDependencies' | 'optionalDependencies';
|
|
4
|
+
}
|
|
5
|
+
export declare function resolveLocalPackageDependencies(tree: Tree, projectGraph: ProjectGraph, projects: ProjectGraphProjectNode[], projectNameToPackageRootMap: Map<string, string>): Record<string, LocalPackageDependency[]>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLocalPackageDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const semver_1 = require("semver");
|
|
6
|
+
const package_1 = require("./package");
|
|
7
|
+
const resolve_version_spec_1 = require("./resolve-version-spec");
|
|
8
|
+
function resolveLocalPackageDependencies(tree, projectGraph, projects, projectNameToPackageRootMap) {
|
|
9
|
+
const localPackageDependencies = {};
|
|
10
|
+
const projectNodeToPackageMap = new Map();
|
|
11
|
+
// Iterate through the projects being released and resolve any relevant package.json data
|
|
12
|
+
for (const projectNode of projects) {
|
|
13
|
+
// Resolve the package.json path for the project, taking into account any custom packageRoot settings
|
|
14
|
+
const packageRoot = projectNameToPackageRootMap.get(projectNode.name);
|
|
15
|
+
if (!packageRoot) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
|
|
19
|
+
if (!tree.exists(packageJsonPath)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const packageJson = (0, devkit_1.readJson)(tree, packageJsonPath);
|
|
23
|
+
const pkg = new package_1.Package(packageJson, devkit_1.workspaceRoot, packageRoot);
|
|
24
|
+
projectNodeToPackageMap.set(projectNode, pkg);
|
|
25
|
+
}
|
|
26
|
+
// populate local npm package dependencies
|
|
27
|
+
for (const projectDeps of Object.values(projectGraph.dependencies)) {
|
|
28
|
+
const workspaceDeps = projectDeps.filter((dep) => !isExternalNpmDependency(dep.target) &&
|
|
29
|
+
!isExternalNpmDependency(dep.source));
|
|
30
|
+
for (const dep of workspaceDeps) {
|
|
31
|
+
const source = projectGraph.nodes[dep.source];
|
|
32
|
+
const target = projectGraph.nodes[dep.target];
|
|
33
|
+
if (!source ||
|
|
34
|
+
!projectNodeToPackageMap.has(source) ||
|
|
35
|
+
!target ||
|
|
36
|
+
!projectNodeToPackageMap.has(target)) {
|
|
37
|
+
// only relevant for dependencies between two workspace projects with Package objects
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const sourcePackage = projectNodeToPackageMap.get(source);
|
|
41
|
+
const targetPackage = projectNodeToPackageMap.get(target);
|
|
42
|
+
const sourceNpmDependency = sourcePackage.getLocalDependency(targetPackage.name);
|
|
43
|
+
if (!sourceNpmDependency) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const targetVersionSpec = (0, resolve_version_spec_1.resolveVersionSpec)(targetPackage.name, targetPackage.version, sourceNpmDependency.spec, sourcePackage.location);
|
|
47
|
+
const targetMatchesRequirement =
|
|
48
|
+
// For file: and workspace: protocols the targetVersionSpec could be a path, so we check if it matches the target's location
|
|
49
|
+
targetVersionSpec === targetPackage.location ||
|
|
50
|
+
(0, semver_1.satisfies)(targetPackage.version, targetVersionSpec);
|
|
51
|
+
if (targetMatchesRequirement) {
|
|
52
|
+
// track only local package dependencies that are satisfied by the target's version
|
|
53
|
+
localPackageDependencies[dep.source] = [
|
|
54
|
+
...(localPackageDependencies[dep.source] || []),
|
|
55
|
+
{
|
|
56
|
+
...dep,
|
|
57
|
+
dependencyCollection: sourceNpmDependency.collection,
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return localPackageDependencies;
|
|
64
|
+
}
|
|
65
|
+
exports.resolveLocalPackageDependencies = resolveLocalPackageDependencies;
|
|
66
|
+
function isExternalNpmDependency(dep) {
|
|
67
|
+
return dep.startsWith('npm:');
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveVersionSpec(name: string, version: string, spec: string, location?: string): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveVersionSpec = void 0;
|
|
4
|
+
const npa = require("npm-package-arg");
|
|
5
|
+
function resolveVersionSpec(name, version, spec, location) {
|
|
6
|
+
// yarn classic uses link instead of file, normalize to match what npm expects
|
|
7
|
+
spec = spec.replace(/^link:/, 'file:');
|
|
8
|
+
// Support workspace: protocol for pnpm and yarn 2+ (https://pnpm.io/workspaces#workspace-protocol-workspace)
|
|
9
|
+
const isWorkspaceSpec = /^workspace:/.test(spec);
|
|
10
|
+
if (isWorkspaceSpec) {
|
|
11
|
+
spec = spec.replace(/^workspace:/, '');
|
|
12
|
+
// replace aliases (https://pnpm.io/workspaces#referencing-workspace-packages-through-aliases)
|
|
13
|
+
if (spec === '*' || spec === '^' || spec === '~') {
|
|
14
|
+
if (version) {
|
|
15
|
+
const prefix = spec === '*' ? '' : spec;
|
|
16
|
+
spec = `${prefix}${version}`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
spec = '*';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const npaResult = npa.resolve(name, spec, location);
|
|
24
|
+
return npaResult.fetchSpec;
|
|
25
|
+
}
|
|
26
|
+
exports.resolveVersionSpec = resolveVersionSpec;
|
package/src/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './utils/typescript/ast-utils';
|
|
|
10
10
|
export * from './utils/package-json';
|
|
11
11
|
export * from './utils/assets';
|
|
12
12
|
export * from './utils/package-json/update-package-json';
|
|
13
|
+
export * from './utils/package-json/create-entry-points';
|
|
13
14
|
export { libraryGenerator } from './generators/library/library';
|
|
14
15
|
export { initGenerator } from './generators/init/init';
|
|
15
16
|
export { createLockFile, getLockFileName, } from 'nx/src/plugins/js/lock-file/lock-file';
|
package/src/index.js
CHANGED
|
@@ -14,6 +14,7 @@ tslib_1.__exportStar(require("./utils/typescript/ast-utils"), exports);
|
|
|
14
14
|
tslib_1.__exportStar(require("./utils/package-json"), exports);
|
|
15
15
|
tslib_1.__exportStar(require("./utils/assets"), exports);
|
|
16
16
|
tslib_1.__exportStar(require("./utils/package-json/update-package-json"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./utils/package-json/create-entry-points"), exports);
|
|
17
18
|
var library_1 = require("./generators/library/library");
|
|
18
19
|
Object.defineProperty(exports, "libraryGenerator", { enumerable: true, get: function () { return library_1.libraryGenerator; } });
|
|
19
20
|
var init_1 = require("./generators/init/init");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createEntryPoints(additionalEntryPoints: undefined | string[], root: string): string[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEntryPoints = void 0;
|
|
4
|
+
const fast_glob_1 = require("fast-glob");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
function createEntryPoints(additionalEntryPoints, root) {
|
|
7
|
+
if (!additionalEntryPoints?.length)
|
|
8
|
+
return [];
|
|
9
|
+
const files = [];
|
|
10
|
+
// NOTE: calling globSync for each pattern is slower than calling it all at once.
|
|
11
|
+
// We're doing it this way in order to show a warning for unmatched patterns.
|
|
12
|
+
// If a pattern is unmatched, it is very likely a mistake by the user.
|
|
13
|
+
// Performance impact should be negligible since there shouldn't be that many entry points.
|
|
14
|
+
// Benchmarks show only 1-3% difference in execution time.
|
|
15
|
+
for (const pattern of additionalEntryPoints) {
|
|
16
|
+
const matched = (0, fast_glob_1.sync)([pattern], { cwd: root });
|
|
17
|
+
if (!matched.length)
|
|
18
|
+
devkit_1.logger.warn(`The pattern ${pattern} did not match any files.`);
|
|
19
|
+
files.push(...matched);
|
|
20
|
+
}
|
|
21
|
+
return files;
|
|
22
|
+
}
|
|
23
|
+
exports.createEntryPoints = createEntryPoints;
|
|
@@ -8,7 +8,6 @@ const create_package_json_1 = require("nx/src/plugins/js/package-json/create-pac
|
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const fs_extra_1 = require("fs-extra");
|
|
11
|
-
const operators_1 = require("nx/src/project-graph/operators");
|
|
12
11
|
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
13
12
|
const fs_1 = require("fs");
|
|
14
13
|
const nx_deps_cache_1 = require("nx/src/project-graph/nx-deps-cache");
|
|
@@ -49,10 +48,16 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
exports.updatePackageJson = updatePackageJson;
|
|
52
|
-
function
|
|
51
|
+
function isNpmNode(node, graph) {
|
|
52
|
+
return !!(graph.externalNodes[node.name]?.type === 'npm');
|
|
53
|
+
}
|
|
54
|
+
function isWorkspaceProject(node, graph) {
|
|
55
|
+
return !!graph.nodes[node.name];
|
|
56
|
+
}
|
|
57
|
+
function addMissingDependencies(packageJson, { projectName, targetName, configurationName, root, projectGraph, }, dependencies, propType = 'dependencies') {
|
|
53
58
|
const workspacePackageJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json'));
|
|
54
59
|
dependencies.forEach((entry) => {
|
|
55
|
-
if ((
|
|
60
|
+
if (isNpmNode(entry.node, projectGraph)) {
|
|
56
61
|
const { packageName, version } = entry.node.data;
|
|
57
62
|
if (packageJson.dependencies?.[packageName] ||
|
|
58
63
|
packageJson.devDependencies?.[packageName] ||
|
|
@@ -65,7 +70,7 @@ function addMissingDependencies(packageJson, { projectName, targetName, configur
|
|
|
65
70
|
packageJson[propType] ??= {};
|
|
66
71
|
packageJson[propType][packageName] = version;
|
|
67
72
|
}
|
|
68
|
-
else {
|
|
73
|
+
else if (isWorkspaceProject(entry.node, projectGraph)) {
|
|
69
74
|
const packageName = entry.name;
|
|
70
75
|
if (!!workspacePackageJson.devDependencies?.[packageName]) {
|
|
71
76
|
return;
|