@yarnpkg/plugin-essentials 4.0.0-rc.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/add.d.ts +1 -1
- package/lib/commands/add.js +34 -25
- package/lib/commands/bin.d.ts +1 -1
- package/lib/commands/bin.js +1 -1
- package/lib/commands/cache/clean.d.ts +1 -1
- package/lib/commands/cache/clean.js +1 -1
- package/lib/commands/config/get.d.ts +2 -1
- package/lib/commands/config/get.js +4 -1
- package/lib/commands/config/set.d.ts +1 -1
- package/lib/commands/config/set.js +1 -1
- package/lib/commands/config/unset.d.ts +1 -1
- package/lib/commands/config/unset.js +1 -1
- package/lib/commands/config.d.ts +5 -3
- package/lib/commands/config.js +96 -39
- package/lib/commands/dedupe.d.ts +1 -1
- package/lib/commands/dedupe.js +7 -8
- package/lib/commands/entries/clipanion.js +1 -1
- package/lib/commands/entries/help.js +1 -1
- package/lib/commands/entries/version.js +1 -1
- package/lib/commands/exec.js +1 -1
- package/lib/commands/explain/peerRequirements.d.ts +2 -2
- package/lib/commands/explain/peerRequirements.js +4 -6
- package/lib/commands/explain.js +1 -1
- package/lib/commands/info.js +10 -18
- package/lib/commands/install.d.ts +1 -1
- package/lib/commands/install.js +245 -205
- package/lib/commands/link.d.ts +2 -2
- package/lib/commands/link.js +36 -32
- package/lib/commands/node.js +1 -1
- package/lib/commands/plugin/check.d.ts +8 -0
- package/lib/commands/plugin/check.js +61 -0
- package/lib/commands/plugin/import/sources.d.ts +3 -3
- package/lib/commands/plugin/import/sources.js +5 -5
- package/lib/commands/plugin/import.d.ts +5 -4
- package/lib/commands/plugin/import.js +15 -28
- package/lib/commands/plugin/list.d.ts +2 -2
- package/lib/commands/plugin/list.js +5 -6
- package/lib/commands/plugin/remove.d.ts +1 -1
- package/lib/commands/plugin/remove.js +14 -13
- package/lib/commands/plugin/runtime.d.ts +2 -2
- package/lib/commands/plugin/runtime.js +4 -4
- package/lib/commands/rebuild.d.ts +2 -2
- package/lib/commands/rebuild.js +10 -10
- package/lib/commands/remove.d.ts +1 -1
- package/lib/commands/remove.js +7 -8
- package/lib/commands/run.js +1 -1
- package/lib/commands/runIndex.d.ts +2 -2
- package/lib/commands/runIndex.js +3 -3
- package/lib/commands/set/resolution.d.ts +1 -1
- package/lib/commands/set/resolution.js +4 -6
- package/lib/commands/set/version/sources.d.ts +3 -2
- package/lib/commands/set/version/sources.js +21 -12
- package/lib/commands/set/version.d.ts +2 -3
- package/lib/commands/set/version.js +20 -16
- package/lib/commands/unlink.d.ts +1 -1
- package/lib/commands/unlink.js +7 -8
- package/lib/commands/up.d.ts +3 -3
- package/lib/commands/up.js +19 -17
- package/lib/commands/why.js +5 -13
- package/lib/commands/workspace.js +2 -5
- package/lib/commands/workspaces/list.d.ts +2 -1
- package/lib/commands/workspaces/list.js +8 -1
- package/lib/dedupeUtils.d.ts +3 -3
- package/lib/dedupeUtils.js +3 -5
- package/lib/index.d.ts +76 -1
- package/lib/index.js +40 -1
- package/lib/suggestUtils.d.ts +4 -4
- package/lib/suggestUtils.js +14 -12
- package/package.json +22 -17
package/lib/commands/runIndex.js
CHANGED
|
@@ -5,7 +5,7 @@ const core_1 = require("@yarnpkg/core");
|
|
|
5
5
|
const core_2 = require("@yarnpkg/core");
|
|
6
6
|
const util_1 = require("util");
|
|
7
7
|
// eslint-disable-next-line arca/no-default-export
|
|
8
|
-
class
|
|
8
|
+
class RunIndexCommand extends cli_1.BaseCommand {
|
|
9
9
|
async execute() {
|
|
10
10
|
const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
|
|
11
11
|
const { project, workspace } = await core_1.Project.find(configuration, this.context.cwd);
|
|
@@ -32,7 +32,7 @@ class RunCommand extends cli_1.BaseCommand {
|
|
|
32
32
|
return report.exitCode();
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
RunCommand.paths = [
|
|
35
|
+
RunIndexCommand.paths = [
|
|
37
36
|
[`run`],
|
|
38
37
|
];
|
|
38
|
+
exports.default = RunIndexCommand;
|
|
@@ -28,16 +28,13 @@ class SetResolutionCommand extends cli_1.BaseCommand {
|
|
|
28
28
|
project.storedDescriptors.set(fromDescriptor.descriptorHash, fromDescriptor);
|
|
29
29
|
project.storedDescriptors.set(toDescriptor.descriptorHash, toDescriptor);
|
|
30
30
|
project.resolutionAliases.set(fromDescriptor.descriptorHash, toDescriptor.descriptorHash);
|
|
31
|
-
|
|
32
|
-
configuration,
|
|
31
|
+
return await project.installWithNewReport({
|
|
33
32
|
stdout: this.context.stdout,
|
|
34
|
-
},
|
|
35
|
-
|
|
33
|
+
}, {
|
|
34
|
+
cache,
|
|
36
35
|
});
|
|
37
|
-
return report.exitCode();
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
|
-
exports.default = SetResolutionCommand;
|
|
41
38
|
SetResolutionCommand.paths = [
|
|
42
39
|
[`set`, `resolution`],
|
|
43
40
|
];
|
|
@@ -55,3 +52,4 @@ SetResolutionCommand.usage = clipanion_1.Command.Usage({
|
|
|
55
52
|
`$0 set resolution lodash@npm:^1.2.3 1.5.0`,
|
|
56
53
|
]],
|
|
57
54
|
});
|
|
55
|
+
exports.default = SetResolutionCommand;
|
|
@@ -9,17 +9,18 @@ export default class SetVersionSourcesCommand extends BaseCommand {
|
|
|
9
9
|
repository: string;
|
|
10
10
|
branch: string;
|
|
11
11
|
plugins: string[];
|
|
12
|
+
dryRun: boolean;
|
|
12
13
|
noMinify: boolean;
|
|
13
14
|
force: boolean;
|
|
14
15
|
skipPlugins: boolean;
|
|
15
|
-
execute(): Promise<
|
|
16
|
+
execute(): Promise<0 | 1>;
|
|
16
17
|
}
|
|
17
18
|
export declare function runWorkflow(workflow: Array<Array<string>>, { configuration, context, target }: {
|
|
18
19
|
configuration: Configuration;
|
|
19
20
|
context: CommandContext;
|
|
20
21
|
target: PortablePath;
|
|
21
22
|
}): Promise<void>;
|
|
22
|
-
export
|
|
23
|
+
export type PrepareSpec = {
|
|
23
24
|
branch: string;
|
|
24
25
|
context: CommandContext;
|
|
25
26
|
force: boolean;
|
|
@@ -27,10 +27,11 @@ const cloneWorkflow = ({ repository, branch }, target) => [
|
|
|
27
27
|
const updateWorkflow = ({ branch }) => [
|
|
28
28
|
[`git`, `fetch`, `origin`, `--depth=1`, getBranchRef(branch), `--force`],
|
|
29
29
|
[`git`, `reset`, `--hard`, `FETCH_HEAD`],
|
|
30
|
-
[`git`, `clean`, `-dfx`],
|
|
30
|
+
[`git`, `clean`, `-dfx`, `-e`, `packages/yarnpkg-cli/bundles`],
|
|
31
31
|
];
|
|
32
|
-
const buildWorkflow = ({ plugins, noMinify }, target) => [
|
|
32
|
+
const buildWorkflow = ({ plugins, noMinify }, output, target) => [
|
|
33
33
|
[`yarn`, `build:cli`, ...new Array().concat(...plugins.map(plugin => [`--plugin`, fslib_1.ppath.resolve(target, plugin)])), ...noMinify ? [`--no-minify`] : [], `|`],
|
|
34
|
+
[`mv`, `packages/yarnpkg-cli/bundles/yarn.js`, fslib_1.npath.fromPortablePath(output), `|`],
|
|
34
35
|
];
|
|
35
36
|
// eslint-disable-next-line arca/no-default-export
|
|
36
37
|
class SetVersionSourcesCommand extends cli_1.BaseCommand {
|
|
@@ -48,6 +49,9 @@ class SetVersionSourcesCommand extends cli_1.BaseCommand {
|
|
|
48
49
|
this.plugins = clipanion_1.Option.Array(`--plugin`, [], {
|
|
49
50
|
description: `An array of additional plugins that should be included in the bundle`,
|
|
50
51
|
});
|
|
52
|
+
this.dryRun = clipanion_1.Option.Boolean(`-n,--dry-run`, false, {
|
|
53
|
+
description: `If set, the bundle will be built but not added to the project`,
|
|
54
|
+
});
|
|
51
55
|
this.noMinify = clipanion_1.Option.Boolean(`--no-minify`, false, {
|
|
52
56
|
description: `Build a bundle for development (debugging) - non-minified and non-mangled`,
|
|
53
57
|
});
|
|
@@ -72,21 +76,25 @@ class SetVersionSourcesCommand extends cli_1.BaseCommand {
|
|
|
72
76
|
report.reportSeparator();
|
|
73
77
|
report.reportInfo(core_1.MessageName.UNNAMED, `Building a fresh bundle`);
|
|
74
78
|
report.reportSeparator();
|
|
75
|
-
await
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
const commitHash = await core_1.execUtils.execvp(`git`, [`rev-parse`, `--short`, `HEAD`], { cwd: target, strict: true });
|
|
80
|
+
const bundlePath = fslib_1.ppath.join(target, `packages/yarnpkg-cli/bundles/yarn-${commitHash.stdout.trim()}.js`);
|
|
81
|
+
if (!fslib_1.xfs.existsSync(bundlePath)) {
|
|
82
|
+
await runWorkflow(buildWorkflow(this, bundlePath, target), { configuration, context: this.context, target });
|
|
83
|
+
report.reportSeparator();
|
|
84
|
+
}
|
|
78
85
|
const bundleBuffer = await fslib_1.xfs.readFilePromise(bundlePath);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
if (!this.dryRun) {
|
|
87
|
+
const { bundleVersion } = await (0, version_1.setVersion)(configuration, null, async () => bundleBuffer, {
|
|
88
|
+
report,
|
|
89
|
+
});
|
|
90
|
+
if (!this.skipPlugins) {
|
|
91
|
+
await updatePlugins(this, bundleVersion, { project, report, target });
|
|
92
|
+
}
|
|
84
93
|
}
|
|
85
94
|
});
|
|
86
95
|
return report.exitCode();
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
|
-
exports.default = SetVersionSourcesCommand;
|
|
90
98
|
SetVersionSourcesCommand.paths = [
|
|
91
99
|
[`set`, `version`, `from`, `sources`],
|
|
92
100
|
];
|
|
@@ -102,6 +110,7 @@ SetVersionSourcesCommand.usage = clipanion_1.Command.Usage({
|
|
|
102
110
|
`$0 set version from sources`,
|
|
103
111
|
]],
|
|
104
112
|
});
|
|
113
|
+
exports.default = SetVersionSourcesCommand;
|
|
105
114
|
async function runWorkflow(workflow, { configuration, context, target }) {
|
|
106
115
|
for (const [fileName, ...args] of workflow) {
|
|
107
116
|
const usePipe = args[args.length - 1] === `|`;
|
|
@@ -141,7 +150,7 @@ async function prepareRepo(spec, { configuration, report, target }) {
|
|
|
141
150
|
await runWorkflow(updateWorkflow(spec), { configuration, context: spec.context, target });
|
|
142
151
|
ready = true;
|
|
143
152
|
}
|
|
144
|
-
catch
|
|
153
|
+
catch {
|
|
145
154
|
report.reportSeparator();
|
|
146
155
|
report.reportWarning(core_1.MessageName.UNNAMED, `Repository update failed; we'll try to regenerate it`);
|
|
147
156
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
2
|
import { BaseCommand } from '@yarnpkg/cli';
|
|
4
3
|
import { Configuration, Report } from '@yarnpkg/core';
|
|
5
4
|
import { Usage } from 'clipanion';
|
|
6
|
-
export
|
|
5
|
+
export type Tags = {
|
|
7
6
|
latest: Record<string, string>;
|
|
8
7
|
tags: Array<string>;
|
|
9
8
|
};
|
|
@@ -13,7 +12,7 @@ export default class SetVersionCommand extends BaseCommand {
|
|
|
13
12
|
useYarnPath: boolean | undefined;
|
|
14
13
|
onlyIfNeeded: boolean;
|
|
15
14
|
version: string;
|
|
16
|
-
execute(): Promise<
|
|
15
|
+
execute(): Promise<0 | 1>;
|
|
17
16
|
}
|
|
18
17
|
export declare function resolveRange(configuration: Configuration, request: string): Promise<string>;
|
|
19
18
|
export declare function resolveTag(configuration: Configuration, request: `stable` | `canary`): Promise<string>;
|
|
@@ -22,8 +22,15 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
22
22
|
}
|
|
23
23
|
async execute() {
|
|
24
24
|
const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
|
|
25
|
-
if (configuration.get(`yarnPath`)
|
|
26
|
-
|
|
25
|
+
if (this.onlyIfNeeded && configuration.get(`yarnPath`)) {
|
|
26
|
+
const yarnPathSource = configuration.sources.get(`yarnPath`);
|
|
27
|
+
if (!yarnPathSource)
|
|
28
|
+
throw new Error(`Assertion failed: Expected 'yarnPath' to have a source`);
|
|
29
|
+
const projectCwd = configuration.projectCwd ?? configuration.startingCwd;
|
|
30
|
+
if (fslib_1.ppath.contains(projectCwd, yarnPathSource)) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
const getBundlePath = () => {
|
|
28
35
|
if (typeof core_1.YarnVersion === `undefined`)
|
|
29
36
|
throw new clipanion_1.UsageError(`The --install flag can only be used without explicit version specifier from the Yarn CLI`);
|
|
@@ -34,13 +41,13 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
34
41
|
return { version, url: url.replace(/\{\}/g, version) };
|
|
35
42
|
};
|
|
36
43
|
if (this.version === `self`)
|
|
37
|
-
bundleRef = { url: getBundlePath(), version: core_1.YarnVersion
|
|
44
|
+
bundleRef = { url: getBundlePath(), version: core_1.YarnVersion ?? `self` };
|
|
38
45
|
else if (this.version === `latest` || this.version === `berry` || this.version === `stable`)
|
|
39
46
|
bundleRef = getRef(`https://repo.yarnpkg.com/{}/packages/yarnpkg-cli/bin/yarn.js`, await resolveTag(configuration, `stable`));
|
|
40
47
|
else if (this.version === `canary`)
|
|
41
48
|
bundleRef = getRef(`https://repo.yarnpkg.com/{}/packages/yarnpkg-cli/bin/yarn.js`, await resolveTag(configuration, `canary`));
|
|
42
49
|
else if (this.version === `classic`)
|
|
43
|
-
bundleRef = { url: `https://
|
|
50
|
+
bundleRef = { url: `https://classic.yarnpkg.com/latest.js`, version: `classic` };
|
|
44
51
|
else if (this.version.match(/^https?:/))
|
|
45
52
|
bundleRef = { url: this.version, version: `remote` };
|
|
46
53
|
else if (this.version.match(/^\.{0,2}[\\/]/) || fslib_1.npath.isAbsolute(this.version))
|
|
@@ -61,11 +68,11 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
61
68
|
const fetchBuffer = async () => {
|
|
62
69
|
const filePrefix = `file://`;
|
|
63
70
|
if (bundleRef.url.startsWith(filePrefix)) {
|
|
64
|
-
report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url,
|
|
71
|
+
report.reportInfo(core_1.MessageName.UNNAMED, `Retrieving ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.PATH)}`);
|
|
65
72
|
return await fslib_1.xfs.readFilePromise(bundleRef.url.slice(filePrefix.length));
|
|
66
73
|
}
|
|
67
74
|
else {
|
|
68
|
-
report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url,
|
|
75
|
+
report.reportInfo(core_1.MessageName.UNNAMED, `Downloading ${core_2.formatUtils.pretty(configuration, bundleRef.url, core_2.formatUtils.Type.URL)}`);
|
|
69
76
|
return await core_2.httpUtils.get(bundleRef.url, { configuration });
|
|
70
77
|
}
|
|
71
78
|
};
|
|
@@ -74,7 +81,6 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
74
81
|
return report.exitCode();
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
|
-
exports.default = SetVersionCommand;
|
|
78
84
|
SetVersionCommand.paths = [
|
|
79
85
|
[`set`, `version`],
|
|
80
86
|
];
|
|
@@ -85,7 +91,7 @@ SetVersionCommand.usage = clipanion_1.Command.Usage({
|
|
|
85
91
|
|
|
86
92
|
By default it only will set the \`packageManager\` field at the root of your project, but if the referenced release cannot be represented this way, if you already have \`yarnPath\` configured, or if you set the \`--yarn-path\` command line flag, then the release will also be downloaded from the Yarn GitHub repository, stored inside your project, and referenced via the \`yarnPath\` settings from your project \`.yarnrc.yml\` file.
|
|
87
93
|
|
|
88
|
-
A very good use case for this command is to enforce the version of Yarn used by
|
|
94
|
+
A very good use case for this command is to enforce the version of Yarn used by any single member of your team inside the same project - by doing this you ensure that you have control over Yarn upgrades and downgrades (including on your deployment servers), and get rid of most of the headaches related to someone using a slightly different version and getting different behavior.
|
|
89
95
|
|
|
90
96
|
The version specifier can be:
|
|
91
97
|
|
|
@@ -131,6 +137,7 @@ SetVersionCommand.usage = clipanion_1.Command.Usage({
|
|
|
131
137
|
`$0 set version self`,
|
|
132
138
|
]],
|
|
133
139
|
});
|
|
140
|
+
exports.default = SetVersionCommand;
|
|
134
141
|
async function resolveRange(configuration, request) {
|
|
135
142
|
const data = await core_2.httpUtils.get(`https://repo.yarnpkg.com/tags`, { configuration, jsonResponse: true });
|
|
136
143
|
const candidates = data.tags.filter(version => core_2.semverUtils.satisfiesWithPrereleases(version, request));
|
|
@@ -148,7 +155,6 @@ async function resolveTag(configuration, request) {
|
|
|
148
155
|
}
|
|
149
156
|
exports.resolveTag = resolveTag;
|
|
150
157
|
async function setVersion(configuration, bundleVersion, fetchBuffer, { report, useYarnPath }) {
|
|
151
|
-
var _a;
|
|
152
158
|
let bundleBuffer;
|
|
153
159
|
const ensureBuffer = async () => {
|
|
154
160
|
if (typeof bundleBuffer === `undefined`)
|
|
@@ -162,7 +168,7 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
|
|
|
162
168
|
await fslib_1.xfs.writeFilePromise(temporaryPath, bundleBuffer);
|
|
163
169
|
const { stdout } = await core_2.execUtils.execvp(process.execPath, [fslib_1.npath.fromPortablePath(temporaryPath), `--version`], {
|
|
164
170
|
cwd: tmpDir,
|
|
165
|
-
env: { ...
|
|
171
|
+
env: { ...configuration.env, YARN_IGNORE_PATH: `1` },
|
|
166
172
|
});
|
|
167
173
|
bundleVersion = stdout.trim();
|
|
168
174
|
if (!semver_1.default.valid(bundleVersion)) {
|
|
@@ -170,7 +176,7 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
|
|
|
170
176
|
}
|
|
171
177
|
});
|
|
172
178
|
}
|
|
173
|
-
const projectCwd =
|
|
179
|
+
const projectCwd = configuration.projectCwd ?? configuration.startingCwd;
|
|
174
180
|
const releaseFolder = fslib_1.ppath.resolve(projectCwd, `.yarn/releases`);
|
|
175
181
|
const absolutePath = fslib_1.ppath.resolve(releaseFolder, `yarn-${bundleVersion}.cjs`);
|
|
176
182
|
const displayPath = fslib_1.ppath.relative(configuration.startingCwd, absolutePath);
|
|
@@ -193,11 +199,9 @@ async function setVersion(configuration, bundleVersion, fetchBuffer, { report, u
|
|
|
193
199
|
await fslib_1.xfs.removePromise(fslib_1.ppath.dirname(absolutePath));
|
|
194
200
|
await fslib_1.xfs.mkdirPromise(fslib_1.ppath.dirname(absolutePath), { recursive: true });
|
|
195
201
|
await fslib_1.xfs.writeFilePromise(absolutePath, bundleBuffer, { mode: 0o755 });
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
});
|
|
200
|
-
}
|
|
202
|
+
await core_1.Configuration.updateConfiguration(projectCwd, {
|
|
203
|
+
yarnPath: fslib_1.ppath.relative(projectCwd, absolutePath),
|
|
204
|
+
});
|
|
201
205
|
}
|
|
202
206
|
else {
|
|
203
207
|
await fslib_1.xfs.removePromise(fslib_1.ppath.dirname(absolutePath));
|
package/lib/commands/unlink.d.ts
CHANGED
package/lib/commands/unlink.js
CHANGED
|
@@ -41,7 +41,7 @@ class UnlinkCommand extends cli_1.BaseCommand {
|
|
|
41
41
|
if (this.all) {
|
|
42
42
|
for (const workspace of project2.workspaces)
|
|
43
43
|
if (workspace.manifest.name)
|
|
44
|
-
workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace.
|
|
44
|
+
workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace.anchoredLocator));
|
|
45
45
|
if (workspacesToUnlink.size === 0) {
|
|
46
46
|
throw new clipanion_1.UsageError(`No workspace found to be unlinked in the target project`);
|
|
47
47
|
}
|
|
@@ -49,7 +49,7 @@ class UnlinkCommand extends cli_1.BaseCommand {
|
|
|
49
49
|
else {
|
|
50
50
|
if (!workspace2.manifest.name)
|
|
51
51
|
throw new clipanion_1.UsageError(`The target workspace doesn't have a name and thus cannot be unlinked`);
|
|
52
|
-
workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace2.
|
|
52
|
+
workspacesToUnlink.add(core_1.structUtils.stringifyIdent(workspace2.anchoredLocator));
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
@@ -63,16 +63,14 @@ class UnlinkCommand extends cli_1.BaseCommand {
|
|
|
63
63
|
topLevelWorkspace.manifest.resolutions = topLevelWorkspace.manifest.resolutions.filter(({ pattern }) => {
|
|
64
64
|
return !workspacesToUnlink.has(pattern.descriptor.fullName);
|
|
65
65
|
});
|
|
66
|
-
|
|
67
|
-
configuration,
|
|
66
|
+
return await project.installWithNewReport({
|
|
68
67
|
stdout: this.context.stdout,
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
quiet: this.context.quiet,
|
|
69
|
+
}, {
|
|
70
|
+
cache,
|
|
71
71
|
});
|
|
72
|
-
return report.exitCode();
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
|
-
exports.default = UnlinkCommand;
|
|
76
74
|
UnlinkCommand.paths = [
|
|
77
75
|
[`unlink`],
|
|
78
76
|
];
|
|
@@ -95,3 +93,4 @@ UnlinkCommand.usage = clipanion_1.Command.Usage({
|
|
|
95
93
|
`$0 unlink '@babel/*' 'pkg-{a,b}'`,
|
|
96
94
|
]],
|
|
97
95
|
});
|
|
96
|
+
exports.default = UnlinkCommand;
|
package/lib/commands/up.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export default class UpCommand extends BaseCommand {
|
|
|
18
18
|
}, {
|
|
19
19
|
[key: string]: unknown;
|
|
20
20
|
}>[];
|
|
21
|
-
execute(): Promise<
|
|
22
|
-
executeUpRecursive(): Promise<
|
|
23
|
-
executeUpClassic(): Promise<
|
|
21
|
+
execute(): Promise<0 | 1>;
|
|
22
|
+
executeUpRecursive(): Promise<0 | 1>;
|
|
23
|
+
executeUpClassic(): Promise<0 | 1>;
|
|
24
24
|
}
|
package/lib/commands/up.js
CHANGED
|
@@ -75,16 +75,14 @@ class UpCommand extends cli_1.BaseCommand {
|
|
|
75
75
|
project.storedDescriptors.delete(descriptor.descriptorHash);
|
|
76
76
|
project.storedResolutions.delete(descriptor.descriptorHash);
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
configuration,
|
|
78
|
+
return await project.installWithNewReport({
|
|
80
79
|
stdout: this.context.stdout,
|
|
81
|
-
},
|
|
82
|
-
|
|
80
|
+
}, {
|
|
81
|
+
cache,
|
|
82
|
+
mode: this.mode,
|
|
83
83
|
});
|
|
84
|
-
return installReport.exitCode();
|
|
85
84
|
}
|
|
86
85
|
async executeUpClassic() {
|
|
87
|
-
var _a;
|
|
88
86
|
const configuration = await core_3.Configuration.find(this.context.cwd, this.context.plugins);
|
|
89
87
|
const { project, workspace } = await core_2.Project.find(configuration, this.context.cwd);
|
|
90
88
|
const cache = await core_3.Cache.find(configuration);
|
|
@@ -94,7 +92,7 @@ class UpCommand extends cli_1.BaseCommand {
|
|
|
94
92
|
restoreResolutions: false,
|
|
95
93
|
});
|
|
96
94
|
const fixed = this.fixed;
|
|
97
|
-
const interactive =
|
|
95
|
+
const interactive = this.interactive ?? configuration.get(`preferInteractive`);
|
|
98
96
|
const modifier = suggestUtils.getModifier(this, project);
|
|
99
97
|
const strategies = interactive ? [
|
|
100
98
|
suggestUtils.Strategy.KEEP,
|
|
@@ -111,13 +109,18 @@ class UpCommand extends cli_1.BaseCommand {
|
|
|
111
109
|
let isReferenced = false;
|
|
112
110
|
// The range has to be static
|
|
113
111
|
const pseudoDescriptor = core_1.structUtils.parseDescriptor(pattern);
|
|
112
|
+
const stringifiedPseudoDescriptor = core_1.structUtils.stringifyIdent(pseudoDescriptor);
|
|
114
113
|
for (const workspace of project.workspaces) {
|
|
115
114
|
for (const target of [suggestUtils.Target.REGULAR, suggestUtils.Target.DEVELOPMENT]) {
|
|
116
115
|
const descriptors = workspace.manifest.getForScope(target);
|
|
117
116
|
const stringifiedIdents = [...descriptors.values()].map(descriptor => {
|
|
118
117
|
return core_1.structUtils.stringifyIdent(descriptor);
|
|
119
118
|
});
|
|
120
|
-
|
|
119
|
+
// As a special case, we support "*" as a pattern to upgrade all packages
|
|
120
|
+
const matches = stringifiedPseudoDescriptor === `*`
|
|
121
|
+
? stringifiedIdents
|
|
122
|
+
: (0, micromatch_1.default)(stringifiedIdents, stringifiedPseudoDescriptor);
|
|
123
|
+
for (const stringifiedIdent of matches) {
|
|
121
124
|
const ident = core_1.structUtils.parseIdent(stringifiedIdent);
|
|
122
125
|
const existingDescriptor = workspace.manifest[target].get(ident.identHash);
|
|
123
126
|
if (typeof existingDescriptor === `undefined`)
|
|
@@ -140,9 +143,9 @@ class UpCommand extends cli_1.BaseCommand {
|
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
if (unreferencedPatterns.length > 1)
|
|
143
|
-
throw new clipanion_1.UsageError(`Patterns ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.
|
|
146
|
+
throw new clipanion_1.UsageError(`Patterns ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.formatUtils.Type.CODE)} don't match any packages referenced by any workspace`);
|
|
144
147
|
if (unreferencedPatterns.length > 0)
|
|
145
|
-
throw new clipanion_1.UsageError(`Pattern ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.
|
|
148
|
+
throw new clipanion_1.UsageError(`Pattern ${core_3.formatUtils.prettyList(configuration, unreferencedPatterns, core_3.formatUtils.Type.CODE)} doesn't match any packages referenced by any workspace`);
|
|
146
149
|
const allSuggestions = await Promise.all(allSuggestionsPromises);
|
|
147
150
|
const checkReport = await core_3.LightReport.start({
|
|
148
151
|
configuration,
|
|
@@ -231,16 +234,14 @@ class UpCommand extends cli_1.BaseCommand {
|
|
|
231
234
|
await configuration.triggerMultipleHooks((hooks) => hooks.afterWorkspaceDependencyReplacement, afterWorkspaceDependencyReplacementList);
|
|
232
235
|
if (askedQuestions)
|
|
233
236
|
this.context.stdout.write(`\n`);
|
|
234
|
-
|
|
235
|
-
configuration,
|
|
237
|
+
return await project.installWithNewReport({
|
|
236
238
|
stdout: this.context.stdout,
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
+
}, {
|
|
240
|
+
cache,
|
|
241
|
+
mode: this.mode,
|
|
239
242
|
});
|
|
240
|
-
return installReport.exitCode();
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
|
-
exports.default = UpCommand;
|
|
244
245
|
UpCommand.paths = [
|
|
245
246
|
[`up`],
|
|
246
247
|
];
|
|
@@ -257,7 +258,7 @@ UpCommand.usage = clipanion_1.Command.Usage({
|
|
|
257
258
|
|
|
258
259
|
If the \`--mode=<mode>\` option is set, Yarn will change which artifacts are generated. The modes currently supported are:
|
|
259
260
|
|
|
260
|
-
- \`skip-build\` will not run the build scripts at all. Note that this is different from setting \`enableScripts\` to false because the
|
|
261
|
+
- \`skip-build\` will not run the build scripts at all. Note that this is different from setting \`enableScripts\` to false because the latter will disable build scripts, and thus affect the content of the artifacts generated on disk, whereas the former will just disable the build step - but not the scripts themselves, which just won't run.
|
|
261
262
|
|
|
262
263
|
- \`update-lockfile\` will skip the link step altogether, and only fetch packages that are missing from the lockfile (or that have no associated checksums). This mode is typically used by tools like Renovate or Dependabot to keep a lockfile up-to-date without incurring the full install cost.
|
|
263
264
|
|
|
@@ -290,3 +291,4 @@ UpCommand.usage = clipanion_1.Command.Usage({
|
|
|
290
291
|
UpCommand.schema = [
|
|
291
292
|
t.hasKeyRelationship(`recursive`, t.KeyRelationship.Forbids, [`interactive`, `exact`, `tilde`, `caret`], { ignore: [undefined, false] }),
|
|
292
293
|
];
|
|
294
|
+
exports.default = UpCommand;
|
package/lib/commands/why.js
CHANGED
|
@@ -38,7 +38,6 @@ class WhyCommand extends cli_1.BaseCommand {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
exports.default = WhyCommand;
|
|
42
41
|
WhyCommand.paths = [
|
|
43
42
|
[`why`],
|
|
44
43
|
];
|
|
@@ -54,6 +53,7 @@ WhyCommand.usage = clipanion_1.Command.Usage({
|
|
|
54
53
|
`$0 why lodash`,
|
|
55
54
|
]],
|
|
56
55
|
});
|
|
56
|
+
exports.default = WhyCommand;
|
|
57
57
|
function whySimple(project, identHash, { configuration, peers }) {
|
|
58
58
|
const sortedPackages = core_3.miscUtils.sortMap(project.storedPackages.values(), pkg => {
|
|
59
59
|
return core_3.structUtils.stringifyLocator(pkg);
|
|
@@ -121,12 +121,8 @@ function whyRecursive(project, identHash, { configuration, peers }) {
|
|
|
121
121
|
dependents.add(pkg.locatorHash);
|
|
122
122
|
return depends;
|
|
123
123
|
};
|
|
124
|
-
for (const workspace of sortedWorkspaces)
|
|
125
|
-
|
|
126
|
-
if (!pkg)
|
|
127
|
-
throw new Error(`Assertion failed: The package should have been registered`);
|
|
128
|
-
markAllDependents(pkg);
|
|
129
|
-
}
|
|
124
|
+
for (const workspace of sortedWorkspaces)
|
|
125
|
+
markAllDependents(workspace.anchoredPackage);
|
|
130
126
|
const printed = new Set();
|
|
131
127
|
const rootChildren = {};
|
|
132
128
|
const root = { children: rootChildren };
|
|
@@ -164,11 +160,7 @@ function whyRecursive(project, identHash, { configuration, peers }) {
|
|
|
164
160
|
printAllDependents(nextPkg, nodeChildren, dependency);
|
|
165
161
|
}
|
|
166
162
|
};
|
|
167
|
-
for (const workspace of sortedWorkspaces)
|
|
168
|
-
|
|
169
|
-
if (!pkg)
|
|
170
|
-
throw new Error(`Assertion failed: The package should have been registered`);
|
|
171
|
-
printAllDependents(pkg, rootChildren, null);
|
|
172
|
-
}
|
|
163
|
+
for (const workspace of sortedWorkspaces)
|
|
164
|
+
printAllDependents(workspace.anchoredPackage, rootChildren, null);
|
|
173
165
|
return root;
|
|
174
166
|
}
|
|
@@ -18,10 +18,7 @@ class WorkspaceCommand extends cli_1.BaseCommand {
|
|
|
18
18
|
if (!cwdWorkspace)
|
|
19
19
|
throw new cli_1.WorkspaceRequiredError(project.cwd, this.context.cwd);
|
|
20
20
|
const candidates = project.workspaces;
|
|
21
|
-
const candidatesByName = new Map(candidates.map((workspace)
|
|
22
|
-
const ident = core_2.structUtils.convertToIdent(workspace.locator);
|
|
23
|
-
return [core_2.structUtils.stringifyIdent(ident), workspace];
|
|
24
|
-
}));
|
|
21
|
+
const candidatesByName = new Map(candidates.map(workspace => [core_2.structUtils.stringifyIdent(workspace.anchoredLocator), workspace]));
|
|
25
22
|
const workspace = candidatesByName.get(this.workspaceName);
|
|
26
23
|
if (workspace === undefined) {
|
|
27
24
|
const otherNames = Array.from(candidatesByName.keys()).sort();
|
|
@@ -30,7 +27,6 @@ class WorkspaceCommand extends cli_1.BaseCommand {
|
|
|
30
27
|
return this.cli.run([this.commandName, ...this.args], { cwd: workspace.cwd });
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.default = WorkspaceCommand;
|
|
34
30
|
WorkspaceCommand.paths = [
|
|
35
31
|
[`workspace`],
|
|
36
32
|
];
|
|
@@ -48,3 +44,4 @@ WorkspaceCommand.usage = clipanion_1.Command.Usage({
|
|
|
48
44
|
`yarn workspace components run build`,
|
|
49
45
|
]],
|
|
50
46
|
});
|
|
47
|
+
exports.default = WorkspaceCommand;
|
|
@@ -5,7 +5,8 @@ export default class WorkspacesListCommand extends BaseCommand {
|
|
|
5
5
|
static usage: Usage;
|
|
6
6
|
since: string | boolean | undefined;
|
|
7
7
|
recursive: boolean;
|
|
8
|
+
noPrivate: boolean | undefined;
|
|
8
9
|
verbose: boolean;
|
|
9
10
|
json: boolean;
|
|
10
|
-
execute(): Promise<
|
|
11
|
+
execute(): Promise<0 | 1>;
|
|
11
12
|
}
|
|
@@ -15,6 +15,9 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
|
|
|
15
15
|
this.recursive = clipanion_1.Option.Boolean(`-R,--recursive`, false, {
|
|
16
16
|
description: `Find packages via dependencies/devDependencies instead of using the workspaces field`,
|
|
17
17
|
});
|
|
18
|
+
this.noPrivate = clipanion_1.Option.Boolean(`--no-private`, {
|
|
19
|
+
description: `Exclude workspaces that have the private field set to true`,
|
|
20
|
+
});
|
|
18
21
|
this.verbose = clipanion_1.Option.Boolean(`-v,--verbose`, false, {
|
|
19
22
|
description: `Also return the cross-dependencies between workspaces`,
|
|
20
23
|
});
|
|
@@ -40,6 +43,8 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
|
|
|
40
43
|
workspaces.add(dependent);
|
|
41
44
|
for (const workspace of workspaces) {
|
|
42
45
|
const { manifest } = workspace;
|
|
46
|
+
if (manifest.private && this.noPrivate)
|
|
47
|
+
continue;
|
|
43
48
|
let extra;
|
|
44
49
|
if (this.verbose) {
|
|
45
50
|
const workspaceDependencies = new Set();
|
|
@@ -79,7 +84,6 @@ class WorkspacesListCommand extends cli_1.BaseCommand {
|
|
|
79
84
|
return report.exitCode();
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
|
-
exports.default = WorkspacesListCommand;
|
|
83
87
|
WorkspacesListCommand.paths = [
|
|
84
88
|
[`workspaces`, `list`],
|
|
85
89
|
];
|
|
@@ -93,6 +97,9 @@ WorkspacesListCommand.usage = clipanion_1.Command.Usage({
|
|
|
93
97
|
|
|
94
98
|
- If \`-R,--recursive\` is set, Yarn will find workspaces to run the command on by recursively evaluating \`dependencies\` and \`devDependencies\` fields, instead of looking at the \`workspaces\` fields.
|
|
95
99
|
|
|
100
|
+
- If \`--no-private\` is set, Yarn will not list any workspaces that have the \`private\` field set to \`true\`.
|
|
101
|
+
|
|
96
102
|
- If both the \`-v,--verbose\` and \`--json\` options are set, Yarn will also return the cross-dependencies between each workspaces (useful when you wish to automatically generate Buck / Bazel rules).
|
|
97
103
|
`,
|
|
98
104
|
});
|
|
105
|
+
exports.default = WorkspacesListCommand;
|
package/lib/dedupeUtils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Project, ResolveOptions, Resolver, Descriptor, Package, Report, Cache } from '@yarnpkg/core';
|
|
2
2
|
import { Fetcher, FetchOptions } from '@yarnpkg/core';
|
|
3
|
-
export
|
|
3
|
+
export type PackageUpdate = {
|
|
4
4
|
descriptor: Descriptor;
|
|
5
5
|
currentPackage: Package;
|
|
6
6
|
updatedPackage: Package;
|
|
7
7
|
resolvedPackage: Package;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type Algorithm = (project: Project, patterns: Array<string>, opts: {
|
|
10
10
|
resolver: Resolver;
|
|
11
11
|
resolveOptions: ResolveOptions;
|
|
12
12
|
fetcher: Fetcher;
|
|
@@ -23,7 +23,7 @@ export declare enum Strategy {
|
|
|
23
23
|
HIGHEST = "highest"
|
|
24
24
|
}
|
|
25
25
|
export declare const acceptedStrategies: Set<Strategy.HIGHEST>;
|
|
26
|
-
export
|
|
26
|
+
export type DedupeOptions = {
|
|
27
27
|
strategy: Strategy;
|
|
28
28
|
patterns: Array<string>;
|
|
29
29
|
cache: Cache;
|
package/lib/dedupeUtils.js
CHANGED
|
@@ -15,7 +15,7 @@ var Strategy;
|
|
|
15
15
|
* - dependencies are never downgraded
|
|
16
16
|
*/
|
|
17
17
|
Strategy["HIGHEST"] = "highest";
|
|
18
|
-
})(Strategy
|
|
18
|
+
})(Strategy || (exports.Strategy = Strategy = {}));
|
|
19
19
|
exports.acceptedStrategies = new Set(Object.values(Strategy));
|
|
20
20
|
const DEDUPE_ALGORITHMS = {
|
|
21
21
|
highest: async (project, patterns, { resolver, fetcher, resolveOptions, fetchOptions }) => {
|
|
@@ -44,7 +44,6 @@ const DEDUPE_ALGORITHMS = {
|
|
|
44
44
|
if (typeof currentPackage === `undefined`)
|
|
45
45
|
throw new Error(`Assertion failed: The package (${currentResolution}) should have been registered`);
|
|
46
46
|
Promise.resolve().then(async () => {
|
|
47
|
-
var _a;
|
|
48
47
|
const dependencies = resolver.getResolutionDependencies(descriptor, resolveOptions);
|
|
49
48
|
const resolvedDependencies = Object.fromEntries(await core_1.miscUtils.allSettledSafe(Object.entries(dependencies).map(async ([dependencyName, dependency]) => {
|
|
50
49
|
const dependencyDeferred = deferredMap.get(dependency.descriptorHash);
|
|
@@ -74,7 +73,7 @@ const DEDUPE_ALGORITHMS = {
|
|
|
74
73
|
return pkg;
|
|
75
74
|
});
|
|
76
75
|
const satisfying = await resolver.getSatisfying(descriptor, resolvedDependencies, candidates, resolveOptions);
|
|
77
|
-
const bestLocator =
|
|
76
|
+
const bestLocator = satisfying.locators?.[0];
|
|
78
77
|
if (typeof bestLocator === `undefined` || !satisfying.sorted)
|
|
79
78
|
return currentPackage;
|
|
80
79
|
const updatedPackage = project.originalPackages.get(bestLocator.locatorHash);
|
|
@@ -109,7 +108,6 @@ async function dedupe(project, { strategy, patterns, cache, report }) {
|
|
|
109
108
|
fetcher,
|
|
110
109
|
project,
|
|
111
110
|
report: throwReport,
|
|
112
|
-
skipIntegrityCheck: true,
|
|
113
111
|
cacheOptions: {
|
|
114
112
|
skipIntegrityCheck: true,
|
|
115
113
|
},
|
|
@@ -124,7 +122,7 @@ async function dedupe(project, { strategy, patterns, cache, report }) {
|
|
|
124
122
|
const algorithm = DEDUPE_ALGORITHMS[strategy];
|
|
125
123
|
const dedupePromises = await algorithm(project, patterns, { resolver, resolveOptions, fetcher, fetchOptions });
|
|
126
124
|
const progress = core_1.Report.progressViaCounter(dedupePromises.length);
|
|
127
|
-
report.reportProgress(progress);
|
|
125
|
+
await report.reportProgress(progress);
|
|
128
126
|
let dedupedPackageCount = 0;
|
|
129
127
|
await Promise.all(dedupePromises.map(dedupePromise => dedupePromise
|
|
130
128
|
.then(dedupe => {
|