@vltpkg/package-info 1.0.0-rc.18 → 1.0.0-rc.22

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/package.json CHANGED
@@ -1,72 +1,76 @@
1
1
  {
2
2
  "name": "@vltpkg/package-info",
3
3
  "description": "Resolve and fetch package metadata and tarballs",
4
- "version": "1.0.0-rc.18",
4
+ "version": "1.0.0-rc.22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/package-info"
9
9
  },
10
- "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh"
13
+ },
11
14
  "dependencies": {
15
+ "@vltpkg/error-cause": "1.0.0-rc.22",
16
+ "@vltpkg/git": "1.0.0-rc.22",
17
+ "@vltpkg/package-json": "1.0.0-rc.22",
18
+ "@vltpkg/pick-manifest": "1.0.0-rc.22",
19
+ "@vltpkg/registry-client": "1.0.0-rc.22",
20
+ "@vltpkg/spec": "1.0.0-rc.22",
21
+ "@vltpkg/tar": "1.0.0-rc.22",
22
+ "@vltpkg/types": "1.0.0-rc.22",
23
+ "@vltpkg/workspaces": "1.0.0-rc.22",
24
+ "@vltpkg/xdg": "1.0.0-rc.22",
12
25
  "ssri": "^13.0.0",
13
- "tar": "^7.5.2",
14
- "@vltpkg/error-cause": "1.0.0-rc.18",
15
- "@vltpkg/package-json": "1.0.0-rc.18",
16
- "@vltpkg/git": "1.0.0-rc.18",
17
- "@vltpkg/pick-manifest": "1.0.0-rc.18",
18
- "@vltpkg/registry-client": "1.0.0-rc.18",
19
- "@vltpkg/spec": "1.0.0-rc.18",
20
- "@vltpkg/tar": "1.0.0-rc.18",
21
- "@vltpkg/types": "1.0.0-rc.18",
22
- "@vltpkg/workspaces": "1.0.0-rc.18",
23
- "@vltpkg/xdg": "1.0.0-rc.18"
26
+ "tar": "^7.5.2"
24
27
  },
25
28
  "devDependencies": {
26
29
  "@eslint/js": "^9.39.1",
27
30
  "@types/node": "^22.19.2",
28
31
  "@types/pacote": "^11.1.8",
32
+ "@vltpkg/benchmark": "0.0.0",
33
+ "@vltpkg/cache-unzip": "1.0.0-rc.22",
34
+ "@vltpkg/vlt-json": "1.0.0-rc.22",
29
35
  "eslint": "^9.39.1",
30
36
  "pacote": "^21.0.4",
31
37
  "prettier": "^3.7.4",
32
38
  "tap": "^21.5.0",
33
39
  "typedoc": "~0.27.9",
34
40
  "typescript": "5.7.3",
35
- "typescript-eslint": "^8.49.0",
36
- "@vltpkg/benchmark": "0.0.0",
37
- "@vltpkg/cache-unzip": "1.0.0-rc.18",
38
- "@vltpkg/vlt-json": "1.0.0-rc.18"
41
+ "typescript-eslint": "^8.49.0"
39
42
  },
40
43
  "license": "BSD-2-Clause-Patent",
41
44
  "engines": {
42
- "node": ">=22.9.0"
45
+ "node": ">=22.22.0"
46
+ },
47
+ "scripts": {
48
+ "benchmark": "./scripts/benchmark.ts",
49
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
50
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
51
+ "lint": "eslint . --fix",
52
+ "lint:check": "eslint .",
53
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
54
+ "snap": "tap",
55
+ "test": "tap",
56
+ "posttest": "tsc --noEmit",
57
+ "typecheck": "tsc --noEmit"
43
58
  },
44
59
  "tap": {
45
60
  "extends": "../../tap-config.yaml"
46
61
  },
47
62
  "prettier": "../../.prettierrc.js",
48
- "module": "./dist/index.js",
63
+ "module": "./src/index.ts",
49
64
  "type": "module",
50
65
  "exports": {
51
66
  "./package.json": "./package.json",
52
67
  ".": {
53
68
  "import": {
54
- "default": "./dist/index.js"
69
+ "default": "./src/index.ts"
55
70
  }
56
71
  }
57
72
  },
