@vltpkg/pick-manifest 0.0.0-0.1730239248325
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/LICENSE +15 -0
- package/README.md +1 -0
- package/dist/esm/index.d.ts +34 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +195 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# `@vltpkg/pick-manifest`
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Range, Version } from '@vltpkg/semver';
|
|
2
|
+
import { Spec } from '@vltpkg/spec';
|
|
3
|
+
import { Manifest, Packument, RevDoc, RevDocEntry } from '@vltpkg/types';
|
|
4
|
+
export type PickManifestOptions = {
|
|
5
|
+
tag?: string;
|
|
6
|
+
before?: Date | number | string;
|
|
7
|
+
'node-version'?: string;
|
|
8
|
+
os?: NodeJS.Platform;
|
|
9
|
+
arch?: NodeJS.Architecture;
|
|
10
|
+
};
|
|
11
|
+
export type Manifestish = Manifest | RevDocEntry;
|
|
12
|
+
export type Packumentish = Packument | RevDoc;
|
|
13
|
+
export type PickManifestish<T extends Packumentish> = T extends RevDoc ? RevDocEntry : Manifest;
|
|
14
|
+
export type ManiCheck<T extends Packumentish> = {
|
|
15
|
+
version: Version;
|
|
16
|
+
deprecated: boolean;
|
|
17
|
+
platform: boolean;
|
|
18
|
+
prerelease: boolean;
|
|
19
|
+
mani: PickManifestish<T>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Call with a manifest and the node version and process platform/arch
|
|
23
|
+
* to check whether a version is suitable for the current platform.
|
|
24
|
+
*/
|
|
25
|
+
export declare const platformCheck: (mani: Manifestish, nodeVersion: Version | string, wantOs?: NodeJS.Process["platform"], wantArch?: NodeJS.Process["arch"]) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Choose the most appropriate manifest from a packument.
|
|
28
|
+
*
|
|
29
|
+
* If `before` is set in the options, then the packument MUST
|
|
30
|
+
* be a full non-minified Packument object. Otherwise, a minified packument
|
|
31
|
+
* is fine.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pickManifest<T extends Packumentish>(packument: T, wanted: Range | Spec | string, opts?: PickManifestOptions): PickManifestish<T> | undefined;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,EAAa,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,WAAW,EACZ,MAAM,eAAe,CAAA;AAItB,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC,YAAY,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA;AAChD,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,CAAA;AAC7C,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,YAAY,IAChD,CAAC,SAAS,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAC3C,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,YAAY,IAAI;IAC9C,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;CACzB,CAAA;AAwCD;;;GAGG;AACH,eAAO,MAAM,aAAa,SAClB,WAAW,eACJ,OAAO,GAAG,MAAM,WACpB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,aACxB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAChC,OAWF,CAAA;AAoBD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,YAAY,EACjD,SAAS,EAAE,CAAC,EACZ,MAAM,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,EAC7B,IAAI,GAAE,mBAAwB,GAC7B,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CA6IhC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { parse, Range, satisfies, Version } from '@vltpkg/semver';
|
|
3
|
+
import { Spec } from '@vltpkg/spec';
|
|
4
|
+
const parsedNodeVersion = Version.parse(process.version);
|
|
5
|
+
const isBefore = (version, before, verTimes) => {
|
|
6
|
+
if (!verTimes || !version || !before)
|
|
7
|
+
return true;
|
|
8
|
+
const time = version && verTimes[version];
|
|
9
|
+
return !!time && Date.parse(time) <= before;
|
|
10
|
+
};
|
|
11
|
+
const checkList = (value, list) => {
|
|
12
|
+
if (typeof list === 'string') {
|
|
13
|
+
list = [list];
|
|
14
|
+
}
|
|
15
|
+
// invalid list is equivalent to 'any'
|
|
16
|
+
if (!Array.isArray(list))
|
|
17
|
+
return true;
|
|
18
|
+
if (list.length === 1 && list[0] === 'any') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
// match none of the negated values, and at least one of the
|
|
22
|
+
// non-negated values, if any are present.
|
|
23
|
+
let negated = 0;
|
|
24
|
+
let match = false;
|
|
25
|
+
for (const entry of list) {
|
|
26
|
+
const negate = entry.startsWith('!');
|
|
27
|
+
const test = negate ? entry.slice(1) : entry;
|
|
28
|
+
if (negate) {
|
|
29
|
+
negated++;
|
|
30
|
+
if (value === test) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
match = match || value === test;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return match || negated === list.length;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Call with a manifest and the node version and process platform/arch
|
|
42
|
+
* to check whether a version is suitable for the current platform.
|
|
43
|
+
*/
|
|
44
|
+
export const platformCheck = (mani, nodeVersion, wantOs, wantArch) => {
|
|
45
|
+
const { engines, os, cpu } = mani;
|
|
46
|
+
if (engines) {
|
|
47
|
+
const { node } = engines;
|
|
48
|
+
if (node && !satisfies(nodeVersion, node, true)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (wantOs && !checkList(wantOs, os))
|
|
53
|
+
return false;
|
|
54
|
+
if (wantArch && !checkList(wantArch, cpu))
|
|
55
|
+
return false;
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
const versionOk = (packument, version, nodeVersion, os, arch, before) => {
|
|
59
|
+
const mani = packument.versions[version];
|
|
60
|
+
/* c8 ignore next */
|
|
61
|
+
if (!mani)
|
|
62
|
+
return false;
|
|
63
|
+
const { time } = packument;
|
|
64
|
+
return (isBefore(version, before, time) &&
|
|
65
|
+
platformCheck(mani, nodeVersion, os, arch));
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Choose the most appropriate manifest from a packument.
|
|
69
|
+
*
|
|
70
|
+
* If `before` is set in the options, then the packument MUST
|
|
71
|
+
* be a full non-minified Packument object. Otherwise, a minified packument
|
|
72
|
+
* is fine.
|
|
73
|
+
*/
|
|
74
|
+
export function pickManifest(packument, wanted, opts = {}) {
|
|
75
|
+
const { tag = 'latest', before, 'node-version': nodeVersion, os = process.platform, arch = process.arch, } = opts;
|
|
76
|
+
const nv = !nodeVersion ? parsedNodeVersion : Version.parse(nodeVersion);
|
|
77
|
+
// cast since 'time' might not be present on minified packuments
|
|
78
|
+
const { name, time: verTimes, versions = {}, 'dist-tags': distTags = {}, } = packument;
|
|
79
|
+
const time = before && verTimes ? +new Date(before) : Infinity;
|
|
80
|
+
let range = undefined;
|
|
81
|
+
let spec = undefined;
|
|
82
|
+
if (typeof wanted === 'object') {
|
|
83
|
+
if (wanted instanceof Spec) {
|
|
84
|
+
const f = wanted.final;
|
|
85
|
+
range = f.range;
|
|
86
|
+
spec = f;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
range = wanted;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
spec = Spec.parse(`${name}@${wanted}`).final;
|
|
94
|
+
range = spec.range;
|
|
95
|
+
}
|
|
96
|
+
if (!range) {
|
|
97
|
+
if (!spec?.distTag) {
|
|
98
|
+
throw error('Only dist-tag or semver range specs are supported', { spec });
|
|
99
|
+
}
|
|
100
|
+
// if there is an explicit dist tag, we must get that version.
|
|
101
|
+
const ver = distTags[spec.distTag];
|
|
102
|
+
if (!ver)
|
|
103
|
+
return undefined;
|
|
104
|
+
// if the version in the dist-tags is before the before date, then
|
|
105
|
+
// we use that. Otherwise, we get the highest precedence version
|
|
106
|
+
// prior to the dist-tag.
|
|
107
|
+
const mani = versions[ver];
|
|
108
|
+
if (mani && versionOk(packument, ver, nv, os, arch, time)) {
|
|
109
|
+
return mani;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
range = new Range(`<=${ver}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (range.isAny)
|
|
116
|
+
range = new Range('*', true);
|
|
117
|
+
// if the range is *, then we prefer the 'latest' if available
|
|
118
|
+
// but skip this if it should be avoided, in that case we have
|
|
119
|
+
// to try a little harder.
|
|
120
|
+
const defaultVer = distTags[tag];
|
|
121
|
+
const defTagVersion = defaultVer ? Version.parse(defaultVer) : undefined;
|
|
122
|
+
if (defaultVer &&
|
|
123
|
+
(range.isAny || defTagVersion?.satisfies(range)) &&
|
|
124
|
+
versionOk(packument, defaultVer, nv, os, arch, time)) {
|
|
125
|
+
return versions[defaultVer];
|
|
126
|
+
}
|
|
127
|
+
// ok, actually have to scan the list
|
|
128
|
+
const entries = Object.entries(versions);
|
|
129
|
+
if (!entries.length) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
let found = undefined;
|
|
133
|
+
let foundIsDefTag = false;
|
|
134
|
+
for (const [ver, mani] of entries) {
|
|
135
|
+
if (time && verTimes && !isBefore(ver, time, verTimes)) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const version = parse(ver);
|
|
139
|
+
if (!version?.satisfies(range)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const mc = {
|
|
143
|
+
version,
|
|
144
|
+
deprecated: !!mani.deprecated,
|
|
145
|
+
platform: platformCheck(mani, nv, os, arch),
|
|
146
|
+
prerelease: !!version.prerelease?.length,
|
|
147
|
+
mani,
|
|
148
|
+
};
|
|
149
|
+
if (!found) {
|
|
150
|
+
found = mc;
|
|
151
|
+
if (defTagVersion?.equals(found.version)) {
|
|
152
|
+
foundIsDefTag = true;
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const mok = !mc.deprecated && mc.platform;
|
|
157
|
+
const fok = !found.deprecated && found.platform;
|
|
158
|
+
if (mok !== fok) {
|
|
159
|
+
if (mok) {
|
|
160
|
+
found = mc;
|
|
161
|
+
foundIsDefTag = !!defTagVersion?.equals(mc.version);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (mc.platform !== found.platform) {
|
|
165
|
+
if (mc.platform) {
|
|
166
|
+
found = mc;
|
|
167
|
+
foundIsDefTag = !!defTagVersion?.equals(mc.version);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (mc.deprecated !== found.deprecated) {
|
|
171
|
+
if (!mc.deprecated) {
|
|
172
|
+
found = mc;
|
|
173
|
+
/* c8 ignore next */
|
|
174
|
+
foundIsDefTag = !!defTagVersion?.equals(mc.version);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (found.prerelease !== mc.prerelease) {
|
|
178
|
+
if (!mc.prerelease) {
|
|
179
|
+
found = mc;
|
|
180
|
+
/* c8 ignore next */
|
|
181
|
+
foundIsDefTag = !!defTagVersion?.equals(mc.version);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
else if (defTagVersion?.equals(mc.version)) {
|
|
185
|
+
found = mc;
|
|
186
|
+
foundIsDefTag = true;
|
|
187
|
+
}
|
|
188
|
+
else if (mc.version.greaterThan(found.version) &&
|
|
189
|
+
!foundIsDefTag) {
|
|
190
|
+
found = mc;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return found?.mani;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAQnC,MAAM,iBAAiB,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAsBxD,MAAM,QAAQ,GAAG,CACf,OAAe,EACf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ver'\nimport { Spec } from '@vltpkg/spec'\nimport {\n Manifest,\n Packument,\n RevDoc,\n RevDocEntry,\n} from '@vltpkg/types'\n\nconst parsedNodeVersion = Version.parse(process.version)\n\nexport type PickManifestOptions = {\n tag?: string\n before?: Date | number | string\n 'node-version'?: string\n os?: NodeJS.Platform\n arch?: NodeJS.Architecture\n}\n\nexport type Manifestish = Manifest | RevDocEntry\nexport type Packumentish = Packument | RevDoc\nexport type PickManifestish<T extends Packumentish> =\n T extends RevDoc ? RevDocEntry : Manifest\nexport type ManiCheck<T extends Packumentish> = {\n version: Version\n deprecated: boolean\n platform: boolean\n prerelease: boolean\n mani: PickManifestish<T>\n}\n\nconst isBefore = (\n version: string,\n before?: number,\n verTimes?: Record<string, string>,\n): boolean => {\n if (!verTimes || !version || !before) return true\n const time = version && verTimes[version]\n return !!time && Date.parse(time) <= before\n}\n\nconst checkList = (value: string, list?: string[] | string) => {\n if (typeof list === 'string') {\n list = [list]\n }\n // invalid list is equivalent to 'any'\n if (!Array.isArray(list)) return true\n if (list.length === 1 && list[0] === 'any') {\n return true\n }\n // match none of the negated values, and at least one of the\n // non-negated values, if any are present.\n let negated = 0\n let match = false\n for (const entry of list) {\n const negate = entry.startsWith('!')\n const test = negate ? entry.slice(1) : entry\n if (negate) {\n negated++\n if (value === test) {\n return false\n }\n } else {\n match = match || value === test\n }\n }\n return match || negated === list.length\n}\n\n/**\n * Call with a manifest and the node version and process platform/arch\n * to check whether a version is suitable for the current platform.\n */\nexport const platformCheck = (\n mani: Manifestish,\n nodeVersion: Version | string,\n wantOs?: NodeJS.Process['platform'],\n wantArch?: NodeJS.Process['arch'],\n): boolean => {\n const { engines, os, cpu } = mani\n if (engines) {\n const { node } = engines\n if (node && !satisfies(nodeVersion, node, true)) {\n return false\n }\n }\n if (wantOs && !checkList(wantOs, os)) return false\n if (wantArch && !checkList(wantArch, cpu)) return false\n return true\n}\n\nconst versionOk = (\n packument: Packumentish,\n version: string,\n nodeVersion: Version,\n os: NodeJS.Process['platform'],\n arch: NodeJS.Process['arch'],\n before?: number,\n) => {\n const mani = packument.versions[version]\n /* c8 ignore next */\n if (!mani) return false\n const { time } = packument\n return (\n isBefore(version, before, time) &&\n platformCheck(mani, nodeVersion, os, arch)\n )\n}\n\n/**\n * Choose the most appropriate manifest from a packument.\n *\n * If `before` is set in the options, then the packument MUST\n * be a full non-minified Packument object. Otherwise, a minified packument\n * is fine.\n */\nexport function pickManifest<T extends Packumentish>(\n packument: T,\n wanted: Range | Spec | string,\n opts: PickManifestOptions = {},\n): PickManifestish<T> | undefined {\n const {\n tag = 'latest',\n before,\n 'node-version': nodeVersion,\n os = process.platform,\n arch = process.arch,\n } = opts\n const nv =\n !nodeVersion ? parsedNodeVersion : Version.parse(nodeVersion)\n\n // cast since 'time' might not be present on minified packuments\n const {\n name,\n time: verTimes,\n versions = {},\n 'dist-tags': distTags = {},\n } = packument\n\n const time = before && verTimes ? +new Date(before) : Infinity\n let range: Range | undefined = undefined\n let spec: Spec | undefined = undefined\n if (typeof wanted === 'object') {\n if (wanted instanceof Spec) {\n const f = wanted.final\n range = f.range\n spec = f\n } else {\n range = wanted\n }\n } else {\n spec = Spec.parse(`${name}@${wanted}`).final\n range = spec.range\n }\n\n if (!range) {\n if (!spec?.distTag) {\n throw error(\n 'Only dist-tag or semver range specs are supported',\n { spec },\n )\n }\n // if there is an explicit dist tag, we must get that version.\n const ver = distTags[spec.distTag]\n if (!ver) return undefined\n // if the version in the dist-tags is before the before date, then\n // we use that. Otherwise, we get the highest precedence version\n // prior to the dist-tag.\n const mani = versions[ver]\n if (mani && versionOk(packument, ver, nv, os, arch, time)) {\n return mani as PickManifestish<T>\n } else {\n range = new Range(`<=${ver}`)\n }\n }\n\n if (range.isAny) range = new Range('*', true)\n\n // if the range is *, then we prefer the 'latest' if available\n // but skip this if it should be avoided, in that case we have\n // to try a little harder.\n const defaultVer = distTags[tag]\n const defTagVersion =\n defaultVer ? Version.parse(defaultVer) : undefined\n if (\n defaultVer &&\n (range.isAny || defTagVersion?.satisfies(range)) &&\n versionOk(packument, defaultVer, nv, os, arch, time)\n ) {\n return versions[defaultVer] as PickManifestish<T>\n }\n\n // ok, actually have to scan the list\n const entries = Object.entries(versions)\n\n if (!entries.length) {\n return undefined\n }\n\n let found: ManiCheck<T> | undefined = undefined\n let foundIsDefTag = false\n\n for (const [ver, mani] of entries) {\n if (time && verTimes && !isBefore(ver, time, verTimes)) {\n continue\n }\n const version = parse(ver)\n if (!version?.satisfies(range)) {\n continue\n }\n const mc = {\n version,\n deprecated: !!mani.deprecated,\n platform: platformCheck(mani, nv, os, arch),\n prerelease: !!version.prerelease?.length,\n mani,\n }\n if (!found) {\n found = mc\n if (defTagVersion?.equals(found.version)) {\n foundIsDefTag = true\n }\n continue\n }\n\n const mok = !mc.deprecated && mc.platform\n const fok = !found.deprecated && found.platform\n\n if (mok !== fok) {\n if (mok) {\n found = mc\n foundIsDefTag = !!defTagVersion?.equals(mc.version)\n }\n } else if (mc.platform !== found.platform) {\n if (mc.platform) {\n found = mc\n foundIsDefTag = !!defTagVersion?.equals(mc.version)\n }\n } else if (mc.deprecated !== found.deprecated) {\n if (!mc.deprecated) {\n found = mc\n /* c8 ignore next */\n foundIsDefTag = !!defTagVersion?.equals(mc.version)\n }\n } else if (found.prerelease !== mc.prerelease) {\n if (!mc.prerelease) {\n found = mc\n /* c8 ignore next */\n foundIsDefTag = !!defTagVersion?.equals(mc.version)\n }\n } else if (defTagVersion?.equals(mc.version)) {\n found = mc\n foundIsDefTag = true\n } else if (\n mc.version.greaterThan(found.version) &&\n !foundIsDefTag\n ) {\n found = mc\n }\n }\n return found?.mani\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/pick-manifest",
|
|
3
|
+
"description": "Choose a manifest from a packument",
|
|
4
|
+
"version": "0.0.0-0.1730239248325",
|
|
5
|
+
"tshy": {
|
|
6
|
+
"selfLink": false,
|
|
7
|
+
"dialects": [
|
|
8
|
+
"esm"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@vltpkg/error-cause": "0.0.0-0.1730239248325",
|
|
17
|
+
"@vltpkg/semver": "0.0.0-0.1730239248325",
|
|
18
|
+
"@vltpkg/spec": "0.0.0-0.1730239248325",
|
|
19
|
+
"@vltpkg/types": "0.0.0-0.1730239248325"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@eslint/js": "^9.8.0",
|
|
23
|
+
"@types/eslint__js": "^8.42.3",
|
|
24
|
+
"@types/node": "^22.4.1",
|
|
25
|
+
"eslint": "^9.8.0",
|
|
26
|
+
"npm-pick-manifest": "^9.1.0",
|
|
27
|
+
"prettier": "^3.3.2",
|
|
28
|
+
"tap": "^21.0.1",
|
|
29
|
+
"tshy": "^3.0.2",
|
|
30
|
+
"typescript": "^5.5.4",
|
|
31
|
+
"typescript-eslint": "^8.0.1",
|
|
32
|
+
"@vltpkg/benchmark": "0.0.0-0"
|
|
33
|
+
},
|
|
34
|
+
"license": "BSD-2-Clause-Patent",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": "20 || >=22"
|
|
37
|
+
},
|
|
38
|
+
"tap": {
|
|
39
|
+
"extends": "../../tap-config.yaml"
|
|
40
|
+
},
|
|
41
|
+
"prettier": "../../.prettierrc.js",
|
|
42
|
+
"module": "./dist/esm/index.js",
|
|
43
|
+
"type": "module",
|
|
44
|
+
"exports": {
|
|
45
|
+
"./package.json": "./package.json",
|
|
46
|
+
".": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/esm/index.d.ts",
|
|
49
|
+
"default": "./dist/esm/index.js"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"prebenchmark": "pnpm vlt-benchmark-download-fixtures",
|
|
58
|
+
"benchmark": "node scripts/benchmark.js",
|
|
59
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
60
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
61
|
+
"lint": "eslint . --fix",
|
|
62
|
+
"lint:check": "eslint .",
|
|
63
|
+
"presnap": "tshy",
|
|
64
|
+
"snap": "tap",
|
|
65
|
+
"pretest": "tshy",
|
|
66
|
+
"test": "tap"
|
|
67
|
+
}
|
|
68
|
+
}
|