@cloudflare/vitest-pool-workers 0.2.10 → 0.2.11
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/dist/config/index.cjs +6 -3
- package/dist/config/index.cjs.map +1 -1
- package/dist/pool/index.mjs +120 -61
- package/dist/pool/index.mjs.map +1 -1
- package/dist/worker/index.mjs +10 -5
- package/dist/worker/index.mjs.map +1 -1
- package/dist/worker/lib/cloudflare/mock-agent.cjs +165 -35
- package/dist/worker/lib/cloudflare/mock-agent.cjs.map +3 -3
- package/dist/worker/lib/cloudflare/test-internal.mjs +35 -20
- package/dist/worker/lib/cloudflare/test-internal.mjs.map +1 -1
- package/dist/worker/lib/cloudflare/test-runner.mjs +6 -3
- package/dist/worker/lib/cloudflare/test-runner.mjs.map +1 -1
- package/dist/worker/lib/node/console.mjs +20 -13
- package/dist/worker/lib/node/console.mjs.map +1 -1
- package/dist/worker/lib/node/url.mjs +2 -2
- package/dist/worker/lib/node/url.mjs.map +1 -1
- package/package.json +3 -3
- package/test/cloudflare-test.d.ts +2 -2
package/dist/config/index.cjs
CHANGED
|
@@ -85,9 +85,11 @@ function mapAnyConfigExport(f, config) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
function ensureArrayIncludes(array, items) {
|
|
88
|
-
for (const item of items)
|
|
89
|
-
if (!array.includes(item))
|
|
88
|
+
for (const item of items) {
|
|
89
|
+
if (!array.includes(item)) {
|
|
90
90
|
array.push(item);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
91
93
|
}
|
|
92
94
|
var requiredConditions = ["workerd", "worker", "browser"];
|
|
93
95
|
var requiredMainFields = ["browser", "module", "jsnext:main", "jsnext"];
|
|
@@ -102,8 +104,9 @@ var configPlugin = {
|
|
|
102
104
|
config.ssr ??= {};
|
|
103
105
|
config.test ??= {};
|
|
104
106
|
const nodeIndex = config.resolve.conditions.indexOf("node");
|
|
105
|
-
if (nodeIndex !== -1)
|
|
107
|
+
if (nodeIndex !== -1) {
|
|
106
108
|
config.resolve.conditions.splice(nodeIndex, 1);
|
|
109
|
+
}
|
|
107
110
|
ensureArrayIncludes(config.resolve.conditions, requiredConditions);
|
|
108
111
|
ensureArrayIncludes(config.resolve.mainFields, requiredMainFields);
|
|
109
112
|
config.ssr.target = "webworker";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/config/index.ts", "../../src/config/d1.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AACnB,iCAAqD;;;ACDrD,qBAAe;AACf,uBAAiB;AAOjB,eAAsB,iBACrB,gBACyB;AACzB,QAAM,EAAE,uBAAuB,IAAI,MAAM,OAAO,UAAU;AAC1D,QAAM,QAAQ,eAAAA,QACZ,YAAY,cAAc,EAC1B,OAAO,CAAC,SAAS,KAAK,SAAS,MAAM,CAAC;AACxC,QAAM,KAAK,CAAC,GAAG,MAAM;AACpB,UAAM,UAAU,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC;AACxC,UAAM,UAAU,SAAS,EAAE,MAAM,GAAG,EAAE,CAAC,CAAC;AACxC,WAAO,UAAU;AAAA,EAClB,CAAC;AACD,SAAO,MAAM,IAAI,CAAC,SAAS;AAC1B,UAAM,gBAAgB,iBAAAC,QAAK,KAAK,gBAAgB,IAAI;AACpD,UAAM,YAAY,eAAAD,QAAG,aAAa,eAAe,MAAM;AACvD,UAAM,UAAU,uBAAuB,SAAS;AAChD,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB,CAAC;AACF;;;ADhBA,IAAI;AACJ,WAAW,oBAAoB,SAAU,OAAO,SAAS;AAExD,cAAY,IAAI,0CAAe;AAC/B,UAAQ,MAAM,MAAM;AACpB,UAAQ,MAAM,MAAM;AACpB,UAAQ,MAAM,YAAY,OAAO,SAAS,QA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AAAA,IAC9C;AAIA,wBAAoB,OAAO,QAAQ,YAAY,kBAAkB;AAIjE,wBAAoB,OAAO,QAAQ,YAAY,kBAAkB;AAIjE,WAAO,IAAI,SAAS;AAIpB,WAAO,KAAK,SAAS;AAAA,EACtB;AACD;AAEA,SAAS,oBAA0C,QAAc;AAChE,SAAO,YAAY,CAAC;AACpB,SAAO,QAAQ,KAAK,YAAY;AAChC,SAAO;AACR;AAEO,SAAS,oBACf,QAC2C;AAC3C,SAAO,mBAAmB,qBAAqB,MAAM;AACtD;AAEO,SAAS,qBACf,QAC8C;AAC9C,SAAO,mBAAmB,qBAAqB,MAAM;AACtD;",
|
|
5
5
|
"names": ["fs", "path", "assert"]
|
|
6
6
|
}
|
package/dist/pool/index.mjs
CHANGED
|
@@ -41,8 +41,9 @@ function createChunkingSocket(socket, maxChunkByteLength = 1048576) {
|
|
|
41
41
|
message = chunks + decoder.decode();
|
|
42
42
|
chunks = void 0;
|
|
43
43
|
}
|
|
44
|
-
for (const listener of listeners)
|
|
44
|
+
for (const listener of listeners) {
|
|
45
45
|
listener(message);
|
|
46
|
+
}
|
|
46
47
|
} else {
|
|
47
48
|
chunks ??= "";
|
|
48
49
|
chunks += decoder.decode(message, { stream: true });
|
|
@@ -88,10 +89,11 @@ function getProjectPath(project) {
|
|
|
88
89
|
}
|
|
89
90
|
function getRelativeProjectPath(project) {
|
|
90
91
|
const projectPath = getProjectPath(project);
|
|
91
|
-
if (typeof projectPath === "number")
|
|
92
|
+
if (typeof projectPath === "number") {
|
|
92
93
|
return projectPath;
|
|
93
|
-
else
|
|
94
|
+
} else {
|
|
94
95
|
return path.relative("", projectPath);
|
|
96
|
+
}
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// src/pool/config.ts
|
|
@@ -132,12 +134,14 @@ function isZodErrorLike(value) {
|
|
|
132
134
|
return typeof value === "object" && value !== null && "issues" in value && Array.isArray(value.issues);
|
|
133
135
|
}
|
|
134
136
|
function coalesceZodErrors(ref, thrown) {
|
|
135
|
-
if (!isZodErrorLike(thrown))
|
|
137
|
+
if (!isZodErrorLike(thrown)) {
|
|
136
138
|
throw thrown;
|
|
137
|
-
|
|
139
|
+
}
|
|
140
|
+
if (ref.value === void 0) {
|
|
138
141
|
ref.value = thrown;
|
|
139
|
-
else
|
|
142
|
+
} else {
|
|
140
143
|
ref.value.issues.push(...thrown.issues);
|
|
144
|
+
}
|
|
141
145
|
}
|
|
142
146
|
function parseWorkerOptions(rootPath, value, withoutScript, opts) {
|
|
143
147
|
if (withoutScript) {
|
|
@@ -156,10 +160,12 @@ function parseWorkerOptions(rootPath, value, withoutScript, opts) {
|
|
|
156
160
|
coalesceZodErrors(errorRef, e);
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
|
-
if (errorRef.value !== void 0)
|
|
163
|
+
if (errorRef.value !== void 0) {
|
|
160
164
|
throw errorRef.value;
|
|
161
|
-
|
|
165
|
+
}
|
|
166
|
+
if (withoutScript) {
|
|
162
167
|
delete value["script"];
|
|
168
|
+
}
|
|
163
169
|
return result;
|
|
164
170
|
}
|
|
165
171
|
async function parseCustomPoolOptions(rootPath, value, opts) {
|
|
@@ -204,8 +210,9 @@ async function parseCustomPoolOptions(rootPath, value, opts) {
|
|
|
204
210
|
}
|
|
205
211
|
});
|
|
206
212
|
}
|
|
207
|
-
if (errorRef.value !== void 0)
|
|
213
|
+
if (errorRef.value !== void 0) {
|
|
208
214
|
throw errorRef.value;
|
|
215
|
+
}
|
|
209
216
|
if (options.wrangler?.configPath !== void 0) {
|
|
210
217
|
const configPath = path2.resolve(rootPath, options.wrangler.configPath);
|
|
211
218
|
options.wrangler.configPath = configPath;
|
|
@@ -255,8 +262,9 @@ async function parseProjectOptions(project) {
|
|
|
255
262
|
path: OPTIONS_PATH_ARRAY
|
|
256
263
|
});
|
|
257
264
|
} catch (e) {
|
|
258
|
-
if (!isZodErrorLike(e))
|
|
265
|
+
if (!isZodErrorLike(e)) {
|
|
259
266
|
throw e;
|
|
267
|
+
}
|
|
260
268
|
let formatted;
|
|
261
269
|
try {
|
|
262
270
|
formatted = formatZodError(e, {
|
|
@@ -288,8 +296,9 @@ import {
|
|
|
288
296
|
} from "miniflare";
|
|
289
297
|
async function handleSnapshotRequest(request, url) {
|
|
290
298
|
const filePath = url.searchParams.get("path");
|
|
291
|
-
if (filePath === null)
|
|
299
|
+
if (filePath === null) {
|
|
292
300
|
return new Response(null, { status: 400 });
|
|
301
|
+
}
|
|
293
302
|
if (request.method === "POST") {
|
|
294
303
|
await fs.mkdir(filePath, { recursive: true });
|
|
295
304
|
return new Response(null, { status: 204 });
|
|
@@ -304,8 +313,9 @@ async function handleSnapshotRequest(request, url) {
|
|
|
304
313
|
try {
|
|
305
314
|
return new Response(await fs.readFile(filePath));
|
|
306
315
|
} catch (e) {
|
|
307
|
-
if (!isFileNotFoundError(e))
|
|
316
|
+
if (!isFileNotFoundError(e)) {
|
|
308
317
|
throw e;
|
|
318
|
+
}
|
|
309
319
|
return new Response(null, { status: 404 });
|
|
310
320
|
}
|
|
311
321
|
}
|
|
@@ -313,8 +323,9 @@ async function handleSnapshotRequest(request, url) {
|
|
|
313
323
|
try {
|
|
314
324
|
await fs.unlink(filePath);
|
|
315
325
|
} catch (e) {
|
|
316
|
-
if (!isFileNotFoundError(e))
|
|
326
|
+
if (!isFileNotFoundError(e)) {
|
|
317
327
|
throw e;
|
|
328
|
+
}
|
|
318
329
|
}
|
|
319
330
|
return new Response(null, { status: 204 });
|
|
320
331
|
}
|
|
@@ -325,8 +336,9 @@ async function emptyDir(dirPath) {
|
|
|
325
336
|
try {
|
|
326
337
|
names = await fs.readdir(dirPath);
|
|
327
338
|
} catch (e) {
|
|
328
|
-
if (isFileNotFoundError(e))
|
|
339
|
+
if (isFileNotFoundError(e)) {
|
|
329
340
|
return;
|
|
341
|
+
}
|
|
330
342
|
throw e;
|
|
331
343
|
}
|
|
332
344
|
for (const name of names) {
|
|
@@ -401,15 +413,17 @@ async function pushStackedStorage(intoDepth, persistPath) {
|
|
|
401
413
|
);
|
|
402
414
|
await fs.mkdir(stackFramePath, { recursive: true });
|
|
403
415
|
for (const key of await fs.readdir(persistPath, { withFileTypes: true })) {
|
|
404
|
-
if (key.name === STACK_DIR_NAME)
|
|
416
|
+
if (key.name === STACK_DIR_NAME) {
|
|
405
417
|
continue;
|
|
418
|
+
}
|
|
406
419
|
const keyPath = path3.join(persistPath, key.name);
|
|
407
420
|
const stackFrameKeyPath = path3.join(stackFramePath, key.name);
|
|
408
421
|
assert2(key.isDirectory(), `Expected ${keyPath} to be a directory`);
|
|
409
422
|
let createdStackFrameKeyPath = false;
|
|
410
423
|
for (const name of await fs.readdir(keyPath)) {
|
|
411
|
-
if (name === BLOBS_DIR_NAME)
|
|
424
|
+
if (name === BLOBS_DIR_NAME) {
|
|
412
425
|
break;
|
|
426
|
+
}
|
|
413
427
|
if (!createdStackFrameKeyPath) {
|
|
414
428
|
createdStackFrameKeyPath = true;
|
|
415
429
|
await fs.mkdir(stackFrameKeyPath);
|
|
@@ -423,12 +437,14 @@ async function pushStackedStorage(intoDepth, persistPath) {
|
|
|
423
437
|
}
|
|
424
438
|
async function popStackedStorage(fromDepth, persistPath) {
|
|
425
439
|
for (const key of await fs.readdir(persistPath, { withFileTypes: true })) {
|
|
426
|
-
if (key.name === STACK_DIR_NAME)
|
|
440
|
+
if (key.name === STACK_DIR_NAME) {
|
|
427
441
|
continue;
|
|
442
|
+
}
|
|
428
443
|
const keyPath = path3.join(persistPath, key.name);
|
|
429
444
|
for (const name of await fs.readdir(keyPath)) {
|
|
430
|
-
if (name === BLOBS_DIR_NAME)
|
|
445
|
+
if (name === BLOBS_DIR_NAME) {
|
|
431
446
|
break;
|
|
447
|
+
}
|
|
432
448
|
const namePath = path3.join(keyPath, name);
|
|
433
449
|
assert2(name.endsWith(".sqlite"), `Expected .sqlite, got ${namePath}`);
|
|
434
450
|
await fs.unlink(namePath);
|
|
@@ -536,12 +552,14 @@ async function handleStorageRequest(request, mf) {
|
|
|
536
552
|
}
|
|
537
553
|
}
|
|
538
554
|
async function handleDurableObjectsRequest(request, mf, url) {
|
|
539
|
-
if (request.method !== "GET")
|
|
555
|
+
if (request.method !== "GET") {
|
|
540
556
|
return new Response(null, { status: 405 });
|
|
557
|
+
}
|
|
541
558
|
const { durableObjectPersistPath } = getState(mf);
|
|
542
559
|
const uniqueKey = url.searchParams.get("unique_key");
|
|
543
|
-
if (uniqueKey === null)
|
|
560
|
+
if (uniqueKey === null) {
|
|
544
561
|
return new Response(null, { status: 400 });
|
|
562
|
+
}
|
|
545
563
|
const namespacePath = path3.join(durableObjectPersistPath, uniqueKey);
|
|
546
564
|
const ids = [];
|
|
547
565
|
try {
|
|
@@ -556,17 +574,20 @@ async function handleDurableObjectsRequest(request, mf, url) {
|
|
|
556
574
|
}
|
|
557
575
|
}
|
|
558
576
|
} catch (e) {
|
|
559
|
-
if (!isFileNotFoundError(e))
|
|
577
|
+
if (!isFileNotFoundError(e)) {
|
|
560
578
|
throw e;
|
|
579
|
+
}
|
|
561
580
|
}
|
|
562
581
|
return Response.json(ids);
|
|
563
582
|
}
|
|
564
583
|
function handleLoopbackRequest(request, mf) {
|
|
565
584
|
const url = new URL(request.url);
|
|
566
|
-
if (url.pathname === "/snapshot")
|
|
585
|
+
if (url.pathname === "/snapshot") {
|
|
567
586
|
return handleSnapshotRequest(request, url);
|
|
568
|
-
|
|
587
|
+
}
|
|
588
|
+
if (url.pathname === "/storage") {
|
|
569
589
|
return handleStorageRequest(request, mf);
|
|
590
|
+
}
|
|
570
591
|
if (url.pathname === "/durable-objects") {
|
|
571
592
|
return handleDurableObjectsRequest(request, mf, url);
|
|
572
593
|
}
|
|
@@ -615,8 +636,9 @@ function isFile(filePath) {
|
|
|
615
636
|
try {
|
|
616
637
|
return fs2.statSync(filePath).isFile();
|
|
617
638
|
} catch (e) {
|
|
618
|
-
if (isFileNotFoundError(e))
|
|
639
|
+
if (isFileNotFoundError(e)) {
|
|
619
640
|
return false;
|
|
641
|
+
}
|
|
620
642
|
throw e;
|
|
621
643
|
}
|
|
622
644
|
}
|
|
@@ -624,8 +646,9 @@ function getParentPaths(filePath) {
|
|
|
624
646
|
const parentPaths = [];
|
|
625
647
|
while (true) {
|
|
626
648
|
const parentPath = posixPath.dirname(filePath);
|
|
627
|
-
if (parentPath === filePath)
|
|
649
|
+
if (parentPath === filePath) {
|
|
628
650
|
return parentPaths;
|
|
651
|
+
}
|
|
629
652
|
parentPaths.push(parentPath);
|
|
630
653
|
filePath = parentPath;
|
|
631
654
|
}
|
|
@@ -635,8 +658,9 @@ function isWithinTypeModuleContext(filePath) {
|
|
|
635
658
|
const parentPaths = getParentPaths(filePath);
|
|
636
659
|
for (const parentPath of parentPaths) {
|
|
637
660
|
const cache = dirPathTypeModuleCache.get(parentPath);
|
|
638
|
-
if (cache !== void 0)
|
|
661
|
+
if (cache !== void 0) {
|
|
639
662
|
return cache;
|
|
663
|
+
}
|
|
640
664
|
}
|
|
641
665
|
for (const parentPath of parentPaths) {
|
|
642
666
|
try {
|
|
@@ -648,8 +672,9 @@ function isWithinTypeModuleContext(filePath) {
|
|
|
648
672
|
dirPathTypeModuleCache.set(parentPath, cache);
|
|
649
673
|
return cache;
|
|
650
674
|
} catch (e) {
|
|
651
|
-
if (!isFileNotFoundError(e))
|
|
675
|
+
if (!isFileNotFoundError(e)) {
|
|
652
676
|
throw e;
|
|
677
|
+
}
|
|
653
678
|
}
|
|
654
679
|
}
|
|
655
680
|
return false;
|
|
@@ -666,8 +691,9 @@ async function getCjsNamedExports(vite, filePath, contents, seen = /* @__PURE__
|
|
|
666
691
|
/* isRequire */
|
|
667
692
|
true
|
|
668
693
|
);
|
|
669
|
-
if (seen.has(resolved))
|
|
694
|
+
if (seen.has(resolved)) {
|
|
670
695
|
continue;
|
|
696
|
+
}
|
|
671
697
|
try {
|
|
672
698
|
const resolvedContents = fs2.readFileSync(resolved, "utf8");
|
|
673
699
|
seen.add(filePath);
|
|
@@ -678,11 +704,13 @@ async function getCjsNamedExports(vite, filePath, contents, seen = /* @__PURE__
|
|
|
678
704
|
seen
|
|
679
705
|
);
|
|
680
706
|
seen.delete(filePath);
|
|
681
|
-
for (const name of resolvedNames)
|
|
707
|
+
for (const name of resolvedNames) {
|
|
682
708
|
result.add(name);
|
|
709
|
+
}
|
|
683
710
|
} catch (e) {
|
|
684
|
-
if (!isFileNotFoundError(e))
|
|
711
|
+
if (!isFileNotFoundError(e)) {
|
|
685
712
|
throw e;
|
|
713
|
+
}
|
|
686
714
|
}
|
|
687
715
|
}
|
|
688
716
|
result.delete("default");
|
|
@@ -690,8 +718,9 @@ async function getCjsNamedExports(vite, filePath, contents, seen = /* @__PURE__
|
|
|
690
718
|
return result;
|
|
691
719
|
}
|
|
692
720
|
function withSourceUrl(contents, url) {
|
|
693
|
-
if (contents.lastIndexOf("//# sourceURL=") !== -1)
|
|
721
|
+
if (contents.lastIndexOf("//# sourceURL=") !== -1) {
|
|
694
722
|
return contents;
|
|
723
|
+
}
|
|
695
724
|
const sourceURL = `
|
|
696
725
|
//# sourceURL=${url.toString()}
|
|
697
726
|
`;
|
|
@@ -703,8 +732,9 @@ function withImportMetaUrl(contents, url) {
|
|
|
703
732
|
var bundleCache = /* @__PURE__ */ new Map();
|
|
704
733
|
function bundleDependency(entryPath) {
|
|
705
734
|
let output = bundleCache.get(entryPath);
|
|
706
|
-
if (output !== void 0)
|
|
735
|
+
if (output !== void 0) {
|
|
707
736
|
return output;
|
|
737
|
+
}
|
|
708
738
|
debuglog(`Bundling ${entryPath}...`);
|
|
709
739
|
const result = buildSync({
|
|
710
740
|
platform: "node",
|
|
@@ -724,19 +754,23 @@ function bundleDependency(entryPath) {
|
|
|
724
754
|
}
|
|
725
755
|
var jsExtensions = [".js", ".mjs", ".cjs"];
|
|
726
756
|
function maybeGetTargetFilePath(target) {
|
|
727
|
-
if (isFile(target))
|
|
757
|
+
if (isFile(target)) {
|
|
728
758
|
return target;
|
|
759
|
+
}
|
|
729
760
|
for (const extension of jsExtensions) {
|
|
730
761
|
const targetWithExtension = target + extension;
|
|
731
|
-
if (fs2.existsSync(targetWithExtension))
|
|
762
|
+
if (fs2.existsSync(targetWithExtension)) {
|
|
732
763
|
return targetWithExtension;
|
|
764
|
+
}
|
|
733
765
|
}
|
|
734
|
-
if (target.endsWith(disableCjsEsmShimSuffix))
|
|
766
|
+
if (target.endsWith(disableCjsEsmShimSuffix)) {
|
|
735
767
|
return target;
|
|
768
|
+
}
|
|
736
769
|
}
|
|
737
770
|
function getApproximateSpecifier(target, referrerDir) {
|
|
738
|
-
if (/^(node|cloudflare|workerd):/.test(target))
|
|
771
|
+
if (/^(node|cloudflare|workerd):/.test(target)) {
|
|
739
772
|
return target;
|
|
773
|
+
}
|
|
740
774
|
return posixPath.relative(referrerDir, target);
|
|
741
775
|
}
|
|
742
776
|
async function viteResolve(vite, specifier, referrer, isRequire) {
|
|
@@ -751,15 +785,18 @@ async function viteResolve(vite, specifier, referrer, isRequire) {
|
|
|
751
785
|
}
|
|
752
786
|
throw new Error("Not found");
|
|
753
787
|
}
|
|
754
|
-
if (resolved.id === "__vite-browser-external")
|
|
788
|
+
if (resolved.id === "__vite-browser-external") {
|
|
755
789
|
return emptyLibPath;
|
|
790
|
+
}
|
|
756
791
|
if (resolved.external) {
|
|
757
792
|
let { id } = resolved;
|
|
758
|
-
if (workerdBuiltinModules.has(id))
|
|
793
|
+
if (workerdBuiltinModules.has(id)) {
|
|
759
794
|
return `/${id}`;
|
|
795
|
+
}
|
|
760
796
|
id = `node:${id}`;
|
|
761
|
-
if (workerdBuiltinModules.has(id))
|
|
797
|
+
if (workerdBuiltinModules.has(id)) {
|
|
762
798
|
return `/${id}`;
|
|
799
|
+
}
|
|
763
800
|
throw new Error("Not found");
|
|
764
801
|
}
|
|
765
802
|
return resolved.id;
|
|
@@ -767,8 +804,9 @@ async function viteResolve(vite, specifier, referrer, isRequire) {
|
|
|
767
804
|
async function resolve(vite, method, target, specifier, referrer) {
|
|
768
805
|
const referrerDir = posixPath.dirname(referrer);
|
|
769
806
|
let filePath = maybeGetTargetFilePath(target);
|
|
770
|
-
if (filePath !== void 0)
|
|
807
|
+
if (filePath !== void 0) {
|
|
771
808
|
return filePath;
|
|
809
|
+
}
|
|
772
810
|
if (referrerDir !== "/" && workerdBuiltinModules.has(specifier)) {
|
|
773
811
|
return `/${specifier}`;
|
|
774
812
|
}
|
|
@@ -777,19 +815,22 @@ async function resolve(vite, method, target, specifier, referrer) {
|
|
|
777
815
|
specifier.replaceAll(":", "/")
|
|
778
816
|
);
|
|
779
817
|
filePath = maybeGetTargetFilePath(specifierLibPath);
|
|
780
|
-
if (filePath !== void 0)
|
|
818
|
+
if (filePath !== void 0) {
|
|
781
819
|
return filePath;
|
|
820
|
+
}
|
|
782
821
|
return viteResolve(vite, specifier, referrer, method === "require");
|
|
783
822
|
}
|
|
784
823
|
function buildRedirectResponse(filePath) {
|
|
785
|
-
if (isWindows && filePath[0] !== "/")
|
|
824
|
+
if (isWindows && filePath[0] !== "/") {
|
|
786
825
|
filePath = `/${filePath}`;
|
|
826
|
+
}
|
|
787
827
|
return new Response2(null, { status: 301, headers: { Location: filePath } });
|
|
788
828
|
}
|
|
789
829
|
function maybeGetForceTypeModuleContents(filePath) {
|
|
790
830
|
const match = forceModuleTypeRegexp.exec(filePath);
|
|
791
|
-
if (match === null)
|
|
831
|
+
if (match === null) {
|
|
792
832
|
return;
|
|
833
|
+
}
|
|
793
834
|
filePath = trimSuffix(match[0], filePath);
|
|
794
835
|
const type = match[1];
|
|
795
836
|
const contents = fs2.readFileSync(filePath);
|
|
@@ -818,8 +859,9 @@ function maybeGetForceTypeModuleContents(filePath) {
|
|
|
818
859
|
}
|
|
819
860
|
function buildModuleResponse(target, contents) {
|
|
820
861
|
let name = target;
|
|
821
|
-
if (!isWindows)
|
|
862
|
+
if (!isWindows) {
|
|
822
863
|
name = posixPath.relative("/", target);
|
|
864
|
+
}
|
|
823
865
|
assert3(name[0] !== "/");
|
|
824
866
|
const result = { name };
|
|
825
867
|
for (const key in contents) {
|
|
@@ -836,8 +878,9 @@ async function load(vite, logBase, method, target, specifier, filePath) {
|
|
|
836
878
|
debuglog(logBase, "redirect:", filePath);
|
|
837
879
|
return buildRedirectResponse(filePath);
|
|
838
880
|
}
|
|
839
|
-
if (filePath.endsWith(".wasm"))
|
|
881
|
+
if (filePath.endsWith(".wasm")) {
|
|
840
882
|
filePath += `?mf_vitest_force=CompiledWasm`;
|
|
883
|
+
}
|
|
841
884
|
const maybeContents = maybeGetForceTypeModuleContents(filePath);
|
|
842
885
|
if (maybeContents !== void 0) {
|
|
843
886
|
debuglog(logBase, "forced:", filePath);
|
|
@@ -888,20 +931,24 @@ async function handleModuleFallbackRequest(vite, request) {
|
|
|
888
931
|
assert3(referrer !== null, "Expected referrer search param");
|
|
889
932
|
const referrerDir = posixPath.dirname(referrer);
|
|
890
933
|
let specifier = getApproximateSpecifier(target, referrerDir);
|
|
891
|
-
if (specifier.startsWith("file:"))
|
|
934
|
+
if (specifier.startsWith("file:")) {
|
|
892
935
|
specifier = specifier.substring(5);
|
|
936
|
+
}
|
|
893
937
|
if (isWindows) {
|
|
894
|
-
if (target[0] === "/")
|
|
938
|
+
if (target[0] === "/") {
|
|
895
939
|
target = target.substring(1);
|
|
896
|
-
|
|
940
|
+
}
|
|
941
|
+
if (referrer[0] === "/") {
|
|
897
942
|
referrer = referrer.substring(1);
|
|
943
|
+
}
|
|
898
944
|
}
|
|
899
945
|
const quotedTarget = JSON.stringify(target);
|
|
900
946
|
const logBase = `${method}(${quotedTarget}) relative to ${referrer}:`;
|
|
901
947
|
try {
|
|
902
948
|
const filePath = await resolve(vite, method, target, specifier, referrer);
|
|
903
|
-
if (bundleDependencies.includes(specifier))
|
|
949
|
+
if (bundleDependencies.includes(specifier)) {
|
|
904
950
|
bundleDependency(filePath);
|
|
951
|
+
}
|
|
905
952
|
return await load(vite, logBase, method, target, specifier, filePath);
|
|
906
953
|
} catch (e) {
|
|
907
954
|
debuglog(logBase, "error:", e);
|
|
@@ -954,25 +1001,29 @@ function handleRuntimeStdio(stdout, stderr) {
|
|
|
954
1001
|
});
|
|
955
1002
|
}
|
|
956
1003
|
function forEachMiniflare(mfs, callback) {
|
|
957
|
-
if (mfs instanceof Miniflare)
|
|
1004
|
+
if (mfs instanceof Miniflare) {
|
|
958
1005
|
return callback(mfs);
|
|
1006
|
+
}
|
|
959
1007
|
const promises = [];
|
|
960
|
-
for (const mf of mfs.values())
|
|
1008
|
+
for (const mf of mfs.values()) {
|
|
961
1009
|
promises.push(callback(mf));
|
|
1010
|
+
}
|
|
962
1011
|
return Promise.all(promises);
|
|
963
1012
|
}
|
|
964
1013
|
var allProjects = /* @__PURE__ */ new Map();
|
|
965
1014
|
function getRunnerName(project, testFile) {
|
|
966
1015
|
const name = `${WORKER_NAME_PREFIX}runner-${project.getName()}`;
|
|
967
|
-
if (testFile === void 0)
|
|
1016
|
+
if (testFile === void 0) {
|
|
968
1017
|
return name;
|
|
1018
|
+
}
|
|
969
1019
|
const testFileHash = crypto.createHash("sha1").update(testFile).digest("hex");
|
|
970
1020
|
testFile = testFile.replace(/[^a-z0-9-]/gi, "_");
|
|
971
1021
|
return `${name}-${testFileHash}-${testFile}`;
|
|
972
1022
|
}
|
|
973
1023
|
function isDurableObjectDesignatorToSelf(value) {
|
|
974
|
-
if (typeof value === "string")
|
|
1024
|
+
if (typeof value === "string") {
|
|
975
1025
|
return true;
|
|
1026
|
+
}
|
|
976
1027
|
return typeof value === "object" && value !== null && "className" in value && typeof value.className === "string" && (!("scriptName" in value) || value.scriptName === void 0);
|
|
977
1028
|
}
|
|
978
1029
|
function getDurableObjectDesignators(options) {
|
|
@@ -1007,8 +1058,9 @@ var DEFINES_MODULE_PATH = path4.join(
|
|
|
1007
1058
|
);
|
|
1008
1059
|
function fixupDurableObjectBindingsToSelf(worker) {
|
|
1009
1060
|
const result = /* @__PURE__ */ new Set();
|
|
1010
|
-
if (worker.durableObjects === void 0)
|
|
1061
|
+
if (worker.durableObjects === void 0) {
|
|
1011
1062
|
return result;
|
|
1063
|
+
}
|
|
1012
1064
|
for (const key of Object.keys(worker.durableObjects)) {
|
|
1013
1065
|
const designator = worker.durableObjects[key];
|
|
1014
1066
|
if (typeof designator === "string") {
|
|
@@ -1116,10 +1168,12 @@ function buildProjectWorkerOptions(project) {
|
|
|
1116
1168
|
${Object.entries(project.options.defines ?? {}).map(([key, value]) => `${JSON.stringify(key)}: ${value}`).join(",\n")}
|
|
1117
1169
|
};
|
|
1118
1170
|
`;
|
|
1119
|
-
if ("script" in runnerWorker)
|
|
1171
|
+
if ("script" in runnerWorker) {
|
|
1120
1172
|
delete runnerWorker.script;
|
|
1121
|
-
|
|
1173
|
+
}
|
|
1174
|
+
if ("scriptPath" in runnerWorker) {
|
|
1122
1175
|
delete runnerWorker.scriptPath;
|
|
1176
|
+
}
|
|
1123
1177
|
const modulesRoot = process.platform === "win32" ? "Z:\\" : "/";
|
|
1124
1178
|
runnerWorker.modulesRoot = modulesRoot;
|
|
1125
1179
|
runnerWorker.modules = [
|
|
@@ -1168,8 +1222,9 @@ var SHARED_MINIFLARE_OPTIONS = {
|
|
|
1168
1222
|
var moduleFallbackServices = /* @__PURE__ */ new WeakMap();
|
|
1169
1223
|
function getModuleFallbackService(ctx) {
|
|
1170
1224
|
let service = moduleFallbackServices.get(ctx);
|
|
1171
|
-
if (service !== void 0)
|
|
1225
|
+
if (service !== void 0) {
|
|
1172
1226
|
return service;
|
|
1227
|
+
}
|
|
1173
1228
|
service = handleModuleFallbackRequest.bind(void 0, ctx.vitenode.server);
|
|
1174
1229
|
moduleFallbackServices.set(ctx, service);
|
|
1175
1230
|
return service;
|
|
@@ -1236,8 +1291,9 @@ async function getProjectMiniflare(ctx, project) {
|
|
|
1236
1291
|
function maybeGetResolvedMainPath(project) {
|
|
1237
1292
|
const projectPath = getProjectPath(project.project);
|
|
1238
1293
|
const main = project.options.main;
|
|
1239
|
-
if (main === void 0)
|
|
1294
|
+
if (main === void 0) {
|
|
1240
1295
|
return;
|
|
1296
|
+
}
|
|
1241
1297
|
if (typeof projectPath === "string") {
|
|
1242
1298
|
return path4.resolve(path4.dirname(projectPath), main);
|
|
1243
1299
|
} else {
|
|
@@ -1357,12 +1413,14 @@ function getPackageJson(dirPath) {
|
|
|
1357
1413
|
const contents = fs3.readFileSync(pkgJsonPath, "utf8");
|
|
1358
1414
|
return JSON.parse(contents);
|
|
1359
1415
|
} catch (e) {
|
|
1360
|
-
if (!isFileNotFoundError(e))
|
|
1416
|
+
if (!isFileNotFoundError(e)) {
|
|
1361
1417
|
throw e;
|
|
1418
|
+
}
|
|
1362
1419
|
}
|
|
1363
1420
|
const nextDirPath = path4.dirname(dirPath);
|
|
1364
|
-
if (nextDirPath === dirPath)
|
|
1421
|
+
if (nextDirPath === dirPath) {
|
|
1365
1422
|
return;
|
|
1423
|
+
}
|
|
1366
1424
|
dirPath = nextDirPath;
|
|
1367
1425
|
}
|
|
1368
1426
|
}
|
|
@@ -1425,8 +1483,9 @@ function pool_default(ctx) {
|
|
|
1425
1483
|
const filesByProject = /* @__PURE__ */ new Map();
|
|
1426
1484
|
for (const [project, file] of specs) {
|
|
1427
1485
|
let group = filesByProject.get(project);
|
|
1428
|
-
if (group === void 0)
|
|
1486
|
+
if (group === void 0) {
|
|
1429
1487
|
filesByProject.set(project, group = []);
|
|
1488
|
+
}
|
|
1430
1489
|
group.push(file);
|
|
1431
1490
|
}
|
|
1432
1491
|
for (const [workspaceProject, files] of filesByProject) {
|