@yarnpkg/plugin-essentials 4.3.2 → 4.4.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.js +11 -1
- package/lib/suggestUtils.js +28 -7
- package/package.json +5 -5
package/lib/commands/add.js
CHANGED
|
@@ -82,10 +82,20 @@ class AddCommand extends cli_1.BaseCommand {
|
|
|
82
82
|
const maxResults = interactive
|
|
83
83
|
? Infinity
|
|
84
84
|
: 1;
|
|
85
|
+
const jsrToDescriptor = (pseudoDescriptor) => {
|
|
86
|
+
const descriptor = core_3.structUtils.tryParseDescriptor(pseudoDescriptor.slice(4));
|
|
87
|
+
if (!descriptor)
|
|
88
|
+
return null;
|
|
89
|
+
if (descriptor.range === `unknown`)
|
|
90
|
+
return core_3.structUtils.makeDescriptor(descriptor, `jsr:${core_3.structUtils.stringifyIdent(descriptor)}@latest`);
|
|
91
|
+
return core_3.structUtils.makeDescriptor(descriptor, `jsr:${descriptor.range}`);
|
|
92
|
+
};
|
|
85
93
|
const allSuggestions = await Promise.all(this.packages.map(async (pseudoDescriptor) => {
|
|
86
94
|
const request = pseudoDescriptor.match(/^\.{0,2}\//)
|
|
87
95
|
? await suggestUtils.extractDescriptorFromPath(pseudoDescriptor, { cwd: this.context.cwd, workspace })
|
|
88
|
-
:
|
|
96
|
+
: pseudoDescriptor.startsWith(`jsr:`)
|
|
97
|
+
? jsrToDescriptor(pseudoDescriptor)
|
|
98
|
+
: core_3.structUtils.tryParseDescriptor(pseudoDescriptor);
|
|
89
99
|
const unsupportedPrefix = pseudoDescriptor.match(/^(https?:|git@github)/);
|
|
90
100
|
if (unsupportedPrefix)
|
|
91
101
|
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.formatUtils.Type.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.formatUtils.Type.CODE)} ${core_1.formatUtils.pretty(configuration, core_3.structUtils.makeDescriptor(core_3.structUtils.makeIdent(null, `my-package`), `${unsupportedPrefix[0]}...`), core_1.formatUtils.Type.DESCRIPTOR)}`);
|
package/lib/suggestUtils.js
CHANGED
|
@@ -167,15 +167,36 @@ async function extractDescriptorFromPath(path, { cwd, workspace }) {
|
|
|
167
167
|
return core_2.structUtils.makeDescriptor(manifest.name, path);
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
+
function extractInferenceParametersFromRequest(request) {
|
|
171
|
+
if (request.range === `unknown`)
|
|
172
|
+
return { type: `resolve`, range: `latest` };
|
|
173
|
+
if (core_2.semverUtils.validRange(request.range))
|
|
174
|
+
return { type: `fixed`, range: request.range };
|
|
175
|
+
if (core_1.TAG_REGEXP.test(request.range))
|
|
176
|
+
return { type: `resolve`, range: request.range };
|
|
177
|
+
const registryProtocol = request.range.match(/^(?:jsr:|npm:)(.*)/);
|
|
178
|
+
if (!registryProtocol)
|
|
179
|
+
return { type: `fixed`, range: request.range };
|
|
180
|
+
let [, range] = registryProtocol;
|
|
181
|
+
// Try to handle the case of "foo@jsr:foo@latest", because otherwise there
|
|
182
|
+
// would be no way to cleanly add a package from a 3rd-party registry using
|
|
183
|
+
// a tag (since foo@jsr:latest would refer to "the package named 'latest'").
|
|
184
|
+
const selfRegistryPrefix = `${core_2.structUtils.stringifyIdent(request)}@`;
|
|
185
|
+
if (range.startsWith(selfRegistryPrefix))
|
|
186
|
+
range = range.slice(selfRegistryPrefix.length);
|
|
187
|
+
if (core_2.semverUtils.validRange(range))
|
|
188
|
+
return { type: `fixed`, range: request.range };
|
|
189
|
+
if (core_1.TAG_REGEXP.test(range))
|
|
190
|
+
return { type: `resolve`, range: request.range };
|
|
191
|
+
return { type: `fixed`, range: request.range };
|
|
192
|
+
}
|
|
170
193
|
async function getSuggestedDescriptors(request, { project, workspace, cache, target, fixed, modifier, strategies, maxResults = Infinity }) {
|
|
171
194
|
if (!(maxResults >= 0))
|
|
172
195
|
throw new Error(`Invalid maxResults (${maxResults})`);
|
|
173
|
-
const
|
|
174
|
-
?
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
: [`unknown`, `latest`];
|
|
178
|
-
if (requestRange !== `unknown`) {
|
|
196
|
+
const inference = !fixed || request.range === `unknown`
|
|
197
|
+
? extractInferenceParametersFromRequest(request)
|
|
198
|
+
: { type: `fixed`, range: request.range };
|
|
199
|
+
if (inference.type === `fixed`) {
|
|
179
200
|
return {
|
|
180
201
|
suggestions: [{
|
|
181
202
|
descriptor: request,
|
|
@@ -289,7 +310,7 @@ async function getSuggestedDescriptors(request, { project, workspace, cache, tar
|
|
|
289
310
|
});
|
|
290
311
|
}
|
|
291
312
|
else {
|
|
292
|
-
const latest = await fetchDescriptorFrom(request,
|
|
313
|
+
const latest = await fetchDescriptorFrom(request, inference.range, { project, cache, workspace, modifier });
|
|
293
314
|
if (latest) {
|
|
294
315
|
suggested.push({
|
|
295
316
|
descriptor: latest,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarnpkg/plugin-essentials",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"license": "BSD-2-Clause",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"typanion": "^3.14.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@yarnpkg/cli": "^4.
|
|
24
|
-
"@yarnpkg/core": "^4.
|
|
23
|
+
"@yarnpkg/cli": "^4.9.0",
|
|
24
|
+
"@yarnpkg/core": "^4.4.0",
|
|
25
25
|
"@yarnpkg/plugin-git": "^3.1.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/lodash": "^4.14.136",
|
|
29
29
|
"@types/micromatch": "^4.0.1",
|
|
30
30
|
"@types/semver": "^7.1.0",
|
|
31
|
-
"@yarnpkg/cli": "^4.
|
|
32
|
-
"@yarnpkg/core": "^4.
|
|
31
|
+
"@yarnpkg/cli": "^4.9.0",
|
|
32
|
+
"@yarnpkg/core": "^4.4.0",
|
|
33
33
|
"@yarnpkg/plugin-git": "^3.1.1"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|