@nx/js 21.0.0-beta.1 → 21.0.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/migrations.json +18 -0
- 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/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 +16 -14
- 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/plugins/jest/start-local-registry.js +6 -2
- package/src/plugins/typescript/plugin.js +433 -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 +189 -0
- 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/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/utils/typescript/tsnode-register.d.ts +0 -1
- package/src/utils/typescript/tsnode-register.js +0 -23
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { type TargetConfiguration } from '@nx/devkit';
|
|
2
2
|
import { type PackageManagerCommands } from 'nx/src/utils/package-manager';
|
|
3
|
+
import { type ParsedCommandLine } from 'typescript';
|
|
4
|
+
export type ExtendedConfigFile = {
|
|
5
|
+
filePath: string;
|
|
6
|
+
externalPackage?: string;
|
|
7
|
+
};
|
|
8
|
+
export type ParsedTsconfigData = Pick<ParsedCommandLine, 'options' | 'projectReferences' | 'raw'> & {
|
|
9
|
+
extendedConfigFiles: ExtendedConfigFile[];
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
5
13
|
*/
|
|
@@ -7,3 +15,4 @@ export declare function addBuildAndWatchDepsTargets(workspaceRoot: string, proje
|
|
|
7
15
|
buildDepsTargetName?: string;
|
|
8
16
|
watchDepsTargetName?: string;
|
|
9
17
|
}, pmc: PackageManagerCommands): void;
|
|
18
|
+
export declare function isValidPackageJsonBuildConfig(tsConfig: ParsedTsconfigData, workspaceRoot: string, projectRoot: string): boolean;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addBuildAndWatchDepsTargets = addBuildAndWatchDepsTargets;
|
|
4
|
+
exports.isValidPackageJsonBuildConfig = isValidPackageJsonBuildConfig;
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const node_fs_1 = require("node:fs");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
6
8
|
const path_1 = require("path");
|
|
7
9
|
/**
|
|
8
10
|
* Allow uses that use incremental builds to run `nx watch-deps` to continuously build all dependencies.
|
|
@@ -27,8 +29,80 @@ function addBuildAndWatchDepsTargets(workspaceRoot, projectRoot, targets, option
|
|
|
27
29
|
dependsOn: ['^build'],
|
|
28
30
|
};
|
|
29
31
|
targets[options.watchDepsTargetName ?? 'watch-deps'] = {
|
|
32
|
+
continuous: true,
|
|
30
33
|
dependsOn: [buildDepsTargetName],
|
|
31
34
|
command: `${pmc.exec} nx watch --projects ${projectName} --includeDependentProjects -- ${pmc.exec} nx ${buildDepsTargetName} ${projectName}`,
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
}
|
|
38
|
+
function isValidPackageJsonBuildConfig(tsConfig, workspaceRoot, projectRoot) {
|
|
39
|
+
const resolvedProjectPath = (0, node_path_1.isAbsolute)(projectRoot)
|
|
40
|
+
? (0, node_path_1.relative)(workspaceRoot, projectRoot)
|
|
41
|
+
: projectRoot;
|
|
42
|
+
const packageJsonPath = (0, path_1.join)(workspaceRoot, resolvedProjectPath, 'package.json');
|
|
43
|
+
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
44
|
+
// If the package.json file does not exist.
|
|
45
|
+
// Assume it's valid because it would be using `project.json` instead.
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
49
|
+
const outDir = tsConfig.options.outFile
|
|
50
|
+
? (0, node_path_1.dirname)(tsConfig.options.outFile)
|
|
51
|
+
: tsConfig.options.outDir;
|
|
52
|
+
const resolvedOutDir = outDir
|
|
53
|
+
? (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, outDir)
|
|
54
|
+
: undefined;
|
|
55
|
+
const isPathSourceFile = (path) => {
|
|
56
|
+
if (resolvedOutDir) {
|
|
57
|
+
const pathToCheck = (0, node_path_1.resolve)(workspaceRoot, resolvedProjectPath, path);
|
|
58
|
+
return !pathToCheck.startsWith(resolvedOutDir);
|
|
59
|
+
}
|
|
60
|
+
const ext = (0, node_path_1.extname)(path);
|
|
61
|
+
// Check that the file extension is a TS file extension. As the source files are in the same directory as the output files.
|
|
62
|
+
return ['.ts', '.tsx', '.cts', '.mts'].includes(ext);
|
|
63
|
+
};
|
|
64
|
+
// Checks if the value is a path within the `src` directory.
|
|
65
|
+
const containsInvalidPath = (value) => {
|
|
66
|
+
if (typeof value === 'string') {
|
|
67
|
+
return isPathSourceFile(value);
|
|
68
|
+
}
|
|
69
|
+
else if (typeof value === 'object') {
|
|
70
|
+
return Object.entries(value).some(([currentKey, subValue]) => {
|
|
71
|
+
// Skip types and development conditions
|
|
72
|
+
if (currentKey === 'types' || currentKey === 'development') {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (typeof subValue === 'string') {
|
|
76
|
+
return isPathSourceFile(subValue);
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
};
|
|
83
|
+
const exports = packageJson?.exports;
|
|
84
|
+
// Check the `.` export if `exports` is defined.
|
|
85
|
+
if (exports) {
|
|
86
|
+
if (typeof exports === 'string') {
|
|
87
|
+
return !isPathSourceFile(exports);
|
|
88
|
+
}
|
|
89
|
+
if (typeof exports === 'object' && '.' in exports) {
|
|
90
|
+
return !containsInvalidPath(exports['.']);
|
|
91
|
+
}
|
|
92
|
+
// Check other exports if `.` is not defined or valid.
|
|
93
|
+
for (const key in exports) {
|
|
94
|
+
if (key !== '.' && containsInvalidPath(exports[key])) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
// If `exports` is not defined, fallback to `main` and `module` fields.
|
|
101
|
+
const buildPaths = ['main', 'module'];
|
|
102
|
+
for (const field of buildPaths) {
|
|
103
|
+
if (packageJson[field] && isPathSourceFile(packageJson[field])) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function updateLockFile(cwd: string, { dryRun, verbose, useLegacyVersioning, options, }: {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
verbose?: boolean;
|
|
4
|
+
useLegacyVersioning?: boolean;
|
|
5
|
+
options?: {
|
|
6
|
+
skipLockFileUpdate?: boolean;
|
|
7
|
+
installArgs?: string;
|
|
8
|
+
installIgnoreScripts?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}): Promise<string[]>;
|
|
@@ -7,8 +7,8 @@ const client_1 = require("nx/src/daemon/client/client");
|
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
8
8
|
const lock_file_1 = require("nx/src/plugins/js/lock-file/lock-file");
|
|
9
9
|
const semver_1 = require("semver");
|
|
10
|
-
async function updateLockFile(cwd, { dryRun, verbose,
|
|
11
|
-
if (
|
|
10
|
+
async function updateLockFile(cwd, { dryRun, verbose, useLegacyVersioning, options, }) {
|
|
11
|
+
if (options?.skipLockFileUpdate) {
|
|
12
12
|
if (verbose) {
|
|
13
13
|
console.log('\nSkipped lock file update because skipLockFileUpdate was set.');
|
|
14
14
|
}
|
|
@@ -36,10 +36,10 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
36
36
|
await client_1.daemonClient.stop();
|
|
37
37
|
}
|
|
38
38
|
const packageManagerCommands = (0, devkit_1.getPackageManagerCommand)(packageManager);
|
|
39
|
-
let installArgs =
|
|
39
|
+
let installArgs = options?.installArgs || '';
|
|
40
40
|
devkit_1.output.logSingleLine(`Updating ${packageManager} lock file`);
|
|
41
41
|
let env = {};
|
|
42
|
-
if (
|
|
42
|
+
if (options?.installIgnoreScripts) {
|
|
43
43
|
if (packageManager === 'yarn') {
|
|
44
44
|
env = { YARN_ENABLE_SCRIPTS: 'false' };
|
|
45
45
|
}
|
|
@@ -62,7 +62,7 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
62
62
|
if (dryRun) {
|
|
63
63
|
return [];
|
|
64
64
|
}
|
|
65
|
-
execLockFileUpdate(command, cwd, env);
|
|
65
|
+
execLockFileUpdate(command, cwd, env, useLegacyVersioning);
|
|
66
66
|
if (isDaemonEnabled) {
|
|
67
67
|
try {
|
|
68
68
|
await client_1.daemonClient.startInBackground();
|
|
@@ -79,7 +79,7 @@ async function updateLockFile(cwd, { dryRun, verbose, generatorOptions, }) {
|
|
|
79
79
|
}
|
|
80
80
|
return [lockFile];
|
|
81
81
|
}
|
|
82
|
-
function execLockFileUpdate(command, cwd, env
|
|
82
|
+
function execLockFileUpdate(command, cwd, env, useLegacyVersioning) {
|
|
83
83
|
try {
|
|
84
84
|
const LARGE_BUFFER = 1024 * 1000000;
|
|
85
85
|
(0, child_process_1.execSync)(command, {
|
|
@@ -93,13 +93,16 @@ function execLockFileUpdate(command, cwd, env = {}) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
catch (e) {
|
|
96
|
+
const configPathStart = useLegacyVersioning
|
|
97
|
+
? 'release.version.generatorOptions'
|
|
98
|
+
: 'release.version.versionActionsOptions';
|
|
96
99
|
devkit_1.output.error({
|
|
97
100
|
title: `Error updating lock file with command '${command}'`,
|
|
98
101
|
bodyLines: [
|
|
99
102
|
`Verify that '${command}' succeeds when run from the workspace root.`,
|
|
100
|
-
`To configure a string of arguments to be passed to this command, set the '
|
|
101
|
-
`To ignore install lifecycle scripts, set '
|
|
102
|
-
`To disable this step entirely, set '
|
|
103
|
+
`To configure a string of arguments to be passed to this command, set the '${configPathStart}.installArgs' property in nx.json.`,
|
|
104
|
+
`To ignore install lifecycle scripts, set '${configPathStart}.installIgnoreScripts' to true in nx.json.`,
|
|
105
|
+
`To disable this step entirely, set '${configPathStart}.skipLockFileUpdate' to true in nx.json.`,
|
|
103
106
|
],
|
|
104
107
|
});
|
|
105
108
|
throw e;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ProjectGraph, Tree } from '@nx/devkit';
|
|
2
|
+
import { AfterAllProjectsVersioned, VersionActions } from 'nx/release';
|
|
3
|
+
import type { NxReleaseVersionV2Configuration } from 'nx/src/config/nx-json';
|
|
4
|
+
export declare const afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
5
|
+
export default class JsVersionActions extends VersionActions {
|
|
6
|
+
validManifestFilenames: string[];
|
|
7
|
+
readCurrentVersionFromSourceManifest(tree: Tree): Promise<{
|
|
8
|
+
currentVersion: string;
|
|
9
|
+
manifestPath: string;
|
|
10
|
+
}>;
|
|
11
|
+
readCurrentVersionFromRegistry(tree: Tree, currentVersionResolverMetadata: NxReleaseVersionV2Configuration['currentVersionResolverMetadata']): Promise<{
|
|
12
|
+
currentVersion: string;
|
|
13
|
+
logText: string;
|
|
14
|
+
}>;
|
|
15
|
+
readCurrentVersionOfDependency(tree: Tree, projectGraph: ProjectGraph, dependencyProjectName: string): Promise<{
|
|
16
|
+
currentVersion: string | null;
|
|
17
|
+
dependencyCollection: string | null;
|
|
18
|
+
}>;
|
|
19
|
+
isLocalDependencyProtocol(versionSpecifier: string): Promise<boolean>;
|
|
20
|
+
updateProjectVersion(tree: Tree, newVersion: string): Promise<string[]>;
|
|
21
|
+
updateProjectDependencies(tree: Tree, projectGraph: ProjectGraph, dependenciesToUpdate: Record<string, string>): Promise<string[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.afterAllProjectsVersioned = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const release_1 = require("nx/release");
|
|
8
|
+
const npm_config_1 = require("../utils/npm-config");
|
|
9
|
+
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
10
|
+
const chalk = require("chalk");
|
|
11
|
+
const afterAllProjectsVersioned = async (cwd, opts) => {
|
|
12
|
+
return {
|
|
13
|
+
changedFiles: await (0, update_lock_file_1.updateLockFile)(cwd, {
|
|
14
|
+
...opts,
|
|
15
|
+
useLegacyVersioning: false,
|
|
16
|
+
}),
|
|
17
|
+
deletedFiles: [],
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
21
|
+
// Cache at the module level to avoid re-detecting the package manager for each instance
|
|
22
|
+
let pm;
|
|
23
|
+
class JsVersionActions extends release_1.VersionActions {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.validManifestFilenames = ['package.json'];
|
|
27
|
+
}
|
|
28
|
+
async readCurrentVersionFromSourceManifest(tree) {
|
|
29
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
30
|
+
try {
|
|
31
|
+
const packageJson = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
32
|
+
return {
|
|
33
|
+
manifestPath: sourcePackageJsonPath,
|
|
34
|
+
currentVersion: packageJson.version,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`Unable to determine the current version for project "${this.projectGraphNode.name}" from ${sourcePackageJsonPath}, please ensure that the "version" field is set within the package.json file`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async readCurrentVersionFromRegistry(tree, currentVersionResolverMetadata) {
|
|
42
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
43
|
+
const packageJson = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
44
|
+
const packageName = packageJson.name;
|
|
45
|
+
const metadata = currentVersionResolverMetadata;
|
|
46
|
+
const registryArg = typeof metadata?.registry === 'string' ? metadata.registry : undefined;
|
|
47
|
+
const tagArg = typeof metadata?.tag === 'string' ? metadata.tag : undefined;
|
|
48
|
+
const warnFn = (message) => {
|
|
49
|
+
console.log(chalk.keyword('orange')(message));
|
|
50
|
+
};
|
|
51
|
+
const { registry, tag, registryConfigKey } = await (0, npm_config_1.parseRegistryOptions)(devkit_1.workspaceRoot, {
|
|
52
|
+
packageRoot: this.projectGraphNode.data.root,
|
|
53
|
+
packageJson,
|
|
54
|
+
}, {
|
|
55
|
+
registry: registryArg,
|
|
56
|
+
tag: tagArg,
|
|
57
|
+
}, warnFn);
|
|
58
|
+
let currentVersion = null;
|
|
59
|
+
try {
|
|
60
|
+
// Must be non-blocking async to allow spinner to render
|
|
61
|
+
currentVersion = await new Promise((resolve, reject) => {
|
|
62
|
+
(0, node_child_process_1.exec)(`npm view ${packageName} version --"${registryConfigKey}=${registry}" --tag=${tag}`, {
|
|
63
|
+
windowsHide: false,
|
|
64
|
+
}, (error, stdout, stderr) => {
|
|
65
|
+
if (error) {
|
|
66
|
+
return reject(error);
|
|
67
|
+
}
|
|
68
|
+
if (stderr) {
|
|
69
|
+
return reject(stderr);
|
|
70
|
+
}
|
|
71
|
+
return resolve(stdout.trim());
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
catch { }
|
|
76
|
+
return {
|
|
77
|
+
currentVersion,
|
|
78
|
+
// Make troubleshooting easier by including the registry and tag data in the log text
|
|
79
|
+
logText: `"${registryConfigKey}=${registry}" tag=${tag}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async readCurrentVersionOfDependency(tree, projectGraph, dependencyProjectName) {
|
|
83
|
+
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
84
|
+
const json = (0, devkit_1.readJson)(tree, sourcePackageJsonPath);
|
|
85
|
+
// Resolve the package name from the project graph metadata, as it may not match the project name
|
|
86
|
+
const dependencyPackageName = projectGraph.nodes[dependencyProjectName].data.metadata?.js?.packageName;
|
|
87
|
+
const dependencyTypes = [
|
|
88
|
+
'dependencies',
|
|
89
|
+
'devDependencies',
|
|
90
|
+
'peerDependencies',
|
|
91
|
+
'optionalDependencies',
|
|
92
|
+
];
|
|
93
|
+
let currentVersion = null;
|
|
94
|
+
let dependencyCollection = null;
|
|
95
|
+
for (const depType of dependencyTypes) {
|
|
96
|
+
if (json[depType] && json[depType][dependencyPackageName]) {
|
|
97
|
+
currentVersion = json[depType][dependencyPackageName];
|
|
98
|
+
dependencyCollection = depType;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
currentVersion,
|
|
104
|
+
dependencyCollection,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// NOTE: The TODOs were carried over from the original implementation, they are not yet implemented
|
|
108
|
+
async isLocalDependencyProtocol(versionSpecifier) {
|
|
109
|
+
const localPackageProtocols = [
|
|
110
|
+
'file:', // all package managers
|
|
111
|
+
'workspace:', // not npm
|
|
112
|
+
// TODO: Support portal protocol at the project graph level before enabling here
|
|
113
|
+
// 'portal:', // modern yarn only
|
|
114
|
+
];
|
|
115
|
+
// Not using a supported local protocol
|
|
116
|
+
if (!localPackageProtocols.some((protocol) => versionSpecifier.startsWith(protocol))) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
// Supported by all package managers
|
|
120
|
+
if (versionSpecifier.startsWith('file:')) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
// Determine specific package manager in use
|
|
124
|
+
if (!pm) {
|
|
125
|
+
pm = (0, devkit_1.detectPackageManager)();
|
|
126
|
+
// pmVersion = getPackageManagerVersion(pm);
|
|
127
|
+
}
|
|
128
|
+
if (pm === 'npm' && versionSpecifier.startsWith('workspace:')) {
|
|
129
|
+
throw new Error(`The "workspace:" protocol is not yet supported by npm (https://github.com/npm/rfcs/issues/765). Please ensure you have a valid setup according to your package manager before attempting to release packages.`);
|
|
130
|
+
}
|
|
131
|
+
// TODO: Support portal protocol at the project graph level before enabling here
|
|
132
|
+
// if (
|
|
133
|
+
// version.startsWith('portal:') &&
|
|
134
|
+
// (pm !== 'yarn' || lt(pmVersion, '2.0.0'))
|
|
135
|
+
// ) {
|
|
136
|
+
// throw new Error(
|
|
137
|
+
// `The "portal:" protocol is only supported by yarn@2.0.0 and above. Please ensure you have a valid setup according to your package manager before attempting to release packages.`
|
|
138
|
+
// );
|
|
139
|
+
// }
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
async updateProjectVersion(tree, newVersion) {
|
|
143
|
+
const logMessages = [];
|
|
144
|
+
for (const manifestPath of this.manifestsToUpdate) {
|
|
145
|
+
(0, devkit_1.updateJson)(tree, manifestPath, (json) => {
|
|
146
|
+
json.version = newVersion;
|
|
147
|
+
return json;
|
|
148
|
+
});
|
|
149
|
+
logMessages.push(`✍️ New version ${newVersion} written to manifest: ${manifestPath}`);
|
|
150
|
+
}
|
|
151
|
+
return logMessages;
|
|
152
|
+
}
|
|
153
|
+
async updateProjectDependencies(tree, projectGraph, dependenciesToUpdate) {
|
|
154
|
+
const numDependenciesToUpdate = Object.keys(dependenciesToUpdate).length;
|
|
155
|
+
const depText = numDependenciesToUpdate === 1 ? 'dependency' : 'dependencies';
|
|
156
|
+
if (numDependenciesToUpdate === 0) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
const logMessages = [];
|
|
160
|
+
for (const manifestPath of this.manifestsToUpdate) {
|
|
161
|
+
(0, devkit_1.updateJson)(tree, manifestPath, (json) => {
|
|
162
|
+
const dependencyTypes = [
|
|
163
|
+
'dependencies',
|
|
164
|
+
'devDependencies',
|
|
165
|
+
'peerDependencies',
|
|
166
|
+
'optionalDependencies',
|
|
167
|
+
];
|
|
168
|
+
for (const depType of dependencyTypes) {
|
|
169
|
+
if (json[depType]) {
|
|
170
|
+
for (const [dep, version] of Object.entries(dependenciesToUpdate)) {
|
|
171
|
+
// Resolve the package name from the project graph metadata, as it may not match the project name
|
|
172
|
+
const packageName = projectGraph.nodes[dep].data.metadata?.js?.packageName;
|
|
173
|
+
if (!packageName) {
|
|
174
|
+
throw new Error(`Unable to determine the package name for project "${dep}" from the project graph metadata, please ensure that the "@nx/js" plugin is installed and the project graph has been built. If the issue persists, please report this issue on https://github.com/nrwl/nx/issues`);
|
|
175
|
+
}
|
|
176
|
+
if (json[depType][packageName]) {
|
|
177
|
+
json[depType][packageName] = version;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return json;
|
|
183
|
+
});
|
|
184
|
+
logMessages.push(`✍️ Updated ${numDependenciesToUpdate} ${depText} in manifest: ${manifestPath}`);
|
|
185
|
+
}
|
|
186
|
+
return logMessages;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.default = JsVersionActions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CopyAssetsHandler = exports.defaultFileEventHandler = void 0;
|
|
4
|
-
const
|
|
4
|
+
const picomatch = require("picomatch");
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
6
|
const pathPosix = require("node:path/posix");
|
|
7
7
|
const path = require("node:path");
|
|
@@ -9,6 +9,7 @@ const ignore_1 = require("ignore");
|
|
|
9
9
|
const tinyglobby_1 = require("tinyglobby");
|
|
10
10
|
const devkit_1 = require("@nx/devkit");
|
|
11
11
|
const client_1 = require("nx/src/daemon/client/client");
|
|
12
|
+
const picocolors_1 = require("picocolors");
|
|
12
13
|
const defaultFileEventHandler = (events) => {
|
|
13
14
|
const dirs = new Set(events.map((event) => path.dirname(event.dest)));
|
|
14
15
|
dirs.forEach((d) => (0, node_fs_1.mkdirSync)(d, { recursive: true }));
|
|
@@ -24,6 +25,9 @@ const defaultFileEventHandler = (events) => {
|
|
|
24
25
|
else {
|
|
25
26
|
devkit_1.logger.error(`Unknown file event: ${event.type}`);
|
|
26
27
|
}
|
|
28
|
+
const eventDir = path.dirname(event.src);
|
|
29
|
+
const relativeDest = path.relative(eventDir, event.dest);
|
|
30
|
+
devkit_1.logger.log(`\n${(0, picocolors_1.dim)(relativeDest)}`);
|
|
27
31
|
});
|
|
28
32
|
};
|
|
29
33
|
exports.defaultFileEventHandler = defaultFileEventHandler;
|
|
@@ -115,10 +119,12 @@ class CopyAssetsHandler {
|
|
|
115
119
|
async processWatchEvents(events) {
|
|
116
120
|
const fileEvents = [];
|
|
117
121
|
for (const event of events) {
|
|
118
|
-
const pathFromRoot = path.
|
|
122
|
+
const pathFromRoot = event.path.startsWith(this.rootDir)
|
|
123
|
+
? path.relative(this.rootDir, event.path)
|
|
124
|
+
: event.path;
|
|
119
125
|
for (const ag of this.assetGlobs) {
|
|
120
|
-
if ((
|
|
121
|
-
!ag.ignore?.some((ig) => (
|
|
126
|
+
if (picomatch(ag.pattern)(pathFromRoot) &&
|
|
127
|
+
!ag.ignore?.some((ig) => picomatch(ig)(pathFromRoot)) &&
|
|
122
128
|
!this.ignore.ignores(pathFromRoot)) {
|
|
123
129
|
const relPath = path.relative(ag.input, pathFromRoot);
|
|
124
130
|
const destPath = relPath.startsWith('..') ? pathFromRoot : relPath;
|
|
@@ -137,7 +143,7 @@ class CopyAssetsHandler {
|
|
|
137
143
|
}
|
|
138
144
|
filesToEvent(files, assetGlob) {
|
|
139
145
|
return files.reduce((acc, src) => {
|
|
140
|
-
if (!assetGlob.ignore?.some((ig) => (
|
|
146
|
+
if (!assetGlob.ignore?.some((ig) => picomatch(ig)(src)) &&
|
|
141
147
|
!this.ignore.ignores(src)) {
|
|
142
148
|
const relPath = path.relative(assetGlob.input, src);
|
|
143
149
|
const dest = relPath.startsWith('..') ? src : relPath;
|
|
@@ -33,8 +33,6 @@ export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph,
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function computeCompilerOptionsPaths(tsConfig: string | ts.ParsedCommandLine, dependencies: DependentBuildableProjectNode[]): ts.MapLike<string[]>;
|
|
35
35
|
export declare function createTmpTsConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, dependencies: DependentBuildableProjectNode[], useWorkspaceAsBaseUrl?: boolean): string;
|
|
36
|
-
export declare function checkDependentProjectsHaveBeenBuilt(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): boolean;
|
|
37
|
-
export declare function findMissingBuildDependencies(root: string, projectName: string, targetName: string, projectDependencies: DependentBuildableProjectNode[]): DependentBuildableProjectNode[];
|
|
38
36
|
export declare function updatePaths(dependencies: DependentBuildableProjectNode[], paths: Record<string, string[]>): void;
|
|
39
37
|
/**
|
|
40
38
|
* Updates the peerDependencies section in the `dist/lib/xyz/package.json` with
|
|
@@ -5,8 +5,6 @@ exports.calculateProjectDependencies = calculateProjectDependencies;
|
|
|
5
5
|
exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
|
|
6
6
|
exports.computeCompilerOptionsPaths = computeCompilerOptionsPaths;
|
|
7
7
|
exports.createTmpTsConfig = createTmpTsConfig;
|
|
8
|
-
exports.checkDependentProjectsHaveBeenBuilt = checkDependentProjectsHaveBeenBuilt;
|
|
9
|
-
exports.findMissingBuildDependencies = findMissingBuildDependencies;
|
|
10
8
|
exports.updatePaths = updatePaths;
|
|
11
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
12
10
|
const devkit_1 = require("@nx/devkit");
|
|
@@ -16,6 +14,8 @@ const fileutils_1 = require("nx/src/utils/fileutils");
|
|
|
16
14
|
const output_1 = require("nx/src/utils/output");
|
|
17
15
|
const path_1 = require("path");
|
|
18
16
|
const ts_config_1 = require("./typescript/ts-config");
|
|
17
|
+
const crypto_1 = require("crypto");
|
|
18
|
+
const project_graph_1 = require("nx/src/config/project-graph");
|
|
19
19
|
function isBuildable(target, node) {
|
|
20
20
|
return (node.data.targets &&
|
|
21
21
|
node.data.targets[target] &&
|
|
@@ -48,7 +48,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
48
48
|
.map(({ name: dep, isTopLevel }) => {
|
|
49
49
|
let project = null;
|
|
50
50
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
51
|
-
if (depNode.type === 'lib') {
|
|
51
|
+
if ((0, project_graph_1.isProjectGraphProjectNode)(depNode) && depNode.type === 'lib') {
|
|
52
52
|
if (isBuildable(targetName, depNode)) {
|
|
53
53
|
const libPackageJsonPath = (0, path_1.join)(root, depNode.data.root, 'package.json');
|
|
54
54
|
project = {
|
|
@@ -67,7 +67,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
67
67
|
nonBuildableDependencies.push(dep);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
else if (
|
|
70
|
+
else if ((0, project_graph_1.isProjectGraphExternalNode)(depNode)) {
|
|
71
71
|
project = {
|
|
72
72
|
name: depNode.data.packageName,
|
|
73
73
|
outputs: [],
|
|
@@ -114,7 +114,7 @@ function readTsConfigWithRemappedPaths(originalTsconfigPath, generatedTsconfigPa
|
|
|
114
114
|
const normalizedTsConfig = (0, path_1.resolve)(workspaceRoot, originalTsconfigPath);
|
|
115
115
|
const normalizedGeneratedTsConfigDir = (0, path_1.resolve)(workspaceRoot, (0, path_1.dirname)(generatedTsconfigPath));
|
|
116
116
|
generatedTsConfig.extends = (0, path_1.relative)(normalizedGeneratedTsConfigDir, normalizedTsConfig);
|
|
117
|
-
generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths(
|
|
117
|
+
generatedTsConfig.compilerOptions.paths = computeCompilerOptionsPaths(normalizedTsConfig, dependencies);
|
|
118
118
|
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
119
119
|
output_1.output.log({
|
|
120
120
|
title: 'TypeScript path mappings have been rewritten.',
|
|
@@ -229,7 +229,7 @@ function computeCompilerOptionsPaths(tsConfig, dependencies) {
|
|
|
229
229
|
return paths;
|
|
230
230
|
}
|
|
231
231
|
function createTmpTsConfig(tsconfigPath, workspaceRoot, projectRoot, dependencies, useWorkspaceAsBaseUrl = false) {
|
|
232
|
-
const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build',
|
|
232
|
+
const tmpTsConfigPath = (0, path_1.join)(workspaceRoot, 'tmp', projectRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', `tsconfig.generated.${(0, crypto_1.randomUUID)()}.json`);
|
|
233
233
|
if (tsconfigPath === tmpTsConfigPath) {
|
|
234
234
|
return tsconfigPath;
|
|
235
235
|
}
|
|
@@ -250,47 +250,16 @@ function cleanupTmpTsConfigFile(tmpTsConfigPath) {
|
|
|
250
250
|
}
|
|
251
251
|
catch (e) { }
|
|
252
252
|
}
|
|
253
|
-
function checkDependentProjectsHaveBeenBuilt(root, projectName, targetName, projectDependencies) {
|
|
254
|
-
const missing = findMissingBuildDependencies(root, projectName, targetName, projectDependencies);
|
|
255
|
-
if (missing.length > 0) {
|
|
256
|
-
console.error((0, devkit_1.stripIndents) `
|
|
257
|
-
It looks like all of ${projectName}'s dependencies have not been built yet:
|
|
258
|
-
${missing.map((x) => ` - ${x.node.name}`).join('\n')}
|
|
259
|
-
|
|
260
|
-
You might be missing a "targetDefaults" configuration in your root nx.json (https://nx.dev/reference/project-configuration#target-defaults),
|
|
261
|
-
or "dependsOn" configured in ${projectName}'s project.json (https://nx.dev/reference/project-configuration#dependson)
|
|
262
|
-
`);
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
return true;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
function findMissingBuildDependencies(root, projectName, targetName, projectDependencies) {
|
|
270
|
-
const depLibsToBuildFirst = [];
|
|
271
|
-
// verify whether all dependent libraries have been built
|
|
272
|
-
projectDependencies.forEach((dep) => {
|
|
273
|
-
if (dep.node.type !== 'lib') {
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const paths = dep.outputs.map((p) => (0, path_1.join)(root, p));
|
|
277
|
-
if (!paths.some(fileutils_1.directoryExists)) {
|
|
278
|
-
depLibsToBuildFirst.push(dep);
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
return depLibsToBuildFirst;
|
|
282
|
-
}
|
|
283
253
|
function updatePaths(dependencies, paths) {
|
|
284
254
|
const pathsKeys = Object.keys(paths);
|
|
285
255
|
// For each registered dependency
|
|
286
|
-
dependencies
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
256
|
+
dependencies
|
|
257
|
+
.filter((dep) => (0, project_graph_1.isProjectGraphProjectNode)(dep.node))
|
|
258
|
+
.forEach((dep) => {
|
|
290
259
|
// If there are outputs
|
|
291
260
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
292
261
|
// Directly map the dependency name to the output paths (dist/packages/..., etc.)
|
|
293
|
-
paths[dep.name] = dep.outputs;
|
|
262
|
+
paths[dep.name] = dep.outputs.map((output) => output.replace(/(\*|\/[^\/]*\*).*$/, ''));
|
|
294
263
|
// check for secondary entrypoints
|
|
295
264
|
// For each registered path
|
|
296
265
|
for (const path of pathsKeys) {
|
|
@@ -350,7 +319,8 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
350
319
|
!hasDependency(packageJson, 'peerDependencies', packageName)) {
|
|
351
320
|
try {
|
|
352
321
|
let depVersion;
|
|
353
|
-
if (entry.node
|
|
322
|
+
if ((0, project_graph_1.isProjectGraphProjectNode)(entry.node) &&
|
|
323
|
+
entry.node.type === 'lib') {
|
|
354
324
|
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
355
325
|
project: projectName,
|
|
356
326
|
target: targetName,
|
|
@@ -22,7 +22,7 @@ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, project
|
|
|
22
22
|
return;
|
|
23
23
|
seen?.add(currentProject.name);
|
|
24
24
|
collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, options.ignoredFiles, options.useLocalPathsForWorkspaceDependencies, collectedDeps);
|
|
25
|
-
collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
|
|
25
|
+
collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, options.runtimeHelpers, collectedDeps);
|
|
26
26
|
if (options.includeTransitiveDependencies) {
|
|
27
27
|
const projectDeps = projectGraph.dependencies[currentProject.name];
|
|
28
28
|
for (const dep of projectDeps) {
|
|
@@ -114,7 +114,17 @@ function readPackageJson(project, workspaceRoot) {
|
|
|
114
114
|
return (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
115
115
|
return null;
|
|
116
116
|
}
|
|
117
|
-
function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, npmDeps) {
|
|
117
|
+
function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, runtimeHelpers, npmDeps) {
|
|
118
|
+
if (runtimeHelpers?.length > 0) {
|
|
119
|
+
for (const helper of runtimeHelpers) {
|
|
120
|
+
if (!npmDeps[helper] &&
|
|
121
|
+
projectGraph.externalNodes[`npm:${helper}`]?.type === 'npm') {
|
|
122
|
+
npmDeps[helper] =
|
|
123
|
+
projectGraph.externalNodes[`npm:${helper}`].data.version;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
118
128
|
const target = sourceProject.data.targets[buildTarget];
|
|
119
129
|
if (!target)
|
|
120
130
|
return;
|
package/src/utils/npm-config.js
CHANGED
|
@@ -78,10 +78,7 @@ async function execAsync(command, cwd) {
|
|
|
78
78
|
return new Promise((resolve, reject) => {
|
|
79
79
|
(0, child_process_1.exec)(command, { cwd, windowsHide: false }, (error, stdout, stderr) => {
|
|
80
80
|
if (error) {
|
|
81
|
-
return reject(error);
|
|
82
|
-
}
|
|
83
|
-
if (stderr) {
|
|
84
|
-
return reject(stderr);
|
|
81
|
+
return reject((stderr ? `${stderr}\n` : '') + error);
|
|
85
82
|
}
|
|
86
83
|
return resolve(stdout.trim());
|
|
87
84
|
});
|
|
@@ -19,6 +19,7 @@ export interface UpdatePackageJsonOption {
|
|
|
19
19
|
buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
|
|
20
20
|
generateLockfile?: boolean;
|
|
21
21
|
packageJsonPath?: string;
|
|
22
|
+
skipDevelopmentExports?: boolean;
|
|
22
23
|
}
|
|
23
24
|
export declare function updatePackageJson(options: UpdatePackageJsonOption, context: ExecutorContext, target: ProjectGraphProjectNode, dependencies: DependentBuildableProjectNode[], fileMap?: ProjectFileMap): void;
|
|
24
25
|
interface Exports {
|