@yarnpkg/plugin-essentials 3.2.2 → 3.2.3
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.js +24 -13
- package/lib/commands/plugin/import/sources.d.ts +1 -1
- package/lib/commands/set/version/sources.d.ts +1 -1
- package/lib/commands/set/version.d.ts +1 -1
- package/lib/commands/set/version.js +26 -22
- package/lib/dedupeUtils.d.ts +2 -2
- package/lib/suggestUtils.d.ts +3 -3
- package/package.json +6 -6
package/lib/commands/add.js
CHANGED
|
@@ -84,21 +84,24 @@ class AddCommand extends cli_1.BaseCommand {
|
|
|
84
84
|
throw new clipanion_1.UsageError(`It seems you are trying to add a package using a ${core_1.formatUtils.pretty(configuration, `${unsupportedPrefix[0]}...`, core_1.FormatType.RANGE)} url; we now require package names to be explicitly specified.\nTry running the command again with the package name prefixed: ${core_1.formatUtils.pretty(configuration, `yarn add`, core_1.FormatType.CODE)} ${core_1.formatUtils.pretty(configuration, core_3.structUtils.makeDescriptor(core_3.structUtils.makeIdent(null, `my-package`), `${unsupportedPrefix[0]}...`), core_1.FormatType.DESCRIPTOR)}`);
|
|
85
85
|
if (!request)
|
|
86
86
|
throw new clipanion_1.UsageError(`The ${core_1.formatUtils.pretty(configuration, pseudoDescriptor, core_1.FormatType.CODE)} string didn't match the required format (package-name@range). Did you perhaps forget to explicitly reference the package name?`);
|
|
87
|
-
const
|
|
87
|
+
const targetList = suggestTargetList(workspace, request, {
|
|
88
88
|
dev: this.dev,
|
|
89
89
|
peer: this.peer,
|
|
90
90
|
preferDev: this.preferDev,
|
|
91
91
|
optional: this.optional,
|
|
92
92
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const results = await Promise.all(targetList.map(async (target) => {
|
|
94
|
+
const suggestedDescriptors = await suggestUtils.getSuggestedDescriptors(request, { project, workspace, cache, target, modifier, strategies, maxResults });
|
|
95
|
+
return { request, suggestedDescriptors, target };
|
|
96
|
+
}));
|
|
97
|
+
return results;
|
|
98
|
+
})).then(results => results.flat());
|
|
96
99
|
const checkReport = await core_1.LightReport.start({
|
|
97
100
|
configuration,
|
|
98
101
|
stdout: this.context.stdout,
|
|
99
102
|
suggestInstall: false,
|
|
100
103
|
}, async (report) => {
|
|
101
|
-
for (const
|
|
104
|
+
for (const { request, suggestedDescriptors: { suggestions, rejections } } of allSuggestions) {
|
|
102
105
|
const nonNullSuggestions = suggestions.filter(suggestion => {
|
|
103
106
|
return suggestion.descriptor !== null;
|
|
104
107
|
});
|
|
@@ -120,7 +123,7 @@ class AddCommand extends cli_1.BaseCommand {
|
|
|
120
123
|
let askedQuestions = false;
|
|
121
124
|
const afterWorkspaceDependencyAdditionList = [];
|
|
122
125
|
const afterWorkspaceDependencyReplacementList = [];
|
|
123
|
-
for (const
|
|
126
|
+
for (const { suggestedDescriptors: { suggestions }, target } of allSuggestions) {
|
|
124
127
|
let selected;
|
|
125
128
|
const nonNullSuggestions = suggestions.filter(suggestion => {
|
|
126
129
|
return suggestion.descriptor !== null;
|
|
@@ -257,7 +260,7 @@ AddCommand.usage = clipanion_1.Command.Usage({
|
|
|
257
260
|
`$0 add lodash-es@lodash/lodash#es`,
|
|
258
261
|
]],
|
|
259
262
|
});
|
|
260
|
-
function
|
|
263
|
+
function suggestTargetList(workspace, ident, { dev, peer, preferDev, optional }) {
|
|
261
264
|
const hasRegular = workspace.manifest[suggestUtils.Target.REGULAR].has(ident.identHash);
|
|
262
265
|
const hasDev = workspace.manifest[suggestUtils.Target.DEVELOPMENT].has(ident.identHash);
|
|
263
266
|
const hasPeer = workspace.manifest[suggestUtils.Target.PEER].has(ident.identHash);
|
|
@@ -271,13 +274,21 @@ function suggestTarget(workspace, ident, { dev, peer, preferDev, optional }) {
|
|
|
271
274
|
throw new clipanion_1.UsageError(`Package "${core_3.structUtils.prettyIdent(workspace.project.configuration, ident)}" is already listed as a peer dependency - remove the -O flag or add the -P flag or remove it from your peer dependencies first`);
|
|
272
275
|
if ((dev || preferDev) && optional)
|
|
273
276
|
throw new clipanion_1.UsageError(`Package "${core_3.structUtils.prettyIdent(workspace.project.configuration, ident)}" cannot simultaneously be a dev dependency and an optional dependency`);
|
|
277
|
+
// When the program executes this line, the command is expected to be legal
|
|
278
|
+
const targetList = [];
|
|
274
279
|
if (peer)
|
|
275
|
-
|
|
280
|
+
targetList.push(suggestUtils.Target.PEER);
|
|
276
281
|
if (dev || preferDev)
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
282
|
+
targetList.push(suggestUtils.Target.DEVELOPMENT);
|
|
283
|
+
if (optional)
|
|
284
|
+
targetList.push(suggestUtils.Target.REGULAR);
|
|
285
|
+
// The user explicitly define the targets
|
|
286
|
+
if (targetList.length > 0)
|
|
287
|
+
return targetList;
|
|
288
|
+
// The user does not define the targets, find it from the `workspace.manifest`
|
|
280
289
|
if (hasDev)
|
|
281
|
-
return suggestUtils.Target.DEVELOPMENT;
|
|
282
|
-
|
|
290
|
+
return [suggestUtils.Target.DEVELOPMENT];
|
|
291
|
+
if (hasPeer)
|
|
292
|
+
return [suggestUtils.Target.PEER];
|
|
293
|
+
return [suggestUtils.Target.REGULAR];
|
|
283
294
|
}
|
|
@@ -14,7 +14,7 @@ export default class PluginDlSourcesCommand extends BaseCommand {
|
|
|
14
14
|
name: string;
|
|
15
15
|
execute(): Promise<1 | 0>;
|
|
16
16
|
}
|
|
17
|
-
export
|
|
17
|
+
export type BuildAndSavePluginsSpec = {
|
|
18
18
|
context: CommandContext;
|
|
19
19
|
noMinify: boolean;
|
|
20
20
|
};
|
|
@@ -19,7 +19,7 @@ export declare function runWorkflow(workflow: Array<Array<string>>, { configurat
|
|
|
19
19
|
context: CommandContext;
|
|
20
20
|
target: PortablePath;
|
|
21
21
|
}): Promise<void>;
|
|
22
|
-
export
|
|
22
|
+
export type PrepareSpec = {
|
|
23
23
|
branch: string;
|
|
24
24
|
context: CommandContext;
|
|
25
25
|
force: boolean;
|
|
@@ -18,9 +18,17 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
18
18
|
this.version = clipanion_1.Option.String();
|
|
19
19
|
}
|
|
20
20
|
async execute() {
|
|
21
|
+
var _a;
|
|
21
22
|
const configuration = await core_1.Configuration.find(this.context.cwd, this.context.plugins);
|
|
22
|
-
if (configuration.get(`yarnPath`)
|
|
23
|
-
|
|
23
|
+
if (this.onlyIfNeeded && configuration.get(`yarnPath`)) {
|
|
24
|
+
const yarnPathSource = configuration.sources.get(`yarnPath`);
|
|
25
|
+
if (!yarnPathSource)
|
|
26
|
+
throw new Error(`Assertion failed: Expected 'yarnPath' to have a source`);
|
|
27
|
+
const projectCwd = (_a = configuration.projectCwd) !== null && _a !== void 0 ? _a : configuration.startingCwd;
|
|
28
|
+
if (fslib_1.ppath.contains(projectCwd, yarnPathSource)) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
24
32
|
const getBundlePath = () => {
|
|
25
33
|
if (typeof core_1.YarnVersion === `undefined`)
|
|
26
34
|
throw new clipanion_1.UsageError(`The --install flag can only be used without explicit version specifier from the Yarn CLI`);
|
|
@@ -34,7 +42,7 @@ class SetVersionCommand extends cli_1.BaseCommand {
|
|
|
34
42
|
else if (this.version === `canary`)
|
|
35
43
|
bundleUrl = `https://repo.yarnpkg.com/${await resolveTag(configuration, `canary`)}/packages/yarnpkg-cli/bin/yarn.js`;
|
|
36
44
|
else if (this.version === `classic`)
|
|
37
|
-
bundleUrl = `https://
|
|
45
|
+
bundleUrl = `https://classic.yarnpkg.com/latest.js`;
|
|
38
46
|
else if (this.version.match(/^https?:/))
|
|
39
47
|
bundleUrl = this.version;
|
|
40
48
|
else if (this.version.match(/^\.{0,2}[\\/]/) || fslib_1.npath.isAbsolute(this.version))
|
|
@@ -159,28 +167,24 @@ async function setVersion(configuration, bundleVersion, bundleBuffer, { report }
|
|
|
159
167
|
const absolutePath = fslib_1.ppath.resolve(releaseFolder, `yarn-${bundleVersion}.cjs`);
|
|
160
168
|
const displayPath = fslib_1.ppath.relative(configuration.startingCwd, absolutePath);
|
|
161
169
|
const projectPath = fslib_1.ppath.relative(projectCwd, absolutePath);
|
|
162
|
-
const yarnPath = configuration.get(`yarnPath`);
|
|
163
|
-
const updateConfig = yarnPath === null || yarnPath.startsWith(`${releaseFolder}/`);
|
|
164
170
|
report.reportInfo(core_1.MessageName.UNNAMED, `Saving the new release in ${core_2.formatUtils.pretty(configuration, displayPath, `magenta`)}`);
|
|
165
171
|
await fslib_1.xfs.removePromise(fslib_1.ppath.dirname(absolutePath));
|
|
166
172
|
await fslib_1.xfs.mkdirPromise(fslib_1.ppath.dirname(absolutePath), { recursive: true });
|
|
167
173
|
await fslib_1.xfs.writeFilePromise(absolutePath, bundleBuffer, { mode: 0o755 });
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
});
|
|
184
|
-
}
|
|
174
|
+
await core_1.Configuration.updateConfiguration(projectCwd, {
|
|
175
|
+
yarnPath: projectPath,
|
|
176
|
+
});
|
|
177
|
+
const manifest = (await core_1.Manifest.tryFind(projectCwd)) || new core_1.Manifest();
|
|
178
|
+
manifest.packageManager = `yarn@${bundleVersion && core_2.miscUtils.isTaggedYarnVersion(bundleVersion)
|
|
179
|
+
? bundleVersion
|
|
180
|
+
// If the version isn't tagged, we use the latest stable version as the wrapper
|
|
181
|
+
: await resolveTag(configuration, `stable`)}`;
|
|
182
|
+
const data = {};
|
|
183
|
+
manifest.exportTo(data);
|
|
184
|
+
const path = fslib_1.ppath.join(projectCwd, core_1.Manifest.fileName);
|
|
185
|
+
const content = `${JSON.stringify(data, null, manifest.indent)}\n`;
|
|
186
|
+
await fslib_1.xfs.changeFilePromise(path, content, {
|
|
187
|
+
automaticNewlines: true,
|
|
188
|
+
});
|
|
185
189
|
}
|
|
186
190
|
exports.setVersion = setVersion;
|
package/lib/dedupeUtils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 Algorithm = (project: Project, patterns: Array<string>, opts: {
|
|
4
4
|
resolver: Resolver;
|
|
5
5
|
resolveOptions: ResolveOptions;
|
|
6
6
|
fetcher: Fetcher;
|
|
@@ -21,7 +21,7 @@ export declare enum Strategy {
|
|
|
21
21
|
HIGHEST = "highest"
|
|
22
22
|
}
|
|
23
23
|
export declare const acceptedStrategies: Set<Strategy.HIGHEST>;
|
|
24
|
-
export
|
|
24
|
+
export type DedupeOptions = {
|
|
25
25
|
strategy: Strategy;
|
|
26
26
|
patterns: Array<string>;
|
|
27
27
|
cache: Cache;
|
package/lib/suggestUtils.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Cache, DescriptorHash, Descriptor, Ident, Locator, Project, Workspace } from '@yarnpkg/core';
|
|
2
2
|
import { PortablePath } from '@yarnpkg/fslib';
|
|
3
|
-
export
|
|
3
|
+
export type Suggestion = {
|
|
4
4
|
descriptor: Descriptor;
|
|
5
5
|
name: string;
|
|
6
6
|
reason: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type NullableSuggestion = {
|
|
9
9
|
descriptor: Descriptor | null;
|
|
10
10
|
name: string;
|
|
11
11
|
reason: string;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type Results = {
|
|
14
14
|
suggestions: Array<NullableSuggestion>;
|
|
15
15
|
rejections: Array<Error>;
|
|
16
16
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarnpkg/plugin-essentials",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"license": "BSD-2-Clause",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@yarnpkg/fslib": "^2.
|
|
7
|
+
"@yarnpkg/fslib": "^2.8.0",
|
|
8
8
|
"@yarnpkg/json-proxy": "^2.1.1",
|
|
9
9
|
"@yarnpkg/parsers": "^2.5.1",
|
|
10
10
|
"ci-info": "^3.2.0",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"typanion": "^3.3.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@yarnpkg/cli": "^3.2.
|
|
21
|
-
"@yarnpkg/core": "^3.2.
|
|
20
|
+
"@yarnpkg/cli": "^3.2.4",
|
|
21
|
+
"@yarnpkg/core": "^3.2.5",
|
|
22
22
|
"@yarnpkg/plugin-git": "^2.6.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@types/micromatch": "^4.0.1",
|
|
27
27
|
"@types/semver": "^7.1.0",
|
|
28
28
|
"@types/treeify": "^1.0.0",
|
|
29
|
-
"@yarnpkg/cli": "^3.2.
|
|
30
|
-
"@yarnpkg/core": "^3.2.
|
|
29
|
+
"@yarnpkg/cli": "^3.2.4",
|
|
30
|
+
"@yarnpkg/core": "^3.2.5",
|
|
31
31
|
"@yarnpkg/plugin-git": "^2.6.2"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|