58
73
  "files": [
59
74
  "dist"
60
- ],
61
- "scripts": {
62
- "benchmark": "./scripts/benchmark.ts",
63
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
64
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
65
- "lint": "eslint . --fix",
66
- "lint:check": "eslint .",
67
- "snap": "tap",
68
- "test": "tap",
69
- "posttest": "tsc --noEmit",
70
- "typecheck": "tsc --noEmit"
71
- }
72
- }
75
+ ]
76
+ }
package/dist/index.d.ts DELETED
@@ -1,56 +0,0 @@
1
- import { PackageJson } from '@vltpkg/package-json';
2
- import type { PickManifestOptions } from '@vltpkg/pick-manifest';
3
- import type { RegistryClientOptions, RegistryClientRequestOptions } from '@vltpkg/registry-client';
4
- import { RegistryClient } from '@vltpkg/registry-client';
5
- import type { SpecOptions } from '@vltpkg/spec';
6
- import { Spec } from '@vltpkg/spec';
7
- import { Pool } from '@vltpkg/tar';
8
- import type { Integrity, Manifest, Packument } from '@vltpkg/types';
9
- import { Monorepo } from '@vltpkg/workspaces';
10
- export declare const delimiter = "~";
11
- export type Resolution = {
12
- resolved: string;
13
- integrity?: Integrity;
14
- signatures?: Exclude<Manifest['dist'], undefined>['signatures'];
15
- spec: Spec;
16
- };
17
- export type PackageInfoClientOptions = RegistryClientOptions & SpecOptions & {
18
- /** root of the project. Defaults to process.cwd() */
19
- projectRoot?: string;
20
- /** PackageJson object */
21
- packageJson?: PackageJson;
22
- monorepo?: Monorepo;
23
- /** workspace groups to load, irrelevant if Monorepo provided */
24
- 'workspace-group'?: string[];
25
- /** workspace paths to load, irrelevant if Monorepo provided */
26
- workspace?: string[];
27
- };
28
- export type PackageInfoClientRequestOptions = PickManifestOptions & RegistryClientRequestOptions & {
29
- /** dir to resolve `file://` specifiers against. Defaults to projectRoot. */
30
- from?: string;
31
- };
32
- export type PackageInfoClientExtractOptions = PackageInfoClientRequestOptions & {
33
- integrity?: Integrity;
34
- resolved?: string;
35
- };
36
- export declare class PackageInfoClient {
37
- #private;
38
- options: PackageInfoClientOptions;
39
- packageJson: PackageJson;
40
- monorepo?: Monorepo;
41
- get registryClient(): RegistryClient;
42
- get tarPool(): Pool;
43
- constructor(options?: PackageInfoClientOptions);
44
- extract(spec: Spec | string, target: string, options?: PackageInfoClientExtractOptions): Promise<Resolution>;
45
- /**
46
- * Conditionally return the path to the manifest cache file. The logic
47
- * to determine if caching should be skipped aligns with `pickManifest`
48
- * and is used to avoid caching manifest results that can be variable.
49
- */
50
- _manifestCachePath(spec: Spec, options: PackageInfoClientRequestOptions): string | undefined;
51
- tarball(spec: Spec | string, options?: PackageInfoClientExtractOptions): Promise<Buffer>;
52
- manifest(spec: Spec | string, options?: PackageInfoClientRequestOptions): Promise<Manifest | import("@vltpkg/types").Override<Manifest, import("@vltpkg/types").NormalizedFields>>;
53
- packument(spec: Spec | string, options?: PackageInfoClientRequestOptions): Promise<Packument>;
54
- resolve(spec: Spec | string, options?: PackageInfoClientRequestOptions): Promise<Resolution>;
55
- }
56
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAEhE,OAAO,KAAK,EACV,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,SAAS,EAEV,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAsB7C,eAAO,MAAM,SAAS,MAAM,CAAA;AAE5B,MAAM,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+B,GACvC,MAAM,GAAG,SAAS;IAwDf,OAAO,CACX,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,MAAM,CAAC;IAsIZ,QAAQ,CACZ,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,GAAE,+BAAoC;IAwLzC,SAAS,CACb,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,SAAS,CAAC;IA8Df,OAAO,CACX,IAAI,EAAE,IAAI,GAAG,MAAM,EACnB,OAAO,GAAE,+BAAoC,GAC5C,OAAO,CAAC,UAAU,CAAC;CAsJvB"}
package/dist/index.js DELETED
@@ -1,666 +0,0 @@
1
- import { error } from '@vltpkg/error-cause';
2
- import { clone, resolve as gitResolve, revs } from '@vltpkg/git';
3
- import { PackageJson } from '@vltpkg/package-json';
4
- import { pickManifest } from '@vltpkg/pick-manifest';
5
- import { RegistryClient } from '@vltpkg/registry-client';
6
- import { Spec } from '@vltpkg/spec';
7
- import { Pool } from '@vltpkg/tar';
8
- import { asPackument, isIntegrity } from '@vltpkg/types';
9
- import ssri from 'ssri';
10
- import { Monorepo } from '@vltpkg/workspaces';
11
- import { XDG } from '@vltpkg/xdg';
12
- import { randomBytes } from 'node:crypto';
13
- import { mkdir, readFile, rm, stat, symlink, unlink, writeFile, } from 'node:fs/promises';
14
- import { basename, dirname, resolve as pathResolve, relative, } from 'node:path';
15
- import { create as tarC } from 'tar';
16
- import { rename } from "./rename.js";
17
- const xdg = new XDG('vlt');
18
- export const delimiter = '~';
19
- // the maximum duration of a manifest cache file
20
- const manifestCacheMaxAge = 5 * 60 * 1000;
21
- export class PackageInfoClient {
22
- #registryClient;
23
- #projectRoot;
24
- #tarPool;
25
- options;
26
- #resolutions = new Map();
27
- packageJson;
28
- monorepo;
29
- #trustedIntegrities = new Map();
30
- #manifestCacheMinAge = Date.now() - manifestCacheMaxAge;
31
- #cachePath;
32
- get registryClient() {
33
- if (!this.#registryClient) {
34
- this.#registryClient = new RegistryClient(this.options);
35
- }
36
- return this.#registryClient;
37
- }
38
- get tarPool() {
39
- if (!this.#tarPool)
40
- this.#tarPool = new Pool();
41
- return this.#tarPool;
42
- }
43
- constructor(options = {}) {
44
- this.options = options;
45
- this.#projectRoot = options.projectRoot || process.cwd();
46
- this.packageJson = options.packageJson ?? new PackageJson();
47
- const wsLoad = {
48
- ...(options.workspace?.length && { paths: options.workspace }),
49
- ...(options['workspace-group']?.length && {
50
- groups: options['workspace-group'],
51
- }),
52
- };
53
- this.monorepo =
54
- options.monorepo ??
55
- Monorepo.maybeLoad(this.#projectRoot, {
56
- load: wsLoad,
57
- packageJson: this.packageJson,
58
- });
59
- this.#cachePath = options.cache ?? xdg.cache();
60
- // optionally create its cache directory if it doesn't exist
61
- void mkdir(pathResolve(this.#cachePath, 'package-info'), {
62
- recursive: true,
63
- }).catch(() => { });
64
- }
65
- async extract(spec, target, options = {}) {
66
- if (typeof spec === 'string')
67
- spec = Spec.parse(spec, this.options);
68
- const { from = this.#projectRoot, integrity, resolved } = options;
69
- const f = spec.final;
70
- const r = integrity && resolved ?
71
- { resolved, integrity, spec }
72
- : await this.resolve(spec, options);
73
- switch (f.type) {
74
- case 'git': {
75
- const { gitRemote, gitCommittish, remoteURL, gitSelectorParsed, } = f;
76
- if (!remoteURL) {
77
- /* c8 ignore start - Impossible, would throw on the resolve */
78
- if (!gitRemote)
79
- throw this.#resolveError(spec, options, 'no remote on git: specifier');
80
- /* c8 ignore stop */
81
- const { path } = gitSelectorParsed ?? {};
82
- if (path !== undefined) {
83
- // use obvious name because it's in node_modules
84
- const tmp = pathResolve(dirname(target), `.TEMP.${basename(target)}-${randomBytes(6).toString('hex')}`);
85
- await clone(gitRemote, gitCommittish, tmp, { spec });
86
- const src = pathResolve(tmp, path);
87
- await rename(src, target);
88
- // intentionally not awaited
89
- void rm(tmp, { recursive: true, force: true });
90
- }
91
- else {
92
- await clone(gitRemote, gitCommittish, target, { spec });
93
- // intentionally not awaited
94
- void rm(target + '/.git', { recursive: true });
95
- }
96
- return r;
97
- }
98
- // fallthrough if a remote tarball url present
99
- }
100
- case 'registry': {
101
- const trustIntegrity = this.#trustedIntegrities.get(r.resolved) === r.integrity;
102
- const response = await this.registryClient.request(r.resolved, {
103
- integrity: r.integrity,
104
- trustIntegrity,
105
- });
106
- if (response.statusCode !== 200) {
107
- throw this.#resolveError(spec, options, 'failed to fetch tarball', {
108
- url: r.resolved,
109
- response,
110
- });
111
- }
112
- // if it's not trusted already, but valid, start trusting
113
- if (!trustIntegrity &&
114
- response.checkIntegrity({ spec, url: resolved })) {
115
- this.#trustedIntegrities.set(r.resolved, response.integrity);
116
- }
117
- try {
118
- await this.tarPool.unpack(response.buffer(), target);
119
- }
120
- catch (er) {
121
- throw this.#resolveError(spec, options, 'tar unpack failed', { cause: er });
122
- }
123
- return r;
124
- }
125
- case 'remote': {
126
- const response = await this.registryClient.request(r.resolved);
127
- if (response.statusCode !== 200) {
128
- throw this.#resolveError(spec, options, 'failed to fetch remote tarball', {
129
- url: r.resolved,
130
- response,
131
- });
132
- }
133
- const buf = response.buffer();
134
- // Compute integrity for remote/git-with-tarball deps
135
- const computed = ssri
136
- .fromData(buf, { algorithms: ['sha512'] })
137
- .toString();
138
- if (r.integrity && r.integrity !== computed) {
139
- throw error('Integrity check failure', {
140
- code: 'EINTEGRITY',
141
- spec,
142
- url: r.resolved,
143
- wanted: r.integrity,
144
- found: computed,
145
- });
146
- }
147
- r.integrity = computed;
148
- try {
149
- await this.tarPool.unpack(buf, target);
150
- }
151
- catch (er) {
152
- throw this.#resolveError(spec, options, 'remote tar unpack failed', { cause: er });
153
- }
154
- return r;
155
- }
156
- case 'file': {
157
- // if it's a directory, then "extract" means "symlink"
158
- const { file } = f;
159
- /* c8 ignore start - asserted in resolve() */
160
- if (file === undefined)
161
- throw this.#resolveError(spec, options, 'no file path');
162
- /* c8 ignore stop */
163
- const path = pathResolve(from, file);
164
- const st = await stat(path);
165
- if (st.isFile()) {
166
- try {
167
- await this.tarPool.unpack(await this.tarball(spec, options), target);
168
- }
169
- catch (er) {
170
- throw this.#resolveError(spec, options, 'tar unpack failed', { cause: er });
171
- }
172
- }
173
- else if (st.isDirectory()) {
174
- const rel = relative(dirname(target), path);
175
- await symlink(rel, target, 'dir');
176
- /* c8 ignore start */
177
- }
178
- else {
179
- throw this.#resolveError(spec, options, 'file: specifier does not resolve to directory or tarball');
180
- }
181
- /* c8 ignore stop */
182
- return r;
183
- }
184
- case 'workspace': {
185
- const ws = this.#getWS(spec, options);
186
- const rel = relative(dirname(target), ws.fullpath);
187
- await symlink(rel, target, 'dir');
188
- return r;
189
- }
190
- }
191
- }
192
- #getWS(spec, options) {
193
- const { workspace } = spec;
194
- /* c8 ignore start - asserted in resolve() */
195
- if (workspace === undefined)
196
- throw this.#resolveError(spec, options, 'no workspace ID');
197
- /* c8 ignore stop */
198
- if (!this.monorepo) {
199
- throw this.#resolveError(spec, options, 'Not in a monorepo, cannot resolve workspace spec');
200
- }
201
- const ws = this.monorepo.get(workspace);
202
- if (!ws) {
203
- throw this.#resolveError(spec, options, 'workspace not found', {
204
- wanted: workspace,
205
- });
206
- }
207
- return ws;
208
- }
209
- /**
210
- * Return the manifest cache key for a spec and the current options.
211
- */
212
- #manifestCacheKey(spec, options) {
213
- let extra = '';
214
- if (options['node-version']) {
215
- extra += `${delimiter}node-version:${options['node-version']}`;
216
- }
217
- if (options.os) {
218
- extra += `${delimiter}os:${options.os}`;
219
- }
220
- if (options.arch) {
221
- extra += `${delimiter}arch:${options.arch}`;
222
- }
223
- return encodeURIComponent(`${spec.registry}${delimiter}${spec}${extra}`);
224
- }
225
- /**
226
- * Conditionally return the path to the manifest cache file. The logic
227
- * to determine if caching should be skipped aligns with `pickManifest`
228
- * and is used to avoid caching manifest results that can be variable.
229
- */
230
- _manifestCachePath(spec, options) {
231
- if (options.before) {
232
- return;
233
- }
234
- // if the final resolved spec is either a dist tag or something that
235
- // matches any range (such as a semver range of `*` or empty string)
236
- // then we skip caching
237
- const f = spec.final;
238
- if (f.distTag || f.range?.isAny) {
239
- return;
240
- }
241
- const key = this.#manifestCacheKey(f, options);
242
- return pathResolve(this.#cachePath, 'package-info', key);
243
- }
244
- async #registryManifestRequest(spec, options) {
245
- const { registry, name, registrySpec } = spec.final;
246
- /* c8 ignore start */
247
- if (!spec.range?.isSingle || !registrySpec) {
248
- throw this.#resolveError(spec, options, 'failed to request manifest', { spec });
249
- }
250
- /* c8 ignore stop */
251
- const possibleLeadingChars = ['=', '^', '~', 'v'];
252
- const hasLeadingRange = possibleLeadingChars.some(char => registrySpec.startsWith(char));
253
- const version = hasLeadingRange ? registrySpec.slice(1) : registrySpec;
254
- const pakuURL = new URL(`${name}/${version}`, registry);
255
- const response = await this.registryClient.request(pakuURL, {
256
- headers: {
257
- accept: 'application/json',
258
- },
259
- });
260
- if (response.statusCode !== 200) {
261
- throw this.#resolveError(spec, options, 'failed to fetch manifest', {
262
- url: pakuURL,
263
- response,
264
- });
265
- }
266
- return response.json();
267
- }
268
- async tarball(spec, options = {}) {
269
- if (typeof spec === 'string')
270
- spec = Spec.parse(spec, this.options);
271
- const f = spec.final;
272
- switch (f.type) {
273
- case 'registry': {
274
- const { dist } = await this.manifest(spec, options);
275
- if (!dist)
276
- throw this.#resolveError(spec, options, 'no dist object found in manifest');
277
- const { tarball, integrity } = dist;
278
- if (!tarball) {
279
- throw this.#resolveError(spec, options, 'no tarball found in manifest.dist');
280
- }
281
- const trustIntegrity = this.#trustedIntegrities.get(tarball) === integrity;
282
- const response = await this.registryClient.request(tarball, {
283
- ...options,
284
- integrity,
285
- trustIntegrity,
286
- });
287
- if (response.statusCode !== 200) {
288
- throw this.#resolveError(spec, options, 'failed to fetch tarball', { response, url: tarball });
289
- }
290
- // if we don't already trust it, but it's valid, start trusting it
291
- if (!trustIntegrity &&
292
- response.checkIntegrity({ spec, url: tarball })) {
293
- this.#trustedIntegrities.set(tarball, response.integrity);
294
- }
295
- return response.buffer();
296
- }
297
- case 'git': {
298
- const { remoteURL, gitRemote, gitCommittish, gitSelectorParsed, } = f;
299
- const s = spec;
300
- if (!remoteURL) {
301
- if (!gitRemote) {
302
- throw this.#resolveError(spec, options, 'no remote on git: specifier');
303
- }
304
- const { path } = gitSelectorParsed ?? {};
305
- return await this.#tmpdir(async (dir) => {
306
- await clone(gitRemote, gitCommittish, dir + '/package', {
307
- spec: s,
308
- });
309
- let cwd = dir;
310
- if (path !== undefined) {
311
- const src = pathResolve(dir, 'package', path);
312
- cwd = dirname(src);
313
- const pkg = pathResolve(cwd, 'package');
314
- if (src !== pkg) {
315
- const rand = randomBytes(6).toString('hex');
316
- // faster than deleting
317
- await rename(pkg, pkg + rand).catch(() => { });
318
- await rename(src, pkg);
319
- }
320
- }
321
- return tarC({ cwd, gzip: true }, ['package']).concat();
322
- });
323
- }
324
- // fallthrough if remoteURL set
325
- }
326
- case 'remote': {
327
- const { remoteURL } = f;
328
- if (!remoteURL) {
329
- throw this.#resolveError(spec, options);
330
- }
331
- const response = await this.registryClient.request(remoteURL);
332
- if (response.statusCode !== 200) {
333
- throw this.#resolveError(spec, options, 'failed to fetch URL', { response, url: remoteURL });
334
- }
335
- return response.buffer();
336
- }
337
- case 'file': {
338
- const { file } = f;
339
- if (file === undefined)
340
- throw this.#resolveError(spec, options, 'no file path');
341
- const { from = this.#projectRoot } = options;
342
- const path = pathResolve(from, file);
343
- const st = await stat(path);
344
- if (st.isDirectory()) {
345
- const p = dirname(path);
346
- const b = basename(path);
347
- // TODO: Pack properly, ignore stuff, bundleDeps, etc
348
- return tarC({ cwd: p, gzip: true }, [b]).concat();
349
- }
350
- return readFile(path);
351
- }
352
- case 'workspace': {
353
- // TODO: Pack properly, ignore stuff, bundleDeps, etc
354
- const ws = this.#getWS(spec, options);
355
- const p = dirname(ws.fullpath);
356
- const b = basename(ws.fullpath);
357
- return tarC({ cwd: p, gzip: true }, [b]).concat();
358
- }
359
- }
360
- }
361
- async manifest(spec, options = {}) {
362
- const { from = this.#projectRoot } = options;
363
- if (typeof spec === 'string')
364
- spec = Spec.parse(spec, this.options);
365
- const f = spec.final;
366
- switch (f.type) {
367
- case 'registry': {
368
- // Check if manifest is cached, if so just return it earlier
369
- const cachePath = this._manifestCachePath(spec, options);
370
- if (cachePath) {
371
- try {
372
- // Cache file exists, read and return it
373
- const cached = await readFile(cachePath, 'utf8');
374
- const json = JSON.parse(cached);
375
- // retrieve timestamp to check if cache is still valid
376
- const timestamp = json.__VLT_MANIFEST_CACHE_TIMESTAMP;
377
- delete json.__VLT_MANIFEST_CACHE_TIMESTAMP;
378
- // removes the cache file if older than its maximum age
379
- if (timestamp != null &&
380
- timestamp < this.#manifestCacheMinAge) {
381
- void unlink(cachePath).catch(() => { });
382
- throw new Error('manifest cache expired');
383
- }
384
- return json;
385
- }
386
- catch {
387
- // Cache miss, fetch from packument
388
- }
389
- }
390
- const mani = spec.range?.isSingle ?
391
- await this.#registryManifestRequest(spec, options)
392
- : pickManifest(await this.packument(f, options), spec, options);
393
- if (!mani)
394
- throw this.#resolveError(spec, options);
395
- const { integrity, tarball } = mani.dist ?? /* c8 ignore next */ {};
396
- if (isIntegrity(integrity) && tarball) {
397
- const registryOrigin = new URL(String(f.registry)).origin;
398
- const tgzOrigin = new URL(tarball).origin;
399
- // if it comes from the same origin, trust the integrity
400
- if (tgzOrigin === registryOrigin) {
401
- this.#trustedIntegrities.set(tarball, integrity);
402
- }
403
- }
404
- // Cache the manifest data
405
- if (cachePath) {
406
- const json = JSON.stringify({
407
- ...mani,
408
- // append a timestamp to the manifest so that we can quickly
409
- // check if the cache is still valid when loading it
410
- __VLT_MANIFEST_CACHE_TIMESTAMP: Date.now(),
411
- });
412
- void writeFile(cachePath, json, 'utf8').catch((err) => {
413
- // in case the cache directory doesn't exist
414
- // just create it and retry
415
- if (err instanceof Error &&
416
- 'code' in err &&
417
- err.code === 'ENOENT') {
418
- void mkdir(dirname(cachePath), {
419
- recursive: true,
420
- }).then(() => {
421
- void writeFile(cachePath, json, 'utf8');
422
- });
423
- }
424
- });
425
- }
426
- return mani;
427
- }
428
- case 'git': {
429
- const { gitRemote, gitCommittish, remoteURL, gitSelectorParsed, } = f;
430
- if (!remoteURL) {
431
- const s = spec;
432
- if (!gitRemote)
433
- throw this.#resolveError(spec, options, 'no git remote');
434
- return await this.#tmpdir(async (dir) => {
435
- await clone(gitRemote, gitCommittish, dir, { spec: s });
436
- const { path } = gitSelectorParsed ?? {};
437
- const pkgDir = path !== undefined ? pathResolve(dir, path) : dir;
438
- return this.packageJson.read(pkgDir);
439
- });
440
- }
441
- // fallthrough to remote
442
- }
443
- case 'remote': {
444
- const { remoteURL } = f;
445
- if (!remoteURL) {
446
- throw this.#resolveError(spec, options, 'no remoteURL on remote specifier');
447
- }
448
- const s = spec;
449
- return await this.#tmpdir(async (dir) => {
450
- const response = await this.registryClient.request(remoteURL);
451
- if (response.statusCode !== 200) {
452
- throw this.#resolveError(s, options, 'failed to fetch URL', { response, url: remoteURL });
453
- }
454
- const buf = response.buffer();
455
- // Compute integrity for remote/git-with-tarball deps
456
- const computed = ssri
457
- .fromData(buf, { algorithms: ['sha512'] })
458
- .toString();
459
- try {
460
- await this.tarPool.unpack(buf, dir);
461
- }
462
- catch (er) {
463
- throw this.#resolveError(s, options, 'tar unpack failed', { cause: er });
464
- }
465
- // return manifest with computed integrity
466
- const mani = this.packageJson.read(dir);
467
- mani.dist = { integrity: computed };
468
- return mani;
469
- });
470
- }
471
- case 'file': {
472
- const { file } = f;
473
- if (file === undefined)
474
- throw this.#resolveError(spec, options, 'no file path');
475
- const path = pathResolve(from, file);
476
- const st = await stat(path);
477
- if (st.isDirectory()) {
478
- return this.packageJson.read(path);
479
- }
480
- const s = spec;
481
- return await this.#tmpdir(async (dir) => {
482
- try {
483
- await this.tarPool.unpack(await readFile(path), dir);
484
- }
485
- catch (er) {
486
- throw this.#resolveError(s, options, 'tar unpack failed', { cause: er });
487
- }
488
- return this.packageJson.read(dir);
489
- });
490
- }
491
- case 'workspace': {
492
- return this.#getWS(spec, options).manifest;
493
- }
494
- }
495
- }
496
- async packument(spec, options = {}) {
497
- if (typeof spec === 'string')
498
- spec = Spec.parse(spec, this.options);
499
- const f = spec.final;
500
- switch (f.type) {
501
- // RevDoc is the equivalent of a packument for a git repo
502
- case 'git': {
503
- const { gitRemote } = f;
504
- if (!gitRemote) {
505
- throw this.#resolveError(spec, options, 'git remote could not be determined');
506
- }
507
- const revDoc = await revs(gitRemote, {
508
- cwd: this.options.projectRoot,
509
- });
510
- if (!revDoc)
511
- throw this.#resolveError(spec, options);
512
- return asPackument(revDoc);
513
- }
514
- // these are all faked packuments
515
- case 'file':
516
- case 'workspace':
517
- case 'remote': {
518
- const manifest = await this.manifest(f, options);
519
- return {
520
- name: manifest.name ?? '',
521
- 'dist-tags': {
522
- latest: manifest.version ?? '',
523
- },
524
- versions: {
525
- [manifest.version ?? '']: manifest,
526
- },
527
- };
528
- }
529
- case 'registry': {
530
- const { registry, name } = f;
531
- const pakuURL = new URL(name, registry);
532
- const response = await this.registryClient.request(pakuURL, {
533
- headers: {
534
- accept: 'application/json',
535
- },
536
- });
537
- if (response.statusCode !== 200) {
538
- throw this.#resolveError(spec, options, 'failed to fetch packument', {
539
- url: pakuURL,
540
- response,
541
- });
542
- }
543
- return response.json();
544
- }
545
- }
546
- }
547
- async resolve(spec, options = {}) {
548
- const memoKey = String(spec);
549
- if (typeof spec === 'string')
550
- spec = Spec.parse(spec, this.options);
551
- const memo = this.#resolutions.get(memoKey);
552
- if (memo)
553
- return memo;
554
- const f = spec.final;
555
- switch (f.type) {
556
- case 'file': {
557
- const { file } = f;
558
- if (!file || !f.file) {
559
- throw this.#resolveError(spec, options, 'no path on file: specifier');
560
- }
561
- const { from = this.#projectRoot } = options;
562
- const resolved = pathResolve(from, f.file);
563
- const r = { resolved, spec };
564
- this.#resolutions.set(memoKey, r);
565
- return r;
566
- }
567
- case 'remote': {
568
- const { remoteURL } = f;
569
- if (!remoteURL)
570
- throw this.#resolveError(spec, options, 'no URL in remote specifier');
571
- const r = { resolved: remoteURL, spec };
572
- this.#resolutions.set(memoKey, r);
573
- return r;
574
- }
575
- case 'workspace': {
576
- const ws = this.#getWS(spec, options);
577
- return {
578
- resolved: ws.fullpath,
579
- spec,
580
- };
581
- }
582
- case 'registry': {
583
- const mani = await this.manifest(spec, options);
584
- if (mani.dist) {
585
- const { integrity, tarball, signatures } = mani.dist;
586
- if (tarball) {
587
- const r = {
588
- resolved: tarball,
589
- integrity,
590
- signatures,
591
- spec,
592
- };
593
- this.#resolutions.set(memoKey, r);
594
- return r;
595
- }
596
- }
597
- throw this.#resolveError(spec, options);
598
- }
599
- case 'git': {
600
- const { gitRemote, remoteURL, gitSelectorParsed } = f;
601
- if (remoteURL && gitSelectorParsed?.path === undefined) {
602
- // known git host with a tarball download endpoint
603
- const r = { resolved: remoteURL, spec };
604
- this.#resolutions.set(memoKey, r);
605
- return r;
606
- }
607
- if (!gitRemote) {
608
- throw this.#resolveError(spec, options, 'no remote on git specifier');
609
- }
610
- const rev = await gitResolve(gitRemote, f.gitCommittish, {
611
- spec,
612
- });
613
- if (rev) {
614
- const r = {
615
- resolved: `${gitRemote}#${rev.sha}`,
616
- spec,
617
- };
618
- if (gitSelectorParsed) {
619
- r.resolved += Object.entries(gitSelectorParsed)
620
- .filter(([_, v]) => v)
621
- .map(([k, v]) => `::${k}:${v}`)
622
- .join('');
623
- }
624
- this.#resolutions.set(memoKey, r);
625
- return r;
626
- }
627
- // have to actually clone somewhere
628
- const s = spec;
629
- return this.#tmpdir(async (tmpdir) => {
630
- const sha = await clone(gitRemote, s.gitCommittish, tmpdir, {
631
- spec: s,
632
- });
633
- const r = {
634
- resolved: `${gitRemote}#${sha}`,
635
- spec: s,
636
- };
637
- this.#resolutions.set(memoKey, r);
638
- return r;
639
- });
640
- }
641
- }
642
- }
643
- async #tmpdir(fn) {
644
- const p = `package-info/${randomBytes(6).toString('hex')}`;
645
- const dir = xdg.runtime(p);
646
- try {
647
- return await fn(dir);
648
- }
649
- finally {
650
- // intentionally do not await
651
- void rm(dir, { recursive: true, force: true });
652
- }
653
- }
654
- // error resolving
655
- #resolveError(spec, options = {}, message = 'Could not resolve', extra = {}) {
656
- const { from = this.#projectRoot } = options;
657
- const er = error(message, {
658
- code: 'ERESOLVE',
659
- spec,
660
- from,
661
- ...extra,
662
- }, this.#resolveError);
663
- return er;
664
- }
665
- }
666
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAKpD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAOlC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EACL,KAAK,EACL,QAAQ,EACR,EAAE,EACF,IAAI,EACJ,OAAO,EACP,MAAM,EACN,SAAS,GACV,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,QAAQ,EACR,OAAO,EACP,OAAO,IAAI,WAAW,EACtB,QAAQ,GACT,MAAM,WAAW,CAAA;AAClB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,OAAO,GAAG,mBAAmB,EAC7B,QAA2B,EAAE;QAE7B,MAAM,EAAE,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,OAAO,CAAA;QAC5C,MAAM,EAAE,GAAG,KAAK,CACd,OAAO,EACP;YACE,IAAI,EAAE,UAAU;YAChB,IAAI;YACJ,IAAI;YACJ,GAAG,KAAK;SACT,EACD,IAAI,CAAC,aAAa,CACnB,CAAA;QACD,OAAO,EAAE,CAAA;IACX,CAAC;CACF","sourcesContent":["import type { ErrorCauseOptions } from '@vltpkg/error-cause'\nimport { error } from '@vltpkg/error-cause'\nimport { clone, resolve as gitResolve, revs } from '@vltpkg/git'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type { PickManifestOptions } from '@vltpkg/pick-manifest'\nimport { pickManifest } from '@vltpkg/pick-manifest'\nimport type {\n RegistryClientOptions,\n RegistryClientRequestOptions,\n} from '@vltpkg/registry-client'\nimport { RegistryClient } from '@vltpkg/registry-client'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport { Spec } from '@vltpkg/spec'\nimport { Pool } from '@vltpkg/tar'\nimport type {\n Integrity,\n Manifest,\n Packument,\n ManifestRegistry,\n} from '@vltpkg/types'\nimport { asPackument, isIntegrity } from '@vltpkg/types'\nimport ssri from 'ssri'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport { XDG } from '@vltpkg/xdg'\nimport { randomBytes } from 'node:crypto'\nimport {\n mkdir,\n readFile,\n rm,\n stat,\n symlink,\n unlink,\n writeFile,\n} from 'node:fs/promises'\nimport {\n basename,\n dirname,\n resolve as pathResolve,\n relative,\n} from 'node:path'\nimport { create as tarC } from 'tar'\nimport { rename } from './rename.ts'\n\nconst xdg = new XDG('vlt')\nexport const delimiter = '~'\n\nexport type Resolution = {\n resolved: string\n integrity?: Integrity\n signatures?: Exclude<Manifest['dist'], undefined>['signatures']\n spec: Spec\n}\n\nexport type PackageInfoClientOptions = RegistryClientOptions &\n SpecOptions & {\n /** root of the project. Defaults to process.cwd() */\n projectRoot?: string\n /** PackageJson object */\n packageJson?: PackageJson\n\n monorepo?: Monorepo\n\n /** workspace groups to load, irrelevant if Monorepo provided */\n 'workspace-group'?: string[]\n\n /** workspace paths to load, irrelevant if Monorepo provided */\n workspace?: string[]\n }\n\nexport type PackageInfoClientRequestOptions = PickManifestOptions &\n RegistryClientRequestOptions & {\n /** dir to resolve `file://` specifiers against. Defaults to projectRoot. */\n from?: string\n }\n\nexport type PackageInfoClientExtractOptions =\n PackageInfoClientRequestOptions & {\n integrity?: Integrity\n resolved?: string\n }\n\n// the maximum duration of a manifest cache file\nconst manifestCacheMaxAge = 5 * 60 * 1000\n\nexport class PackageInfoClient {\n #registryClient?: RegistryClient\n #projectRoot: string\n #tarPool?: Pool\n options: PackageInfoClientOptions\n #resolutions = new Map<string, Resolution>()\n packageJson: PackageJson\n monorepo?: Monorepo\n #trustedIntegrities = new Map<string, Integrity>()\n #manifestCacheMinAge = Date.now() - manifestCacheMaxAge\n #cachePath: string\n\n get registryClient() {\n if (!this.#registryClient) {\n this.#registryClient = new RegistryClient(this.options)\n }\n return this.#registryClient\n }\n\n get tarPool() {\n if (!this.#tarPool) this.#tarPool = new Pool()\n return this.#tarPool\n }\n\n constructor(options: PackageInfoClientOptions = {}) {\n this.options = options\n this.#projectRoot = options.projectRoot || process.cwd()\n this.packageJson = options.packageJson ?? new PackageJson()\n const wsLoad = {\n ...(options.workspace?.length && { paths: options.workspace }),\n ...(options['workspace-group']?.length && {\n groups: options['workspace-group'],\n }),\n }\n this.monorepo =\n options.monorepo ??\n Monorepo.maybeLoad(this.#projectRoot, {\n load: wsLoad,\n packageJson: this.packageJson,\n })\n this.#cachePath = options.cache ?? xdg.cache()\n // optionally create its cache directory if it doesn't exist\n void mkdir(pathResolve(this.#cachePath, 'package-info'), {\n recursive: true,\n }).catch(() => {})\n }\n\n async extract(\n spec: Spec | string,\n target: string,\n options: PackageInfoClientExtractOptions = {},\n ): Promise<Resolution> {\n if (typeof spec === 'string')\n spec = Spec.parse(spec, this.options)\n const { from = this.#projectRoot, integrity, resolved } = options\n const f = spec.final\n const r =\n integrity && resolved ?\n { resolved, integrity, spec }\n : await this.resolve(spec, options)\n\n switch (f.type) {\n case 'git': {\n const {\n gitRemote,\n gitCommittish,\n remoteURL,\n gitSelectorParsed,\n } = f\n if (!remoteURL) {\n /* c8 ignore start - Impossible, would throw on the resolve */\n if (!gitRemote)\n throw this.#resolveError(\n spec,\n options,\n 'no remote on git: specifier',\n )\n /* c8 ignore stop */\n const { path } = gitSelectorParsed ?? {}\n if (path !== undefined) {\n // use obvious name because it's in node_modules\n const tmp = pathResolve(\n dirname(target),\n `.TEMP.${basename(target)}-${randomBytes(6).toString('hex')}`,\n )\n await clone(gitRemote, gitCommittish, tmp, { spec })\n const src = pathResolve(tmp, path)\n await rename(src, target)\n // intentionally not awaited\n void rm(tmp, { recursive: true, force: true })\n } else {\n await clone(gitRemote, gitCommittish, target, { spec })\n // intentionally not awaited\n void rm(target + '/.git', { recursive: true })\n }\n return r\n }\n // fallthrough if a remote tarball url present\n }\n\n case 'registry': {\n const trustIntegrity =\n this.#trustedIntegrities.get(r.resolved) === r.integrity\n\n const response = await this.registryClient.request(\n r.resolved,\n {\n integrity: r.integrity,\n trustIntegrity,\n },\n )\n\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch tarball',\n {\n url: r.resolved,\n response,\n },\n )\n }\n\n // if it's not trusted already, but valid, start trusting\n if (\n !trustIntegrity &&\n response.checkIntegrity({ spec, url: resolved })\n ) {\n this.#trustedIntegrities.set(r.resolved, response.integrity)\n }\n\n try {\n await this.tarPool.unpack(response.buffer(), target)\n } catch (er) {\n throw this.#resolveError(\n spec,\n options,\n 'tar unpack failed',\n { cause: er },\n )\n }\n return r\n }\n\n case 'remote': {\n const response = await this.registryClient.request(r.resolved)\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch remote tarball',\n {\n url: r.resolved,\n response,\n },\n )\n }\n\n const buf = response.buffer()\n\n // Compute integrity for remote/git-with-tarball deps\n const computed = ssri\n .fromData(buf, { algorithms: ['sha512'] })\n .toString()\n if (r.integrity && r.integrity !== computed) {\n throw error('Integrity check failure', {\n code: 'EINTEGRITY',\n spec,\n url: r.resolved,\n wanted: r.integrity,\n found: computed,\n })\n }\n r.integrity = computed as Integrity\n\n try {\n await this.tarPool.unpack(buf, target)\n } catch (er) {\n throw this.#resolveError(\n spec,\n options,\n 'remote tar unpack failed',\n { cause: er },\n )\n }\n return r\n }\n case 'file': {\n // if it's a directory, then \"extract\" means \"symlink\"\n const { file } = f\n /* c8 ignore start - asserted in resolve() */\n if (file === undefined)\n throw this.#resolveError(spec, options, 'no file path')\n /* c8 ignore stop */\n const path = pathResolve(from, file)\n const st = await stat(path)\n if (st.isFile()) {\n try {\n await this.tarPool.unpack(\n await this.tarball(spec, options),\n target,\n )\n } catch (er) {\n throw this.#resolveError(\n spec,\n options,\n 'tar unpack failed',\n { cause: er },\n )\n }\n } else if (st.isDirectory()) {\n const rel = relative(dirname(target), path)\n await symlink(rel, target, 'dir')\n /* c8 ignore start */\n } else {\n throw this.#resolveError(\n spec,\n options,\n 'file: specifier does not resolve to directory or tarball',\n )\n }\n /* c8 ignore stop */\n return r\n }\n case 'workspace': {\n const ws = this.#getWS(spec, options)\n const rel = relative(dirname(target), ws.fullpath)\n await symlink(rel, target, 'dir')\n return r\n }\n }\n }\n\n #getWS(spec: Spec, options: PackageInfoClientRequestOptions) {\n const { workspace } = spec\n /* c8 ignore start - asserted in resolve() */\n if (workspace === undefined)\n throw this.#resolveError(spec, options, 'no workspace ID')\n /* c8 ignore stop */\n if (!this.monorepo) {\n throw this.#resolveError(\n spec,\n options,\n 'Not in a monorepo, cannot resolve workspace spec',\n )\n }\n const ws = this.monorepo.get(workspace)\n if (!ws) {\n throw this.#resolveError(spec, options, 'workspace not found', {\n wanted: workspace,\n })\n }\n return ws\n }\n\n /**\n * Return the manifest cache key for a spec and the current options.\n */\n #manifestCacheKey(\n spec: Spec,\n options: PackageInfoClientRequestOptions,\n ): string {\n let extra = ''\n if (options['node-version']) {\n extra += `${delimiter}node-version:${options['node-version']}`\n }\n if (options.os) {\n extra += `${delimiter}os:${options.os}`\n }\n if (options.arch) {\n extra += `${delimiter}arch:${options.arch}`\n }\n return encodeURIComponent(\n `${spec.registry}${delimiter}${spec}${extra}`,\n )\n }\n\n /**\n * Conditionally return the path to the manifest cache file. The logic\n * to determine if caching should be skipped aligns with `pickManifest`\n * and is used to avoid caching manifest results that can be variable.\n */\n _manifestCachePath(\n spec: Spec,\n options: PackageInfoClientRequestOptions,\n ): string | undefined {\n if (options.before) {\n return\n }\n // if the final resolved spec is either a dist tag or something that\n // matches any range (such as a semver range of `*` or empty string)\n // then we skip caching\n const f = spec.final\n if (f.distTag || f.range?.isAny) {\n return\n }\n const key = this.#manifestCacheKey(f, options)\n return pathResolve(this.#cachePath, 'package-info', key)\n }\n\n async #registryManifestRequest(\n spec: Spec,\n options: PackageInfoClientRequestOptions,\n ): Promise<ManifestRegistry> {\n const { registry, name, registrySpec } = spec.final\n /* c8 ignore start */\n if (!spec.range?.isSingle || !registrySpec) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to request manifest',\n { spec },\n )\n }\n /* c8 ignore stop */\n const possibleLeadingChars = ['=', '^', '~', 'v']\n const hasLeadingRange = possibleLeadingChars.some(char =>\n registrySpec.startsWith(char),\n )\n const version =\n hasLeadingRange ? registrySpec.slice(1) : registrySpec\n const pakuURL = new URL(`${name}/${version}`, registry)\n const response = await this.registryClient.request(pakuURL, {\n headers: {\n accept: 'application/json',\n },\n })\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch manifest',\n {\n url: pakuURL,\n response,\n },\n )\n }\n return response.json() as ManifestRegistry\n }\n\n async tarball(\n spec: Spec | string,\n options: PackageInfoClientExtractOptions = {},\n ): Promise<Buffer> {\n if (typeof spec === 'string')\n spec = Spec.parse(spec, this.options)\n const f = spec.final\n\n switch (f.type) {\n case 'registry': {\n const { dist } = await this.manifest(spec, options)\n if (!dist)\n throw this.#resolveError(\n spec,\n options,\n 'no dist object found in manifest',\n )\n\n const { tarball, integrity } = dist\n if (!tarball) {\n throw this.#resolveError(\n spec,\n options,\n 'no tarball found in manifest.dist',\n )\n }\n\n const trustIntegrity =\n this.#trustedIntegrities.get(tarball) === integrity\n\n const response = await this.registryClient.request(tarball, {\n ...options,\n integrity,\n trustIntegrity,\n })\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch tarball',\n { response, url: tarball },\n )\n }\n\n // if we don't already trust it, but it's valid, start trusting it\n if (\n !trustIntegrity &&\n response.checkIntegrity({ spec, url: tarball })\n ) {\n this.#trustedIntegrities.set(tarball, response.integrity)\n }\n\n return response.buffer()\n }\n\n case 'git': {\n const {\n remoteURL,\n gitRemote,\n gitCommittish,\n gitSelectorParsed,\n } = f\n const s: Spec = spec\n if (!remoteURL) {\n if (!gitRemote) {\n throw this.#resolveError(\n spec,\n options,\n 'no remote on git: specifier',\n )\n }\n const { path } = gitSelectorParsed ?? {}\n return await this.#tmpdir(async dir => {\n await clone(gitRemote, gitCommittish, dir + '/package', {\n spec: s,\n })\n let cwd = dir\n if (path !== undefined) {\n const src = pathResolve(dir, 'package', path)\n cwd = dirname(src)\n const pkg = pathResolve(cwd, 'package')\n if (src !== pkg) {\n const rand = randomBytes(6).toString('hex')\n // faster than deleting\n await rename(pkg, pkg + rand).catch(() => {})\n await rename(src, pkg)\n }\n }\n return tarC({ cwd, gzip: true }, ['package']).concat()\n })\n }\n // fallthrough if remoteURL set\n }\n\n case 'remote': {\n const { remoteURL } = f\n if (!remoteURL) {\n throw this.#resolveError(spec, options)\n }\n const response = await this.registryClient.request(remoteURL)\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch URL',\n { response, url: remoteURL },\n )\n }\n return response.buffer()\n }\n\n case 'file': {\n const { file } = f\n if (file === undefined)\n throw this.#resolveError(spec, options, 'no file path')\n const { from = this.#projectRoot } = options\n const path = pathResolve(from, file)\n const st = await stat(path)\n if (st.isDirectory()) {\n const p = dirname(path)\n const b = basename(path)\n // TODO: Pack properly, ignore stuff, bundleDeps, etc\n return tarC({ cwd: p, gzip: true }, [b]).concat()\n }\n return readFile(path)\n }\n\n case 'workspace': {\n // TODO: Pack properly, ignore stuff, bundleDeps, etc\n const ws = this.#getWS(spec, options)\n const p = dirname(ws.fullpath)\n const b = basename(ws.fullpath)\n return tarC({ cwd: p, gzip: true }, [b]).concat()\n }\n }\n }\n\n async manifest(\n spec: Spec | string,\n options: PackageInfoClientRequestOptions = {},\n ) {\n const { from = this.#projectRoot } = options\n if (typeof spec === 'string')\n spec = Spec.parse(spec, this.options)\n const f = spec.final\n\n switch (f.type) {\n case 'registry': {\n // Check if manifest is cached, if so just return it earlier\n const cachePath = this._manifestCachePath(spec, options)\n if (cachePath) {\n try {\n // Cache file exists, read and return it\n const cached = await readFile(cachePath, 'utf8')\n const json = JSON.parse(cached) as Manifest & {\n __VLT_MANIFEST_CACHE_TIMESTAMP?: number\n }\n // retrieve timestamp to check if cache is still valid\n const timestamp = json.__VLT_MANIFEST_CACHE_TIMESTAMP\n delete json.__VLT_MANIFEST_CACHE_TIMESTAMP\n // removes the cache file if older than its maximum age\n if (\n timestamp != null &&\n timestamp < this.#manifestCacheMinAge\n ) {\n void unlink(cachePath).catch(() => {})\n throw new Error('manifest cache expired')\n }\n return json\n } catch {\n // Cache miss, fetch from packument\n }\n }\n\n const mani =\n spec.range?.isSingle ?\n await this.#registryManifestRequest(spec, options)\n : pickManifest(\n await this.packument(f, options),\n spec,\n options,\n )\n if (!mani) throw this.#resolveError(spec, options)\n const { integrity, tarball } =\n mani.dist ?? /* c8 ignore next */ {}\n if (isIntegrity(integrity) && tarball) {\n const registryOrigin = new URL(String(f.registry)).origin\n const tgzOrigin = new URL(tarball).origin\n // if it comes from the same origin, trust the integrity\n if (tgzOrigin === registryOrigin) {\n this.#trustedIntegrities.set(tarball, integrity)\n }\n }\n\n // Cache the manifest data\n if (cachePath) {\n const json = JSON.stringify({\n ...mani,\n // append a timestamp to the manifest so that we can quickly\n // check if the cache is still valid when loading it\n __VLT_MANIFEST_CACHE_TIMESTAMP: Date.now(),\n })\n void writeFile(cachePath, json, 'utf8').catch(\n (err: unknown) => {\n // in case the cache directory doesn't exist\n // just create it and retry\n if (\n err instanceof Error &&\n 'code' in err &&\n err.code === 'ENOENT'\n ) {\n void mkdir(dirname(cachePath), {\n recursive: true,\n }).then(() => {\n void writeFile(cachePath, json, 'utf8')\n })\n }\n },\n )\n }\n\n return mani\n }\n\n case 'git': {\n const {\n gitRemote,\n gitCommittish,\n remoteURL,\n gitSelectorParsed,\n } = f\n if (!remoteURL) {\n const s = spec\n if (!gitRemote)\n throw this.#resolveError(spec, options, 'no git remote')\n return await this.#tmpdir(async dir => {\n await clone(gitRemote, gitCommittish, dir, { spec: s })\n const { path } = gitSelectorParsed ?? {}\n const pkgDir =\n path !== undefined ? pathResolve(dir, path) : dir\n return this.packageJson.read(pkgDir)\n })\n }\n // fallthrough to remote\n }\n\n case 'remote': {\n const { remoteURL } = f\n if (!remoteURL) {\n throw this.#resolveError(\n spec,\n options,\n 'no remoteURL on remote specifier',\n )\n }\n const s = spec\n return await this.#tmpdir(async dir => {\n const response =\n await this.registryClient.request(remoteURL)\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n s,\n options,\n 'failed to fetch URL',\n { response, url: remoteURL },\n )\n }\n const buf = response.buffer()\n\n // Compute integrity for remote/git-with-tarball deps\n const computed = ssri\n .fromData(buf, { algorithms: ['sha512'] })\n .toString()\n\n try {\n await this.tarPool.unpack(buf, dir)\n } catch (er) {\n throw this.#resolveError(\n s,\n options,\n 'tar unpack failed',\n { cause: er },\n )\n }\n\n // return manifest with computed integrity\n const mani = this.packageJson.read(dir)\n mani.dist = { integrity: computed as Integrity }\n return mani\n })\n }\n\n case 'file': {\n const { file } = f\n if (file === undefined)\n throw this.#resolveError(spec, options, 'no file path')\n const path = pathResolve(from, file)\n const st = await stat(path)\n if (st.isDirectory()) {\n return this.packageJson.read(path)\n }\n const s = spec\n return await this.#tmpdir(async dir => {\n try {\n await this.tarPool.unpack(await readFile(path), dir)\n } catch (er) {\n throw this.#resolveError(\n s,\n options,\n 'tar unpack failed',\n { cause: er },\n )\n }\n return this.packageJson.read(dir)\n })\n }\n\n case 'workspace': {\n return this.#getWS(spec, options).manifest\n }\n }\n }\n\n async packument(\n spec: Spec | string,\n options: PackageInfoClientRequestOptions = {},\n ): Promise<Packument> {\n if (typeof spec === 'string')\n spec = Spec.parse(spec, this.options)\n const f = spec.final\n switch (f.type) {\n // RevDoc is the equivalent of a packument for a git repo\n case 'git': {\n const { gitRemote } = f\n if (!gitRemote) {\n throw this.#resolveError(\n spec,\n options,\n 'git remote could not be determined',\n )\n }\n const revDoc = await revs(gitRemote, {\n cwd: this.options.projectRoot,\n })\n if (!revDoc) throw this.#resolveError(spec, options)\n return asPackument(revDoc)\n }\n\n // these are all faked packuments\n case 'file':\n case 'workspace':\n case 'remote': {\n const manifest = await this.manifest(f, options)\n return {\n name: manifest.name ?? '',\n 'dist-tags': {\n latest: manifest.version ?? '',\n },\n versions: {\n [manifest.version ?? '']: manifest as Manifest,\n },\n }\n }\n\n case 'registry': {\n const { registry, name } = f\n const pakuURL = new URL(name, registry)\n const response = await this.registryClient.request(pakuURL, {\n headers: {\n accept: 'application/json',\n },\n })\n if (response.statusCode !== 200) {\n throw this.#resolveError(\n spec,\n options,\n 'failed to fetch packument',\n {\n url: pakuURL,\n response,\n },\n )\n }\n return response.json() as Packument\n }\n }\n }\n\n async resolve(\n spec: Spec | string,\n options: PackageInfoClientRequestOptions = {},\n ): Promise<Resolution> {\n const memoKey = String(spec)\n if (typeof spec === 'string')\n spec = Spec.parse(spec, this.options)\n\n const memo = this.#resolutions.get(memoKey)\n if (memo) return memo\n const f = spec.final\n\n switch (f.type) {\n case 'file': {\n const { file } = f\n if (!file || !f.file) {\n throw this.#resolveError(\n spec,\n options,\n 'no path on file: specifier',\n )\n }\n const { from = this.#projectRoot } = options\n const resolved = pathResolve(from, f.file)\n const r = { resolved, spec }\n this.#resolutions.set(memoKey, r)\n return r\n }\n\n case 'remote': {\n const { remoteURL } = f\n if (!remoteURL)\n throw this.#resolveError(\n spec,\n options,\n 'no URL in remote specifier',\n )\n const r = { resolved: remoteURL, spec }\n this.#resolutions.set(memoKey, r)\n return r\n }\n\n case 'workspace': {\n const ws = this.#getWS(spec, options)\n return {\n resolved: ws.fullpath,\n spec,\n }\n }\n\n case 'registry': {\n const mani = await this.manifest(spec, options)\n if (mani.dist) {\n const { integrity, tarball, signatures } = mani.dist\n if (tarball) {\n const r = {\n resolved: tarball,\n integrity,\n signatures,\n spec,\n }\n this.#resolutions.set(memoKey, r)\n return r\n }\n }\n throw this.#resolveError(spec, options)\n }\n\n case 'git': {\n const { gitRemote, remoteURL, gitSelectorParsed } = f\n if (remoteURL && gitSelectorParsed?.path === undefined) {\n // known git host with a tarball download endpoint\n const r = { resolved: remoteURL, spec }\n this.#resolutions.set(memoKey, r)\n return r\n }\n if (!gitRemote) {\n throw this.#resolveError(\n spec,\n options,\n 'no remote on git specifier',\n )\n }\n const rev = await gitResolve(gitRemote, f.gitCommittish, {\n spec,\n })\n if (rev) {\n const r = {\n resolved: `${gitRemote}#${rev.sha}`,\n spec,\n }\n if (gitSelectorParsed) {\n r.resolved += Object.entries(gitSelectorParsed)\n .filter(([_, v]) => v)\n .map(([k, v]) => `::${k}:${v}`)\n .join('')\n }\n this.#resolutions.set(memoKey, r)\n return r\n }\n // have to actually clone somewhere\n const s: Spec = spec\n return this.#tmpdir(async tmpdir => {\n const sha = await clone(\n gitRemote,\n s.gitCommittish,\n tmpdir,\n {\n spec: s,\n },\n )\n const r = {\n resolved: `${gitRemote}#${sha}`,\n spec: s,\n }\n this.#resolutions.set(memoKey, r)\n return r\n })\n }\n }\n }\n\n async #tmpdir<T>(fn: (dir: string) => Promise<T>): Promise<T> {\n const p = `package-info/${randomBytes(6).toString('hex')}`\n const dir = xdg.runtime(p)\n try {\n return await fn(dir)\n } finally {\n // intentionally do not await\n void rm(dir, { recursive: true, force: true })\n }\n }\n\n // error resolving\n #resolveError(\n spec?: Spec,\n options: PackageInfoClientRequestOptions = {},\n message = 'Could not resolve',\n extra: ErrorCauseOptions = {},\n ) {\n const { from = this.#projectRoot } = options\n const er = error(\n message,\n {\n code: 'ERESOLVE',\n spec,\n from,\n ...extra,\n },\n this.#resolveError,\n )\n return er\n }\n}\n"]}
package/dist/rename.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { rename as fsRename } from 'node:fs/promises';
2
- export declare const rename: typeof fsRename;
3
- //# sourceMappingURL=rename.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../src/rename.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAM,MAAM,kBAAkB,CAAA;AACzD,eAAO,MAAM,MAAM,iBAqBhB,CAAA"}
package/dist/rename.js DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * On posix systems, rename is atomic and will clobber anything in its way
3
- * However, on Windows, it can fail with the rather unhelpful EPERM error if
4
- * the target directory is not removed in time or is currently in use.
5
- *
6
- * While true atomic semantics is not available on Windows in this case, we can
7
- * at least implement the posix overwrite semantics by explicitly removing the
8
- * target when this error occurs.
9
- *
10
- * This is only relevant when renaming *directories*, since files will
11
- * generally not raise problems. When/if we rename directories outside of
12
- * package-info, this can be moved to its own shared module.
13
- * @module
14
- */
15
- const { platform } = process;
16
- import { rename as fsRename, rm } from 'node:fs/promises';
17
- export const rename = platform !== 'win32' ? fsRename : (async function (oldPath, newPath) {
18
- let retries = 3;
19
- const retry = async (er) => {
20
- if (retries > 0 &&
21
- er.code === 'EPERM') {
22
- retries--;
23
- await rm(newPath, { recursive: true, force: true });
24
- return fsRename(oldPath, newPath).then(() => { }, retry);
25
- }
26
- else {
27
- throw er;
28
- }
29
- };
30
- return fsRename(oldPath, newPath).then(() => { }, retry);
31
- });
32
- //# sourceMappingURL=rename.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rename.js","sourceRoot":"","sources":["../src/rename.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;AAE5B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACzD,MAAM,CAAC,MAAM,MAAM,GACjB,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAChC,KAAK,WACH,OAAiB,EACjB,OAAiB;IAEjB,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,MAAM,KAAK,GAAG,KAAK,EAAE,EAAW,EAAiB,EAAE;QACjD,IACE,OAAO,GAAG,CAAC;YACV,EAA4B,CAAC,IAAI,KAAK,OAAO,EAC9C,CAAC;YACD,OAAO,EAAE,CAAA;YACT,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;YACnD,OAAO,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,KAAK,CAAC,CAAA;QACzD,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAA;QACV,CAAC;IACH,CAAC,CAAA;IACD,OAAO,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,EAAE,KAAK,CAAC,CAAA;AACzD,CAAC,CACF,CAAA","sourcesContent":["/**\n * On posix systems, rename is atomic and will clobber anything in its way\n * However, on Windows, it can fail with the rather unhelpful EPERM error if\n * the target directory is not removed in time or is currently in use.\n *\n * While true atomic semantics is not available on Windows in this case, we can\n * at least implement the posix overwrite semantics by explicitly removing the\n * target when this error occurs.\n *\n * This is only relevant when renaming *directories*, since files will\n * generally not raise problems. When/if we rename directories outside of\n * package-info, this can be moved to its own shared module.\n * @module\n */\nconst { platform } = process\nimport type { PathLike } from 'node:fs'\nimport { rename as fsRename, rm } from 'node:fs/promises'\nexport const rename =\n platform !== 'win32' ? fsRename : (\n async function (\n oldPath: PathLike,\n newPath: PathLike,\n ): Promise<void> {\n let retries = 3\n const retry = async (er: unknown): Promise<void> => {\n if (\n retries > 0 &&\n (er as NodeJS.ErrnoException).code === 'EPERM'\n ) {\n retries--\n await rm(newPath, { recursive: true, force: true })\n return fsRename(oldPath, newPath).then(() => {}, retry)\n } else {\n throw er\n }\n }\n return fsRename(oldPath, newPath).then(() => {}, retry)\n }\n )\n"]}