shopify-preconnect 1.0.14 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/shopify-connect.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.pnp.cjs +30584 -0
- package/.pnp.loader.mjs +2042 -0
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/preconnect.min.js +1 -0
- package/dist/with-delay.min.js +1 -0
- package/package.json +72 -6
- package/index.min.js +0 -1
package/.pnp.loader.mjs
ADDED
@@ -0,0 +1,2042 @@
|
|
1
|
+
import { URL as URL$1, fileURLToPath, pathToFileURL } from 'url';
|
2
|
+
import fs from 'fs';
|
3
|
+
import path from 'path';
|
4
|
+
import moduleExports, { Module } from 'module';
|
5
|
+
import { EOL } from 'os';
|
6
|
+
import assert from 'assert';
|
7
|
+
|
8
|
+
const SAFE_TIME = 456789e3;
|
9
|
+
|
10
|
+
const PortablePath = {
|
11
|
+
root: `/`,
|
12
|
+
dot: `.`,
|
13
|
+
parent: `..`
|
14
|
+
};
|
15
|
+
const npath = Object.create(path);
|
16
|
+
const ppath = Object.create(path.posix);
|
17
|
+
npath.cwd = () => process.cwd();
|
18
|
+
ppath.cwd = () => toPortablePath(process.cwd());
|
19
|
+
ppath.resolve = (...segments) => {
|
20
|
+
if (segments.length > 0 && ppath.isAbsolute(segments[0])) {
|
21
|
+
return path.posix.resolve(...segments);
|
22
|
+
} else {
|
23
|
+
return path.posix.resolve(ppath.cwd(), ...segments);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
const contains = function(pathUtils, from, to) {
|
27
|
+
from = pathUtils.normalize(from);
|
28
|
+
to = pathUtils.normalize(to);
|
29
|
+
if (from === to)
|
30
|
+
return `.`;
|
31
|
+
if (!from.endsWith(pathUtils.sep))
|
32
|
+
from = from + pathUtils.sep;
|
33
|
+
if (to.startsWith(from)) {
|
34
|
+
return to.slice(from.length);
|
35
|
+
} else {
|
36
|
+
return null;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
npath.fromPortablePath = fromPortablePath;
|
40
|
+
npath.toPortablePath = toPortablePath;
|
41
|
+
npath.contains = (from, to) => contains(npath, from, to);
|
42
|
+
ppath.contains = (from, to) => contains(ppath, from, to);
|
43
|
+
const WINDOWS_PATH_REGEXP = /^([a-zA-Z]:.*)$/;
|
44
|
+
const UNC_WINDOWS_PATH_REGEXP = /^\/\/(\.\/)?(.*)$/;
|
45
|
+
const PORTABLE_PATH_REGEXP = /^\/([a-zA-Z]:.*)$/;
|
46
|
+
const UNC_PORTABLE_PATH_REGEXP = /^\/unc\/(\.dot\/)?(.*)$/;
|
47
|
+
function fromPortablePath(p) {
|
48
|
+
if (process.platform !== `win32`)
|
49
|
+
return p;
|
50
|
+
let portablePathMatch, uncPortablePathMatch;
|
51
|
+
if (portablePathMatch = p.match(PORTABLE_PATH_REGEXP))
|
52
|
+
p = portablePathMatch[1];
|
53
|
+
else if (uncPortablePathMatch = p.match(UNC_PORTABLE_PATH_REGEXP))
|
54
|
+
p = `\\\\${uncPortablePathMatch[1] ? `.\\` : ``}${uncPortablePathMatch[2]}`;
|
55
|
+
else
|
56
|
+
return p;
|
57
|
+
return p.replace(/\//g, `\\`);
|
58
|
+
}
|
59
|
+
function toPortablePath(p) {
|
60
|
+
if (process.platform !== `win32`)
|
61
|
+
return p;
|
62
|
+
p = p.replace(/\\/g, `/`);
|
63
|
+
let windowsPathMatch, uncWindowsPathMatch;
|
64
|
+
if (windowsPathMatch = p.match(WINDOWS_PATH_REGEXP))
|
65
|
+
p = `/${windowsPathMatch[1]}`;
|
66
|
+
else if (uncWindowsPathMatch = p.match(UNC_WINDOWS_PATH_REGEXP))
|
67
|
+
p = `/unc/${uncWindowsPathMatch[1] ? `.dot/` : ``}${uncWindowsPathMatch[2]}`;
|
68
|
+
return p;
|
69
|
+
}
|
70
|
+
function convertPath(targetPathUtils, sourcePath) {
|
71
|
+
return targetPathUtils === npath ? fromPortablePath(sourcePath) : toPortablePath(sourcePath);
|
72
|
+
}
|
73
|
+
|
74
|
+
const defaultTime = new Date(SAFE_TIME * 1e3);
|
75
|
+
async function copyPromise(destinationFs, destination, sourceFs, source, opts) {
|
76
|
+
const normalizedDestination = destinationFs.pathUtils.normalize(destination);
|
77
|
+
const normalizedSource = sourceFs.pathUtils.normalize(source);
|
78
|
+
const prelayout = [];
|
79
|
+
const postlayout = [];
|
80
|
+
const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : await sourceFs.lstatPromise(normalizedSource);
|
81
|
+
await destinationFs.mkdirpPromise(destinationFs.pathUtils.dirname(destination), { utimes: [atime, mtime] });
|
82
|
+
const updateTime = typeof destinationFs.lutimesPromise === `function` ? destinationFs.lutimesPromise.bind(destinationFs) : destinationFs.utimesPromise.bind(destinationFs);
|
83
|
+
await copyImpl(prelayout, postlayout, updateTime, destinationFs, normalizedDestination, sourceFs, normalizedSource, { ...opts, didParentExist: true });
|
84
|
+
for (const operation of prelayout)
|
85
|
+
await operation();
|
86
|
+
await Promise.all(postlayout.map((operation) => {
|
87
|
+
return operation();
|
88
|
+
}));
|
89
|
+
}
|
90
|
+
async function copyImpl(prelayout, postlayout, updateTime, destinationFs, destination, sourceFs, source, opts) {
|
91
|
+
var _a, _b;
|
92
|
+
const destinationStat = opts.didParentExist ? await maybeLStat(destinationFs, destination) : null;
|
93
|
+
const sourceStat = await sourceFs.lstatPromise(source);
|
94
|
+
const { atime, mtime } = opts.stableTime ? { atime: defaultTime, mtime: defaultTime } : sourceStat;
|
95
|
+
let updated;
|
96
|
+
switch (true) {
|
97
|
+
case sourceStat.isDirectory():
|
98
|
+
{
|
99
|
+
updated = await copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
|
100
|
+
}
|
101
|
+
break;
|
102
|
+
case sourceStat.isFile():
|
103
|
+
{
|
104
|
+
updated = await copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
|
105
|
+
}
|
106
|
+
break;
|
107
|
+
case sourceStat.isSymbolicLink():
|
108
|
+
{
|
109
|
+
updated = await copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts);
|
110
|
+
}
|
111
|
+
break;
|
112
|
+
default:
|
113
|
+
{
|
114
|
+
throw new Error(`Unsupported file type (${sourceStat.mode})`);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
if (updated || ((_a = destinationStat == null ? void 0 : destinationStat.mtime) == null ? void 0 : _a.getTime()) !== mtime.getTime() || ((_b = destinationStat == null ? void 0 : destinationStat.atime) == null ? void 0 : _b.getTime()) !== atime.getTime()) {
|
118
|
+
postlayout.push(() => updateTime(destination, atime, mtime));
|
119
|
+
updated = true;
|
120
|
+
}
|
121
|
+
if (destinationStat === null || (destinationStat.mode & 511) !== (sourceStat.mode & 511)) {
|
122
|
+
postlayout.push(() => destinationFs.chmodPromise(destination, sourceStat.mode & 511));
|
123
|
+
updated = true;
|
124
|
+
}
|
125
|
+
return updated;
|
126
|
+
}
|
127
|
+
async function maybeLStat(baseFs, p) {
|
128
|
+
try {
|
129
|
+
return await baseFs.lstatPromise(p);
|
130
|
+
} catch (e) {
|
131
|
+
return null;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
async function copyFolder(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
|
135
|
+
if (destinationStat !== null && !destinationStat.isDirectory()) {
|
136
|
+
if (opts.overwrite) {
|
137
|
+
prelayout.push(async () => destinationFs.removePromise(destination));
|
138
|
+
destinationStat = null;
|
139
|
+
} else {
|
140
|
+
return false;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
let updated = false;
|
144
|
+
if (destinationStat === null) {
|
145
|
+
prelayout.push(async () => {
|
146
|
+
try {
|
147
|
+
await destinationFs.mkdirPromise(destination, { mode: sourceStat.mode });
|
148
|
+
} catch (err) {
|
149
|
+
if (err.code !== `EEXIST`) {
|
150
|
+
throw err;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
});
|
154
|
+
updated = true;
|
155
|
+
}
|
156
|
+
const entries = await sourceFs.readdirPromise(source);
|
157
|
+
const nextOpts = opts.didParentExist && !destinationStat ? { ...opts, didParentExist: false } : opts;
|
158
|
+
if (opts.stableSort) {
|
159
|
+
for (const entry of entries.sort()) {
|
160
|
+
if (await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts)) {
|
161
|
+
updated = true;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
} else {
|
165
|
+
const entriesUpdateStatus = await Promise.all(entries.map(async (entry) => {
|
166
|
+
await copyImpl(prelayout, postlayout, updateTime, destinationFs, destinationFs.pathUtils.join(destination, entry), sourceFs, sourceFs.pathUtils.join(source, entry), nextOpts);
|
167
|
+
}));
|
168
|
+
if (entriesUpdateStatus.some((status) => status)) {
|
169
|
+
updated = true;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return updated;
|
173
|
+
}
|
174
|
+
const isCloneSupportedCache = /* @__PURE__ */ new WeakMap();
|
175
|
+
function makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy) {
|
176
|
+
return async () => {
|
177
|
+
await opFs.linkPromise(source, destination);
|
178
|
+
if (linkStrategy === "readOnly" /* ReadOnly */) {
|
179
|
+
sourceStat.mode &= ~146;
|
180
|
+
await opFs.chmodPromise(destination, sourceStat.mode);
|
181
|
+
}
|
182
|
+
};
|
183
|
+
}
|
184
|
+
function makeCloneLinkOperation(opFs, destination, source, sourceStat, linkStrategy) {
|
185
|
+
const isCloneSupported = isCloneSupportedCache.get(opFs);
|
186
|
+
if (typeof isCloneSupported === `undefined`) {
|
187
|
+
return async () => {
|
188
|
+
try {
|
189
|
+
await opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE);
|
190
|
+
isCloneSupportedCache.set(opFs, true);
|
191
|
+
} catch (err) {
|
192
|
+
if (err.code === `ENOSYS` || err.code === `ENOTSUP`) {
|
193
|
+
isCloneSupportedCache.set(opFs, false);
|
194
|
+
await makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy)();
|
195
|
+
} else {
|
196
|
+
throw err;
|
197
|
+
}
|
198
|
+
}
|
199
|
+
};
|
200
|
+
} else {
|
201
|
+
if (isCloneSupported) {
|
202
|
+
return async () => opFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE_FORCE);
|
203
|
+
} else {
|
204
|
+
return makeLinkOperation(opFs, destination, source, sourceStat, linkStrategy);
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
async function copyFile(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
|
209
|
+
var _a;
|
210
|
+
if (destinationStat !== null) {
|
211
|
+
if (opts.overwrite) {
|
212
|
+
prelayout.push(async () => destinationFs.removePromise(destination));
|
213
|
+
destinationStat = null;
|
214
|
+
} else {
|
215
|
+
return false;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
const linkStrategy = (_a = opts.linkStrategy) != null ? _a : null;
|
219
|
+
const op = destinationFs === sourceFs ? linkStrategy !== null ? makeCloneLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.copyFilePromise(source, destination, fs.constants.COPYFILE_FICLONE) : linkStrategy !== null ? makeLinkOperation(destinationFs, destination, source, sourceStat, linkStrategy) : async () => destinationFs.writeFilePromise(destination, await sourceFs.readFilePromise(source));
|
220
|
+
prelayout.push(async () => op());
|
221
|
+
return true;
|
222
|
+
}
|
223
|
+
async function copySymlink(prelayout, postlayout, updateTime, destinationFs, destination, destinationStat, sourceFs, source, sourceStat, opts) {
|
224
|
+
if (destinationStat !== null) {
|
225
|
+
if (opts.overwrite) {
|
226
|
+
prelayout.push(async () => destinationFs.removePromise(destination));
|
227
|
+
destinationStat = null;
|
228
|
+
} else {
|
229
|
+
return false;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
prelayout.push(async () => {
|
233
|
+
await destinationFs.symlinkPromise(convertPath(destinationFs.pathUtils, await sourceFs.readlinkPromise(source)), destination);
|
234
|
+
});
|
235
|
+
return true;
|
236
|
+
}
|
237
|
+
|
238
|
+
function makeError(code, message) {
|
239
|
+
return Object.assign(new Error(`${code}: ${message}`), { code });
|
240
|
+
}
|
241
|
+
function ENOSYS(message, reason) {
|
242
|
+
return makeError(`ENOSYS`, `${message}, ${reason}`);
|
243
|
+
}
|
244
|
+
|
245
|
+
class FakeFS {
|
246
|
+
constructor(pathUtils) {
|
247
|
+
this.pathUtils = pathUtils;
|
248
|
+
}
|
249
|
+
async *genTraversePromise(init, { stableSort = false } = {}) {
|
250
|
+
const stack = [init];
|
251
|
+
while (stack.length > 0) {
|
252
|
+
const p = stack.shift();
|
253
|
+
const entry = await this.lstatPromise(p);
|
254
|
+
if (entry.isDirectory()) {
|
255
|
+
const entries = await this.readdirPromise(p);
|
256
|
+
if (stableSort) {
|
257
|
+
for (const entry2 of entries.sort()) {
|
258
|
+
stack.push(this.pathUtils.join(p, entry2));
|
259
|
+
}
|
260
|
+
} else {
|
261
|
+
throw new Error(`Not supported`);
|
262
|
+
}
|
263
|
+
} else {
|
264
|
+
yield p;
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
268
|
+
async removePromise(p, { recursive = true, maxRetries = 5 } = {}) {
|
269
|
+
let stat;
|
270
|
+
try {
|
271
|
+
stat = await this.lstatPromise(p);
|
272
|
+
} catch (error) {
|
273
|
+
if (error.code === `ENOENT`) {
|
274
|
+
return;
|
275
|
+
} else {
|
276
|
+
throw error;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
if (stat.isDirectory()) {
|
280
|
+
if (recursive) {
|
281
|
+
const entries = await this.readdirPromise(p);
|
282
|
+
await Promise.all(entries.map((entry) => {
|
283
|
+
return this.removePromise(this.pathUtils.resolve(p, entry));
|
284
|
+
}));
|
285
|
+
}
|
286
|
+
for (let t = 0; t <= maxRetries; t++) {
|
287
|
+
try {
|
288
|
+
await this.rmdirPromise(p);
|
289
|
+
break;
|
290
|
+
} catch (error) {
|
291
|
+
if (error.code !== `EBUSY` && error.code !== `ENOTEMPTY`) {
|
292
|
+
throw error;
|
293
|
+
} else if (t < maxRetries) {
|
294
|
+
await new Promise((resolve) => setTimeout(resolve, t * 100));
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
} else {
|
299
|
+
await this.unlinkPromise(p);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
removeSync(p, { recursive = true } = {}) {
|
303
|
+
let stat;
|
304
|
+
try {
|
305
|
+
stat = this.lstatSync(p);
|
306
|
+
} catch (error) {
|
307
|
+
if (error.code === `ENOENT`) {
|
308
|
+
return;
|
309
|
+
} else {
|
310
|
+
throw error;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
if (stat.isDirectory()) {
|
314
|
+
if (recursive)
|
315
|
+
for (const entry of this.readdirSync(p))
|
316
|
+
this.removeSync(this.pathUtils.resolve(p, entry));
|
317
|
+
this.rmdirSync(p);
|
318
|
+
} else {
|
319
|
+
this.unlinkSync(p);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
async mkdirpPromise(p, { chmod, utimes } = {}) {
|
323
|
+
p = this.resolve(p);
|
324
|
+
if (p === this.pathUtils.dirname(p))
|
325
|
+
return void 0;
|
326
|
+
const parts = p.split(this.pathUtils.sep);
|
327
|
+
let createdDirectory;
|
328
|
+
for (let u = 2; u <= parts.length; ++u) {
|
329
|
+
const subPath = parts.slice(0, u).join(this.pathUtils.sep);
|
330
|
+
if (!this.existsSync(subPath)) {
|
331
|
+
try {
|
332
|
+
await this.mkdirPromise(subPath);
|
333
|
+
} catch (error) {
|
334
|
+
if (error.code === `EEXIST`) {
|
335
|
+
continue;
|
336
|
+
} else {
|
337
|
+
throw error;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
createdDirectory != null ? createdDirectory : createdDirectory = subPath;
|
341
|
+
if (chmod != null)
|
342
|
+
await this.chmodPromise(subPath, chmod);
|
343
|
+
if (utimes != null) {
|
344
|
+
await this.utimesPromise(subPath, utimes[0], utimes[1]);
|
345
|
+
} else {
|
346
|
+
const parentStat = await this.statPromise(this.pathUtils.dirname(subPath));
|
347
|
+
await this.utimesPromise(subPath, parentStat.atime, parentStat.mtime);
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
return createdDirectory;
|
352
|
+
}
|
353
|
+
mkdirpSync(p, { chmod, utimes } = {}) {
|
354
|
+
p = this.resolve(p);
|
355
|
+
if (p === this.pathUtils.dirname(p))
|
356
|
+
return void 0;
|
357
|
+
const parts = p.split(this.pathUtils.sep);
|
358
|
+
let createdDirectory;
|
359
|
+
for (let u = 2; u <= parts.length; ++u) {
|
360
|
+
const subPath = parts.slice(0, u).join(this.pathUtils.sep);
|
361
|
+
if (!this.existsSync(subPath)) {
|
362
|
+
try {
|
363
|
+
this.mkdirSync(subPath);
|
364
|
+
} catch (error) {
|
365
|
+
if (error.code === `EEXIST`) {
|
366
|
+
continue;
|
367
|
+
} else {
|
368
|
+
throw error;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
createdDirectory != null ? createdDirectory : createdDirectory = subPath;
|
372
|
+
if (chmod != null)
|
373
|
+
this.chmodSync(subPath, chmod);
|
374
|
+
if (utimes != null) {
|
375
|
+
this.utimesSync(subPath, utimes[0], utimes[1]);
|
376
|
+
} else {
|
377
|
+
const parentStat = this.statSync(this.pathUtils.dirname(subPath));
|
378
|
+
this.utimesSync(subPath, parentStat.atime, parentStat.mtime);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
}
|
382
|
+
return createdDirectory;
|
383
|
+
}
|
384
|
+
async copyPromise(destination, source, { baseFs = this, overwrite = true, stableSort = false, stableTime = false, linkStrategy = null } = {}) {
|
385
|
+
return await copyPromise(this, destination, baseFs, source, { overwrite, stableSort, stableTime, linkStrategy });
|
386
|
+
}
|
387
|
+
copySync(destination, source, { baseFs = this, overwrite = true } = {}) {
|
388
|
+
const stat = baseFs.lstatSync(source);
|
389
|
+
const exists = this.existsSync(destination);
|
390
|
+
if (stat.isDirectory()) {
|
391
|
+
this.mkdirpSync(destination);
|
392
|
+
const directoryListing = baseFs.readdirSync(source);
|
393
|
+
for (const entry of directoryListing) {
|
394
|
+
this.copySync(this.pathUtils.join(destination, entry), baseFs.pathUtils.join(source, entry), { baseFs, overwrite });
|
395
|
+
}
|
396
|
+
} else if (stat.isFile()) {
|
397
|
+
if (!exists || overwrite) {
|
398
|
+
if (exists)
|
399
|
+
this.removeSync(destination);
|
400
|
+
const content = baseFs.readFileSync(source);
|
401
|
+
this.writeFileSync(destination, content);
|
402
|
+
}
|
403
|
+
} else if (stat.isSymbolicLink()) {
|
404
|
+
if (!exists || overwrite) {
|
405
|
+
if (exists)
|
406
|
+
this.removeSync(destination);
|
407
|
+
const target = baseFs.readlinkSync(source);
|
408
|
+
this.symlinkSync(convertPath(this.pathUtils, target), destination);
|
409
|
+
}
|
410
|
+
} else {
|
411
|
+
throw new Error(`Unsupported file type (file: ${source}, mode: 0o${stat.mode.toString(8).padStart(6, `0`)})`);
|
412
|
+
}
|
413
|
+
const mode = stat.mode & 511;
|
414
|
+
this.chmodSync(destination, mode);
|
415
|
+
}
|
416
|
+
async changeFilePromise(p, content, opts = {}) {
|
417
|
+
if (Buffer.isBuffer(content)) {
|
418
|
+
return this.changeFileBufferPromise(p, content, opts);
|
419
|
+
} else {
|
420
|
+
return this.changeFileTextPromise(p, content, opts);
|
421
|
+
}
|
422
|
+
}
|
423
|
+
async changeFileBufferPromise(p, content, { mode } = {}) {
|
424
|
+
let current = Buffer.alloc(0);
|
425
|
+
try {
|
426
|
+
current = await this.readFilePromise(p);
|
427
|
+
} catch (error) {
|
428
|
+
}
|
429
|
+
if (Buffer.compare(current, content) === 0)
|
430
|
+
return;
|
431
|
+
await this.writeFilePromise(p, content, { mode });
|
432
|
+
}
|
433
|
+
async changeFileTextPromise(p, content, { automaticNewlines, mode } = {}) {
|
434
|
+
let current = ``;
|
435
|
+
try {
|
436
|
+
current = await this.readFilePromise(p, `utf8`);
|
437
|
+
} catch (error) {
|
438
|
+
}
|
439
|
+
const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content;
|
440
|
+
if (current === normalizedContent)
|
441
|
+
return;
|
442
|
+
await this.writeFilePromise(p, normalizedContent, { mode });
|
443
|
+
}
|
444
|
+
changeFileSync(p, content, opts = {}) {
|
445
|
+
if (Buffer.isBuffer(content)) {
|
446
|
+
return this.changeFileBufferSync(p, content, opts);
|
447
|
+
} else {
|
448
|
+
return this.changeFileTextSync(p, content, opts);
|
449
|
+
}
|
450
|
+
}
|
451
|
+
changeFileBufferSync(p, content, { mode } = {}) {
|
452
|
+
let current = Buffer.alloc(0);
|
453
|
+
try {
|
454
|
+
current = this.readFileSync(p);
|
455
|
+
} catch (error) {
|
456
|
+
}
|
457
|
+
if (Buffer.compare(current, content) === 0)
|
458
|
+
return;
|
459
|
+
this.writeFileSync(p, content, { mode });
|
460
|
+
}
|
461
|
+
changeFileTextSync(p, content, { automaticNewlines = false, mode } = {}) {
|
462
|
+
let current = ``;
|
463
|
+
try {
|
464
|
+
current = this.readFileSync(p, `utf8`);
|
465
|
+
} catch (error) {
|
466
|
+
}
|
467
|
+
const normalizedContent = automaticNewlines ? normalizeLineEndings(current, content) : content;
|
468
|
+
if (current === normalizedContent)
|
469
|
+
return;
|
470
|
+
this.writeFileSync(p, normalizedContent, { mode });
|
471
|
+
}
|
472
|
+
async movePromise(fromP, toP) {
|
473
|
+
try {
|
474
|
+
await this.renamePromise(fromP, toP);
|
475
|
+
} catch (error) {
|
476
|
+
if (error.code === `EXDEV`) {
|
477
|
+
await this.copyPromise(toP, fromP);
|
478
|
+
await this.removePromise(fromP);
|
479
|
+
} else {
|
480
|
+
throw error;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
}
|
484
|
+
moveSync(fromP, toP) {
|
485
|
+
try {
|
486
|
+
this.renameSync(fromP, toP);
|
487
|
+
} catch (error) {
|
488
|
+
if (error.code === `EXDEV`) {
|
489
|
+
this.copySync(toP, fromP);
|
490
|
+
this.removeSync(fromP);
|
491
|
+
} else {
|
492
|
+
throw error;
|
493
|
+
}
|
494
|
+
}
|
495
|
+
}
|
496
|
+
async lockPromise(affectedPath, callback) {
|
497
|
+
const lockPath = `${affectedPath}.flock`;
|
498
|
+
const interval = 1e3 / 60;
|
499
|
+
const startTime = Date.now();
|
500
|
+
let fd = null;
|
501
|
+
const isAlive = async () => {
|
502
|
+
let pid;
|
503
|
+
try {
|
504
|
+
[pid] = await this.readJsonPromise(lockPath);
|
505
|
+
} catch (error) {
|
506
|
+
return Date.now() - startTime < 500;
|
507
|
+
}
|
508
|
+
try {
|
509
|
+
process.kill(pid, 0);
|
510
|
+
return true;
|
511
|
+
} catch (error) {
|
512
|
+
return false;
|
513
|
+
}
|
514
|
+
};
|
515
|
+
while (fd === null) {
|
516
|
+
try {
|
517
|
+
fd = await this.openPromise(lockPath, `wx`);
|
518
|
+
} catch (error) {
|
519
|
+
if (error.code === `EEXIST`) {
|
520
|
+
if (!await isAlive()) {
|
521
|
+
try {
|
522
|
+
await this.unlinkPromise(lockPath);
|
523
|
+
continue;
|
524
|
+
} catch (error2) {
|
525
|
+
}
|
526
|
+
}
|
527
|
+
if (Date.now() - startTime < 60 * 1e3) {
|
528
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
529
|
+
} else {
|
530
|
+
throw new Error(`Couldn't acquire a lock in a reasonable time (via ${lockPath})`);
|
531
|
+
}
|
532
|
+
} else {
|
533
|
+
throw error;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
}
|
537
|
+
await this.writePromise(fd, JSON.stringify([process.pid]));
|
538
|
+
try {
|
539
|
+
return await callback();
|
540
|
+
} finally {
|
541
|
+
try {
|
542
|
+
await this.closePromise(fd);
|
543
|
+
await this.unlinkPromise(lockPath);
|
544
|
+
} catch (error) {
|
545
|
+
}
|
546
|
+
}
|
547
|
+
}
|
548
|
+
async readJsonPromise(p) {
|
549
|
+
const content = await this.readFilePromise(p, `utf8`);
|
550
|
+
try {
|
551
|
+
return JSON.parse(content);
|
552
|
+
} catch (error) {
|
553
|
+
error.message += ` (in ${p})`;
|
554
|
+
throw error;
|
555
|
+
}
|
556
|
+
}
|
557
|
+
readJsonSync(p) {
|
558
|
+
const content = this.readFileSync(p, `utf8`);
|
559
|
+
try {
|
560
|
+
return JSON.parse(content);
|
561
|
+
} catch (error) {
|
562
|
+
error.message += ` (in ${p})`;
|
563
|
+
throw error;
|
564
|
+
}
|
565
|
+
}
|
566
|
+
async writeJsonPromise(p, data) {
|
567
|
+
return await this.writeFilePromise(p, `${JSON.stringify(data, null, 2)}
|
568
|
+
`);
|
569
|
+
}
|
570
|
+
writeJsonSync(p, data) {
|
571
|
+
return this.writeFileSync(p, `${JSON.stringify(data, null, 2)}
|
572
|
+
`);
|
573
|
+
}
|
574
|
+
async preserveTimePromise(p, cb) {
|
575
|
+
const stat = await this.lstatPromise(p);
|
576
|
+
const result = await cb();
|
577
|
+
if (typeof result !== `undefined`)
|
578
|
+
p = result;
|
579
|
+
if (this.lutimesPromise) {
|
580
|
+
await this.lutimesPromise(p, stat.atime, stat.mtime);
|
581
|
+
} else if (!stat.isSymbolicLink()) {
|
582
|
+
await this.utimesPromise(p, stat.atime, stat.mtime);
|
583
|
+
}
|
584
|
+
}
|
585
|
+
async preserveTimeSync(p, cb) {
|
586
|
+
const stat = this.lstatSync(p);
|
587
|
+
const result = cb();
|
588
|
+
if (typeof result !== `undefined`)
|
589
|
+
p = result;
|
590
|
+
if (this.lutimesSync) {
|
591
|
+
this.lutimesSync(p, stat.atime, stat.mtime);
|
592
|
+
} else if (!stat.isSymbolicLink()) {
|
593
|
+
this.utimesSync(p, stat.atime, stat.mtime);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
}
|
597
|
+
class BasePortableFakeFS extends FakeFS {
|
598
|
+
constructor() {
|
599
|
+
super(ppath);
|
600
|
+
}
|
601
|
+
}
|
602
|
+
function getEndOfLine(content) {
|
603
|
+
const matches = content.match(/\r?\n/g);
|
604
|
+
if (matches === null)
|
605
|
+
return EOL;
|
606
|
+
const crlf = matches.filter((nl) => nl === `\r
|
607
|
+
`).length;
|
608
|
+
const lf = matches.length - crlf;
|
609
|
+
return crlf > lf ? `\r
|
610
|
+
` : `
|
611
|
+
`;
|
612
|
+
}
|
613
|
+
function normalizeLineEndings(originalContent, newContent) {
|
614
|
+
return newContent.replace(/\r?\n/g, getEndOfLine(originalContent));
|
615
|
+
}
|
616
|
+
|
617
|
+
class NodeFS extends BasePortableFakeFS {
|
618
|
+
constructor(realFs = fs) {
|
619
|
+
super();
|
620
|
+
this.realFs = realFs;
|
621
|
+
if (typeof this.realFs.lutimes !== `undefined`) {
|
622
|
+
this.lutimesPromise = this.lutimesPromiseImpl;
|
623
|
+
this.lutimesSync = this.lutimesSyncImpl;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
getExtractHint() {
|
627
|
+
return false;
|
628
|
+
}
|
629
|
+
getRealPath() {
|
630
|
+
return PortablePath.root;
|
631
|
+
}
|
632
|
+
resolve(p) {
|
633
|
+
return ppath.resolve(p);
|
634
|
+
}
|
635
|
+
async openPromise(p, flags, mode) {
|
636
|
+
return await new Promise((resolve, reject) => {
|
637
|
+
this.realFs.open(npath.fromPortablePath(p), flags, mode, this.makeCallback(resolve, reject));
|
638
|
+
});
|
639
|
+
}
|
640
|
+
openSync(p, flags, mode) {
|
641
|
+
return this.realFs.openSync(npath.fromPortablePath(p), flags, mode);
|
642
|
+
}
|
643
|
+
async opendirPromise(p, opts) {
|
644
|
+
return await new Promise((resolve, reject) => {
|
645
|
+
if (typeof opts !== `undefined`) {
|
646
|
+
this.realFs.opendir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
647
|
+
} else {
|
648
|
+
this.realFs.opendir(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
649
|
+
}
|
650
|
+
}).then((dir) => {
|
651
|
+
return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true });
|
652
|
+
});
|
653
|
+
}
|
654
|
+
opendirSync(p, opts) {
|
655
|
+
const dir = typeof opts !== `undefined` ? this.realFs.opendirSync(npath.fromPortablePath(p), opts) : this.realFs.opendirSync(npath.fromPortablePath(p));
|
656
|
+
return Object.defineProperty(dir, `path`, { value: p, configurable: true, writable: true });
|
657
|
+
}
|
658
|
+
async readPromise(fd, buffer, offset = 0, length = 0, position = -1) {
|
659
|
+
return await new Promise((resolve, reject) => {
|
660
|
+
this.realFs.read(fd, buffer, offset, length, position, (error, bytesRead) => {
|
661
|
+
if (error) {
|
662
|
+
reject(error);
|
663
|
+
} else {
|
664
|
+
resolve(bytesRead);
|
665
|
+
}
|
666
|
+
});
|
667
|
+
});
|
668
|
+
}
|
669
|
+
readSync(fd, buffer, offset, length, position) {
|
670
|
+
return this.realFs.readSync(fd, buffer, offset, length, position);
|
671
|
+
}
|
672
|
+
async writePromise(fd, buffer, offset, length, position) {
|
673
|
+
return await new Promise((resolve, reject) => {
|
674
|
+
if (typeof buffer === `string`) {
|
675
|
+
return this.realFs.write(fd, buffer, offset, this.makeCallback(resolve, reject));
|
676
|
+
} else {
|
677
|
+
return this.realFs.write(fd, buffer, offset, length, position, this.makeCallback(resolve, reject));
|
678
|
+
}
|
679
|
+
});
|
680
|
+
}
|
681
|
+
writeSync(fd, buffer, offset, length, position) {
|
682
|
+
if (typeof buffer === `string`) {
|
683
|
+
return this.realFs.writeSync(fd, buffer, offset);
|
684
|
+
} else {
|
685
|
+
return this.realFs.writeSync(fd, buffer, offset, length, position);
|
686
|
+
}
|
687
|
+
}
|
688
|
+
async closePromise(fd) {
|
689
|
+
await new Promise((resolve, reject) => {
|
690
|
+
this.realFs.close(fd, this.makeCallback(resolve, reject));
|
691
|
+
});
|
692
|
+
}
|
693
|
+
closeSync(fd) {
|
694
|
+
this.realFs.closeSync(fd);
|
695
|
+
}
|
696
|
+
createReadStream(p, opts) {
|
697
|
+
const realPath = p !== null ? npath.fromPortablePath(p) : p;
|
698
|
+
return this.realFs.createReadStream(realPath, opts);
|
699
|
+
}
|
700
|
+
createWriteStream(p, opts) {
|
701
|
+
const realPath = p !== null ? npath.fromPortablePath(p) : p;
|
702
|
+
return this.realFs.createWriteStream(realPath, opts);
|
703
|
+
}
|
704
|
+
async realpathPromise(p) {
|
705
|
+
return await new Promise((resolve, reject) => {
|
706
|
+
this.realFs.realpath(npath.fromPortablePath(p), {}, this.makeCallback(resolve, reject));
|
707
|
+
}).then((path) => {
|
708
|
+
return npath.toPortablePath(path);
|
709
|
+
});
|
710
|
+
}
|
711
|
+
realpathSync(p) {
|
712
|
+
return npath.toPortablePath(this.realFs.realpathSync(npath.fromPortablePath(p), {}));
|
713
|
+
}
|
714
|
+
async existsPromise(p) {
|
715
|
+
return await new Promise((resolve) => {
|
716
|
+
this.realFs.exists(npath.fromPortablePath(p), resolve);
|
717
|
+
});
|
718
|
+
}
|
719
|
+
accessSync(p, mode) {
|
720
|
+
return this.realFs.accessSync(npath.fromPortablePath(p), mode);
|
721
|
+
}
|
722
|
+
async accessPromise(p, mode) {
|
723
|
+
return await new Promise((resolve, reject) => {
|
724
|
+
this.realFs.access(npath.fromPortablePath(p), mode, this.makeCallback(resolve, reject));
|
725
|
+
});
|
726
|
+
}
|
727
|
+
existsSync(p) {
|
728
|
+
return this.realFs.existsSync(npath.fromPortablePath(p));
|
729
|
+
}
|
730
|
+
async statPromise(p, opts) {
|
731
|
+
return await new Promise((resolve, reject) => {
|
732
|
+
if (opts) {
|
733
|
+
this.realFs.stat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
734
|
+
} else {
|
735
|
+
this.realFs.stat(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
736
|
+
}
|
737
|
+
});
|
738
|
+
}
|
739
|
+
statSync(p, opts) {
|
740
|
+
if (opts) {
|
741
|
+
return this.realFs.statSync(npath.fromPortablePath(p), opts);
|
742
|
+
} else {
|
743
|
+
return this.realFs.statSync(npath.fromPortablePath(p));
|
744
|
+
}
|
745
|
+
}
|
746
|
+
async fstatPromise(fd, opts) {
|
747
|
+
return await new Promise((resolve, reject) => {
|
748
|
+
if (opts) {
|
749
|
+
this.realFs.fstat(fd, opts, this.makeCallback(resolve, reject));
|
750
|
+
} else {
|
751
|
+
this.realFs.fstat(fd, this.makeCallback(resolve, reject));
|
752
|
+
}
|
753
|
+
});
|
754
|
+
}
|
755
|
+
fstatSync(fd, opts) {
|
756
|
+
if (opts) {
|
757
|
+
return this.realFs.fstatSync(fd, opts);
|
758
|
+
} else {
|
759
|
+
return this.realFs.fstatSync(fd);
|
760
|
+
}
|
761
|
+
}
|
762
|
+
async lstatPromise(p, opts) {
|
763
|
+
return await new Promise((resolve, reject) => {
|
764
|
+
if (opts) {
|
765
|
+
this.realFs.lstat(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
766
|
+
} else {
|
767
|
+
this.realFs.lstat(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
768
|
+
}
|
769
|
+
});
|
770
|
+
}
|
771
|
+
lstatSync(p, opts) {
|
772
|
+
if (opts) {
|
773
|
+
return this.realFs.lstatSync(npath.fromPortablePath(p), opts);
|
774
|
+
} else {
|
775
|
+
return this.realFs.lstatSync(npath.fromPortablePath(p));
|
776
|
+
}
|
777
|
+
}
|
778
|
+
async fchmodPromise(fd, mask) {
|
779
|
+
return await new Promise((resolve, reject) => {
|
780
|
+
this.realFs.fchmod(fd, mask, this.makeCallback(resolve, reject));
|
781
|
+
});
|
782
|
+
}
|
783
|
+
fchmodSync(fd, mask) {
|
784
|
+
return this.realFs.fchmodSync(fd, mask);
|
785
|
+
}
|
786
|
+
async chmodPromise(p, mask) {
|
787
|
+
return await new Promise((resolve, reject) => {
|
788
|
+
this.realFs.chmod(npath.fromPortablePath(p), mask, this.makeCallback(resolve, reject));
|
789
|
+
});
|
790
|
+
}
|
791
|
+
chmodSync(p, mask) {
|
792
|
+
return this.realFs.chmodSync(npath.fromPortablePath(p), mask);
|
793
|
+
}
|
794
|
+
async fchownPromise(fd, uid, gid) {
|
795
|
+
return await new Promise((resolve, reject) => {
|
796
|
+
this.realFs.fchown(fd, uid, gid, this.makeCallback(resolve, reject));
|
797
|
+
});
|
798
|
+
}
|
799
|
+
fchownSync(fd, uid, gid) {
|
800
|
+
return this.realFs.fchownSync(fd, uid, gid);
|
801
|
+
}
|
802
|
+
async chownPromise(p, uid, gid) {
|
803
|
+
return await new Promise((resolve, reject) => {
|
804
|
+
this.realFs.chown(npath.fromPortablePath(p), uid, gid, this.makeCallback(resolve, reject));
|
805
|
+
});
|
806
|
+
}
|
807
|
+
chownSync(p, uid, gid) {
|
808
|
+
return this.realFs.chownSync(npath.fromPortablePath(p), uid, gid);
|
809
|
+
}
|
810
|
+
async renamePromise(oldP, newP) {
|
811
|
+
return await new Promise((resolve, reject) => {
|
812
|
+
this.realFs.rename(npath.fromPortablePath(oldP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject));
|
813
|
+
});
|
814
|
+
}
|
815
|
+
renameSync(oldP, newP) {
|
816
|
+
return this.realFs.renameSync(npath.fromPortablePath(oldP), npath.fromPortablePath(newP));
|
817
|
+
}
|
818
|
+
async copyFilePromise(sourceP, destP, flags = 0) {
|
819
|
+
return await new Promise((resolve, reject) => {
|
820
|
+
this.realFs.copyFile(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags, this.makeCallback(resolve, reject));
|
821
|
+
});
|
822
|
+
}
|
823
|
+
copyFileSync(sourceP, destP, flags = 0) {
|
824
|
+
return this.realFs.copyFileSync(npath.fromPortablePath(sourceP), npath.fromPortablePath(destP), flags);
|
825
|
+
}
|
826
|
+
async appendFilePromise(p, content, opts) {
|
827
|
+
return await new Promise((resolve, reject) => {
|
828
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
829
|
+
if (opts) {
|
830
|
+
this.realFs.appendFile(fsNativePath, content, opts, this.makeCallback(resolve, reject));
|
831
|
+
} else {
|
832
|
+
this.realFs.appendFile(fsNativePath, content, this.makeCallback(resolve, reject));
|
833
|
+
}
|
834
|
+
});
|
835
|
+
}
|
836
|
+
appendFileSync(p, content, opts) {
|
837
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
838
|
+
if (opts) {
|
839
|
+
this.realFs.appendFileSync(fsNativePath, content, opts);
|
840
|
+
} else {
|
841
|
+
this.realFs.appendFileSync(fsNativePath, content);
|
842
|
+
}
|
843
|
+
}
|
844
|
+
async writeFilePromise(p, content, opts) {
|
845
|
+
return await new Promise((resolve, reject) => {
|
846
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
847
|
+
if (opts) {
|
848
|
+
this.realFs.writeFile(fsNativePath, content, opts, this.makeCallback(resolve, reject));
|
849
|
+
} else {
|
850
|
+
this.realFs.writeFile(fsNativePath, content, this.makeCallback(resolve, reject));
|
851
|
+
}
|
852
|
+
});
|
853
|
+
}
|
854
|
+
writeFileSync(p, content, opts) {
|
855
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
856
|
+
if (opts) {
|
857
|
+
this.realFs.writeFileSync(fsNativePath, content, opts);
|
858
|
+
} else {
|
859
|
+
this.realFs.writeFileSync(fsNativePath, content);
|
860
|
+
}
|
861
|
+
}
|
862
|
+
async unlinkPromise(p) {
|
863
|
+
return await new Promise((resolve, reject) => {
|
864
|
+
this.realFs.unlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
865
|
+
});
|
866
|
+
}
|
867
|
+
unlinkSync(p) {
|
868
|
+
return this.realFs.unlinkSync(npath.fromPortablePath(p));
|
869
|
+
}
|
870
|
+
async utimesPromise(p, atime, mtime) {
|
871
|
+
return await new Promise((resolve, reject) => {
|
872
|
+
this.realFs.utimes(npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject));
|
873
|
+
});
|
874
|
+
}
|
875
|
+
utimesSync(p, atime, mtime) {
|
876
|
+
this.realFs.utimesSync(npath.fromPortablePath(p), atime, mtime);
|
877
|
+
}
|
878
|
+
async lutimesPromiseImpl(p, atime, mtime) {
|
879
|
+
const lutimes = this.realFs.lutimes;
|
880
|
+
if (typeof lutimes === `undefined`)
|
881
|
+
throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);
|
882
|
+
return await new Promise((resolve, reject) => {
|
883
|
+
lutimes.call(this.realFs, npath.fromPortablePath(p), atime, mtime, this.makeCallback(resolve, reject));
|
884
|
+
});
|
885
|
+
}
|
886
|
+
lutimesSyncImpl(p, atime, mtime) {
|
887
|
+
const lutimesSync = this.realFs.lutimesSync;
|
888
|
+
if (typeof lutimesSync === `undefined`)
|
889
|
+
throw ENOSYS(`unavailable Node binding`, `lutimes '${p}'`);
|
890
|
+
lutimesSync.call(this.realFs, npath.fromPortablePath(p), atime, mtime);
|
891
|
+
}
|
892
|
+
async mkdirPromise(p, opts) {
|
893
|
+
return await new Promise((resolve, reject) => {
|
894
|
+
this.realFs.mkdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
895
|
+
});
|
896
|
+
}
|
897
|
+
mkdirSync(p, opts) {
|
898
|
+
return this.realFs.mkdirSync(npath.fromPortablePath(p), opts);
|
899
|
+
}
|
900
|
+
async rmdirPromise(p, opts) {
|
901
|
+
return await new Promise((resolve, reject) => {
|
902
|
+
if (opts) {
|
903
|
+
this.realFs.rmdir(npath.fromPortablePath(p), opts, this.makeCallback(resolve, reject));
|
904
|
+
} else {
|
905
|
+
this.realFs.rmdir(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
906
|
+
}
|
907
|
+
});
|
908
|
+
}
|
909
|
+
rmdirSync(p, opts) {
|
910
|
+
return this.realFs.rmdirSync(npath.fromPortablePath(p), opts);
|
911
|
+
}
|
912
|
+
async linkPromise(existingP, newP) {
|
913
|
+
return await new Promise((resolve, reject) => {
|
914
|
+
this.realFs.link(npath.fromPortablePath(existingP), npath.fromPortablePath(newP), this.makeCallback(resolve, reject));
|
915
|
+
});
|
916
|
+
}
|
917
|
+
linkSync(existingP, newP) {
|
918
|
+
return this.realFs.linkSync(npath.fromPortablePath(existingP), npath.fromPortablePath(newP));
|
919
|
+
}
|
920
|
+
async symlinkPromise(target, p, type) {
|
921
|
+
return await new Promise((resolve, reject) => {
|
922
|
+
this.realFs.symlink(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type, this.makeCallback(resolve, reject));
|
923
|
+
});
|
924
|
+
}
|
925
|
+
symlinkSync(target, p, type) {
|
926
|
+
return this.realFs.symlinkSync(npath.fromPortablePath(target.replace(/\/+$/, ``)), npath.fromPortablePath(p), type);
|
927
|
+
}
|
928
|
+
async readFilePromise(p, encoding) {
|
929
|
+
return await new Promise((resolve, reject) => {
|
930
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
931
|
+
this.realFs.readFile(fsNativePath, encoding, this.makeCallback(resolve, reject));
|
932
|
+
});
|
933
|
+
}
|
934
|
+
readFileSync(p, encoding) {
|
935
|
+
const fsNativePath = typeof p === `string` ? npath.fromPortablePath(p) : p;
|
936
|
+
return this.realFs.readFileSync(fsNativePath, encoding);
|
937
|
+
}
|
938
|
+
async readdirPromise(p, opts) {
|
939
|
+
return await new Promise((resolve, reject) => {
|
940
|
+
if (opts == null ? void 0 : opts.withFileTypes) {
|
941
|
+
this.realFs.readdir(npath.fromPortablePath(p), { withFileTypes: true }, this.makeCallback(resolve, reject));
|
942
|
+
} else {
|
943
|
+
this.realFs.readdir(npath.fromPortablePath(p), this.makeCallback((value) => resolve(value), reject));
|
944
|
+
}
|
945
|
+
});
|
946
|
+
}
|
947
|
+
readdirSync(p, opts) {
|
948
|
+
if (opts == null ? void 0 : opts.withFileTypes) {
|
949
|
+
return this.realFs.readdirSync(npath.fromPortablePath(p), { withFileTypes: true });
|
950
|
+
} else {
|
951
|
+
return this.realFs.readdirSync(npath.fromPortablePath(p));
|
952
|
+
}
|
953
|
+
}
|
954
|
+
async readlinkPromise(p) {
|
955
|
+
return await new Promise((resolve, reject) => {
|
956
|
+
this.realFs.readlink(npath.fromPortablePath(p), this.makeCallback(resolve, reject));
|
957
|
+
}).then((path) => {
|
958
|
+
return npath.toPortablePath(path);
|
959
|
+
});
|
960
|
+
}
|
961
|
+
readlinkSync(p) {
|
962
|
+
return npath.toPortablePath(this.realFs.readlinkSync(npath.fromPortablePath(p)));
|
963
|
+
}
|
964
|
+
async truncatePromise(p, len) {
|
965
|
+
return await new Promise((resolve, reject) => {
|
966
|
+
this.realFs.truncate(npath.fromPortablePath(p), len, this.makeCallback(resolve, reject));
|
967
|
+
});
|
968
|
+
}
|
969
|
+
truncateSync(p, len) {
|
970
|
+
return this.realFs.truncateSync(npath.fromPortablePath(p), len);
|
971
|
+
}
|
972
|
+
async ftruncatePromise(fd, len) {
|
973
|
+
return await new Promise((resolve, reject) => {
|
974
|
+
this.realFs.ftruncate(fd, len, this.makeCallback(resolve, reject));
|
975
|
+
});
|
976
|
+
}
|
977
|
+
ftruncateSync(fd, len) {
|
978
|
+
return this.realFs.ftruncateSync(fd, len);
|
979
|
+
}
|
980
|
+
watch(p, a, b) {
|
981
|
+
return this.realFs.watch(
|
982
|
+
npath.fromPortablePath(p),
|
983
|
+
a,
|
984
|
+
b
|
985
|
+
);
|
986
|
+
}
|
987
|
+
watchFile(p, a, b) {
|
988
|
+
return this.realFs.watchFile(
|
989
|
+
npath.fromPortablePath(p),
|
990
|
+
a,
|
991
|
+
b
|
992
|
+
);
|
993
|
+
}
|
994
|
+
unwatchFile(p, cb) {
|
995
|
+
return this.realFs.unwatchFile(npath.fromPortablePath(p), cb);
|
996
|
+
}
|
997
|
+
makeCallback(resolve, reject) {
|
998
|
+
return (err, result) => {
|
999
|
+
if (err) {
|
1000
|
+
reject(err);
|
1001
|
+
} else {
|
1002
|
+
resolve(result);
|
1003
|
+
}
|
1004
|
+
};
|
1005
|
+
}
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
class ProxiedFS extends FakeFS {
|
1009
|
+
getExtractHint(hints) {
|
1010
|
+
return this.baseFs.getExtractHint(hints);
|
1011
|
+
}
|
1012
|
+
resolve(path) {
|
1013
|
+
return this.mapFromBase(this.baseFs.resolve(this.mapToBase(path)));
|
1014
|
+
}
|
1015
|
+
getRealPath() {
|
1016
|
+
return this.mapFromBase(this.baseFs.getRealPath());
|
1017
|
+
}
|
1018
|
+
async openPromise(p, flags, mode) {
|
1019
|
+
return this.baseFs.openPromise(this.mapToBase(p), flags, mode);
|
1020
|
+
}
|
1021
|
+
openSync(p, flags, mode) {
|
1022
|
+
return this.baseFs.openSync(this.mapToBase(p), flags, mode);
|
1023
|
+
}
|
1024
|
+
async opendirPromise(p, opts) {
|
1025
|
+
return Object.assign(await this.baseFs.opendirPromise(this.mapToBase(p), opts), { path: p });
|
1026
|
+
}
|
1027
|
+
opendirSync(p, opts) {
|
1028
|
+
return Object.assign(this.baseFs.opendirSync(this.mapToBase(p), opts), { path: p });
|
1029
|
+
}
|
1030
|
+
async readPromise(fd, buffer, offset, length, position) {
|
1031
|
+
return await this.baseFs.readPromise(fd, buffer, offset, length, position);
|
1032
|
+
}
|
1033
|
+
readSync(fd, buffer, offset, length, position) {
|
1034
|
+
return this.baseFs.readSync(fd, buffer, offset, length, position);
|
1035
|
+
}
|
1036
|
+
async writePromise(fd, buffer, offset, length, position) {
|
1037
|
+
if (typeof buffer === `string`) {
|
1038
|
+
return await this.baseFs.writePromise(fd, buffer, offset);
|
1039
|
+
} else {
|
1040
|
+
return await this.baseFs.writePromise(fd, buffer, offset, length, position);
|
1041
|
+
}
|
1042
|
+
}
|
1043
|
+
writeSync(fd, buffer, offset, length, position) {
|
1044
|
+
if (typeof buffer === `string`) {
|
1045
|
+
return this.baseFs.writeSync(fd, buffer, offset);
|
1046
|
+
} else {
|
1047
|
+
return this.baseFs.writeSync(fd, buffer, offset, length, position);
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
async closePromise(fd) {
|
1051
|
+
return this.baseFs.closePromise(fd);
|
1052
|
+
}
|
1053
|
+
closeSync(fd) {
|
1054
|
+
this.baseFs.closeSync(fd);
|
1055
|
+
}
|
1056
|
+
createReadStream(p, opts) {
|
1057
|
+
return this.baseFs.createReadStream(p !== null ? this.mapToBase(p) : p, opts);
|
1058
|
+
}
|
1059
|
+
createWriteStream(p, opts) {
|
1060
|
+
return this.baseFs.createWriteStream(p !== null ? this.mapToBase(p) : p, opts);
|
1061
|
+
}
|
1062
|
+
async realpathPromise(p) {
|
1063
|
+
return this.mapFromBase(await this.baseFs.realpathPromise(this.mapToBase(p)));
|
1064
|
+
}
|
1065
|
+
realpathSync(p) {
|
1066
|
+
return this.mapFromBase(this.baseFs.realpathSync(this.mapToBase(p)));
|
1067
|
+
}
|
1068
|
+
async existsPromise(p) {
|
1069
|
+
return this.baseFs.existsPromise(this.mapToBase(p));
|
1070
|
+
}
|
1071
|
+
existsSync(p) {
|
1072
|
+
return this.baseFs.existsSync(this.mapToBase(p));
|
1073
|
+
}
|
1074
|
+
accessSync(p, mode) {
|
1075
|
+
return this.baseFs.accessSync(this.mapToBase(p), mode);
|
1076
|
+
}
|
1077
|
+
async accessPromise(p, mode) {
|
1078
|
+
return this.baseFs.accessPromise(this.mapToBase(p), mode);
|
1079
|
+
}
|
1080
|
+
async statPromise(p, opts) {
|
1081
|
+
return this.baseFs.statPromise(this.mapToBase(p), opts);
|
1082
|
+
}
|
1083
|
+
statSync(p, opts) {
|
1084
|
+
return this.baseFs.statSync(this.mapToBase(p), opts);
|
1085
|
+
}
|
1086
|
+
async fstatPromise(fd, opts) {
|
1087
|
+
return this.baseFs.fstatPromise(fd, opts);
|
1088
|
+
}
|
1089
|
+
fstatSync(fd, opts) {
|
1090
|
+
return this.baseFs.fstatSync(fd, opts);
|
1091
|
+
}
|
1092
|
+
lstatPromise(p, opts) {
|
1093
|
+
return this.baseFs.lstatPromise(this.mapToBase(p), opts);
|
1094
|
+
}
|
1095
|
+
lstatSync(p, opts) {
|
1096
|
+
return this.baseFs.lstatSync(this.mapToBase(p), opts);
|
1097
|
+
}
|
1098
|
+
async fchmodPromise(fd, mask) {
|
1099
|
+
return this.baseFs.fchmodPromise(fd, mask);
|
1100
|
+
}
|
1101
|
+
fchmodSync(fd, mask) {
|
1102
|
+
return this.baseFs.fchmodSync(fd, mask);
|
1103
|
+
}
|
1104
|
+
async chmodPromise(p, mask) {
|
1105
|
+
return this.baseFs.chmodPromise(this.mapToBase(p), mask);
|
1106
|
+
}
|
1107
|
+
chmodSync(p, mask) {
|
1108
|
+
return this.baseFs.chmodSync(this.mapToBase(p), mask);
|
1109
|
+
}
|
1110
|
+
async fchownPromise(fd, uid, gid) {
|
1111
|
+
return this.baseFs.fchownPromise(fd, uid, gid);
|
1112
|
+
}
|
1113
|
+
fchownSync(fd, uid, gid) {
|
1114
|
+
return this.baseFs.fchownSync(fd, uid, gid);
|
1115
|
+
}
|
1116
|
+
async chownPromise(p, uid, gid) {
|
1117
|
+
return this.baseFs.chownPromise(this.mapToBase(p), uid, gid);
|
1118
|
+
}
|
1119
|
+
chownSync(p, uid, gid) {
|
1120
|
+
return this.baseFs.chownSync(this.mapToBase(p), uid, gid);
|
1121
|
+
}
|
1122
|
+
async renamePromise(oldP, newP) {
|
1123
|
+
return this.baseFs.renamePromise(this.mapToBase(oldP), this.mapToBase(newP));
|
1124
|
+
}
|
1125
|
+
renameSync(oldP, newP) {
|
1126
|
+
return this.baseFs.renameSync(this.mapToBase(oldP), this.mapToBase(newP));
|
1127
|
+
}
|
1128
|
+
async copyFilePromise(sourceP, destP, flags = 0) {
|
1129
|
+
return this.baseFs.copyFilePromise(this.mapToBase(sourceP), this.mapToBase(destP), flags);
|
1130
|
+
}
|
1131
|
+
copyFileSync(sourceP, destP, flags = 0) {
|
1132
|
+
return this.baseFs.copyFileSync(this.mapToBase(sourceP), this.mapToBase(destP), flags);
|
1133
|
+
}
|
1134
|
+
async appendFilePromise(p, content, opts) {
|
1135
|
+
return this.baseFs.appendFilePromise(this.fsMapToBase(p), content, opts);
|
1136
|
+
}
|
1137
|
+
appendFileSync(p, content, opts) {
|
1138
|
+
return this.baseFs.appendFileSync(this.fsMapToBase(p), content, opts);
|
1139
|
+
}
|
1140
|
+
async writeFilePromise(p, content, opts) {
|
1141
|
+
return this.baseFs.writeFilePromise(this.fsMapToBase(p), content, opts);
|
1142
|
+
}
|
1143
|
+
writeFileSync(p, content, opts) {
|
1144
|
+
return this.baseFs.writeFileSync(this.fsMapToBase(p), content, opts);
|
1145
|
+
}
|
1146
|
+
async unlinkPromise(p) {
|
1147
|
+
return this.baseFs.unlinkPromise(this.mapToBase(p));
|
1148
|
+
}
|
1149
|
+
unlinkSync(p) {
|
1150
|
+
return this.baseFs.unlinkSync(this.mapToBase(p));
|
1151
|
+
}
|
1152
|
+
async utimesPromise(p, atime, mtime) {
|
1153
|
+
return this.baseFs.utimesPromise(this.mapToBase(p), atime, mtime);
|
1154
|
+
}
|
1155
|
+
utimesSync(p, atime, mtime) {
|
1156
|
+
return this.baseFs.utimesSync(this.mapToBase(p), atime, mtime);
|
1157
|
+
}
|
1158
|
+
async mkdirPromise(p, opts) {
|
1159
|
+
return this.baseFs.mkdirPromise(this.mapToBase(p), opts);
|
1160
|
+
}
|
1161
|
+
mkdirSync(p, opts) {
|
1162
|
+
return this.baseFs.mkdirSync(this.mapToBase(p), opts);
|
1163
|
+
}
|
1164
|
+
async rmdirPromise(p, opts) {
|
1165
|
+
return this.baseFs.rmdirPromise(this.mapToBase(p), opts);
|
1166
|
+
}
|
1167
|
+
rmdirSync(p, opts) {
|
1168
|
+
return this.baseFs.rmdirSync(this.mapToBase(p), opts);
|
1169
|
+
}
|
1170
|
+
async linkPromise(existingP, newP) {
|
1171
|
+
return this.baseFs.linkPromise(this.mapToBase(existingP), this.mapToBase(newP));
|
1172
|
+
}
|
1173
|
+
linkSync(existingP, newP) {
|
1174
|
+
return this.baseFs.linkSync(this.mapToBase(existingP), this.mapToBase(newP));
|
1175
|
+
}
|
1176
|
+
async symlinkPromise(target, p, type) {
|
1177
|
+
const mappedP = this.mapToBase(p);
|
1178
|
+
if (this.pathUtils.isAbsolute(target))
|
1179
|
+
return this.baseFs.symlinkPromise(this.mapToBase(target), mappedP, type);
|
1180
|
+
const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
|
1181
|
+
const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
|
1182
|
+
return this.baseFs.symlinkPromise(mappedTarget, mappedP, type);
|
1183
|
+
}
|
1184
|
+
symlinkSync(target, p, type) {
|
1185
|
+
const mappedP = this.mapToBase(p);
|
1186
|
+
if (this.pathUtils.isAbsolute(target))
|
1187
|
+
return this.baseFs.symlinkSync(this.mapToBase(target), mappedP, type);
|
1188
|
+
const mappedAbsoluteTarget = this.mapToBase(this.pathUtils.join(this.pathUtils.dirname(p), target));
|
1189
|
+
const mappedTarget = this.baseFs.pathUtils.relative(this.baseFs.pathUtils.dirname(mappedP), mappedAbsoluteTarget);
|
1190
|
+
return this.baseFs.symlinkSync(mappedTarget, mappedP, type);
|
1191
|
+
}
|
1192
|
+
async readFilePromise(p, encoding) {
|
1193
|
+
if (encoding === `utf8`) {
|
1194
|
+
return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
|
1195
|
+
} else {
|
1196
|
+
return this.baseFs.readFilePromise(this.fsMapToBase(p), encoding);
|
1197
|
+
}
|
1198
|
+
}
|
1199
|
+
readFileSync(p, encoding) {
|
1200
|
+
if (encoding === `utf8`) {
|
1201
|
+
return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
|
1202
|
+
} else {
|
1203
|
+
return this.baseFs.readFileSync(this.fsMapToBase(p), encoding);
|
1204
|
+
}
|
1205
|
+
}
|
1206
|
+
async readdirPromise(p, opts) {
|
1207
|
+
return this.baseFs.readdirPromise(this.mapToBase(p), opts);
|
1208
|
+
}
|
1209
|
+
readdirSync(p, opts) {
|
1210
|
+
return this.baseFs.readdirSync(this.mapToBase(p), opts);
|
1211
|
+
}
|
1212
|
+
async readlinkPromise(p) {
|
1213
|
+
return this.mapFromBase(await this.baseFs.readlinkPromise(this.mapToBase(p)));
|
1214
|
+
}
|
1215
|
+
readlinkSync(p) {
|
1216
|
+
return this.mapFromBase(this.baseFs.readlinkSync(this.mapToBase(p)));
|
1217
|
+
}
|
1218
|
+
async truncatePromise(p, len) {
|
1219
|
+
return this.baseFs.truncatePromise(this.mapToBase(p), len);
|
1220
|
+
}
|
1221
|
+
truncateSync(p, len) {
|
1222
|
+
return this.baseFs.truncateSync(this.mapToBase(p), len);
|
1223
|
+
}
|
1224
|
+
async ftruncatePromise(fd, len) {
|
1225
|
+
return this.baseFs.ftruncatePromise(fd, len);
|
1226
|
+
}
|
1227
|
+
ftruncateSync(fd, len) {
|
1228
|
+
return this.baseFs.ftruncateSync(fd, len);
|
1229
|
+
}
|
1230
|
+
watch(p, a, b) {
|
1231
|
+
return this.baseFs.watch(
|
1232
|
+
this.mapToBase(p),
|
1233
|
+
a,
|
1234
|
+
b
|
1235
|
+
);
|
1236
|
+
}
|
1237
|
+
watchFile(p, a, b) {
|
1238
|
+
return this.baseFs.watchFile(
|
1239
|
+
this.mapToBase(p),
|
1240
|
+
a,
|
1241
|
+
b
|
1242
|
+
);
|
1243
|
+
}
|
1244
|
+
unwatchFile(p, cb) {
|
1245
|
+
return this.baseFs.unwatchFile(this.mapToBase(p), cb);
|
1246
|
+
}
|
1247
|
+
fsMapToBase(p) {
|
1248
|
+
if (typeof p === `number`) {
|
1249
|
+
return p;
|
1250
|
+
} else {
|
1251
|
+
return this.mapToBase(p);
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
const NUMBER_REGEXP = /^[0-9]+$/;
|
1257
|
+
const VIRTUAL_REGEXP = /^(\/(?:[^/]+\/)*?(?:\$\$virtual|__virtual__))((?:\/((?:[^/]+-)?[a-f0-9]+)(?:\/([^/]+))?)?((?:\/.*)?))$/;
|
1258
|
+
const VALID_COMPONENT = /^([^/]+-)?[a-f0-9]+$/;
|
1259
|
+
class VirtualFS extends ProxiedFS {
|
1260
|
+
constructor({ baseFs = new NodeFS() } = {}) {
|
1261
|
+
super(ppath);
|
1262
|
+
this.baseFs = baseFs;
|
1263
|
+
}
|
1264
|
+
static makeVirtualPath(base, component, to) {
|
1265
|
+
if (ppath.basename(base) !== `__virtual__`)
|
1266
|
+
throw new Error(`Assertion failed: Virtual folders must be named "__virtual__"`);
|
1267
|
+
if (!ppath.basename(component).match(VALID_COMPONENT))
|
1268
|
+
throw new Error(`Assertion failed: Virtual components must be ended by an hexadecimal hash`);
|
1269
|
+
const target = ppath.relative(ppath.dirname(base), to);
|
1270
|
+
const segments = target.split(`/`);
|
1271
|
+
let depth = 0;
|
1272
|
+
while (depth < segments.length && segments[depth] === `..`)
|
1273
|
+
depth += 1;
|
1274
|
+
const finalSegments = segments.slice(depth);
|
1275
|
+
const fullVirtualPath = ppath.join(base, component, String(depth), ...finalSegments);
|
1276
|
+
return fullVirtualPath;
|
1277
|
+
}
|
1278
|
+
static resolveVirtual(p) {
|
1279
|
+
const match = p.match(VIRTUAL_REGEXP);
|
1280
|
+
if (!match || !match[3] && match[5])
|
1281
|
+
return p;
|
1282
|
+
const target = ppath.dirname(match[1]);
|
1283
|
+
if (!match[3] || !match[4])
|
1284
|
+
return target;
|
1285
|
+
const isnum = NUMBER_REGEXP.test(match[4]);
|
1286
|
+
if (!isnum)
|
1287
|
+
return p;
|
1288
|
+
const depth = Number(match[4]);
|
1289
|
+
const backstep = `../`.repeat(depth);
|
1290
|
+
const subpath = match[5] || `.`;
|
1291
|
+
return VirtualFS.resolveVirtual(ppath.join(target, backstep, subpath));
|
1292
|
+
}
|
1293
|
+
getExtractHint(hints) {
|
1294
|
+
return this.baseFs.getExtractHint(hints);
|
1295
|
+
}
|
1296
|
+
getRealPath() {
|
1297
|
+
return this.baseFs.getRealPath();
|
1298
|
+
}
|
1299
|
+
realpathSync(p) {
|
1300
|
+
const match = p.match(VIRTUAL_REGEXP);
|
1301
|
+
if (!match)
|
1302
|
+
return this.baseFs.realpathSync(p);
|
1303
|
+
if (!match[5])
|
1304
|
+
return p;
|
1305
|
+
const realpath = this.baseFs.realpathSync(this.mapToBase(p));
|
1306
|
+
return VirtualFS.makeVirtualPath(match[1], match[3], realpath);
|
1307
|
+
}
|
1308
|
+
async realpathPromise(p) {
|
1309
|
+
const match = p.match(VIRTUAL_REGEXP);
|
1310
|
+
if (!match)
|
1311
|
+
return await this.baseFs.realpathPromise(p);
|
1312
|
+
if (!match[5])
|
1313
|
+
return p;
|
1314
|
+
const realpath = await this.baseFs.realpathPromise(this.mapToBase(p));
|
1315
|
+
return VirtualFS.makeVirtualPath(match[1], match[3], realpath);
|
1316
|
+
}
|
1317
|
+
mapToBase(p) {
|
1318
|
+
if (p === ``)
|
1319
|
+
return p;
|
1320
|
+
if (this.pathUtils.isAbsolute(p))
|
1321
|
+
return VirtualFS.resolveVirtual(p);
|
1322
|
+
const resolvedRoot = VirtualFS.resolveVirtual(this.baseFs.resolve(PortablePath.dot));
|
1323
|
+
const resolvedP = VirtualFS.resolveVirtual(this.baseFs.resolve(p));
|
1324
|
+
return ppath.relative(resolvedRoot, resolvedP) || PortablePath.dot;
|
1325
|
+
}
|
1326
|
+
mapFromBase(p) {
|
1327
|
+
return p;
|
1328
|
+
}
|
1329
|
+
}
|
1330
|
+
|
1331
|
+
const [major, minor] = process.versions.node.split(`.`).map((value) => parseInt(value, 10));
|
1332
|
+
const HAS_CONSOLIDATED_HOOKS = major > 16 || major === 16 && minor >= 12;
|
1333
|
+
const HAS_UNFLAGGED_JSON_MODULES = major > 17 || major === 17 && minor >= 5 || major === 16 && minor >= 15;
|
1334
|
+
const HAS_JSON_IMPORT_ASSERTION_REQUIREMENT = major > 17 || major === 17 && minor >= 1 || major === 16 && minor > 14;
|
1335
|
+
const WATCH_MODE_MESSAGE_USES_ARRAYS = major > 19 || major === 19 && minor >= 2 || major === 18 && minor >= 13;
|
1336
|
+
|
1337
|
+
const builtinModules = new Set(Module.builtinModules || Object.keys(process.binding(`natives`)));
|
1338
|
+
const isBuiltinModule = (request) => request.startsWith(`node:`) || builtinModules.has(request);
|
1339
|
+
function readPackageScope(checkPath) {
|
1340
|
+
const rootSeparatorIndex = checkPath.indexOf(npath.sep);
|
1341
|
+
let separatorIndex;
|
1342
|
+
do {
|
1343
|
+
separatorIndex = checkPath.lastIndexOf(npath.sep);
|
1344
|
+
checkPath = checkPath.slice(0, separatorIndex);
|
1345
|
+
if (checkPath.endsWith(`${npath.sep}node_modules`))
|
1346
|
+
return false;
|
1347
|
+
const pjson = readPackage(checkPath + npath.sep);
|
1348
|
+
if (pjson) {
|
1349
|
+
return {
|
1350
|
+
data: pjson,
|
1351
|
+
path: checkPath
|
1352
|
+
};
|
1353
|
+
}
|
1354
|
+
} while (separatorIndex > rootSeparatorIndex);
|
1355
|
+
return false;
|
1356
|
+
}
|
1357
|
+
function readPackage(requestPath) {
|
1358
|
+
const jsonPath = npath.resolve(requestPath, `package.json`);
|
1359
|
+
if (!fs.existsSync(jsonPath))
|
1360
|
+
return null;
|
1361
|
+
return JSON.parse(fs.readFileSync(jsonPath, `utf8`));
|
1362
|
+
}
|
1363
|
+
|
1364
|
+
async function tryReadFile$1(path2) {
|
1365
|
+
try {
|
1366
|
+
return await fs.promises.readFile(path2, `utf8`);
|
1367
|
+
} catch (error) {
|
1368
|
+
if (error.code === `ENOENT`)
|
1369
|
+
return null;
|
1370
|
+
throw error;
|
1371
|
+
}
|
1372
|
+
}
|
1373
|
+
function tryParseURL(str, base) {
|
1374
|
+
try {
|
1375
|
+
return new URL$1(str, base);
|
1376
|
+
} catch {
|
1377
|
+
return null;
|
1378
|
+
}
|
1379
|
+
}
|
1380
|
+
let entrypointPath = null;
|
1381
|
+
function setEntrypointPath(file) {
|
1382
|
+
entrypointPath = file;
|
1383
|
+
}
|
1384
|
+
function getFileFormat(filepath) {
|
1385
|
+
var _a, _b;
|
1386
|
+
const ext = path.extname(filepath);
|
1387
|
+
switch (ext) {
|
1388
|
+
case `.mjs`: {
|
1389
|
+
return `module`;
|
1390
|
+
}
|
1391
|
+
case `.cjs`: {
|
1392
|
+
return `commonjs`;
|
1393
|
+
}
|
1394
|
+
case `.wasm`: {
|
1395
|
+
throw new Error(
|
1396
|
+
`Unknown file extension ".wasm" for ${filepath}`
|
1397
|
+
);
|
1398
|
+
}
|
1399
|
+
case `.json`: {
|
1400
|
+
if (HAS_UNFLAGGED_JSON_MODULES)
|
1401
|
+
return `json`;
|
1402
|
+
throw new Error(
|
1403
|
+
`Unknown file extension ".json" for ${filepath}`
|
1404
|
+
);
|
1405
|
+
}
|
1406
|
+
case `.js`: {
|
1407
|
+
const pkg = readPackageScope(filepath);
|
1408
|
+
if (!pkg)
|
1409
|
+
return `commonjs`;
|
1410
|
+
return (_a = pkg.data.type) != null ? _a : `commonjs`;
|
1411
|
+
}
|
1412
|
+
default: {
|
1413
|
+
if (entrypointPath !== filepath)
|
1414
|
+
return null;
|
1415
|
+
const pkg = readPackageScope(filepath);
|
1416
|
+
if (!pkg)
|
1417
|
+
return `commonjs`;
|
1418
|
+
if (pkg.data.type === `module`)
|
1419
|
+
return null;
|
1420
|
+
return (_b = pkg.data.type) != null ? _b : `commonjs`;
|
1421
|
+
}
|
1422
|
+
}
|
1423
|
+
}
|
1424
|
+
|
1425
|
+
async function getFormat$1(resolved, context, defaultGetFormat) {
|
1426
|
+
const url = tryParseURL(resolved);
|
1427
|
+
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
1428
|
+
return defaultGetFormat(resolved, context, defaultGetFormat);
|
1429
|
+
const format = getFileFormat(fileURLToPath(url));
|
1430
|
+
if (format) {
|
1431
|
+
return {
|
1432
|
+
format
|
1433
|
+
};
|
1434
|
+
}
|
1435
|
+
return defaultGetFormat(resolved, context, defaultGetFormat);
|
1436
|
+
}
|
1437
|
+
|
1438
|
+
async function getSource$1(urlString, context, defaultGetSource) {
|
1439
|
+
const url = tryParseURL(urlString);
|
1440
|
+
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
1441
|
+
return defaultGetSource(urlString, context, defaultGetSource);
|
1442
|
+
return {
|
1443
|
+
source: await fs.promises.readFile(fileURLToPath(url), `utf8`)
|
1444
|
+
};
|
1445
|
+
}
|
1446
|
+
|
1447
|
+
async function load$1(urlString, context, nextLoad) {
|
1448
|
+
var _a;
|
1449
|
+
const url = tryParseURL(urlString);
|
1450
|
+
if ((url == null ? void 0 : url.protocol) !== `file:`)
|
1451
|
+
return nextLoad(urlString, context, nextLoad);
|
1452
|
+
const filePath = fileURLToPath(url);
|
1453
|
+
const format = getFileFormat(filePath);
|
1454
|
+
if (!format)
|
1455
|
+
return nextLoad(urlString, context, nextLoad);
|
1456
|
+
if (HAS_JSON_IMPORT_ASSERTION_REQUIREMENT && format === `json` && ((_a = context.importAssertions) == null ? void 0 : _a.type) !== `json`) {
|
1457
|
+
const err = new TypeError(`[ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "${urlString}" needs an import assertion of type "json"`);
|
1458
|
+
err.code = `ERR_IMPORT_ASSERTION_TYPE_MISSING`;
|
1459
|
+
throw err;
|
1460
|
+
}
|
1461
|
+
if (process.env.WATCH_REPORT_DEPENDENCIES && process.send) {
|
1462
|
+
const pathToSend = pathToFileURL(
|
1463
|
+
npath.fromPortablePath(
|
1464
|
+
VirtualFS.resolveVirtual(npath.toPortablePath(filePath))
|
1465
|
+
)
|
1466
|
+
).href;
|
1467
|
+
process.send({
|
1468
|
+
"watch:import": WATCH_MODE_MESSAGE_USES_ARRAYS ? [pathToSend] : pathToSend
|
1469
|
+
});
|
1470
|
+
}
|
1471
|
+
return {
|
1472
|
+
format,
|
1473
|
+
source: await fs.promises.readFile(filePath, `utf8`),
|
1474
|
+
shortCircuit: true
|
1475
|
+
};
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
const ArrayIsArray = Array.isArray;
|
1479
|
+
const JSONStringify = JSON.stringify;
|
1480
|
+
const ObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
|
1481
|
+
const ObjectPrototypeHasOwnProperty = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
1482
|
+
const RegExpPrototypeExec = (obj, string) => RegExp.prototype.exec.call(obj, string);
|
1483
|
+
const RegExpPrototypeSymbolReplace = (obj, ...rest) => RegExp.prototype[Symbol.replace].apply(obj, rest);
|
1484
|
+
const StringPrototypeEndsWith = (str, ...rest) => String.prototype.endsWith.apply(str, rest);
|
1485
|
+
const StringPrototypeIncludes = (str, ...rest) => String.prototype.includes.apply(str, rest);
|
1486
|
+
const StringPrototypeLastIndexOf = (str, ...rest) => String.prototype.lastIndexOf.apply(str, rest);
|
1487
|
+
const StringPrototypeIndexOf = (str, ...rest) => String.prototype.indexOf.apply(str, rest);
|
1488
|
+
const StringPrototypeReplace = (str, ...rest) => String.prototype.replace.apply(str, rest);
|
1489
|
+
const StringPrototypeSlice = (str, ...rest) => String.prototype.slice.apply(str, rest);
|
1490
|
+
const StringPrototypeStartsWith = (str, ...rest) => String.prototype.startsWith.apply(str, rest);
|
1491
|
+
const SafeMap = Map;
|
1492
|
+
const JSONParse = JSON.parse;
|
1493
|
+
|
1494
|
+
function createErrorType(code, messageCreator, errorType) {
|
1495
|
+
return class extends errorType {
|
1496
|
+
constructor(...args) {
|
1497
|
+
super(messageCreator(...args));
|
1498
|
+
this.code = code;
|
1499
|
+
this.name = `${errorType.name} [${code}]`;
|
1500
|
+
}
|
1501
|
+
};
|
1502
|
+
}
|
1503
|
+
const ERR_PACKAGE_IMPORT_NOT_DEFINED = createErrorType(
|
1504
|
+
`ERR_PACKAGE_IMPORT_NOT_DEFINED`,
|
1505
|
+
(specifier, packagePath, base) => {
|
1506
|
+
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ``} imported from ${base}`;
|
1507
|
+
},
|
1508
|
+
TypeError
|
1509
|
+
);
|
1510
|
+
const ERR_INVALID_MODULE_SPECIFIER = createErrorType(
|
1511
|
+
`ERR_INVALID_MODULE_SPECIFIER`,
|
1512
|
+
(request, reason, base = void 0) => {
|
1513
|
+
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ``}`;
|
1514
|
+
},
|
1515
|
+
TypeError
|
1516
|
+
);
|
1517
|
+
const ERR_INVALID_PACKAGE_TARGET = createErrorType(
|
1518
|
+
`ERR_INVALID_PACKAGE_TARGET`,
|
1519
|
+
(pkgPath, key, target, isImport = false, base = void 0) => {
|
1520
|
+
const relError = typeof target === `string` && !isImport && target.length && !StringPrototypeStartsWith(target, `./`);
|
1521
|
+
if (key === `.`) {
|
1522
|
+
assert(isImport === false);
|
1523
|
+
return `Invalid "exports" main target ${JSONStringify(target)} defined in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`;
|
1524
|
+
}
|
1525
|
+
return `Invalid "${isImport ? `imports` : `exports`}" target ${JSONStringify(
|
1526
|
+
target
|
1527
|
+
)} defined for '${key}' in the package config ${pkgPath}package.json${base ? ` imported from ${base}` : ``}${relError ? `; targets must start with "./"` : ``}`;
|
1528
|
+
},
|
1529
|
+
Error
|
1530
|
+
);
|
1531
|
+
const ERR_INVALID_PACKAGE_CONFIG = createErrorType(
|
1532
|
+
`ERR_INVALID_PACKAGE_CONFIG`,
|
1533
|
+
(path, base, message) => {
|
1534
|
+
return `Invalid package config ${path}${base ? ` while importing ${base}` : ``}${message ? `. ${message}` : ``}`;
|
1535
|
+
},
|
1536
|
+
Error
|
1537
|
+
);
|
1538
|
+
|
1539
|
+
function filterOwnProperties(source, keys) {
|
1540
|
+
const filtered = /* @__PURE__ */ Object.create(null);
|
1541
|
+
for (let i = 0; i < keys.length; i++) {
|
1542
|
+
const key = keys[i];
|
1543
|
+
if (ObjectPrototypeHasOwnProperty(source, key)) {
|
1544
|
+
filtered[key] = source[key];
|
1545
|
+
}
|
1546
|
+
}
|
1547
|
+
return filtered;
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
const packageJSONCache = new SafeMap();
|
1551
|
+
function getPackageConfig(path, specifier, base, readFileSyncFn) {
|
1552
|
+
const existing = packageJSONCache.get(path);
|
1553
|
+
if (existing !== void 0) {
|
1554
|
+
return existing;
|
1555
|
+
}
|
1556
|
+
const source = readFileSyncFn(path);
|
1557
|
+
if (source === void 0) {
|
1558
|
+
const packageConfig2 = {
|
1559
|
+
pjsonPath: path,
|
1560
|
+
exists: false,
|
1561
|
+
main: void 0,
|
1562
|
+
name: void 0,
|
1563
|
+
type: "none",
|
1564
|
+
exports: void 0,
|
1565
|
+
imports: void 0
|
1566
|
+
};
|
1567
|
+
packageJSONCache.set(path, packageConfig2);
|
1568
|
+
return packageConfig2;
|
1569
|
+
}
|
1570
|
+
let packageJSON;
|
1571
|
+
try {
|
1572
|
+
packageJSON = JSONParse(source);
|
1573
|
+
} catch (error) {
|
1574
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
1575
|
+
path,
|
1576
|
+
(base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier),
|
1577
|
+
error.message
|
1578
|
+
);
|
1579
|
+
}
|
1580
|
+
let { imports, main, name, type } = filterOwnProperties(packageJSON, [
|
1581
|
+
"imports",
|
1582
|
+
"main",
|
1583
|
+
"name",
|
1584
|
+
"type"
|
1585
|
+
]);
|
1586
|
+
const exports = ObjectPrototypeHasOwnProperty(packageJSON, "exports") ? packageJSON.exports : void 0;
|
1587
|
+
if (typeof imports !== "object" || imports === null) {
|
1588
|
+
imports = void 0;
|
1589
|
+
}
|
1590
|
+
if (typeof main !== "string") {
|
1591
|
+
main = void 0;
|
1592
|
+
}
|
1593
|
+
if (typeof name !== "string") {
|
1594
|
+
name = void 0;
|
1595
|
+
}
|
1596
|
+
if (type !== "module" && type !== "commonjs") {
|
1597
|
+
type = "none";
|
1598
|
+
}
|
1599
|
+
const packageConfig = {
|
1600
|
+
pjsonPath: path,
|
1601
|
+
exists: true,
|
1602
|
+
main,
|
1603
|
+
name,
|
1604
|
+
type,
|
1605
|
+
exports,
|
1606
|
+
imports
|
1607
|
+
};
|
1608
|
+
packageJSONCache.set(path, packageConfig);
|
1609
|
+
return packageConfig;
|
1610
|
+
}
|
1611
|
+
function getPackageScopeConfig(resolved, readFileSyncFn) {
|
1612
|
+
let packageJSONUrl = new URL("./package.json", resolved);
|
1613
|
+
while (true) {
|
1614
|
+
const packageJSONPath2 = packageJSONUrl.pathname;
|
1615
|
+
if (StringPrototypeEndsWith(packageJSONPath2, "node_modules/package.json")) {
|
1616
|
+
break;
|
1617
|
+
}
|
1618
|
+
const packageConfig2 = getPackageConfig(
|
1619
|
+
fileURLToPath(packageJSONUrl),
|
1620
|
+
resolved,
|
1621
|
+
void 0,
|
1622
|
+
readFileSyncFn
|
1623
|
+
);
|
1624
|
+
if (packageConfig2.exists) {
|
1625
|
+
return packageConfig2;
|
1626
|
+
}
|
1627
|
+
const lastPackageJSONUrl = packageJSONUrl;
|
1628
|
+
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
1629
|
+
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
|
1630
|
+
break;
|
1631
|
+
}
|
1632
|
+
}
|
1633
|
+
const packageJSONPath = fileURLToPath(packageJSONUrl);
|
1634
|
+
const packageConfig = {
|
1635
|
+
pjsonPath: packageJSONPath,
|
1636
|
+
exists: false,
|
1637
|
+
main: void 0,
|
1638
|
+
name: void 0,
|
1639
|
+
type: "none",
|
1640
|
+
exports: void 0,
|
1641
|
+
imports: void 0
|
1642
|
+
};
|
1643
|
+
packageJSONCache.set(packageJSONPath, packageConfig);
|
1644
|
+
return packageConfig;
|
1645
|
+
}
|
1646
|
+
|
1647
|
+
/**
|
1648
|
+
@license
|
1649
|
+
Copyright Node.js contributors. All rights reserved.
|
1650
|
+
|
1651
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
1652
|
+
of this software and associated documentation files (the "Software"), to
|
1653
|
+
deal in the Software without restriction, including without limitation the
|
1654
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
1655
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
1656
|
+
furnished to do so, subject to the following conditions:
|
1657
|
+
|
1658
|
+
The above copyright notice and this permission notice shall be included in
|
1659
|
+
all copies or substantial portions of the Software.
|
1660
|
+
|
1661
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
1662
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
1663
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
1664
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
1665
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
1666
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
1667
|
+
IN THE SOFTWARE.
|
1668
|
+
*/
|
1669
|
+
function throwImportNotDefined(specifier, packageJSONUrl, base) {
|
1670
|
+
throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
|
1671
|
+
specifier,
|
1672
|
+
packageJSONUrl && fileURLToPath(new URL(".", packageJSONUrl)),
|
1673
|
+
fileURLToPath(base)
|
1674
|
+
);
|
1675
|
+
}
|
1676
|
+
function throwInvalidSubpath(subpath, packageJSONUrl, internal, base) {
|
1677
|
+
const reason = `request is not a valid subpath for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJSONUrl)}`;
|
1678
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(
|
1679
|
+
subpath,
|
1680
|
+
reason,
|
1681
|
+
base && fileURLToPath(base)
|
1682
|
+
);
|
1683
|
+
}
|
1684
|
+
function throwInvalidPackageTarget(subpath, target, packageJSONUrl, internal, base) {
|
1685
|
+
if (typeof target === "object" && target !== null) {
|
1686
|
+
target = JSONStringify(target, null, "");
|
1687
|
+
} else {
|
1688
|
+
target = `${target}`;
|
1689
|
+
}
|
1690
|
+
throw new ERR_INVALID_PACKAGE_TARGET(
|
1691
|
+
fileURLToPath(new URL(".", packageJSONUrl)),
|
1692
|
+
subpath,
|
1693
|
+
target,
|
1694
|
+
internal,
|
1695
|
+
base && fileURLToPath(base)
|
1696
|
+
);
|
1697
|
+
}
|
1698
|
+
const invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
1699
|
+
const patternRegEx = /\*/g;
|
1700
|
+
function resolvePackageTargetString(target, subpath, match, packageJSONUrl, base, pattern, internal, conditions) {
|
1701
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/")
|
1702
|
+
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
|
1703
|
+
if (!StringPrototypeStartsWith(target, "./")) {
|
1704
|
+
if (internal && !StringPrototypeStartsWith(target, "../") && !StringPrototypeStartsWith(target, "/")) {
|
1705
|
+
let isURL = false;
|
1706
|
+
try {
|
1707
|
+
new URL(target);
|
1708
|
+
isURL = true;
|
1709
|
+
} catch {
|
1710
|
+
}
|
1711
|
+
if (!isURL) {
|
1712
|
+
const exportTarget = pattern ? RegExpPrototypeSymbolReplace(patternRegEx, target, () => subpath) : target + subpath;
|
1713
|
+
return exportTarget;
|
1714
|
+
}
|
1715
|
+
}
|
1716
|
+
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
|
1717
|
+
}
|
1718
|
+
if (RegExpPrototypeExec(
|
1719
|
+
invalidSegmentRegEx,
|
1720
|
+
StringPrototypeSlice(target, 2)
|
1721
|
+
) !== null)
|
1722
|
+
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
|
1723
|
+
const resolved = new URL(target, packageJSONUrl);
|
1724
|
+
const resolvedPath = resolved.pathname;
|
1725
|
+
const packagePath = new URL(".", packageJSONUrl).pathname;
|
1726
|
+
if (!StringPrototypeStartsWith(resolvedPath, packagePath))
|
1727
|
+
throwInvalidPackageTarget(match, target, packageJSONUrl, internal, base);
|
1728
|
+
if (subpath === "")
|
1729
|
+
return resolved;
|
1730
|
+
if (RegExpPrototypeExec(invalidSegmentRegEx, subpath) !== null) {
|
1731
|
+
const request = pattern ? StringPrototypeReplace(match, "*", () => subpath) : match + subpath;
|
1732
|
+
throwInvalidSubpath(request, packageJSONUrl, internal, base);
|
1733
|
+
}
|
1734
|
+
if (pattern) {
|
1735
|
+
return new URL(
|
1736
|
+
RegExpPrototypeSymbolReplace(patternRegEx, resolved.href, () => subpath)
|
1737
|
+
);
|
1738
|
+
}
|
1739
|
+
return new URL(subpath, resolved);
|
1740
|
+
}
|
1741
|
+
function isArrayIndex(key) {
|
1742
|
+
const keyNum = +key;
|
1743
|
+
if (`${keyNum}` !== key)
|
1744
|
+
return false;
|
1745
|
+
return keyNum >= 0 && keyNum < 4294967295;
|
1746
|
+
}
|
1747
|
+
function resolvePackageTarget(packageJSONUrl, target, subpath, packageSubpath, base, pattern, internal, conditions) {
|
1748
|
+
if (typeof target === "string") {
|
1749
|
+
return resolvePackageTargetString(
|
1750
|
+
target,
|
1751
|
+
subpath,
|
1752
|
+
packageSubpath,
|
1753
|
+
packageJSONUrl,
|
1754
|
+
base,
|
1755
|
+
pattern,
|
1756
|
+
internal);
|
1757
|
+
} else if (ArrayIsArray(target)) {
|
1758
|
+
if (target.length === 0) {
|
1759
|
+
return null;
|
1760
|
+
}
|
1761
|
+
let lastException;
|
1762
|
+
for (let i = 0; i < target.length; i++) {
|
1763
|
+
const targetItem = target[i];
|
1764
|
+
let resolveResult;
|
1765
|
+
try {
|
1766
|
+
resolveResult = resolvePackageTarget(
|
1767
|
+
packageJSONUrl,
|
1768
|
+
targetItem,
|
1769
|
+
subpath,
|
1770
|
+
packageSubpath,
|
1771
|
+
base,
|
1772
|
+
pattern,
|
1773
|
+
internal,
|
1774
|
+
conditions
|
1775
|
+
);
|
1776
|
+
} catch (e) {
|
1777
|
+
lastException = e;
|
1778
|
+
if (e.code === "ERR_INVALID_PACKAGE_TARGET") {
|
1779
|
+
continue;
|
1780
|
+
}
|
1781
|
+
throw e;
|
1782
|
+
}
|
1783
|
+
if (resolveResult === void 0) {
|
1784
|
+
continue;
|
1785
|
+
}
|
1786
|
+
if (resolveResult === null) {
|
1787
|
+
lastException = null;
|
1788
|
+
continue;
|
1789
|
+
}
|
1790
|
+
return resolveResult;
|
1791
|
+
}
|
1792
|
+
if (lastException === void 0 || lastException === null)
|
1793
|
+
return lastException;
|
1794
|
+
throw lastException;
|
1795
|
+
} else if (typeof target === "object" && target !== null) {
|
1796
|
+
const keys = ObjectGetOwnPropertyNames(target);
|
1797
|
+
for (let i = 0; i < keys.length; i++) {
|
1798
|
+
const key = keys[i];
|
1799
|
+
if (isArrayIndex(key)) {
|
1800
|
+
throw new ERR_INVALID_PACKAGE_CONFIG(
|
1801
|
+
fileURLToPath(packageJSONUrl),
|
1802
|
+
base,
|
1803
|
+
'"exports" cannot contain numeric property keys.'
|
1804
|
+
);
|
1805
|
+
}
|
1806
|
+
}
|
1807
|
+
for (let i = 0; i < keys.length; i++) {
|
1808
|
+
const key = keys[i];
|
1809
|
+
if (key === "default" || conditions.has(key)) {
|
1810
|
+
const conditionalTarget = target[key];
|
1811
|
+
const resolveResult = resolvePackageTarget(
|
1812
|
+
packageJSONUrl,
|
1813
|
+
conditionalTarget,
|
1814
|
+
subpath,
|
1815
|
+
packageSubpath,
|
1816
|
+
base,
|
1817
|
+
pattern,
|
1818
|
+
internal,
|
1819
|
+
conditions
|
1820
|
+
);
|
1821
|
+
if (resolveResult === void 0)
|
1822
|
+
continue;
|
1823
|
+
return resolveResult;
|
1824
|
+
}
|
1825
|
+
}
|
1826
|
+
return void 0;
|
1827
|
+
} else if (target === null) {
|
1828
|
+
return null;
|
1829
|
+
}
|
1830
|
+
throwInvalidPackageTarget(
|
1831
|
+
packageSubpath,
|
1832
|
+
target,
|
1833
|
+
packageJSONUrl,
|
1834
|
+
internal,
|
1835
|
+
base
|
1836
|
+
);
|
1837
|
+
}
|
1838
|
+
function patternKeyCompare(a, b) {
|
1839
|
+
const aPatternIndex = StringPrototypeIndexOf(a, "*");
|
1840
|
+
const bPatternIndex = StringPrototypeIndexOf(b, "*");
|
1841
|
+
const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
1842
|
+
const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
1843
|
+
if (baseLenA > baseLenB)
|
1844
|
+
return -1;
|
1845
|
+
if (baseLenB > baseLenA)
|
1846
|
+
return 1;
|
1847
|
+
if (aPatternIndex === -1)
|
1848
|
+
return 1;
|
1849
|
+
if (bPatternIndex === -1)
|
1850
|
+
return -1;
|
1851
|
+
if (a.length > b.length)
|
1852
|
+
return -1;
|
1853
|
+
if (b.length > a.length)
|
1854
|
+
return 1;
|
1855
|
+
return 0;
|
1856
|
+
}
|
1857
|
+
function packageImportsResolve({
|
1858
|
+
name,
|
1859
|
+
base,
|
1860
|
+
conditions,
|
1861
|
+
readFileSyncFn
|
1862
|
+
}) {
|
1863
|
+
if (name === "#" || StringPrototypeStartsWith(name, "#/") || StringPrototypeEndsWith(name, "/")) {
|
1864
|
+
const reason = "is not a valid internal imports specifier name";
|
1865
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath(base));
|
1866
|
+
}
|
1867
|
+
let packageJSONUrl;
|
1868
|
+
const packageConfig = getPackageScopeConfig(base, readFileSyncFn);
|
1869
|
+
if (packageConfig.exists) {
|
1870
|
+
packageJSONUrl = pathToFileURL(packageConfig.pjsonPath);
|
1871
|
+
const imports = packageConfig.imports;
|
1872
|
+
if (imports) {
|
1873
|
+
if (ObjectPrototypeHasOwnProperty(imports, name) && !StringPrototypeIncludes(name, "*")) {
|
1874
|
+
const resolveResult = resolvePackageTarget(
|
1875
|
+
packageJSONUrl,
|
1876
|
+
imports[name],
|
1877
|
+
"",
|
1878
|
+
name,
|
1879
|
+
base,
|
1880
|
+
false,
|
1881
|
+
true,
|
1882
|
+
conditions
|
1883
|
+
);
|
1884
|
+
if (resolveResult != null) {
|
1885
|
+
return resolveResult;
|
1886
|
+
}
|
1887
|
+
} else {
|
1888
|
+
let bestMatch = "";
|
1889
|
+
let bestMatchSubpath;
|
1890
|
+
const keys = ObjectGetOwnPropertyNames(imports);
|
1891
|
+
for (let i = 0; i < keys.length; i++) {
|
1892
|
+
const key = keys[i];
|
1893
|
+
const patternIndex = StringPrototypeIndexOf(key, "*");
|
1894
|
+
if (patternIndex !== -1 && StringPrototypeStartsWith(
|
1895
|
+
name,
|
1896
|
+
StringPrototypeSlice(key, 0, patternIndex)
|
1897
|
+
)) {
|
1898
|
+
const patternTrailer = StringPrototypeSlice(key, patternIndex + 1);
|
1899
|
+
if (name.length >= key.length && StringPrototypeEndsWith(name, patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && StringPrototypeLastIndexOf(key, "*") === patternIndex) {
|
1900
|
+
bestMatch = key;
|
1901
|
+
bestMatchSubpath = StringPrototypeSlice(
|
1902
|
+
name,
|
1903
|
+
patternIndex,
|
1904
|
+
name.length - patternTrailer.length
|
1905
|
+
);
|
1906
|
+
}
|
1907
|
+
}
|
1908
|
+
}
|
1909
|
+
if (bestMatch) {
|
1910
|
+
const target = imports[bestMatch];
|
1911
|
+
const resolveResult = resolvePackageTarget(
|
1912
|
+
packageJSONUrl,
|
1913
|
+
target,
|
1914
|
+
bestMatchSubpath,
|
1915
|
+
bestMatch,
|
1916
|
+
base,
|
1917
|
+
true,
|
1918
|
+
true,
|
1919
|
+
conditions
|
1920
|
+
);
|
1921
|
+
if (resolveResult != null) {
|
1922
|
+
return resolveResult;
|
1923
|
+
}
|
1924
|
+
}
|
1925
|
+
}
|
1926
|
+
}
|
1927
|
+
}
|
1928
|
+
throwImportNotDefined(name, packageJSONUrl, base);
|
1929
|
+
}
|
1930
|
+
|
1931
|
+
const pathRegExp = /^(?![a-zA-Z]:[\\/]|\\\\|\.{0,2}(?:\/|$))((?:node:)?(?:@[^/]+\/)?[^/]+)\/*(.*|)$/;
|
1932
|
+
const isRelativeRegexp = /^\.{0,2}\//;
|
1933
|
+
function tryReadFile(filePath) {
|
1934
|
+
try {
|
1935
|
+
return fs.readFileSync(filePath, `utf8`);
|
1936
|
+
} catch (err) {
|
1937
|
+
if (err.code === `ENOENT`)
|
1938
|
+
return void 0;
|
1939
|
+
throw err;
|
1940
|
+
}
|
1941
|
+
}
|
1942
|
+
async function resolvePrivateRequest(specifier, issuer, context, nextResolve) {
|
1943
|
+
const resolved = packageImportsResolve({
|
1944
|
+
name: specifier,
|
1945
|
+
base: pathToFileURL(issuer),
|
1946
|
+
conditions: new Set(context.conditions),
|
1947
|
+
readFileSyncFn: tryReadFile
|
1948
|
+
});
|
1949
|
+
if (resolved instanceof URL$1) {
|
1950
|
+
return { url: resolved.href, shortCircuit: true };
|
1951
|
+
} else {
|
1952
|
+
if (resolved.startsWith(`#`))
|
1953
|
+
throw new Error(`Mapping from one private import to another isn't allowed`);
|
1954
|
+
return resolve$1(resolved, context, nextResolve);
|
1955
|
+
}
|
1956
|
+
}
|
1957
|
+
async function resolve$1(originalSpecifier, context, nextResolve) {
|
1958
|
+
var _a;
|
1959
|
+
const { findPnpApi } = moduleExports;
|
1960
|
+
if (!findPnpApi || isBuiltinModule(originalSpecifier))
|
1961
|
+
return nextResolve(originalSpecifier, context, nextResolve);
|
1962
|
+
let specifier = originalSpecifier;
|
1963
|
+
const url = tryParseURL(specifier, isRelativeRegexp.test(specifier) ? context.parentURL : void 0);
|
1964
|
+
if (url) {
|
1965
|
+
if (url.protocol !== `file:`)
|
1966
|
+
return nextResolve(originalSpecifier, context, nextResolve);
|
1967
|
+
specifier = fileURLToPath(url);
|
1968
|
+
}
|
1969
|
+
const { parentURL, conditions = [] } = context;
|
1970
|
+
const issuer = parentURL ? fileURLToPath(parentURL) : process.cwd();
|
1971
|
+
const pnpapi = (_a = findPnpApi(issuer)) != null ? _a : url ? findPnpApi(specifier) : null;
|
1972
|
+
if (!pnpapi)
|
1973
|
+
return nextResolve(originalSpecifier, context, nextResolve);
|
1974
|
+
if (specifier.startsWith(`#`))
|
1975
|
+
return resolvePrivateRequest(specifier, issuer, context, nextResolve);
|
1976
|
+
const dependencyNameMatch = specifier.match(pathRegExp);
|
1977
|
+
let allowLegacyResolve = false;
|
1978
|
+
if (dependencyNameMatch) {
|
1979
|
+
const [, dependencyName, subPath] = dependencyNameMatch;
|
1980
|
+
if (subPath === `` && dependencyName !== `pnpapi`) {
|
1981
|
+
const resolved = pnpapi.resolveToUnqualified(`${dependencyName}/package.json`, issuer);
|
1982
|
+
if (resolved) {
|
1983
|
+
const content = await tryReadFile$1(resolved);
|
1984
|
+
if (content) {
|
1985
|
+
const pkg = JSON.parse(content);
|
1986
|
+
allowLegacyResolve = pkg.exports == null;
|
1987
|
+
}
|
1988
|
+
}
|
1989
|
+
}
|
1990
|
+
}
|
1991
|
+
const result = pnpapi.resolveRequest(specifier, issuer, {
|
1992
|
+
conditions: new Set(conditions),
|
1993
|
+
extensions: allowLegacyResolve ? void 0 : []
|
1994
|
+
});
|
1995
|
+
if (!result)
|
1996
|
+
throw new Error(`Resolving '${specifier}' from '${issuer}' failed`);
|
1997
|
+
const resultURL = pathToFileURL(result);
|
1998
|
+
if (url) {
|
1999
|
+
resultURL.search = url.search;
|
2000
|
+
resultURL.hash = url.hash;
|
2001
|
+
}
|
2002
|
+
if (!parentURL)
|
2003
|
+
setEntrypointPath(fileURLToPath(resultURL));
|
2004
|
+
return {
|
2005
|
+
url: resultURL.href,
|
2006
|
+
shortCircuit: true
|
2007
|
+
};
|
2008
|
+
}
|
2009
|
+
|
2010
|
+
const binding = process.binding(`fs`);
|
2011
|
+
const originalfstat = binding.fstat;
|
2012
|
+
const ZIP_MASK = 4278190080;
|
2013
|
+
const ZIP_MAGIC = 704643072;
|
2014
|
+
binding.fstat = function(...args) {
|
2015
|
+
const [fd, useBigint, req] = args;
|
2016
|
+
if ((fd & ZIP_MASK) === ZIP_MAGIC && useBigint === false && req === void 0) {
|
2017
|
+
try {
|
2018
|
+
const stats = fs.fstatSync(fd);
|
2019
|
+
return new Float64Array([
|
2020
|
+
stats.dev,
|
2021
|
+
stats.mode,
|
2022
|
+
stats.nlink,
|
2023
|
+
stats.uid,
|
2024
|
+
stats.gid,
|
2025
|
+
stats.rdev,
|
2026
|
+
stats.blksize,
|
2027
|
+
stats.ino,
|
2028
|
+
stats.size,
|
2029
|
+
stats.blocks
|
2030
|
+
]);
|
2031
|
+
} catch {
|
2032
|
+
}
|
2033
|
+
}
|
2034
|
+
return originalfstat.apply(this, args);
|
2035
|
+
};
|
2036
|
+
|
2037
|
+
const resolve = resolve$1;
|
2038
|
+
const getFormat = HAS_CONSOLIDATED_HOOKS ? void 0 : getFormat$1;
|
2039
|
+
const getSource = HAS_CONSOLIDATED_HOOKS ? void 0 : getSource$1;
|
2040
|
+
const load = HAS_CONSOLIDATED_HOOKS ? load$1 : void 0;
|
2041
|
+
|
2042
|
+
export { getFormat, getSource, load, resolve };
|