@valbuild/shared 0.148.7 → 0.150.1
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/CHANGELOG.md +62 -0
- package/client/dist/valbuild-shared-client.cjs.dev.js +2 -1
- package/client/dist/valbuild-shared-client.cjs.prod.js +2 -1
- package/client/dist/valbuild-shared-client.esm.js +2 -1
- package/dist/acquireTypes-50960f2c.esm.js +1801 -0
- package/dist/acquireTypes-de10005d.cjs.dev.js +1815 -0
- package/dist/acquireTypes-e9467a2a.cjs.prod.js +1815 -0
- package/dist/createForOfIteratorHelper-3db5d737.esm.js +121 -0
- package/dist/createForOfIteratorHelper-90e6a8b6.cjs.prod.js +129 -0
- package/dist/createForOfIteratorHelper-d86bb352.cjs.dev.js +129 -0
- package/dist/declarations/src/internal/ApiRoutes.d.ts +3 -3
- package/dist/declarations/src/internal/index.d.ts +2 -0
- package/dist/declarations/src/internal/selfCheck.d.ts +51 -0
- package/dist/declarations/src/internal/validation/validationWarnings.d.ts +33 -0
- package/dist/declarations/src/publish/buildProposal.d.ts +106 -0
- package/dist/declarations/src/publish/builder.d.ts +22 -0
- package/dist/declarations/src/publish/callJson.d.ts +21 -0
- package/dist/declarations/src/publish/index.d.ts +23 -0
- package/dist/declarations/src/publish/jobClient.d.ts +96 -0
- package/dist/declarations/src/publish/loadedLayer.d.ts +50 -0
- package/dist/declarations/src/publish/proposalProject.d.ts +2 -0
- package/dist/declarations/src/publish/publishClient.d.ts +95 -0
- package/dist/declarations/src/publish/runStudioDeploy.d.ts +244 -0
- package/dist/declarations/src/publish/runStudioJob.d.ts +102 -0
- package/dist/declarations/src/publish/runStudioPublish.d.ts +80 -0
- package/dist/declarations/src/typecheck/acquireTypes.d.ts +109 -0
- package/dist/declarations/src/typecheck/adeptSources.d.ts +9 -0
- package/dist/declarations/src/typecheck/index.d.ts +20 -0
- package/dist/declarations/src/typecheck/linkedFileSystem.d.ts +53 -0
- package/dist/declarations/src/typecheck/lockedVersions.d.ts +14 -0
- package/dist/declarations/src/typecheck/pnpmLayout.d.ts +95 -0
- package/dist/declarations/src/typecheck/pnpmLockfile.d.ts +57 -0
- package/dist/declarations/src/typecheck/proposalTypecheck.d.ts +76 -0
- package/dist/declarations/src/typecheck/testing/index.d.ts +6 -0
- package/dist/declarations/src/typecheck/testing/nodeModulesSources.d.ts +5 -0
- package/dist/declarations/src/typecheck/typecheckProject.d.ts +89 -0
- package/dist/declarations/src/typecheck/typescriptCompiler.d.ts +52 -0
- package/dist/{getSitemapTree-40d76bf8.cjs.prod.js → getSitemapTree-0fa0569c.cjs.dev.js} +5 -131
- package/dist/{getSitemapTree-cd006a36.esm.js → getSitemapTree-5afbc3ac.esm.js} +2 -121
- package/dist/{getSitemapTree-a7f2cc6d.cjs.dev.js → getSitemapTree-667bcb3c.cjs.prod.js} +5 -131
- package/dist/proposalProject-28550146.cjs.prod.js +18 -0
- package/dist/proposalProject-a3d3ad76.esm.js +16 -0
- package/dist/proposalProject-cdc53711.cjs.dev.js +18 -0
- package/dist/protocol-1c13de0d.cjs.prod.js +433 -0
- package/dist/protocol-3b9ef786.esm.js +413 -0
- package/dist/protocol-d8a6efda.cjs.dev.js +433 -0
- package/dist/slicedToArray-62e428df.cjs.dev.js +309 -0
- package/dist/slicedToArray-6cd80315.esm.js +299 -0
- package/dist/slicedToArray-af50e684.cjs.prod.js +309 -0
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +464 -888
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +464 -888
- package/internal/dist/valbuild-shared-internal.esm.js +276 -707
- package/package.json +28 -5
- package/publish/dist/valbuild-shared-publish.cjs.d.ts +2 -0
- package/publish/dist/valbuild-shared-publish.cjs.dev.js +2466 -0
- package/publish/dist/valbuild-shared-publish.cjs.js +7 -0
- package/publish/dist/valbuild-shared-publish.cjs.prod.js +2466 -0
- package/publish/dist/valbuild-shared-publish.esm.js +2428 -0
- package/publish/package.json +4 -0
- package/typecheck/dist/valbuild-shared-typecheck.cjs.d.ts +2 -0
- package/typecheck/dist/valbuild-shared-typecheck.cjs.dev.js +1173 -0
- package/typecheck/dist/valbuild-shared-typecheck.cjs.js +7 -0
- package/typecheck/dist/valbuild-shared-typecheck.cjs.prod.js +1173 -0
- package/typecheck/dist/valbuild-shared-typecheck.esm.js +1152 -0
- package/typecheck/package.json +4 -0
- package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.d.ts +2 -0
- package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.dev.js +202 -0
- package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.js +7 -0
- package/typecheck/testing/dist/valbuild-shared-typecheck-testing.cjs.prod.js +202 -0
- package/typecheck/testing/dist/valbuild-shared-typecheck-testing.esm.js +177 -0
- package/typecheck/testing/package.json +4 -0
|
@@ -0,0 +1,1815 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var slicedToArray = require('./slicedToArray-af50e684.cjs.prod.js');
|
|
4
|
+
var createForOfIteratorHelper = require('./createForOfIteratorHelper-90e6a8b6.cjs.prod.js');
|
|
5
|
+
var yaml = require('yaml');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The parts of a `pnpm-lock.yaml` (lockfile version 9) that decide what
|
|
9
|
+
* `pnpm install` puts in `node_modules`.
|
|
10
|
+
*
|
|
11
|
+
* Only what the layout needs is kept: each importer's direct dependencies,
|
|
12
|
+
* each package's integrity and platform constraints, and each snapshot's own
|
|
13
|
+
* dependencies. Everything is a plain string as pnpm wrote it -- a reference
|
|
14
|
+
* such as `19.3.0(react@19.3.0)` is turned into a snapshot key by
|
|
15
|
+
* {@link snapshotKeyOf}, as pnpm's lockfile crate does.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** An importer's dependencies, alias to the reference pnpm locked it at. */
|
|
19
|
+
|
|
20
|
+
/** A lockfile this cannot read: not YAML, or not pnpm's version 9 shape. */
|
|
21
|
+
var LockfileError = /*#__PURE__*/function (_Error) {
|
|
22
|
+
function LockfileError() {
|
|
23
|
+
slicedToArray._classCallCheck(this, LockfileError);
|
|
24
|
+
return slicedToArray._callSuper(this, LockfileError, arguments);
|
|
25
|
+
}
|
|
26
|
+
slicedToArray._inherits(LockfileError, _Error);
|
|
27
|
+
return slicedToArray._createClass(LockfileError);
|
|
28
|
+
}(/*#__PURE__*/slicedToArray._wrapNativeSuper(Error));
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return createForOfIteratorHelper._typeof(value) === "object" && value !== null && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** YAML reads `1.0` as a number; a lockfile means the text. */
|
|
34
|
+
function textOf(value) {
|
|
35
|
+
if (typeof value === "string") return value;
|
|
36
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
37
|
+
return String(value);
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function stringList(value) {
|
|
42
|
+
if (value === undefined || value === null) return null;
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value.flatMap(function (item) {
|
|
45
|
+
var text = textOf(item);
|
|
46
|
+
return text === null ? [] : [text];
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
var text = textOf(value);
|
|
50
|
+
return text === null ? null : [text];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** `alias: <reference>` in a snapshot, or `alias: { specifier, version }` in an importer. */
|
|
54
|
+
function referenceMap(value, where) {
|
|
55
|
+
var out = {};
|
|
56
|
+
if (value === undefined || value === null) return out;
|
|
57
|
+
if (!isRecord(value)) {
|
|
58
|
+
throw new LockfileError("".concat(where, " is not a map of dependencies."));
|
|
59
|
+
}
|
|
60
|
+
for (var _i = 0, _Object$entries = Object.entries(value); _i < _Object$entries.length; _i++) {
|
|
61
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
|
|
62
|
+
alias = _Object$entries$_i[0],
|
|
63
|
+
entry = _Object$entries$_i[1];
|
|
64
|
+
var version = isRecord(entry) ? textOf(entry["version"]) : textOf(entry);
|
|
65
|
+
if (version === null) {
|
|
66
|
+
throw new LockfileError("".concat(where, " has no version for ").concat(alias, "."));
|
|
67
|
+
}
|
|
68
|
+
out[alias] = version;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reads a pnpm 9 lockfile. pnpm 11 and later may put a document of their own
|
|
75
|
+
* (the package manager's dependencies) before the project's, so the document
|
|
76
|
+
* read is the one that has `importers`.
|
|
77
|
+
*/
|
|
78
|
+
function parsePnpmLockfile(text) {
|
|
79
|
+
var documents;
|
|
80
|
+
try {
|
|
81
|
+
documents = yaml.parseAllDocuments(text).flatMap(function (document) {
|
|
82
|
+
if (!("toJS" in document)) return [];
|
|
83
|
+
if (document.errors.length > 0) {
|
|
84
|
+
throw new LockfileError(document.errors[0].message);
|
|
85
|
+
}
|
|
86
|
+
return [document.toJS({
|
|
87
|
+
maxAliasCount: -1
|
|
88
|
+
})];
|
|
89
|
+
});
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (error instanceof LockfileError) throw error;
|
|
92
|
+
throw new LockfileError("pnpm-lock.yaml is not YAML: ".concat(error instanceof Error ? error.message : String(error)));
|
|
93
|
+
}
|
|
94
|
+
var lockfile = documents.find(function (document) {
|
|
95
|
+
return isRecord(document) && "importers" in document;
|
|
96
|
+
});
|
|
97
|
+
if (!isRecord(lockfile)) {
|
|
98
|
+
throw new LockfileError("pnpm-lock.yaml has no importers.");
|
|
99
|
+
}
|
|
100
|
+
var version = textOf(lockfile["lockfileVersion"]);
|
|
101
|
+
if (version === null || !/^9(\.|$)/.test(version)) {
|
|
102
|
+
throw new LockfileError("pnpm-lock.yaml is lockfile version ".concat(version !== null && version !== void 0 ? version : "(none)", "; only version 9 (pnpm 9 and later) can be read."));
|
|
103
|
+
}
|
|
104
|
+
var importers = {};
|
|
105
|
+
var rawImporters = lockfile["importers"];
|
|
106
|
+
if (!isRecord(rawImporters)) {
|
|
107
|
+
throw new LockfileError("pnpm-lock.yaml's importers is not a map.");
|
|
108
|
+
}
|
|
109
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(rawImporters); _i2 < _Object$entries2.length; _i2++) {
|
|
110
|
+
var _Object$entries2$_i = slicedToArray._slicedToArray(_Object$entries2[_i2], 2),
|
|
111
|
+
id = _Object$entries2$_i[0],
|
|
112
|
+
raw = _Object$entries2$_i[1];
|
|
113
|
+
var importer = isRecord(raw) ? raw : {};
|
|
114
|
+
var where = "importer '".concat(id, "'");
|
|
115
|
+
importers[id] = {
|
|
116
|
+
dependencies: referenceMap(importer["dependencies"], where),
|
|
117
|
+
devDependencies: referenceMap(importer["devDependencies"], where),
|
|
118
|
+
optionalDependencies: referenceMap(importer["optionalDependencies"], where)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
var packages = {};
|
|
122
|
+
var rawPackages = lockfile["packages"];
|
|
123
|
+
if (isRecord(rawPackages)) {
|
|
124
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(rawPackages); _i3 < _Object$entries3.length; _i3++) {
|
|
125
|
+
var _Object$entries3$_i = slicedToArray._slicedToArray(_Object$entries3[_i3], 2),
|
|
126
|
+
key = _Object$entries3$_i[0],
|
|
127
|
+
_raw = _Object$entries3$_i[1];
|
|
128
|
+
var info = isRecord(_raw) ? _raw : {};
|
|
129
|
+
var resolution = isRecord(info["resolution"]) ? info["resolution"] : {};
|
|
130
|
+
packages[key] = {
|
|
131
|
+
integrity: textOf(resolution["integrity"]),
|
|
132
|
+
tarball: textOf(resolution["tarball"]),
|
|
133
|
+
os: stringList(info["os"]),
|
|
134
|
+
cpu: stringList(info["cpu"]),
|
|
135
|
+
libc: stringList(info["libc"]),
|
|
136
|
+
hasBin: info["hasBin"] === true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
var snapshots = {};
|
|
141
|
+
var rawSnapshots = lockfile["snapshots"];
|
|
142
|
+
if (isRecord(rawSnapshots)) {
|
|
143
|
+
for (var _i4 = 0, _Object$entries4 = Object.entries(rawSnapshots); _i4 < _Object$entries4.length; _i4++) {
|
|
144
|
+
var _Object$entries4$_i = slicedToArray._slicedToArray(_Object$entries4[_i4], 2),
|
|
145
|
+
_key = _Object$entries4$_i[0],
|
|
146
|
+
_raw2 = _Object$entries4$_i[1];
|
|
147
|
+
var snapshot = isRecord(_raw2) ? _raw2 : {};
|
|
148
|
+
var _where = "snapshot '".concat(_key, "'");
|
|
149
|
+
snapshots[_key] = {
|
|
150
|
+
dependencies: referenceMap(snapshot["dependencies"], _where),
|
|
151
|
+
optionalDependencies: referenceMap(snapshot["optionalDependencies"], _where),
|
|
152
|
+
optional: snapshot["optional"] === true
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
importers: importers,
|
|
158
|
+
packages: packages,
|
|
159
|
+
snapshots: snapshots
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The index of the `@` between a key's name and its version: the first one
|
|
165
|
+
* after a scope's leading `@`.
|
|
166
|
+
*/
|
|
167
|
+
function versionSeparator(key) {
|
|
168
|
+
return key.indexOf("@", 1);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** `@scope/name` of `@scope/name@1.0.0(peer@2.0.0)`. */
|
|
172
|
+
function nameOfKey(key) {
|
|
173
|
+
var at = versionSeparator(key);
|
|
174
|
+
return at < 0 ? key : key.slice(0, at);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** `1.0.0` of `@scope/name@1.0.0(peer@2.0.0)`: the version, without peers. */
|
|
178
|
+
function versionOfKey(key) {
|
|
179
|
+
var at = versionSeparator(key);
|
|
180
|
+
var rest = at < 0 ? "" : key.slice(at + 1);
|
|
181
|
+
var peers = rest.indexOf("(");
|
|
182
|
+
return peers < 0 ? rest : rest.slice(0, peers);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The `packages:` key a snapshot key's metadata is under: the key without its peers. */
|
|
186
|
+
function packageKeyOf(snapshotKey) {
|
|
187
|
+
return "".concat(nameOfKey(snapshotKey), "@").concat(versionOfKey(snapshotKey));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Whether a reference names another package (an npm alias, `foo:
|
|
192
|
+
* string-width@4.2.3`) rather than a version of the alias itself. pnpm's
|
|
193
|
+
* `looks_like_alias`: a leading `@` is a scoped name, and otherwise the `@`
|
|
194
|
+
* has to come before any `:` or `(`.
|
|
195
|
+
*/
|
|
196
|
+
function looksLikeAlias(reference) {
|
|
197
|
+
if (reference.startsWith("@")) return true;
|
|
198
|
+
var at = reference.indexOf("@");
|
|
199
|
+
if (at < 0) return false;
|
|
200
|
+
var colon = reference.indexOf(":");
|
|
201
|
+
var paren = reference.indexOf("(");
|
|
202
|
+
return (colon < 0 || at < colon) && (paren < 0 || at < paren);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* The snapshot a dependency reference points at, or `null` for a `link:` to
|
|
207
|
+
* a directory (a workspace sibling), which is not in the virtual store.
|
|
208
|
+
*/
|
|
209
|
+
function snapshotKeyOf(alias, reference) {
|
|
210
|
+
if (reference.startsWith("link:")) return null;
|
|
211
|
+
if (looksLikeAlias(reference)) return reference;
|
|
212
|
+
return "".concat(alias, "@").concat(reference);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* SHA-256 of a string's UTF-8, as lowercase hex, synchronously.
|
|
217
|
+
*
|
|
218
|
+
* pnpm names a virtual-store directory that is too long, or has upper case
|
|
219
|
+
* in it, with a hash of the name, and the layout is computed synchronously.
|
|
220
|
+
* `crypto.subtle` is asynchronous and only exists in a secure context, and
|
|
221
|
+
* `@valbuild/core`'s `Internal.getSHA256Hash` would bring all of core into
|
|
222
|
+
* the typecheck worker for this one function (168 kB of its 286), so this is
|
|
223
|
+
* the plain algorithm (FIPS 180-4). `pnpmLayout.test.ts` checks it against
|
|
224
|
+
* the hashed names a real `pnpm install` made, and against Node's own.
|
|
225
|
+
*/
|
|
226
|
+
var K = new Uint32Array([0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]);
|
|
227
|
+
var rotr = function rotr(x, n) {
|
|
228
|
+
return x >>> n | x << 32 - n;
|
|
229
|
+
};
|
|
230
|
+
function sha256Hex(text) {
|
|
231
|
+
var bytes = new TextEncoder().encode(text);
|
|
232
|
+
// The message, a 1 bit, zeros, and its length in bits as 64 bits: a
|
|
233
|
+
// multiple of 64 bytes.
|
|
234
|
+
var blocks = Math.ceil((bytes.length + 9) / 64);
|
|
235
|
+
var padded = new Uint8Array(blocks * 64);
|
|
236
|
+
padded.set(bytes);
|
|
237
|
+
padded[bytes.length] = 0x80;
|
|
238
|
+
var view = new DataView(padded.buffer);
|
|
239
|
+
var bits = bytes.length * 8;
|
|
240
|
+
view.setUint32(padded.length - 8, Math.floor(bits / 0x100000000));
|
|
241
|
+
view.setUint32(padded.length - 4, bits >>> 0);
|
|
242
|
+
var h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
|
|
243
|
+
var w = new Uint32Array(64);
|
|
244
|
+
for (var block = 0; block < blocks; block++) {
|
|
245
|
+
for (var i = 0; i < 16; i++) w[i] = view.getUint32(block * 64 + i * 4);
|
|
246
|
+
for (var _i = 16; _i < 64; _i++) {
|
|
247
|
+
var w15 = w[_i - 15];
|
|
248
|
+
var w2 = w[_i - 2];
|
|
249
|
+
var s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
|
|
250
|
+
var s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
|
|
251
|
+
w[_i] = w[_i - 16] + s0 + w[_i - 7] + s1 >>> 0;
|
|
252
|
+
}
|
|
253
|
+
var _h = slicedToArray._slicedToArray(h, 8),
|
|
254
|
+
a = _h[0],
|
|
255
|
+
b = _h[1],
|
|
256
|
+
c = _h[2],
|
|
257
|
+
d = _h[3],
|
|
258
|
+
e = _h[4],
|
|
259
|
+
f = _h[5],
|
|
260
|
+
g = _h[6],
|
|
261
|
+
hh = _h[7];
|
|
262
|
+
for (var _i2 = 0; _i2 < 64; _i2++) {
|
|
263
|
+
var _s = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
264
|
+
var ch = e & f ^ ~e & g;
|
|
265
|
+
var t1 = hh + _s + ch + K[_i2] + w[_i2] >>> 0;
|
|
266
|
+
var _s2 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
267
|
+
var maj = a & b ^ a & c ^ b & c;
|
|
268
|
+
var t2 = _s2 + maj >>> 0;
|
|
269
|
+
hh = g;
|
|
270
|
+
g = f;
|
|
271
|
+
f = e;
|
|
272
|
+
e = d + t1 >>> 0;
|
|
273
|
+
d = c;
|
|
274
|
+
c = b;
|
|
275
|
+
b = a;
|
|
276
|
+
a = t1 + t2 >>> 0;
|
|
277
|
+
}
|
|
278
|
+
h[0] = h[0] + a >>> 0;
|
|
279
|
+
h[1] = h[1] + b >>> 0;
|
|
280
|
+
h[2] = h[2] + c >>> 0;
|
|
281
|
+
h[3] = h[3] + d >>> 0;
|
|
282
|
+
h[4] = h[4] + e >>> 0;
|
|
283
|
+
h[5] = h[5] + f >>> 0;
|
|
284
|
+
h[6] = h[6] + g >>> 0;
|
|
285
|
+
h[7] = h[7] + hh >>> 0;
|
|
286
|
+
}
|
|
287
|
+
return Array.from(h, function (word) {
|
|
288
|
+
return word.toString(16).padStart(8, "0");
|
|
289
|
+
}).join("");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* What `pnpm install --frozen-lockfile` puts in `node_modules`, computed from
|
|
294
|
+
* the lockfile alone, as a table of symlinks.
|
|
295
|
+
*
|
|
296
|
+
* Ported from pnpm's own crates (valbuild/pnpm, pacquet 12.13.0):
|
|
297
|
+
* `deps-path/src/dep_path_to_filename.rs` names each snapshot's directory in
|
|
298
|
+
* the virtual store, and `deps-restorer/src/hoist.rs` decides which
|
|
299
|
+
* transitive dependencies are also linked into the private hoist
|
|
300
|
+
* (`node_modules/.pnpm/node_modules`). The defaults are pnpm 12's: hoist
|
|
301
|
+
* `["*"]` privately, nothing publicly, virtual store names at most 120 bytes,
|
|
302
|
+
* no global virtual store. `pnpmLayout.test.ts` compares the result with
|
|
303
|
+
* what a real install left on disk.
|
|
304
|
+
*
|
|
305
|
+
* Every path is absolute, under `root` (default `/project`), with `/`
|
|
306
|
+
* separators.
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
/** What `pnpm install` checks optional packages' `os`, `cpu` and `libc` against. */
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Linux on x64 with glibc: what a CI runner and the build are, and so the
|
|
313
|
+
* install the typecheck is compared with. It only decides which optional,
|
|
314
|
+
* platform-specific packages exist, which hardly ever carry types.
|
|
315
|
+
*/
|
|
316
|
+
var DEFAULT_PLATFORM = {
|
|
317
|
+
os: "linux",
|
|
318
|
+
cpu: "x64",
|
|
319
|
+
libc: "glibc"
|
|
320
|
+
};
|
|
321
|
+
var DEFAULT_VIRTUAL_STORE_DIR_MAX_LENGTH = 120;
|
|
322
|
+
var encoder = new TextEncoder();
|
|
323
|
+
var byteLength = function byteLength(text) {
|
|
324
|
+
return encoder.encode(text).length;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/** The first 32 hex characters of the SHA-256 of `input`: pnpm's `create_short_hash`. */
|
|
328
|
+
function shortHash(input) {
|
|
329
|
+
return sha256Hex(input).slice(0, 32);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The longest prefix of `text` that is at most `bytes` bytes of UTF-8. */
|
|
333
|
+
function prefixOfBytes(text, bytes) {
|
|
334
|
+
if (byteLength(text) <= bytes) return text;
|
|
335
|
+
var out = "";
|
|
336
|
+
var used = 0;
|
|
337
|
+
var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(text),
|
|
338
|
+
_step;
|
|
339
|
+
try {
|
|
340
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
341
|
+
var _char = _step.value;
|
|
342
|
+
var size = byteLength(_char);
|
|
343
|
+
if (used + size > bytes) break;
|
|
344
|
+
out += _char;
|
|
345
|
+
used += size;
|
|
346
|
+
}
|
|
347
|
+
} catch (err) {
|
|
348
|
+
_iterator.e(err);
|
|
349
|
+
} finally {
|
|
350
|
+
_iterator.f();
|
|
351
|
+
}
|
|
352
|
+
return out;
|
|
353
|
+
}
|
|
354
|
+
function hashSuffixVirtualStoreName(filename, hashInput, maxLength) {
|
|
355
|
+
var cap = Math.max(0, maxLength - 33);
|
|
356
|
+
return "".concat(prefixOfBytes(filename, cap), "_").concat(shortHash(hashInput));
|
|
357
|
+
}
|
|
358
|
+
function shortenVirtualStoreName(filename, maxLength) {
|
|
359
|
+
var needsShortening = byteLength(filename) > maxLength || filename !== filename.toLowerCase() && !filename.startsWith("file+");
|
|
360
|
+
return needsShortening ? hashSuffixVirtualStoreName(filename, filename, maxLength) : filename;
|
|
361
|
+
}
|
|
362
|
+
var RESERVED_VERSION_PREFIXES = new Set(["bitbucket", "catalog", "custom", "file", "git", "github", "gitlab", "http", "https", "jsr", "link", "npm", "pkg", "runtime", "ssh", "tool", "workspace"]);
|
|
363
|
+
var SEMVER = /^v?\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/;
|
|
364
|
+
|
|
365
|
+
/** `registry:1.0.0`: a version qualified by a named registry, which escapes unambiguously. */
|
|
366
|
+
function isRegistryQualifiedVersion(version) {
|
|
367
|
+
var colon = version.indexOf(":");
|
|
368
|
+
if (colon < 0) return false;
|
|
369
|
+
var registry = version.slice(0, colon);
|
|
370
|
+
return registry !== "" && !RESERVED_VERSION_PREFIXES.has(registry) && /^[A-Za-z][A-Za-z0-9._-]*$/.test(registry) && SEMVER.test(version.slice(colon + 1));
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Whether escaping the URL or path of a non-registry dependency could map
|
|
375
|
+
* two distinct dep paths to one name (`has_ambiguous_escape`).
|
|
376
|
+
*/
|
|
377
|
+
function hasAmbiguousEscape(depPath) {
|
|
378
|
+
var _depPath$split$;
|
|
379
|
+
var packageId = (_depPath$split$ = depPath.split("(")[0]) !== null && _depPath$split$ !== void 0 ? _depPath$split$ : "";
|
|
380
|
+
if (packageId.startsWith("/")) packageId = packageId.slice(1);
|
|
381
|
+
var version;
|
|
382
|
+
if (packageId.startsWith("file:")) {
|
|
383
|
+
version = packageId;
|
|
384
|
+
} else {
|
|
385
|
+
var at = packageId.indexOf("@", 1);
|
|
386
|
+
if (at < 0) return false;
|
|
387
|
+
version = packageId.slice(at + 1);
|
|
388
|
+
}
|
|
389
|
+
var colon = version.indexOf(":");
|
|
390
|
+
if (colon < 0) return false;
|
|
391
|
+
if (isRegistryQualifiedVersion(version)) return false;
|
|
392
|
+
var location = version.slice(colon + 1);
|
|
393
|
+
if (location.startsWith("//")) location = location.slice(2);
|
|
394
|
+
return /[+\\:*?"<>|#]/.test(location);
|
|
395
|
+
}
|
|
396
|
+
function depPathToFilenameUnescaped(depPath) {
|
|
397
|
+
if (depPath.startsWith("file:")) return depPath.replace(":", "+");
|
|
398
|
+
var trimmed = depPath.startsWith("/") ? depPath.slice(1) : depPath;
|
|
399
|
+
return trimmed;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* The directory name of a snapshot in the virtual store: pnpm's
|
|
404
|
+
* `dep_path_to_filename`. `@scope/foo@1.0.0(bar@2.0.0)` is
|
|
405
|
+
* `@scope+foo@1.0.0_bar@2.0.0`; a name longer than `maxLength` bytes, or with
|
|
406
|
+
* upper case letters, is cut and given a hash of the whole.
|
|
407
|
+
*/
|
|
408
|
+
function depPathToFilename(depPath) {
|
|
409
|
+
var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_VIRTUAL_STORE_DIR_MAX_LENGTH;
|
|
410
|
+
var filename = depPathToFilenameUnescaped(depPath).replace(/[\\/:*?"<>|#]/g, "+");
|
|
411
|
+
if (filename.includes("(")) {
|
|
412
|
+
if (filename.endsWith(")")) filename = filename.slice(0, -1);
|
|
413
|
+
filename = filename.split(")(").join("_").replace(/[()]/g, "_");
|
|
414
|
+
}
|
|
415
|
+
var kept = filename.replace(/[. ]+$/, "").length;
|
|
416
|
+
var trailing = filename.length - kept;
|
|
417
|
+
var ambiguous = hasAmbiguousEscape(depPath);
|
|
418
|
+
if (trailing > 0) {
|
|
419
|
+
var escaped = filename.slice(0, kept) + "+".repeat(trailing);
|
|
420
|
+
return hashSuffixVirtualStoreName(escaped, ambiguous ? depPath : filename, maxLength);
|
|
421
|
+
}
|
|
422
|
+
if (ambiguous) {
|
|
423
|
+
return hashSuffixVirtualStoreName(filename, depPath, maxLength);
|
|
424
|
+
}
|
|
425
|
+
return shortenVirtualStoreName(filename, maxLength);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* pnpm's `WildcardMatcher` lists: `*` is any run of characters, `?` one, a
|
|
430
|
+
* leading `!` excludes, and a later exclude cancels an earlier include.
|
|
431
|
+
*/
|
|
432
|
+
function createMatcher(patterns) {
|
|
433
|
+
if (patterns.length === 0) return function () {
|
|
434
|
+
return false;
|
|
435
|
+
};
|
|
436
|
+
var compiled = patterns.map(function (pattern) {
|
|
437
|
+
var ignore = pattern.startsWith("!");
|
|
438
|
+
var glob = ignore ? pattern.slice(1) : pattern;
|
|
439
|
+
var source = glob.split("").map(function (_char2) {
|
|
440
|
+
return _char2 === "*" ? ".*" : _char2 === "?" ? "." : _char2.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
441
|
+
}).join("");
|
|
442
|
+
return {
|
|
443
|
+
ignore: ignore,
|
|
444
|
+
regexp: new RegExp("^".concat(source, "$"), "s")
|
|
445
|
+
};
|
|
446
|
+
});
|
|
447
|
+
var hasInclude = compiled.some(function (pattern) {
|
|
448
|
+
return !pattern.ignore;
|
|
449
|
+
});
|
|
450
|
+
var hasIgnore = compiled.some(function (pattern) {
|
|
451
|
+
return pattern.ignore;
|
|
452
|
+
});
|
|
453
|
+
if (compiled.length === 1) {
|
|
454
|
+
var only = compiled[0];
|
|
455
|
+
return function (input) {
|
|
456
|
+
return only.regexp.test(input) !== only.ignore;
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (!hasIgnore) {
|
|
460
|
+
return function (input) {
|
|
461
|
+
return compiled.some(function (pattern) {
|
|
462
|
+
return pattern.regexp.test(input);
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (!hasInclude) {
|
|
467
|
+
return function (input) {
|
|
468
|
+
return !compiled.some(function (pattern) {
|
|
469
|
+
return pattern.regexp.test(input);
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return function (input) {
|
|
474
|
+
var matched = false;
|
|
475
|
+
var _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(compiled),
|
|
476
|
+
_step2;
|
|
477
|
+
try {
|
|
478
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
479
|
+
var pattern = _step2.value;
|
|
480
|
+
if (!pattern.regexp.test(input)) continue;
|
|
481
|
+
matched = !pattern.ignore;
|
|
482
|
+
}
|
|
483
|
+
} catch (err) {
|
|
484
|
+
_iterator2.e(err);
|
|
485
|
+
} finally {
|
|
486
|
+
_iterator2.f();
|
|
487
|
+
}
|
|
488
|
+
return matched;
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** npm's `checkList`: `any`, a list of allowed values, or of `!`excluded ones. */
|
|
493
|
+
function platformAllows(list, value) {
|
|
494
|
+
if (list === null || list.length === 0) return true;
|
|
495
|
+
if (list.length === 1 && list[0] === "any") return true;
|
|
496
|
+
if (value === null) return true;
|
|
497
|
+
var match = false;
|
|
498
|
+
var excluded = 0;
|
|
499
|
+
var _iterator3 = createForOfIteratorHelper._createForOfIteratorHelper(list),
|
|
500
|
+
_step3;
|
|
501
|
+
try {
|
|
502
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
503
|
+
var entry = _step3.value;
|
|
504
|
+
if (entry.startsWith("!")) {
|
|
505
|
+
if (entry.slice(1) === value) return false;
|
|
506
|
+
excluded++;
|
|
507
|
+
} else if (entry === value) {
|
|
508
|
+
match = true;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
} catch (err) {
|
|
512
|
+
_iterator3.e(err);
|
|
513
|
+
} finally {
|
|
514
|
+
_iterator3.f();
|
|
515
|
+
}
|
|
516
|
+
return match || excluded === list.length;
|
|
517
|
+
}
|
|
518
|
+
var OS_TOKENS = {
|
|
519
|
+
aix: "aix",
|
|
520
|
+
android: "android",
|
|
521
|
+
darwin: "darwin",
|
|
522
|
+
macos: "darwin",
|
|
523
|
+
osx: "darwin",
|
|
524
|
+
freebsd: "freebsd",
|
|
525
|
+
linux: "linux",
|
|
526
|
+
netbsd: "netbsd",
|
|
527
|
+
openbsd: "openbsd",
|
|
528
|
+
openharmony: "openharmony",
|
|
529
|
+
sunos: "sunos",
|
|
530
|
+
win32: "win32",
|
|
531
|
+
windows: "win32"
|
|
532
|
+
};
|
|
533
|
+
var CPU_TOKENS = {
|
|
534
|
+
arm: "arm",
|
|
535
|
+
armv6: "arm",
|
|
536
|
+
armv7: "arm",
|
|
537
|
+
arm64: "arm64",
|
|
538
|
+
aarch64: "arm64",
|
|
539
|
+
ia32: "ia32",
|
|
540
|
+
loong64: "loong64",
|
|
541
|
+
mips64el: "mips64el",
|
|
542
|
+
ppc64: "ppc64",
|
|
543
|
+
ppc64le: "ppc64",
|
|
544
|
+
riscv64: "riscv64",
|
|
545
|
+
s390x: "s390x",
|
|
546
|
+
x64: "x64",
|
|
547
|
+
amd64: "x64",
|
|
548
|
+
wasm32: "wasm32"
|
|
549
|
+
};
|
|
550
|
+
var LIBC_TOKENS = {
|
|
551
|
+
glibc: "glibc",
|
|
552
|
+
gnu: "glibc",
|
|
553
|
+
gnueabihf: "glibc",
|
|
554
|
+
musl: "musl",
|
|
555
|
+
musleabihf: "musl"
|
|
556
|
+
};
|
|
557
|
+
function tokenValues(tokens, table) {
|
|
558
|
+
var values = [];
|
|
559
|
+
var _iterator4 = createForOfIteratorHelper._createForOfIteratorHelper(tokens),
|
|
560
|
+
_step4;
|
|
561
|
+
try {
|
|
562
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
563
|
+
var token = _step4.value;
|
|
564
|
+
var value = Object.prototype.hasOwnProperty.call(table, token) ? table[token] : undefined;
|
|
565
|
+
if (value !== undefined && !values.includes(value)) values.push(value);
|
|
566
|
+
}
|
|
567
|
+
} catch (err) {
|
|
568
|
+
_iterator4.e(err);
|
|
569
|
+
} finally {
|
|
570
|
+
_iterator4.f();
|
|
571
|
+
}
|
|
572
|
+
return values.length > 0 ? values : null;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The platform an optional package is for, with what its name says filling
|
|
577
|
+
* in what its manifest leaves out: `lightningcss-linux-x64-musl` declares
|
|
578
|
+
* `os` and `cpu` but not `libc`. pnpm's `inferred_platform`.
|
|
579
|
+
*/
|
|
580
|
+
function wantedPlatform(name, info) {
|
|
581
|
+
var _info$os, _info$cpu, _info$libc;
|
|
582
|
+
if (info.os !== null && info.cpu !== null && info.libc !== null) return info;
|
|
583
|
+
var bare = name.includes("/") ? name.slice(name.indexOf("/") + 1) : name;
|
|
584
|
+
var tokens = bare.toLowerCase().split(/[-_.]/);
|
|
585
|
+
var os = tokenValues(tokens, OS_TOKENS);
|
|
586
|
+
var cpu = tokenValues(tokens, CPU_TOKENS);
|
|
587
|
+
var libc = tokenValues(tokens, LIBC_TOKENS);
|
|
588
|
+
if (os === null && cpu === null && libc === null) return info;
|
|
589
|
+
var declares = info.os !== null || info.cpu !== null || info.libc !== null;
|
|
590
|
+
if (!declares && os === null) return info;
|
|
591
|
+
return {
|
|
592
|
+
os: (_info$os = info.os) !== null && _info$os !== void 0 ? _info$os : os,
|
|
593
|
+
cpu: (_info$cpu = info.cpu) !== null && _info$cpu !== void 0 ? _info$cpu : cpu,
|
|
594
|
+
libc: (_info$libc = info.libc) !== null && _info$libc !== void 0 ? _info$libc : libc
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function isInstallable(name, info, platform) {
|
|
598
|
+
var wanted = wantedPlatform(name, info);
|
|
599
|
+
return platformAllows(wanted.os, platform.os) && platformAllows(wanted.cpu, platform.cpu) && platformAllows(wanted.libc, platform.libc);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* The snapshots the importers reach, not passing through any in `blocked`:
|
|
604
|
+
* pnpm's `collect_reachable`.
|
|
605
|
+
*/
|
|
606
|
+
function reachableSnapshots(lockfile, blocked) {
|
|
607
|
+
var seen = new Set();
|
|
608
|
+
var queue = [];
|
|
609
|
+
var visit = function visit(alias, reference) {
|
|
610
|
+
var key = snapshotKeyOf(alias, reference);
|
|
611
|
+
if (key === null || seen.has(key) || blocked.has(key)) return;
|
|
612
|
+
if (!lockfile.snapshots[key]) return;
|
|
613
|
+
seen.add(key);
|
|
614
|
+
queue.push(key);
|
|
615
|
+
};
|
|
616
|
+
for (var _i = 0, _Object$values = Object.values(lockfile.importers); _i < _Object$values.length; _i++) {
|
|
617
|
+
var importer = _Object$values[_i];
|
|
618
|
+
for (var _i2 = 0, _arr = [importer.dependencies, importer.devDependencies, importer.optionalDependencies]; _i2 < _arr.length; _i2++) {
|
|
619
|
+
var group = _arr[_i2];
|
|
620
|
+
for (var _i3 = 0, _Object$entries = Object.entries(group); _i3 < _Object$entries.length; _i3++) {
|
|
621
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i3], 2),
|
|
622
|
+
alias = _Object$entries$_i[0],
|
|
623
|
+
reference = _Object$entries$_i[1];
|
|
624
|
+
visit(alias, reference);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
for (var key = queue.shift(); key !== undefined; key = queue.shift()) {
|
|
629
|
+
var snapshot = lockfile.snapshots[key];
|
|
630
|
+
for (var _i4 = 0, _arr2 = [snapshot.dependencies, snapshot.optionalDependencies]; _i4 < _arr2.length; _i4++) {
|
|
631
|
+
var _group = _arr2[_i4];
|
|
632
|
+
for (var _i5 = 0, _Object$entries2 = Object.entries(_group); _i5 < _Object$entries2.length; _i5++) {
|
|
633
|
+
var _Object$entries2$_i = slicedToArray._slicedToArray(_Object$entries2[_i5], 2),
|
|
634
|
+
_alias = _Object$entries2$_i[0],
|
|
635
|
+
_reference = _Object$entries2$_i[1];
|
|
636
|
+
visit(_alias, _reference);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return seen;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* The snapshots `pnpm install` leaves out on `platform`: the optional ones
|
|
645
|
+
* that are not for it (`compute_skipped_snapshots`), and then everything the
|
|
646
|
+
* importers can reach only through one of those
|
|
647
|
+
* (`extend_skipped_with_dependency_closure`).
|
|
648
|
+
*/
|
|
649
|
+
function skippedSnapshots(lockfile, platform) {
|
|
650
|
+
var skipped = new Set();
|
|
651
|
+
for (var _i6 = 0, _Object$entries3 = Object.entries(lockfile.snapshots); _i6 < _Object$entries3.length; _i6++) {
|
|
652
|
+
var _Object$entries3$_i = slicedToArray._slicedToArray(_Object$entries3[_i6], 2),
|
|
653
|
+
key = _Object$entries3$_i[0],
|
|
654
|
+
snapshot = _Object$entries3$_i[1];
|
|
655
|
+
var info = lockfile.packages[packageKeyOf(key)];
|
|
656
|
+
if (snapshot.optional && info && !isInstallable(nameOfKey(key), info, platform)) {
|
|
657
|
+
skipped.add(key);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (skipped.size === 0) return skipped;
|
|
661
|
+
var all = reachableSnapshots(lockfile, new Set());
|
|
662
|
+
var kept = reachableSnapshots(lockfile, skipped);
|
|
663
|
+
var _iterator5 = createForOfIteratorHelper._createForOfIteratorHelper(all),
|
|
664
|
+
_step5;
|
|
665
|
+
try {
|
|
666
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
667
|
+
var _key = _step5.value;
|
|
668
|
+
if (!kept.has(_key)) skipped.add(_key);
|
|
669
|
+
}
|
|
670
|
+
} catch (err) {
|
|
671
|
+
_iterator5.e(err);
|
|
672
|
+
} finally {
|
|
673
|
+
_iterator5.f();
|
|
674
|
+
}
|
|
675
|
+
return skipped;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/** `a/b/../c` → `a/c`, for absolute `/`-separated paths. */
|
|
679
|
+
function normalizePath(path) {
|
|
680
|
+
var out = [];
|
|
681
|
+
var _iterator6 = createForOfIteratorHelper._createForOfIteratorHelper(path.split("/")),
|
|
682
|
+
_step6;
|
|
683
|
+
try {
|
|
684
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
685
|
+
var segment = _step6.value;
|
|
686
|
+
if (segment === "" || segment === ".") continue;
|
|
687
|
+
if (segment === "..") out.pop();else out.push(segment);
|
|
688
|
+
}
|
|
689
|
+
} catch (err) {
|
|
690
|
+
_iterator6.e(err);
|
|
691
|
+
} finally {
|
|
692
|
+
_iterator6.f();
|
|
693
|
+
}
|
|
694
|
+
return "/".concat(out.join("/"));
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/** Each hoisted alias: a snapshot in the virtual store, or a workspace project's directory. */
|
|
698
|
+
|
|
699
|
+
/** Dependencies, then optional ones, each sorted by alias: `snapshot_children`. */
|
|
700
|
+
function snapshotChildren(lockfile, key) {
|
|
701
|
+
var snapshot = lockfile.snapshots[key];
|
|
702
|
+
var children = new Map();
|
|
703
|
+
for (var _i7 = 0, _arr3 = [snapshot.dependencies, snapshot.optionalDependencies]; _i7 < _arr3.length; _i7++) {
|
|
704
|
+
var group = _arr3[_i7];
|
|
705
|
+
var _iterator7 = createForOfIteratorHelper._createForOfIteratorHelper(Object.keys(group).sort(compareBytes)),
|
|
706
|
+
_step7;
|
|
707
|
+
try {
|
|
708
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
709
|
+
var alias = _step7.value;
|
|
710
|
+
var child = snapshotKeyOf(alias, group[alias]);
|
|
711
|
+
if (child !== null) children.set(alias, child);
|
|
712
|
+
}
|
|
713
|
+
} catch (err) {
|
|
714
|
+
_iterator7.e(err);
|
|
715
|
+
} finally {
|
|
716
|
+
_iterator7.f();
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return children;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** Rust's `str` order: by code unit, which for these names is by byte. */
|
|
723
|
+
function compareBytes(a, b) {
|
|
724
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Each importer's direct dependencies, alias to snapshot key, for the hoist:
|
|
729
|
+
* `build_direct_deps_by_importer`. Importers in id order; within one, the
|
|
730
|
+
* aliases of devDependencies, then dependencies, then optionalDependencies,
|
|
731
|
+
* each sorted, with the first group that resolves an alias owning it.
|
|
732
|
+
*/
|
|
733
|
+
function directDepsByImporter(lockfile) {
|
|
734
|
+
var result = new Map();
|
|
735
|
+
var _iterator8 = createForOfIteratorHelper._createForOfIteratorHelper(Object.keys(lockfile.importers).sort(compareBytes)),
|
|
736
|
+
_step8;
|
|
737
|
+
try {
|
|
738
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
739
|
+
var id = _step8.value;
|
|
740
|
+
var importer = lockfile.importers[id];
|
|
741
|
+
var resolved = new Map();
|
|
742
|
+
for (var _i8 = 0, _arr4 = [importer.dependencies, importer.devDependencies, importer.optionalDependencies]; _i8 < _arr4.length; _i8++) {
|
|
743
|
+
var group = _arr4[_i8];
|
|
744
|
+
for (var _i9 = 0, _Object$entries4 = Object.entries(group); _i9 < _Object$entries4.length; _i9++) {
|
|
745
|
+
var _Object$entries4$_i = slicedToArray._slicedToArray(_Object$entries4[_i9], 2),
|
|
746
|
+
alias = _Object$entries4$_i[0],
|
|
747
|
+
reference = _Object$entries4$_i[1];
|
|
748
|
+
var key = snapshotKeyOf(alias, reference);
|
|
749
|
+
if (key !== null && !resolved.has(alias)) resolved.set(alias, key);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
var deps = new Map();
|
|
753
|
+
for (var _i0 = 0, _arr5 = [importer.devDependencies, importer.dependencies, importer.optionalDependencies]; _i0 < _arr5.length; _i0++) {
|
|
754
|
+
var _group2 = _arr5[_i0];
|
|
755
|
+
var _iterator9 = createForOfIteratorHelper._createForOfIteratorHelper(Object.keys(_group2).sort(compareBytes)),
|
|
756
|
+
_step9;
|
|
757
|
+
try {
|
|
758
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
759
|
+
var _alias2 = _step9.value;
|
|
760
|
+
var _key2 = resolved.get(_alias2);
|
|
761
|
+
if (_key2 !== undefined && !deps.has(_alias2)) deps.set(_alias2, _key2);
|
|
762
|
+
}
|
|
763
|
+
} catch (err) {
|
|
764
|
+
_iterator9.e(err);
|
|
765
|
+
} finally {
|
|
766
|
+
_iterator9.f();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
result.set(id, deps);
|
|
770
|
+
}
|
|
771
|
+
} catch (err) {
|
|
772
|
+
_iterator8.e(err);
|
|
773
|
+
} finally {
|
|
774
|
+
_iterator8.f();
|
|
775
|
+
}
|
|
776
|
+
return result;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Which aliases are hoisted, and to which snapshot each points:
|
|
781
|
+
* `get_hoisted_dependencies`, for an install with no workspace packages to
|
|
782
|
+
* hoist and root dependencies that the virtual store can reach.
|
|
783
|
+
*
|
|
784
|
+
* The graph is walked in pnpm's graph-walker order -- each step's children
|
|
785
|
+
* are the next step, depth first over steps -- and the entries are then
|
|
786
|
+
* sorted by depth and virtual-store name. The first entry to claim an alias
|
|
787
|
+
* (lower-cased) wins it; the root importer's own aliases are claimed from the
|
|
788
|
+
* start, as they are already in `node_modules`.
|
|
789
|
+
*/
|
|
790
|
+
function hoist(lockfile, graph, skipped, kindOf, workspacePackages) {
|
|
791
|
+
var _direct$get$keys, _direct$get;
|
|
792
|
+
var direct = directDepsByImporter(lockfile);
|
|
793
|
+
var merged = new Map();
|
|
794
|
+
var _iterator0 = createForOfIteratorHelper._createForOfIteratorHelper(direct.values()),
|
|
795
|
+
_step0;
|
|
796
|
+
try {
|
|
797
|
+
for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
|
|
798
|
+
var deps = _step0.value;
|
|
799
|
+
var _iterator16 = createForOfIteratorHelper._createForOfIteratorHelper(deps),
|
|
800
|
+
_step16;
|
|
801
|
+
try {
|
|
802
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
803
|
+
var _step16$value = slicedToArray._slicedToArray(_step16.value, 2),
|
|
804
|
+
_alias3 = _step16$value[0],
|
|
805
|
+
key = _step16$value[1];
|
|
806
|
+
if (!merged.has(_alias3)) merged.set(_alias3, key);
|
|
807
|
+
}
|
|
808
|
+
} catch (err) {
|
|
809
|
+
_iterator16.e(err);
|
|
810
|
+
} finally {
|
|
811
|
+
_iterator16.f();
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
} catch (err) {
|
|
815
|
+
_iterator0.e(err);
|
|
816
|
+
} finally {
|
|
817
|
+
_iterator0.f();
|
|
818
|
+
}
|
|
819
|
+
var visited = new Set();
|
|
820
|
+
var directNodes = [];
|
|
821
|
+
var _iterator1 = createForOfIteratorHelper._createForOfIteratorHelper(direct.values()),
|
|
822
|
+
_step1;
|
|
823
|
+
try {
|
|
824
|
+
for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
|
|
825
|
+
var _deps = _step1.value;
|
|
826
|
+
var _iterator17 = createForOfIteratorHelper._createForOfIteratorHelper(_deps.values()),
|
|
827
|
+
_step17;
|
|
828
|
+
try {
|
|
829
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
830
|
+
var _key3 = _step17.value;
|
|
831
|
+
if (graph.has(_key3) && !visited.has(_key3)) {
|
|
832
|
+
visited.add(_key3);
|
|
833
|
+
directNodes.push(_key3);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
} catch (err) {
|
|
837
|
+
_iterator17.e(err);
|
|
838
|
+
} finally {
|
|
839
|
+
_iterator17.f();
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
} catch (err) {
|
|
843
|
+
_iterator1.e(err);
|
|
844
|
+
} finally {
|
|
845
|
+
_iterator1.f();
|
|
846
|
+
}
|
|
847
|
+
var entries = [{
|
|
848
|
+
depth: -1,
|
|
849
|
+
sortKey: "",
|
|
850
|
+
children: merged
|
|
851
|
+
}];
|
|
852
|
+
var steps = [{
|
|
853
|
+
nodes: directNodes,
|
|
854
|
+
depth: 0
|
|
855
|
+
}];
|
|
856
|
+
for (var step = steps.pop(); step; step = steps.pop()) {
|
|
857
|
+
var _iterator10 = createForOfIteratorHelper._createForOfIteratorHelper(step.nodes),
|
|
858
|
+
_step10;
|
|
859
|
+
try {
|
|
860
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
861
|
+
var node = _step10.value;
|
|
862
|
+
var _ref = graph.get(node),
|
|
863
|
+
sortKey = _ref.sortKey,
|
|
864
|
+
children = _ref.children;
|
|
865
|
+
entries.push({
|
|
866
|
+
depth: step.depth,
|
|
867
|
+
sortKey: sortKey,
|
|
868
|
+
children: children
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
} catch (err) {
|
|
872
|
+
_iterator10.e(err);
|
|
873
|
+
} finally {
|
|
874
|
+
_iterator10.f();
|
|
875
|
+
}
|
|
876
|
+
var next = step.nodes.map(function (node) {
|
|
877
|
+
var nodes = [];
|
|
878
|
+
var _iterator11 = createForOfIteratorHelper._createForOfIteratorHelper(graph.get(node).children.values()),
|
|
879
|
+
_step11;
|
|
880
|
+
try {
|
|
881
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
882
|
+
var child = _step11.value;
|
|
883
|
+
if (graph.has(child) && !visited.has(child)) {
|
|
884
|
+
visited.add(child);
|
|
885
|
+
nodes.push(child);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
} catch (err) {
|
|
889
|
+
_iterator11.e(err);
|
|
890
|
+
} finally {
|
|
891
|
+
_iterator11.f();
|
|
892
|
+
}
|
|
893
|
+
return nodes;
|
|
894
|
+
});
|
|
895
|
+
var _iterator12 = createForOfIteratorHelper._createForOfIteratorHelper(next.reverse()),
|
|
896
|
+
_step12;
|
|
897
|
+
try {
|
|
898
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
899
|
+
var nodes = _step12.value;
|
|
900
|
+
if (nodes.length > 0) steps.push({
|
|
901
|
+
nodes: nodes,
|
|
902
|
+
depth: step.depth + 1
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
} catch (err) {
|
|
906
|
+
_iterator12.e(err);
|
|
907
|
+
} finally {
|
|
908
|
+
_iterator12.f();
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
entries.sort(function (a, b) {
|
|
912
|
+
return a.depth - b.depth || compareBytes(a.sortKey, b.sortKey);
|
|
913
|
+
});
|
|
914
|
+
var claimed = new Set(slicedToArray._toConsumableArray((_direct$get$keys = (_direct$get = direct.get(".")) === null || _direct$get === void 0 ? void 0 : _direct$get.keys()) !== null && _direct$get$keys !== void 0 ? _direct$get$keys : []).map(function (alias) {
|
|
915
|
+
return alias.toLowerCase();
|
|
916
|
+
}));
|
|
917
|
+
var hoisted = new Map();
|
|
918
|
+
/*
|
|
919
|
+
* Named workspace projects are considered after every importer's direct
|
|
920
|
+
* dependencies and before anything transitive; a name that two projects
|
|
921
|
+
* share (ignoring case) is hoisted for neither.
|
|
922
|
+
*/
|
|
923
|
+
var workspaceDone = false;
|
|
924
|
+
var hoistWorkspace = function hoistWorkspace() {
|
|
925
|
+
workspaceDone = true;
|
|
926
|
+
var candidates = slicedToArray._toConsumableArray(workspacePackages).flatMap(function (_ref2) {
|
|
927
|
+
var _ref3 = slicedToArray._slicedToArray(_ref2, 2),
|
|
928
|
+
name = _ref3[0],
|
|
929
|
+
dir = _ref3[1];
|
|
930
|
+
var kind = kindOf(name);
|
|
931
|
+
return kind !== null && !claimed.has(name.toLowerCase()) ? [{
|
|
932
|
+
name: name,
|
|
933
|
+
dir: dir,
|
|
934
|
+
kind: kind
|
|
935
|
+
}] : [];
|
|
936
|
+
});
|
|
937
|
+
var counts = new Map();
|
|
938
|
+
var _iterator13 = createForOfIteratorHelper._createForOfIteratorHelper(candidates),
|
|
939
|
+
_step13;
|
|
940
|
+
try {
|
|
941
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
942
|
+
var _counts$get;
|
|
943
|
+
var name = _step13.value.name;
|
|
944
|
+
var normalized = name.toLowerCase();
|
|
945
|
+
counts.set(normalized, ((_counts$get = counts.get(normalized)) !== null && _counts$get !== void 0 ? _counts$get : 0) + 1);
|
|
946
|
+
}
|
|
947
|
+
} catch (err) {
|
|
948
|
+
_iterator13.e(err);
|
|
949
|
+
} finally {
|
|
950
|
+
_iterator13.f();
|
|
951
|
+
}
|
|
952
|
+
var _iterator14 = createForOfIteratorHelper._createForOfIteratorHelper(candidates),
|
|
953
|
+
_step14;
|
|
954
|
+
try {
|
|
955
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
956
|
+
var _step14$value = _step14.value,
|
|
957
|
+
_name = _step14$value.name,
|
|
958
|
+
dir = _step14$value.dir,
|
|
959
|
+
kind = _step14$value.kind;
|
|
960
|
+
var _normalized = _name.toLowerCase();
|
|
961
|
+
if (counts.get(_normalized) !== 1 || claimed.has(_normalized)) continue;
|
|
962
|
+
claimed.add(_normalized);
|
|
963
|
+
hoisted.set(_name, {
|
|
964
|
+
kind: kind,
|
|
965
|
+
target: {
|
|
966
|
+
dir: dir
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
} catch (err) {
|
|
971
|
+
_iterator14.e(err);
|
|
972
|
+
} finally {
|
|
973
|
+
_iterator14.f();
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
for (var _i1 = 0, _entries = entries; _i1 < _entries.length; _i1++) {
|
|
977
|
+
var entry = _entries[_i1];
|
|
978
|
+
if (!workspaceDone && entry.depth >= 0) hoistWorkspace();
|
|
979
|
+
var _iterator15 = createForOfIteratorHelper._createForOfIteratorHelper(entry.children),
|
|
980
|
+
_step15;
|
|
981
|
+
try {
|
|
982
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
983
|
+
var _step15$value = slicedToArray._slicedToArray(_step15.value, 2),
|
|
984
|
+
alias = _step15$value[0],
|
|
985
|
+
child = _step15$value[1];
|
|
986
|
+
var kind = kindOf(alias);
|
|
987
|
+
if (kind === null) continue;
|
|
988
|
+
var normalized = alias.toLowerCase();
|
|
989
|
+
if (claimed.has(normalized)) continue;
|
|
990
|
+
// A missing or skipped node does not claim the alias, so a later one
|
|
991
|
+
// with the same alias still can.
|
|
992
|
+
if (!graph.has(child) || skipped.has(child)) continue;
|
|
993
|
+
claimed.add(normalized);
|
|
994
|
+
hoisted.set(alias, {
|
|
995
|
+
kind: kind,
|
|
996
|
+
target: {
|
|
997
|
+
snapshot: child
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
} catch (err) {
|
|
1002
|
+
_iterator15.e(err);
|
|
1003
|
+
} finally {
|
|
1004
|
+
_iterator15.f();
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
if (!workspaceDone) hoistWorkspace();
|
|
1008
|
+
return hoisted;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
/** A setting in `pnpm-workspace.yaml` the layout cannot follow. */
|
|
1012
|
+
var UnsupportedLayoutError = /*#__PURE__*/function (_Error) {
|
|
1013
|
+
function UnsupportedLayoutError() {
|
|
1014
|
+
slicedToArray._classCallCheck(this, UnsupportedLayoutError);
|
|
1015
|
+
return slicedToArray._callSuper(this, UnsupportedLayoutError, arguments);
|
|
1016
|
+
}
|
|
1017
|
+
slicedToArray._inherits(UnsupportedLayoutError, _Error);
|
|
1018
|
+
return slicedToArray._createClass(UnsupportedLayoutError);
|
|
1019
|
+
}(/*#__PURE__*/slicedToArray._wrapNativeSuper(Error));
|
|
1020
|
+
function isPatternList(value) {
|
|
1021
|
+
return Array.isArray(value) && value.every(function (item) {
|
|
1022
|
+
return typeof item === "string";
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* The settings in `pnpm-workspace.yaml` that change the layout: `hoist`,
|
|
1028
|
+
* `hoistPattern`, `publicHoistPattern`, `shamefullyHoist` and
|
|
1029
|
+
* `virtualStoreDirMaxLength`. pnpm 11 and later read these from there and not
|
|
1030
|
+
* from `.npmrc`. `nodeLinker` other than `isolated` is a different layout
|
|
1031
|
+
* altogether, and refused.
|
|
1032
|
+
*/
|
|
1033
|
+
function layoutOptionsOfWorkspace(workspace) {
|
|
1034
|
+
var options = {};
|
|
1035
|
+
var linker = workspace["nodeLinker"];
|
|
1036
|
+
if (linker !== undefined && linker !== "isolated") {
|
|
1037
|
+
throw new UnsupportedLayoutError("pnpm-workspace.yaml sets nodeLinker to ".concat(String(linker), "; only the default, isolated, can be typechecked."));
|
|
1038
|
+
}
|
|
1039
|
+
if (workspace["enableGlobalVirtualStore"] === true) {
|
|
1040
|
+
throw new UnsupportedLayoutError("pnpm-workspace.yaml sets enableGlobalVirtualStore, whose layout cannot be typechecked yet.");
|
|
1041
|
+
}
|
|
1042
|
+
var hoistPattern = workspace["hoistPattern"];
|
|
1043
|
+
if (isPatternList(hoistPattern)) options.hoistPattern = hoistPattern;
|
|
1044
|
+
if (workspace["hoist"] === false) options.hoistPattern = [];
|
|
1045
|
+
var publicHoistPattern = workspace["publicHoistPattern"];
|
|
1046
|
+
if (isPatternList(publicHoistPattern)) {
|
|
1047
|
+
options.publicHoistPattern = publicHoistPattern;
|
|
1048
|
+
}
|
|
1049
|
+
if (workspace["shamefullyHoist"] === true) options.publicHoistPattern = ["*"];
|
|
1050
|
+
if (workspace["hoistWorkspacePackages"] === false) {
|
|
1051
|
+
options.hoistWorkspacePackages = false;
|
|
1052
|
+
}
|
|
1053
|
+
var maxLength = workspace["virtualStoreDirMaxLength"];
|
|
1054
|
+
if (typeof maxLength === "number") options.virtualStoreDirMaxLength = maxLength;
|
|
1055
|
+
return options;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** What `pnpm install` would put in `node_modules` for this lockfile. */
|
|
1059
|
+
function computePnpmLayout(lockfile) {
|
|
1060
|
+
var _options$root, _options$virtualStore, _options$hoistPattern, _options$publicHoistP;
|
|
1061
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1062
|
+
var root = normalizePath((_options$root = options.root) !== null && _options$root !== void 0 ? _options$root : "/project");
|
|
1063
|
+
var maxLength = (_options$virtualStore = options.virtualStoreDirMaxLength) !== null && _options$virtualStore !== void 0 ? _options$virtualStore : DEFAULT_VIRTUAL_STORE_DIR_MAX_LENGTH;
|
|
1064
|
+
var platform = options.platform === undefined ? DEFAULT_PLATFORM : options.platform;
|
|
1065
|
+
var virtualStore = "".concat(root, "/node_modules/.pnpm");
|
|
1066
|
+
var join = function join(dir, relative) {
|
|
1067
|
+
return normalizePath("".concat(dir, "/").concat(relative));
|
|
1068
|
+
};
|
|
1069
|
+
var importerDir = function importerDir(id) {
|
|
1070
|
+
return id === "." ? root : join(root, id);
|
|
1071
|
+
};
|
|
1072
|
+
var skipped = platform === null ? new Set() : skippedSnapshots(lockfile, platform);
|
|
1073
|
+
var storeNames = new Map();
|
|
1074
|
+
var storeName = function storeName(key) {
|
|
1075
|
+
var name = storeNames.get(key);
|
|
1076
|
+
if (name === undefined) {
|
|
1077
|
+
name = depPathToFilename(key, maxLength);
|
|
1078
|
+
storeNames.set(key, name);
|
|
1079
|
+
}
|
|
1080
|
+
return name;
|
|
1081
|
+
};
|
|
1082
|
+
var packageDir = function packageDir(key) {
|
|
1083
|
+
return "".concat(virtualStore, "/").concat(storeName(key), "/node_modules/").concat(nameOfKey(key));
|
|
1084
|
+
};
|
|
1085
|
+
var links = new Map();
|
|
1086
|
+
var packages = new Map();
|
|
1087
|
+
var importers = new Map();
|
|
1088
|
+
|
|
1089
|
+
/** A dependency reference, linked from `modulesDir/<alias>`; `link:` is relative to `base`. */
|
|
1090
|
+
var linkDependency = function linkDependency(modulesDir, alias, reference, base) {
|
|
1091
|
+
var path = "".concat(modulesDir, "/").concat(alias);
|
|
1092
|
+
if (links.has(path)) return;
|
|
1093
|
+
if (reference.startsWith("link:")) {
|
|
1094
|
+
links.set(path, join(base, reference.slice("link:".length)));
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
var key = snapshotKeyOf(alias, reference);
|
|
1098
|
+
if (key === null || skipped.has(key) || !lockfile.snapshots[key]) return;
|
|
1099
|
+
var target = packageDir(key);
|
|
1100
|
+
if (target !== path) links.set(path, target);
|
|
1101
|
+
};
|
|
1102
|
+
for (var _i10 = 0, _Object$entries5 = Object.entries(lockfile.importers); _i10 < _Object$entries5.length; _i10++) {
|
|
1103
|
+
var _Object$entries5$_i = slicedToArray._slicedToArray(_Object$entries5[_i10], 2),
|
|
1104
|
+
id = _Object$entries5$_i[0],
|
|
1105
|
+
importer = _Object$entries5$_i[1];
|
|
1106
|
+
var dir = importerDir(id);
|
|
1107
|
+
importers.set(id, dir);
|
|
1108
|
+
for (var _i11 = 0, _arr6 = [importer.dependencies, importer.devDependencies, importer.optionalDependencies]; _i11 < _arr6.length; _i11++) {
|
|
1109
|
+
var group = _arr6[_i11];
|
|
1110
|
+
for (var _i12 = 0, _Object$entries6 = Object.entries(group); _i12 < _Object$entries6.length; _i12++) {
|
|
1111
|
+
var _Object$entries6$_i = slicedToArray._slicedToArray(_Object$entries6[_i12], 2),
|
|
1112
|
+
alias = _Object$entries6$_i[0],
|
|
1113
|
+
reference = _Object$entries6$_i[1];
|
|
1114
|
+
linkDependency("".concat(dir, "/node_modules"), alias, reference, dir);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
var graph = new Map();
|
|
1119
|
+
for (var _i13 = 0, _Object$entries7 = Object.entries(lockfile.snapshots); _i13 < _Object$entries7.length; _i13++) {
|
|
1120
|
+
var _info$integrity;
|
|
1121
|
+
var _Object$entries7$_i = slicedToArray._slicedToArray(_Object$entries7[_i13], 2),
|
|
1122
|
+
key = _Object$entries7$_i[0],
|
|
1123
|
+
snapshot = _Object$entries7$_i[1];
|
|
1124
|
+
var packageKey = packageKeyOf(key);
|
|
1125
|
+
var info = lockfile.packages[packageKey];
|
|
1126
|
+
if (info) {
|
|
1127
|
+
graph.set(key, {
|
|
1128
|
+
children: snapshotChildren(lockfile, key),
|
|
1129
|
+
sortKey: storeName(key)
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
if (skipped.has(key)) continue;
|
|
1133
|
+
var _dir = packageDir(key);
|
|
1134
|
+
var version = versionOfKey(key);
|
|
1135
|
+
packages.set(_dir, {
|
|
1136
|
+
snapshot: key,
|
|
1137
|
+
name: nameOfKey(key),
|
|
1138
|
+
version: version,
|
|
1139
|
+
integrity: (_info$integrity = info === null || info === void 0 ? void 0 : info.integrity) !== null && _info$integrity !== void 0 ? _info$integrity : null,
|
|
1140
|
+
fromRegistry: SEMVER.test(version) && !(info !== null && info !== void 0 && info.tarball)
|
|
1141
|
+
});
|
|
1142
|
+
var modulesDir = "".concat(virtualStore, "/").concat(storeName(key), "/node_modules");
|
|
1143
|
+
for (var _i14 = 0, _arr7 = [snapshot.dependencies, snapshot.optionalDependencies]; _i14 < _arr7.length; _i14++) {
|
|
1144
|
+
var _group3 = _arr7[_i14];
|
|
1145
|
+
for (var _i15 = 0, _Object$entries8 = Object.entries(_group3); _i15 < _Object$entries8.length; _i15++) {
|
|
1146
|
+
var _Object$entries8$_i = slicedToArray._slicedToArray(_Object$entries8[_i15], 2),
|
|
1147
|
+
_alias4 = _Object$entries8$_i[0],
|
|
1148
|
+
_reference2 = _Object$entries8$_i[1];
|
|
1149
|
+
linkDependency(modulesDir, _alias4, _reference2, root);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
var isPrivate = createMatcher((_options$hoistPattern = options.hoistPattern) !== null && _options$hoistPattern !== void 0 ? _options$hoistPattern : ["*"]);
|
|
1154
|
+
var isPublic = createMatcher((_options$publicHoistP = options.publicHoistPattern) !== null && _options$publicHoistP !== void 0 ? _options$publicHoistP : []);
|
|
1155
|
+
var workspacePackages = new Map();
|
|
1156
|
+
if (options.hoistWorkspacePackages !== false) {
|
|
1157
|
+
for (var _i16 = 0, _Object$entries9 = Object.entries((_options$workspaceNam = options.workspaceNames) !== null && _options$workspaceNam !== void 0 ? _options$workspaceNam : {}); _i16 < _Object$entries9.length; _i16++) {
|
|
1158
|
+
var _options$workspaceNam;
|
|
1159
|
+
var _Object$entries9$_i = slicedToArray._slicedToArray(_Object$entries9[_i16], 2),
|
|
1160
|
+
_id = _Object$entries9$_i[0],
|
|
1161
|
+
name = _Object$entries9$_i[1];
|
|
1162
|
+
if (_id !== "." && lockfile.importers[_id]) {
|
|
1163
|
+
workspacePackages.set(name, importerDir(_id));
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
var hoisted = hoist(lockfile, graph, skipped, function (alias) {
|
|
1168
|
+
return isPublic(alias) ? "public" : isPrivate(alias) ? "private" : null;
|
|
1169
|
+
}, workspacePackages);
|
|
1170
|
+
var _iterator18 = createForOfIteratorHelper._createForOfIteratorHelper(hoisted),
|
|
1171
|
+
_step18;
|
|
1172
|
+
try {
|
|
1173
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
1174
|
+
var _step18$value = slicedToArray._slicedToArray(_step18.value, 2),
|
|
1175
|
+
_alias5 = _step18$value[0],
|
|
1176
|
+
_step18$value$ = _step18$value[1],
|
|
1177
|
+
kind = _step18$value$.kind,
|
|
1178
|
+
target = _step18$value$.target;
|
|
1179
|
+
var _modulesDir = kind === "public" ? "".concat(root, "/node_modules") : "".concat(virtualStore, "/node_modules");
|
|
1180
|
+
var path = "".concat(_modulesDir, "/").concat(_alias5);
|
|
1181
|
+
if (!links.has(path)) {
|
|
1182
|
+
links.set(path, "dir" in target ? target.dir : packageDir(target.snapshot));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
} catch (err) {
|
|
1186
|
+
_iterator18.e(err);
|
|
1187
|
+
} finally {
|
|
1188
|
+
_iterator18.f();
|
|
1189
|
+
}
|
|
1190
|
+
return {
|
|
1191
|
+
root: root,
|
|
1192
|
+
virtualStore: virtualStore,
|
|
1193
|
+
links: links,
|
|
1194
|
+
packages: packages,
|
|
1195
|
+
importers: importers,
|
|
1196
|
+
skipped: skipped
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Files in memory, with directory symlinks: enough of a disk for
|
|
1202
|
+
* TypeScript's module resolution to see `node_modules` as pnpm leaves it.
|
|
1203
|
+
*
|
|
1204
|
+
* Files are written at their real paths. A link maps a path to the directory
|
|
1205
|
+
* it points at, and every read goes through `realpath` first, so
|
|
1206
|
+
* `/project/node_modules/react/index.d.ts` reads the file written at
|
|
1207
|
+
* `/project/node_modules/.pnpm/react@19.3.0/node_modules/react/index.d.ts`.
|
|
1208
|
+
*
|
|
1209
|
+
* The directory index is what makes resolution work, and it needs two things
|
|
1210
|
+
* a list of files does not give: every directory a file is in (TypeScript
|
|
1211
|
+
* asks `directoryExists` before it looks inside), and every linked directory
|
|
1212
|
+
* -- a link's own name is listed in its parent, and the directory it points
|
|
1213
|
+
* at exists even before anything has been written into it. Without the
|
|
1214
|
+
* first, packages are reported missing; without the second, so are packages
|
|
1215
|
+
* whose files have not been fetched, and `node_modules/@types` cannot be
|
|
1216
|
+
* listed.
|
|
1217
|
+
*
|
|
1218
|
+
* Every lookup of a path is also reported to `onLookup`, with the real path
|
|
1219
|
+
* it resolved to, so that a caller can tell which packages TypeScript went
|
|
1220
|
+
* looking in.
|
|
1221
|
+
*/
|
|
1222
|
+
var LinkedFileSystem = /*#__PURE__*/function () {
|
|
1223
|
+
function LinkedFileSystem(links) {
|
|
1224
|
+
slicedToArray._classCallCheck(this, LinkedFileSystem);
|
|
1225
|
+
createForOfIteratorHelper._defineProperty(this, "files", new Map());
|
|
1226
|
+
/** Real directory → the names of its entries, files and directories (links included). */
|
|
1227
|
+
createForOfIteratorHelper._defineProperty(this, "directories", new Map());
|
|
1228
|
+
createForOfIteratorHelper._defineProperty(this, "links", void 0);
|
|
1229
|
+
/** The links never change, so neither does a path's real path. */
|
|
1230
|
+
createForOfIteratorHelper._defineProperty(this, "realpaths", new Map());
|
|
1231
|
+
createForOfIteratorHelper._defineProperty(this, "onLookup", null);
|
|
1232
|
+
this.links = links;
|
|
1233
|
+
this.addDirectory("/");
|
|
1234
|
+
var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(links),
|
|
1235
|
+
_step;
|
|
1236
|
+
try {
|
|
1237
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1238
|
+
var _step$value = slicedToArray._slicedToArray(_step.value, 2),
|
|
1239
|
+
link = _step$value[0],
|
|
1240
|
+
target = _step$value[1];
|
|
1241
|
+
this.addDirectory(target);
|
|
1242
|
+
this.addEntry(link, "directory");
|
|
1243
|
+
}
|
|
1244
|
+
} catch (err) {
|
|
1245
|
+
_iterator.e(err);
|
|
1246
|
+
} finally {
|
|
1247
|
+
_iterator.f();
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return slicedToArray._createClass(LinkedFileSystem, [{
|
|
1251
|
+
key: "entriesOf",
|
|
1252
|
+
value: function entriesOf(realDir) {
|
|
1253
|
+
var entries = this.directories.get(realDir);
|
|
1254
|
+
if (!entries) {
|
|
1255
|
+
entries = {
|
|
1256
|
+
files: new Set(),
|
|
1257
|
+
directories: new Set()
|
|
1258
|
+
};
|
|
1259
|
+
this.directories.set(realDir, entries);
|
|
1260
|
+
}
|
|
1261
|
+
return entries;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/** `dir` and every directory above it. */
|
|
1265
|
+
}, {
|
|
1266
|
+
key: "addDirectory",
|
|
1267
|
+
value: function addDirectory(dir) {
|
|
1268
|
+
for (var at = dir;; at = parentOf(at)) {
|
|
1269
|
+
var known = this.directories.has(at);
|
|
1270
|
+
this.entriesOf(at);
|
|
1271
|
+
if (at === "/") return;
|
|
1272
|
+
this.entriesOf(parentOf(at)).directories.add(baseName(at));
|
|
1273
|
+
if (known) return;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/** Lists `path` in its parent; the parent's real path, as `path` may sit under a link. */
|
|
1278
|
+
}, {
|
|
1279
|
+
key: "addEntry",
|
|
1280
|
+
value: function addEntry(path, kind) {
|
|
1281
|
+
var parent = this.realpath(parentOf(path));
|
|
1282
|
+
this.addDirectory(parent);
|
|
1283
|
+
var entries = this.entriesOf(parent);
|
|
1284
|
+
if (kind === "file") entries.files.add(baseName(path));else entries.directories.add(baseName(path));
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
/** Resolves every link along `path`, as `fs.realpathSync` does. */
|
|
1288
|
+
}, {
|
|
1289
|
+
key: "realpath",
|
|
1290
|
+
value: function realpath(path) {
|
|
1291
|
+
var known = this.realpaths.get(path);
|
|
1292
|
+
if (known !== undefined) return known;
|
|
1293
|
+
var real = this.resolveLinks(path);
|
|
1294
|
+
this.realpaths.set(path, real);
|
|
1295
|
+
return real;
|
|
1296
|
+
}
|
|
1297
|
+
}, {
|
|
1298
|
+
key: "resolveLinks",
|
|
1299
|
+
value: function resolveLinks(path) {
|
|
1300
|
+
var current = normalizePath(path);
|
|
1301
|
+
for (var hops = 0; hops < 40; hops++) {
|
|
1302
|
+
var segments = current.split("/").slice(1);
|
|
1303
|
+
var resolved = null;
|
|
1304
|
+
for (var i = segments.length; i > 0; i--) {
|
|
1305
|
+
var prefix = "/".concat(segments.slice(0, i).join("/"));
|
|
1306
|
+
var target = this.links.get(prefix);
|
|
1307
|
+
if (target !== undefined) {
|
|
1308
|
+
var rest = segments.slice(i).join("/");
|
|
1309
|
+
resolved = rest === "" ? target : "".concat(target, "/").concat(rest);
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
if (resolved === null) return current;
|
|
1314
|
+
current = resolved;
|
|
1315
|
+
}
|
|
1316
|
+
return current;
|
|
1317
|
+
}
|
|
1318
|
+
}, {
|
|
1319
|
+
key: "writeFile",
|
|
1320
|
+
value: function writeFile(realPath, text) {
|
|
1321
|
+
var path = normalizePath(realPath);
|
|
1322
|
+
this.files.set(path, text);
|
|
1323
|
+
this.addEntry(path, "file");
|
|
1324
|
+
}
|
|
1325
|
+
}, {
|
|
1326
|
+
key: "lookup",
|
|
1327
|
+
value: function lookup(path) {
|
|
1328
|
+
var _this$onLookup;
|
|
1329
|
+
var real = this.realpath(path);
|
|
1330
|
+
(_this$onLookup = this.onLookup) === null || _this$onLookup === void 0 || _this$onLookup.call(this, real);
|
|
1331
|
+
return real;
|
|
1332
|
+
}
|
|
1333
|
+
}, {
|
|
1334
|
+
key: "readFile",
|
|
1335
|
+
value: function readFile(path) {
|
|
1336
|
+
return this.files.get(this.lookup(path));
|
|
1337
|
+
}
|
|
1338
|
+
}, {
|
|
1339
|
+
key: "fileExists",
|
|
1340
|
+
value: function fileExists(path) {
|
|
1341
|
+
return this.files.has(this.lookup(path));
|
|
1342
|
+
}
|
|
1343
|
+
}, {
|
|
1344
|
+
key: "directoryExists",
|
|
1345
|
+
value: function directoryExists(path) {
|
|
1346
|
+
return this.directories.has(this.lookup(path));
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/** The directories in `path`, links to directories included. */
|
|
1350
|
+
}, {
|
|
1351
|
+
key: "getDirectories",
|
|
1352
|
+
value: function getDirectories(path) {
|
|
1353
|
+
var entries = this.directories.get(this.lookup(path));
|
|
1354
|
+
return entries ? slicedToArray._toConsumableArray(entries.directories).sort() : [];
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** The files in `path`. */
|
|
1358
|
+
}, {
|
|
1359
|
+
key: "getFiles",
|
|
1360
|
+
value: function getFiles(path) {
|
|
1361
|
+
var entries = this.directories.get(this.lookup(path));
|
|
1362
|
+
return entries ? slicedToArray._toConsumableArray(entries.files).sort() : [];
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/** Every file written, by real path. */
|
|
1366
|
+
}, {
|
|
1367
|
+
key: "allFiles",
|
|
1368
|
+
value: function allFiles() {
|
|
1369
|
+
return this.files.keys();
|
|
1370
|
+
}
|
|
1371
|
+
}]);
|
|
1372
|
+
}();
|
|
1373
|
+
function parentOf(path) {
|
|
1374
|
+
var slash = path.lastIndexOf("/");
|
|
1375
|
+
return slash <= 0 ? "/" : path.slice(0, slash);
|
|
1376
|
+
}
|
|
1377
|
+
function baseName(path) {
|
|
1378
|
+
return path.slice(path.lastIndexOf("/") + 1);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* adept's `/types/<partition>/<name>@<version>`: a package version's
|
|
1383
|
+
* declaration files and every `package.json`, by path relative to the
|
|
1384
|
+
* package's root, and the names of its JavaScript files.
|
|
1385
|
+
*/
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Where bundles and compilers come from. In the Studio that is adept,
|
|
1389
|
+
* through the Studio's server (`adeptSources.ts`); tests and Node scripts
|
|
1390
|
+
* give their own.
|
|
1391
|
+
*/
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* A failed request for a bundle or a compiler, by what can be done about it.
|
|
1395
|
+
* `status` 401 means signed out, and stops the whole check: every other
|
|
1396
|
+
* request would fail the same way.
|
|
1397
|
+
*/
|
|
1398
|
+
var SourceError = /*#__PURE__*/function (_Error) {
|
|
1399
|
+
function SourceError(message, code, retryable) {
|
|
1400
|
+
var _this;
|
|
1401
|
+
var status = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
1402
|
+
slicedToArray._classCallCheck(this, SourceError);
|
|
1403
|
+
_this = slicedToArray._callSuper(this, SourceError, [message]);
|
|
1404
|
+
_this.code = code;
|
|
1405
|
+
_this.retryable = retryable;
|
|
1406
|
+
_this.status = status;
|
|
1407
|
+
return _this;
|
|
1408
|
+
}
|
|
1409
|
+
slicedToArray._inherits(SourceError, _Error);
|
|
1410
|
+
return slicedToArray._createClass(SourceError);
|
|
1411
|
+
}(/*#__PURE__*/slicedToArray._wrapNativeSuper(Error));
|
|
1412
|
+
|
|
1413
|
+
/** A package whose types could not be had, so the check that follows is incomplete. */
|
|
1414
|
+
|
|
1415
|
+
var DECLARATION = /\.d\.[mc]?ts$/;
|
|
1416
|
+
|
|
1417
|
+
/**
|
|
1418
|
+
* The package a bare specifier names: `react` of `react/jsx-runtime`,
|
|
1419
|
+
* `@tanstack/react-router` of itself. `null` for anything that is not looked
|
|
1420
|
+
* up in `node_modules`: relative and absolute paths, `#subpath` imports and
|
|
1421
|
+
* `node:` and other schemes.
|
|
1422
|
+
*/
|
|
1423
|
+
function packageNameOf(specifier) {
|
|
1424
|
+
if (specifier === "" || specifier.startsWith(".") || specifier.startsWith("/") || specifier.startsWith("#") || /^[A-Za-z][A-Za-z0-9+.-]*:/.test(specifier)) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
var parts = specifier.split("/");
|
|
1428
|
+
if (specifier.startsWith("@")) {
|
|
1429
|
+
return parts[0].length > 1 && parts[1] ? "".concat(parts[0], "/").concat(parts[1]) : null;
|
|
1430
|
+
}
|
|
1431
|
+
return parts[0];
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
/** `@types/node` for `node`, `@types/scope__name` for `@scope/name`. */
|
|
1435
|
+
function typesPackageOf(name) {
|
|
1436
|
+
return "@types/".concat(name.startsWith("@") ? name.slice(1).replace("/", "__") : name);
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
/** The package directory a real path is in: up to the name after its last `node_modules`. */
|
|
1440
|
+
function packageDirOf(realPath) {
|
|
1441
|
+
var at = realPath.lastIndexOf("/node_modules/");
|
|
1442
|
+
if (at < 0) return null;
|
|
1443
|
+
var rest = realPath.slice(at + "/node_modules/".length).split("/");
|
|
1444
|
+
var name = rest[0].startsWith("@") ? rest.slice(0, 2).join("/") : rest[0];
|
|
1445
|
+
if (name === "" || name.startsWith(".") || name.startsWith("@") && !name.includes("/")) {
|
|
1446
|
+
return null;
|
|
1447
|
+
}
|
|
1448
|
+
return "".concat(realPath.slice(0, at), "/node_modules/").concat(name);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
/** A bundle path that stays inside its package. */
|
|
1452
|
+
function isSafeRelative(path) {
|
|
1453
|
+
return path !== "" && !path.startsWith("/") && !path.split("/").some(function (segment) {
|
|
1454
|
+
return segment === ".." || segment === "";
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* Fetches the types a project's imports reach, and only those, and writes
|
|
1460
|
+
* each bundle at its snapshot's directory in the virtual store, so that the
|
|
1461
|
+
* layout's links make it visible wherever pnpm would.
|
|
1462
|
+
*
|
|
1463
|
+
* {@link wantImportsOf} scans a file's imports and type references; each
|
|
1464
|
+
* bare one is looked for as Node looks for it, from the file's directory up
|
|
1465
|
+
* through each `node_modules` (and its `@types` twin), and the nearest level
|
|
1466
|
+
* that has it is fetched. A fetched bundle's declaration files are scanned in
|
|
1467
|
+
* turn, so type dependencies are followed transitively. {@link wantPackage}
|
|
1468
|
+
* fetches a package by directory, for when TypeScript itself went looking in
|
|
1469
|
+
* one.
|
|
1470
|
+
*/
|
|
1471
|
+
var TypeAcquisition = /*#__PURE__*/function () {
|
|
1472
|
+
function TypeAcquisition(ts, fs, layout, sources) {
|
|
1473
|
+
var concurrency = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 8;
|
|
1474
|
+
slicedToArray._classCallCheck(this, TypeAcquisition);
|
|
1475
|
+
createForOfIteratorHelper._defineProperty(this, "started", new Set());
|
|
1476
|
+
createForOfIteratorHelper._defineProperty(this, "running", new Set());
|
|
1477
|
+
createForOfIteratorHelper._defineProperty(this, "queue", []);
|
|
1478
|
+
createForOfIteratorHelper._defineProperty(this, "fatal", null);
|
|
1479
|
+
createForOfIteratorHelper._defineProperty(this, "missing", []);
|
|
1480
|
+
createForOfIteratorHelper._defineProperty(this, "stats", {
|
|
1481
|
+
scanned: 0,
|
|
1482
|
+
resolved: 0,
|
|
1483
|
+
files: 0,
|
|
1484
|
+
stubs: 0,
|
|
1485
|
+
bytes: 0
|
|
1486
|
+
});
|
|
1487
|
+
this.ts = ts;
|
|
1488
|
+
this.fs = fs;
|
|
1489
|
+
this.layout = layout;
|
|
1490
|
+
this.sources = sources;
|
|
1491
|
+
this.concurrency = concurrency;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
/** Whether `dir` is a package this has fetched, or tried to. */
|
|
1495
|
+
return slicedToArray._createClass(TypeAcquisition, [{
|
|
1496
|
+
key: "has",
|
|
1497
|
+
value: function has(dir) {
|
|
1498
|
+
return this.started.has(dir);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
/** The installed package at a real directory, if it is one. */
|
|
1502
|
+
}, {
|
|
1503
|
+
key: "packageAt",
|
|
1504
|
+
value: function packageAt(dir) {
|
|
1505
|
+
return this.layout.packages.get(dir);
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* The packages a bare name reaches from `fromDir`: at the nearest
|
|
1510
|
+
* `node_modules` that has the package or its `@types`, both.
|
|
1511
|
+
*/
|
|
1512
|
+
}, {
|
|
1513
|
+
key: "findPackages",
|
|
1514
|
+
value: function findPackages(fromDir, name) {
|
|
1515
|
+
var _this2 = this;
|
|
1516
|
+
var typesName = typesPackageOf(name);
|
|
1517
|
+
var _loop = function _loop() {
|
|
1518
|
+
var modules = at === "/" ? "/node_modules" : "".concat(at, "/node_modules");
|
|
1519
|
+
var found = [name, typesName].flatMap(function (candidate) {
|
|
1520
|
+
var real = _this2.fs.realpath("".concat(modules, "/").concat(candidate));
|
|
1521
|
+
return _this2.layout.packages.has(real) ? [real] : [];
|
|
1522
|
+
});
|
|
1523
|
+
if (found.length > 0) return {
|
|
1524
|
+
v: found
|
|
1525
|
+
};
|
|
1526
|
+
if (at === "/") return {
|
|
1527
|
+
v: []
|
|
1528
|
+
};
|
|
1529
|
+
},
|
|
1530
|
+
_ret;
|
|
1531
|
+
for (var at = fromDir;; at = parentOf(at)) {
|
|
1532
|
+
_ret = _loop();
|
|
1533
|
+
if (_ret) return _ret.v;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
/** Wants what a bare specifier names, from a file in `fromDir`. */
|
|
1538
|
+
}, {
|
|
1539
|
+
key: "wantSpecifier",
|
|
1540
|
+
value: function wantSpecifier(fromDir, specifier) {
|
|
1541
|
+
var name = packageNameOf(specifier);
|
|
1542
|
+
if (name === null) return;
|
|
1543
|
+
var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(this.findPackages(fromDir, name)),
|
|
1544
|
+
_step;
|
|
1545
|
+
try {
|
|
1546
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1547
|
+
var dir = _step.value;
|
|
1548
|
+
this.wantPackage(dir, "scanned");
|
|
1549
|
+
}
|
|
1550
|
+
} catch (err) {
|
|
1551
|
+
_iterator.e(err);
|
|
1552
|
+
} finally {
|
|
1553
|
+
_iterator.f();
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
/** Wants every package a file's imports and type references reach. */
|
|
1558
|
+
}, {
|
|
1559
|
+
key: "wantImportsOf",
|
|
1560
|
+
value: function wantImportsOf(realPath, text) {
|
|
1561
|
+
var info = this.ts.preProcessFile(text, true, true);
|
|
1562
|
+
var dir = parentOf(realPath);
|
|
1563
|
+
var _iterator2 = createForOfIteratorHelper._createForOfIteratorHelper(info.importedFiles),
|
|
1564
|
+
_step2;
|
|
1565
|
+
try {
|
|
1566
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1567
|
+
var imported = _step2.value;
|
|
1568
|
+
this.wantSpecifier(dir, imported.fileName);
|
|
1569
|
+
}
|
|
1570
|
+
} catch (err) {
|
|
1571
|
+
_iterator2.e(err);
|
|
1572
|
+
} finally {
|
|
1573
|
+
_iterator2.f();
|
|
1574
|
+
}
|
|
1575
|
+
var _iterator3 = createForOfIteratorHelper._createForOfIteratorHelper(info.typeReferenceDirectives),
|
|
1576
|
+
_step3;
|
|
1577
|
+
try {
|
|
1578
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1579
|
+
var reference = _step3.value;
|
|
1580
|
+
this.wantSpecifier(dir, reference.fileName);
|
|
1581
|
+
}
|
|
1582
|
+
} catch (err) {
|
|
1583
|
+
_iterator3.e(err);
|
|
1584
|
+
} finally {
|
|
1585
|
+
_iterator3.f();
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
}, {
|
|
1589
|
+
key: "wantPackage",
|
|
1590
|
+
value: function wantPackage(dir, via) {
|
|
1591
|
+
if (this.started.has(dir) || !this.layout.packages.has(dir)) return;
|
|
1592
|
+
this.started.add(dir);
|
|
1593
|
+
this.queue.push({
|
|
1594
|
+
dir: dir,
|
|
1595
|
+
via: via
|
|
1596
|
+
});
|
|
1597
|
+
this.pump();
|
|
1598
|
+
}
|
|
1599
|
+
}, {
|
|
1600
|
+
key: "pump",
|
|
1601
|
+
value: function pump() {
|
|
1602
|
+
var _this3 = this;
|
|
1603
|
+
var _loop2 = function _loop2() {
|
|
1604
|
+
var next = _this3.queue.shift();
|
|
1605
|
+
var task = _this3.fetch(next.dir, next.via)["finally"](function () {
|
|
1606
|
+
_this3.running["delete"](task);
|
|
1607
|
+
_this3.pump();
|
|
1608
|
+
});
|
|
1609
|
+
_this3.running.add(task);
|
|
1610
|
+
};
|
|
1611
|
+
while (this.running.size < this.concurrency && this.queue.length > 0) {
|
|
1612
|
+
_loop2();
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
/** Resolves when everything wanted so far, and everything that wanted, is fetched. */
|
|
1617
|
+
}, {
|
|
1618
|
+
key: "settle",
|
|
1619
|
+
value: (function () {
|
|
1620
|
+
var _settle = slicedToArray._asyncToGenerator(/*#__PURE__*/slicedToArray._regenerator().m(function _callee() {
|
|
1621
|
+
return slicedToArray._regenerator().w(function (_context) {
|
|
1622
|
+
while (1) switch (_context.n) {
|
|
1623
|
+
case 0:
|
|
1624
|
+
if (!(this.running.size > 0)) {
|
|
1625
|
+
_context.n = 3;
|
|
1626
|
+
break;
|
|
1627
|
+
}
|
|
1628
|
+
_context.n = 1;
|
|
1629
|
+
return Promise.race(this.running);
|
|
1630
|
+
case 1:
|
|
1631
|
+
if (!(this.fatal !== null)) {
|
|
1632
|
+
_context.n = 2;
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
throw this.fatal;
|
|
1636
|
+
case 2:
|
|
1637
|
+
_context.n = 0;
|
|
1638
|
+
break;
|
|
1639
|
+
case 3:
|
|
1640
|
+
if (!(this.fatal !== null)) {
|
|
1641
|
+
_context.n = 4;
|
|
1642
|
+
break;
|
|
1643
|
+
}
|
|
1644
|
+
throw this.fatal;
|
|
1645
|
+
case 4:
|
|
1646
|
+
return _context.a(2);
|
|
1647
|
+
}
|
|
1648
|
+
}, _callee, this);
|
|
1649
|
+
}));
|
|
1650
|
+
function settle() {
|
|
1651
|
+
return _settle.apply(this, arguments);
|
|
1652
|
+
}
|
|
1653
|
+
return settle;
|
|
1654
|
+
}())
|
|
1655
|
+
}, {
|
|
1656
|
+
key: "fetch",
|
|
1657
|
+
value: function () {
|
|
1658
|
+
var _fetch = slicedToArray._asyncToGenerator(/*#__PURE__*/slicedToArray._regenerator().m(function _callee2(dir, via) {
|
|
1659
|
+
var pkg, ref, bundle, attempt, _retryable, _i, _Object$entries, _Object$entries$_i, path, text, _iterator4, _step4, stub, _i2, _Object$entries2, _Object$entries2$_i, _path, _text, _t, _t2;
|
|
1660
|
+
return slicedToArray._regenerator().w(function (_context2) {
|
|
1661
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
1662
|
+
case 0:
|
|
1663
|
+
pkg = this.layout.packages.get(dir);
|
|
1664
|
+
ref = {
|
|
1665
|
+
name: pkg.name,
|
|
1666
|
+
version: pkg.version,
|
|
1667
|
+
integrity: pkg.integrity
|
|
1668
|
+
};
|
|
1669
|
+
if (pkg.fromRegistry) {
|
|
1670
|
+
_context2.n = 1;
|
|
1671
|
+
break;
|
|
1672
|
+
}
|
|
1673
|
+
this.missing.push(createForOfIteratorHelper._objectSpread2(createForOfIteratorHelper._objectSpread2({}, ref), {}, {
|
|
1674
|
+
code: "not-from-registry",
|
|
1675
|
+
message: "".concat(pkg.name, " is not installed from a registry by version, so its types cannot be fetched."),
|
|
1676
|
+
retryable: false
|
|
1677
|
+
}));
|
|
1678
|
+
return _context2.a(2);
|
|
1679
|
+
case 1:
|
|
1680
|
+
bundle = null;
|
|
1681
|
+
attempt = 0;
|
|
1682
|
+
case 2:
|
|
1683
|
+
if (!(attempt < 2 && bundle === null)) {
|
|
1684
|
+
_context2.n = 9;
|
|
1685
|
+
break;
|
|
1686
|
+
}
|
|
1687
|
+
_context2.p = 3;
|
|
1688
|
+
_context2.n = 4;
|
|
1689
|
+
return this.sources.types(ref);
|
|
1690
|
+
case 4:
|
|
1691
|
+
bundle = _context2.v;
|
|
1692
|
+
_context2.n = 8;
|
|
1693
|
+
break;
|
|
1694
|
+
case 5:
|
|
1695
|
+
_context2.p = 5;
|
|
1696
|
+
_t = _context2.v;
|
|
1697
|
+
if (!(_t instanceof SourceError && _t.status === 401)) {
|
|
1698
|
+
_context2.n = 6;
|
|
1699
|
+
break;
|
|
1700
|
+
}
|
|
1701
|
+
this.fatal = _t;
|
|
1702
|
+
return _context2.a(2);
|
|
1703
|
+
case 6:
|
|
1704
|
+
_retryable = _t instanceof SourceError ? _t.retryable : true;
|
|
1705
|
+
if (!(_retryable && attempt === 0)) {
|
|
1706
|
+
_context2.n = 7;
|
|
1707
|
+
break;
|
|
1708
|
+
}
|
|
1709
|
+
return _context2.a(3, 8);
|
|
1710
|
+
case 7:
|
|
1711
|
+
this.missing.push(createForOfIteratorHelper._objectSpread2(createForOfIteratorHelper._objectSpread2({}, ref), {}, {
|
|
1712
|
+
code: _t instanceof SourceError ? _t.code : "network",
|
|
1713
|
+
message: _t instanceof Error ? _t.message : String(_t),
|
|
1714
|
+
retryable: _retryable
|
|
1715
|
+
}));
|
|
1716
|
+
return _context2.a(2);
|
|
1717
|
+
case 8:
|
|
1718
|
+
attempt++;
|
|
1719
|
+
_context2.n = 2;
|
|
1720
|
+
break;
|
|
1721
|
+
case 9:
|
|
1722
|
+
if (!(bundle === null)) {
|
|
1723
|
+
_context2.n = 10;
|
|
1724
|
+
break;
|
|
1725
|
+
}
|
|
1726
|
+
return _context2.a(2);
|
|
1727
|
+
case 10:
|
|
1728
|
+
this.stats[via]++;
|
|
1729
|
+
_i = 0, _Object$entries = Object.entries(bundle.files);
|
|
1730
|
+
case 11:
|
|
1731
|
+
if (!(_i < _Object$entries.length)) {
|
|
1732
|
+
_context2.n = 14;
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
_Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2), path = _Object$entries$_i[0], text = _Object$entries$_i[1];
|
|
1736
|
+
if (isSafeRelative(path)) {
|
|
1737
|
+
_context2.n = 12;
|
|
1738
|
+
break;
|
|
1739
|
+
}
|
|
1740
|
+
return _context2.a(3, 13);
|
|
1741
|
+
case 12:
|
|
1742
|
+
this.fs.writeFile("".concat(dir, "/").concat(path), text);
|
|
1743
|
+
this.stats.files++;
|
|
1744
|
+
this.stats.bytes += text.length;
|
|
1745
|
+
case 13:
|
|
1746
|
+
_i++;
|
|
1747
|
+
_context2.n = 11;
|
|
1748
|
+
break;
|
|
1749
|
+
case 14:
|
|
1750
|
+
_iterator4 = createForOfIteratorHelper._createForOfIteratorHelper(bundle.stubs);
|
|
1751
|
+
_context2.p = 15;
|
|
1752
|
+
_iterator4.s();
|
|
1753
|
+
case 16:
|
|
1754
|
+
if ((_step4 = _iterator4.n()).done) {
|
|
1755
|
+
_context2.n = 19;
|
|
1756
|
+
break;
|
|
1757
|
+
}
|
|
1758
|
+
stub = _step4.value;
|
|
1759
|
+
if (isSafeRelative(stub)) {
|
|
1760
|
+
_context2.n = 17;
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
return _context2.a(3, 18);
|
|
1764
|
+
case 17:
|
|
1765
|
+
if (!Object.prototype.hasOwnProperty.call(bundle.files, stub)) {
|
|
1766
|
+
this.fs.writeFile("".concat(dir, "/").concat(stub), "");
|
|
1767
|
+
this.stats.stubs++;
|
|
1768
|
+
}
|
|
1769
|
+
case 18:
|
|
1770
|
+
_context2.n = 16;
|
|
1771
|
+
break;
|
|
1772
|
+
case 19:
|
|
1773
|
+
_context2.n = 21;
|
|
1774
|
+
break;
|
|
1775
|
+
case 20:
|
|
1776
|
+
_context2.p = 20;
|
|
1777
|
+
_t2 = _context2.v;
|
|
1778
|
+
_iterator4.e(_t2);
|
|
1779
|
+
case 21:
|
|
1780
|
+
_context2.p = 21;
|
|
1781
|
+
_iterator4.f();
|
|
1782
|
+
return _context2.f(21);
|
|
1783
|
+
case 22:
|
|
1784
|
+
for (_i2 = 0, _Object$entries2 = Object.entries(bundle.files); _i2 < _Object$entries2.length; _i2++) {
|
|
1785
|
+
_Object$entries2$_i = slicedToArray._slicedToArray(_Object$entries2[_i2], 2), _path = _Object$entries2$_i[0], _text = _Object$entries2$_i[1];
|
|
1786
|
+
if (DECLARATION.test(_path) && isSafeRelative(_path)) {
|
|
1787
|
+
this.wantImportsOf("".concat(dir, "/").concat(_path), _text);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
case 23:
|
|
1791
|
+
return _context2.a(2);
|
|
1792
|
+
}
|
|
1793
|
+
}, _callee2, this, [[15, 20, 21, 22], [3, 5]]);
|
|
1794
|
+
}));
|
|
1795
|
+
function fetch(_x, _x2) {
|
|
1796
|
+
return _fetch.apply(this, arguments);
|
|
1797
|
+
}
|
|
1798
|
+
return fetch;
|
|
1799
|
+
}()
|
|
1800
|
+
}]);
|
|
1801
|
+
}();
|
|
1802
|
+
|
|
1803
|
+
exports.LinkedFileSystem = LinkedFileSystem;
|
|
1804
|
+
exports.LockfileError = LockfileError;
|
|
1805
|
+
exports.SourceError = SourceError;
|
|
1806
|
+
exports.TypeAcquisition = TypeAcquisition;
|
|
1807
|
+
exports.UnsupportedLayoutError = UnsupportedLayoutError;
|
|
1808
|
+
exports.computePnpmLayout = computePnpmLayout;
|
|
1809
|
+
exports.layoutOptionsOfWorkspace = layoutOptionsOfWorkspace;
|
|
1810
|
+
exports.normalizePath = normalizePath;
|
|
1811
|
+
exports.packageDirOf = packageDirOf;
|
|
1812
|
+
exports.packageNameOf = packageNameOf;
|
|
1813
|
+
exports.parentOf = parentOf;
|
|
1814
|
+
exports.parsePnpmLockfile = parsePnpmLockfile;
|
|
1815
|
+
exports.typesPackageOf = typesPackageOf;
|