miniflare 0.0.0-e4fe35cc5 → 0.0.0-eaf71b86c
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/README.md +11 -0
- package/dist/src/index.d.ts +145 -69
- package/dist/src/index.js +152 -78
- package/dist/src/index.js.map +3 -3
- package/dist/src/workers/assets/assets-kv.worker.js +5 -1
- package/dist/src/workers/assets/assets-kv.worker.js.map +1 -1
- package/dist/src/workers/assets/assets.worker.js +76 -21
- package/dist/src/workers/assets/assets.worker.js.map +1 -1
- package/dist/src/workers/core/entry.worker.js +5 -2
- package/dist/src/workers/core/entry.worker.js.map +1 -1
- package/package.json +4 -4
package/dist/src/index.js
CHANGED
|
@@ -2547,7 +2547,7 @@ __export(src_exports, {
|
|
|
2547
2547
|
_transformsForContentEncodingAndContentType: () => _transformsForContentEncodingAndContentType,
|
|
2548
2548
|
base64Decode: () => base64Decode,
|
|
2549
2549
|
base64Encode: () => base64Encode,
|
|
2550
|
-
|
|
2550
|
+
buildAssetManifest: () => buildAssetManifest,
|
|
2551
2551
|
compileModuleRules: () => compileModuleRules,
|
|
2552
2552
|
coupleWebSocket: () => coupleWebSocket,
|
|
2553
2553
|
createFetchMock: () => createFetchMock,
|
|
@@ -2567,6 +2567,7 @@ __export(src_exports, {
|
|
|
2567
2567
|
getFreshSourceMapSupport: () => getFreshSourceMapSupport,
|
|
2568
2568
|
getGlobalServices: () => getGlobalServices,
|
|
2569
2569
|
getMiniflareObjectBindings: () => getMiniflareObjectBindings,
|
|
2570
|
+
getNodeCompat: () => getNodeCompat,
|
|
2570
2571
|
getPersistPath: () => getPersistPath,
|
|
2571
2572
|
getRootPath: () => getRootPath,
|
|
2572
2573
|
globsToRegExps: () => globsToRegExps,
|
|
@@ -4587,7 +4588,7 @@ var import_undici4 = require("undici");
|
|
|
4587
4588
|
// src/plugins/assets/index.ts
|
|
4588
4589
|
var import_node_crypto = __toESM(require("node:crypto"));
|
|
4589
4590
|
var import_promises7 = __toESM(require("node:fs/promises"));
|
|
4590
|
-
var
|
|
4591
|
+
var import_node_path2 = __toESM(require("node:path"));
|
|
4591
4592
|
|
|
4592
4593
|
// ../workers-shared/utils/constants.ts
|
|
4593
4594
|
var HEADER_SIZE = 20;
|
|
@@ -4616,10 +4617,13 @@ var AssetConfigSchema = import_zod4.z.object({
|
|
|
4616
4617
|
});
|
|
4617
4618
|
|
|
4618
4619
|
// ../workers-shared/utils/helpers.ts
|
|
4620
|
+
var import_node_path = require("node:path");
|
|
4619
4621
|
var import_mime = __toESM(require_mime());
|
|
4620
|
-
var
|
|
4621
|
-
|
|
4622
|
-
|
|
4622
|
+
var normalizeFilePath = (relativeFilepath) => {
|
|
4623
|
+
if ((0, import_node_path.isAbsolute)(relativeFilepath)) {
|
|
4624
|
+
throw new Error(`Expected relative path`);
|
|
4625
|
+
}
|
|
4626
|
+
return "/" + relativeFilepath.split(import_node_path.sep).join("/");
|
|
4623
4627
|
};
|
|
4624
4628
|
var getContentType = (absFilePath) => {
|
|
4625
4629
|
let contentType = (0, import_mime.getType)(absFilePath) || "application/octet-stream";
|
|
@@ -4945,6 +4949,12 @@ var Runtime = class {
|
|
|
4945
4949
|
}
|
|
4946
4950
|
};
|
|
4947
4951
|
|
|
4952
|
+
// src/plugins/assets/constants.ts
|
|
4953
|
+
var ASSETS_PLUGIN_NAME = "assets";
|
|
4954
|
+
var ASSETS_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:assets-service`;
|
|
4955
|
+
var ROUTER_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:router`;
|
|
4956
|
+
var ASSETS_KV_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:kv`;
|
|
4957
|
+
|
|
4948
4958
|
// src/plugins/cache/index.ts
|
|
4949
4959
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
4950
4960
|
|
|
@@ -5482,6 +5492,51 @@ var import_util = require("util");
|
|
|
5482
5492
|
var import_acorn = require("acorn");
|
|
5483
5493
|
var import_acorn_walk = require("acorn-walk");
|
|
5484
5494
|
var import_zod9 = require("zod");
|
|
5495
|
+
|
|
5496
|
+
// src/plugins/core/node-compat.ts
|
|
5497
|
+
function getNodeCompat(compatibilityDate = "2000-01-01", compatibilityFlags, opts) {
|
|
5498
|
+
const { nodeCompat = false } = opts ?? {};
|
|
5499
|
+
const {
|
|
5500
|
+
hasNodejsAlsFlag,
|
|
5501
|
+
hasNodejsCompatFlag,
|
|
5502
|
+
hasNodejsCompatV2Flag,
|
|
5503
|
+
hasNoNodejsCompatV2Flag,
|
|
5504
|
+
hasExperimentalNodejsCompatV2Flag
|
|
5505
|
+
} = parseNodeCompatibilityFlags(compatibilityFlags);
|
|
5506
|
+
const nodeCompatSwitchOverDate = "2024-09-23";
|
|
5507
|
+
const legacy = nodeCompat === true;
|
|
5508
|
+
let mode = null;
|
|
5509
|
+
if (hasNodejsCompatV2Flag || hasNodejsCompatFlag && compatibilityDate >= nodeCompatSwitchOverDate && !hasNoNodejsCompatV2Flag) {
|
|
5510
|
+
mode = "v2";
|
|
5511
|
+
} else if (hasNodejsCompatFlag) {
|
|
5512
|
+
mode = "v1";
|
|
5513
|
+
} else if (hasNodejsAlsFlag) {
|
|
5514
|
+
mode = "als";
|
|
5515
|
+
} else if (legacy) {
|
|
5516
|
+
mode = "legacy";
|
|
5517
|
+
}
|
|
5518
|
+
return {
|
|
5519
|
+
mode,
|
|
5520
|
+
hasNodejsAlsFlag,
|
|
5521
|
+
hasNodejsCompatFlag,
|
|
5522
|
+
hasNodejsCompatV2Flag,
|
|
5523
|
+
hasNoNodejsCompatV2Flag,
|
|
5524
|
+
hasExperimentalNodejsCompatV2Flag
|
|
5525
|
+
};
|
|
5526
|
+
}
|
|
5527
|
+
function parseNodeCompatibilityFlags(compatibilityFlags) {
|
|
5528
|
+
return {
|
|
5529
|
+
hasNodejsAlsFlag: compatibilityFlags.includes("nodejs_als"),
|
|
5530
|
+
hasNodejsCompatFlag: compatibilityFlags.includes("nodejs_compat"),
|
|
5531
|
+
hasNodejsCompatV2Flag: compatibilityFlags.includes("nodejs_compat_v2"),
|
|
5532
|
+
hasNoNodejsCompatV2Flag: compatibilityFlags.includes("no_nodejs_compat_v2"),
|
|
5533
|
+
hasExperimentalNodejsCompatV2Flag: compatibilityFlags.includes(
|
|
5534
|
+
"experimental:nodejs_compat_v2"
|
|
5535
|
+
)
|
|
5536
|
+
};
|
|
5537
|
+
}
|
|
5538
|
+
|
|
5539
|
+
// src/plugins/core/modules.ts
|
|
5485
5540
|
var SUGGEST_BUNDLE = "If you're trying to import an npm package, you'll need to bundle your Worker first.";
|
|
5486
5541
|
var SUGGEST_NODE = "If you're trying to import a Node.js built-in module, or an npm package that uses Node.js built-ins, you'll either need to:\n- Bundle your Worker, configuring your bundler to polyfill Node.js built-ins\n- Configure your bundler to load Workers-compatible builds by changing the main fields/conditions\n- Enable the `nodejs_compat` compatibility flag and use the `NodeJsCompatModule` module type\n- Find an alternative package that doesn't require Node.js built-ins";
|
|
5487
5542
|
var builtinModulesWithPrefix = import_module.builtinModules.concat(
|
|
@@ -5589,15 +5644,18 @@ function getResolveErrorPrefix(referencingPath) {
|
|
|
5589
5644
|
return `Unable to resolve "${relative}" dependency`;
|
|
5590
5645
|
}
|
|
5591
5646
|
var ModuleLocator = class {
|
|
5592
|
-
constructor(modulesRoot, additionalModuleNames, rules = [], compatibilityFlags) {
|
|
5647
|
+
constructor(modulesRoot, additionalModuleNames, rules = [], compatibilityDate, compatibilityFlags) {
|
|
5593
5648
|
this.modulesRoot = modulesRoot;
|
|
5594
5649
|
this.additionalModuleNames = additionalModuleNames;
|
|
5595
5650
|
rules = rules.concat(DEFAULT_MODULE_RULES);
|
|
5596
5651
|
this.#compiledRules = compileModuleRules(rules);
|
|
5597
|
-
this.#
|
|
5652
|
+
this.#nodejsCompatMode = getNodeCompat(
|
|
5653
|
+
compatibilityDate,
|
|
5654
|
+
compatibilityFlags ?? []
|
|
5655
|
+
).mode;
|
|
5598
5656
|
}
|
|
5599
5657
|
#compiledRules;
|
|
5600
|
-
#
|
|
5658
|
+
#nodejsCompatMode;
|
|
5601
5659
|
#visitedPaths = /* @__PURE__ */ new Set();
|
|
5602
5660
|
modules = [];
|
|
5603
5661
|
visitEntrypoint(code, modulePath) {
|
|
@@ -5681,7 +5739,14 @@ ${dim(modulesConfig)}`;
|
|
|
5681
5739
|
}
|
|
5682
5740
|
const spec = specExpression.value;
|
|
5683
5741
|
const isNodeJsCompatModule = referencingType === "NodeJsCompatModule";
|
|
5684
|
-
if (
|
|
5742
|
+
if (
|
|
5743
|
+
// `cloudflare:` and `workerd:` imports don't need to be included explicitly
|
|
5744
|
+
spec.startsWith("cloudflare:") || spec.startsWith("workerd:") || // Node.js compat v1 requires imports to be prefixed with `node:`
|
|
5745
|
+
this.#nodejsCompatMode === "v1" && spec.startsWith("node:") || // Node.js compat modules and v2 can also handle non-prefixed imports
|
|
5746
|
+
(this.#nodejsCompatMode === "v2" || isNodeJsCompatModule) && builtinModulesWithPrefix.includes(spec) || // Async Local Storage mode (node_als) only deals with `node:async_hooks` imports
|
|
5747
|
+
this.#nodejsCompatMode === "als" && spec === "node:async_hooks" || // Any "additional" external modules can be ignored
|
|
5748
|
+
this.additionalModuleNames.includes(spec)
|
|
5749
|
+
) {
|
|
5685
5750
|
return;
|
|
5686
5751
|
}
|
|
5687
5752
|
if (maybeGetStringScriptPathIndex(referencingName) !== void 0) {
|
|
@@ -6866,7 +6931,11 @@ var CoreOptionsSchemaInput = import_zod12.z.intersection(
|
|
|
6866
6931
|
unsafeEphemeralDurableObjects: import_zod12.z.boolean().optional(),
|
|
6867
6932
|
unsafeDirectSockets: UnsafeDirectSocketSchema.array().optional(),
|
|
6868
6933
|
unsafeEvalBinding: import_zod12.z.string().optional(),
|
|
6869
|
-
unsafeUseModuleFallbackService: import_zod12.z.boolean().optional()
|
|
6934
|
+
unsafeUseModuleFallbackService: import_zod12.z.boolean().optional(),
|
|
6935
|
+
/** Used to set the vitest pool worker SELF binding to point to the router worker if there are assets.
|
|
6936
|
+
(If there are assets but we're not using vitest, the miniflare entry worker can point directly to RW.)
|
|
6937
|
+
*/
|
|
6938
|
+
hasAssetsAndIsVitest: import_zod12.z.boolean().optional()
|
|
6870
6939
|
})
|
|
6871
6940
|
);
|
|
6872
6941
|
var CoreOptionsSchema = CoreOptionsSchemaInput.transform((value) => {
|
|
@@ -6931,7 +7000,7 @@ var SCRIPT_CUSTOM_SERVICE = `addEventListener("fetch", (event) => {
|
|
|
6931
7000
|
request.headers.set("${CoreHeaders.ORIGINAL_URL}", request.url);
|
|
6932
7001
|
event.respondWith(${CoreBindings.SERVICE_LOOPBACK}.fetch(request));
|
|
6933
7002
|
})`;
|
|
6934
|
-
function getCustomServiceDesignator(refererName, workerIndex, kind, name, service) {
|
|
7003
|
+
function getCustomServiceDesignator(refererName, workerIndex, kind, name, service, hasAssetsAndIsVitest = false) {
|
|
6935
7004
|
let serviceName;
|
|
6936
7005
|
let entrypoint;
|
|
6937
7006
|
if (typeof service === "function") {
|
|
@@ -6948,7 +7017,7 @@ function getCustomServiceDesignator(refererName, workerIndex, kind, name, servic
|
|
|
6948
7017
|
serviceName = getBuiltinServiceName(workerIndex, kind, name);
|
|
6949
7018
|
}
|
|
6950
7019
|
} else if (service === kCurrentWorker) {
|
|
6951
|
-
serviceName = getUserServiceName(refererName);
|
|
7020
|
+
serviceName = hasAssetsAndIsVitest ? ROUTER_SERVICE_NAME : getUserServiceName(refererName);
|
|
6952
7021
|
} else {
|
|
6953
7022
|
serviceName = getUserServiceName(service);
|
|
6954
7023
|
}
|
|
@@ -7059,7 +7128,8 @@ var CORE_PLUGIN = {
|
|
|
7059
7128
|
workerIndex,
|
|
7060
7129
|
"#" /* UNKNOWN */,
|
|
7061
7130
|
name,
|
|
7062
|
-
service
|
|
7131
|
+
service,
|
|
7132
|
+
options.hasAssetsAndIsVitest
|
|
7063
7133
|
)
|
|
7064
7134
|
};
|
|
7065
7135
|
})
|
|
@@ -7281,7 +7351,8 @@ Ensure ${stringName} doesn't include unbundled \`import\`s.`
|
|
|
7281
7351
|
workerIndex,
|
|
7282
7352
|
"$" /* KNOWN */,
|
|
7283
7353
|
CUSTOM_SERVICE_KNOWN_OUTBOUND,
|
|
7284
|
-
options.outboundService
|
|
7354
|
+
options.outboundService,
|
|
7355
|
+
options.hasAssetsAndIsVitest
|
|
7285
7356
|
),
|
|
7286
7357
|
cacheApiOutbound: { name: getCacheServiceName(workerIndex) },
|
|
7287
7358
|
moduleFallback: options.unsafeUseModuleFallbackService && sharedOptions.unsafeModuleFallbackService !== void 0 ? `localhost:${loopbackPort}` : void 0
|
|
@@ -7444,6 +7515,7 @@ function getWorkerScript(options, workerIndex, additionalModuleNames) {
|
|
|
7444
7515
|
modulesRoot,
|
|
7445
7516
|
additionalModuleNames,
|
|
7446
7517
|
options.modulesRules,
|
|
7518
|
+
options.compatibilityDate,
|
|
7447
7519
|
options.compatibilityFlags
|
|
7448
7520
|
);
|
|
7449
7521
|
locator.visitEntrypoint(code, scriptPath);
|
|
@@ -7454,21 +7526,17 @@ function getWorkerScript(options, workerIndex, additionalModuleNames) {
|
|
|
7454
7526
|
}
|
|
7455
7527
|
}
|
|
7456
7528
|
|
|
7457
|
-
// src/plugins/assets/constants.ts
|
|
7458
|
-
var ASSETS_PLUGIN_NAME = "assets";
|
|
7459
|
-
var ASSETS_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:assets-service`;
|
|
7460
|
-
var ROUTER_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:router`;
|
|
7461
|
-
var ASSETS_KV_SERVICE_NAME = `${ASSETS_PLUGIN_NAME}:kv`;
|
|
7462
|
-
|
|
7463
7529
|
// src/plugins/assets/schema.ts
|
|
7464
7530
|
var import_zod13 = require("zod");
|
|
7465
7531
|
var AssetsOptionsSchema = import_zod13.z.object({
|
|
7466
7532
|
assets: import_zod13.z.object({
|
|
7533
|
+
// User worker name or vitest runner - this is only ever set inside miniflare
|
|
7534
|
+
// The assets plugin needs access to the worker name to create the router worker - user worker binding
|
|
7467
7535
|
workerName: import_zod13.z.string().optional(),
|
|
7468
|
-
|
|
7469
|
-
|
|
7470
|
-
routingConfig: RoutingConfigSchema,
|
|
7471
|
-
assetConfig: AssetConfigSchema
|
|
7536
|
+
directory: PathSchema,
|
|
7537
|
+
binding: import_zod13.z.string().optional(),
|
|
7538
|
+
routingConfig: RoutingConfigSchema.optional(),
|
|
7539
|
+
assetConfig: AssetConfigSchema.optional()
|
|
7472
7540
|
}).optional()
|
|
7473
7541
|
});
|
|
7474
7542
|
|
|
@@ -7476,35 +7544,37 @@ var AssetsOptionsSchema = import_zod13.z.object({
|
|
|
7476
7544
|
var ASSETS_PLUGIN = {
|
|
7477
7545
|
options: AssetsOptionsSchema,
|
|
7478
7546
|
async getBindings(options) {
|
|
7479
|
-
if (!options.assets?.
|
|
7547
|
+
if (!options.assets?.binding) {
|
|
7480
7548
|
return [];
|
|
7481
7549
|
}
|
|
7482
7550
|
return [
|
|
7483
7551
|
{
|
|
7484
7552
|
// binding between User Worker and Asset Worker
|
|
7485
|
-
name: options.assets.
|
|
7553
|
+
name: options.assets.binding,
|
|
7486
7554
|
service: { name: ASSETS_SERVICE_NAME }
|
|
7487
7555
|
}
|
|
7488
7556
|
];
|
|
7489
7557
|
},
|
|
7490
7558
|
async getNodeBindings(options) {
|
|
7491
|
-
if (!options.assets?.
|
|
7559
|
+
if (!options.assets?.binding) {
|
|
7492
7560
|
return {};
|
|
7493
7561
|
}
|
|
7494
7562
|
return {
|
|
7495
|
-
[options.assets.
|
|
7563
|
+
[options.assets.binding]: new ProxyNodeBinding()
|
|
7496
7564
|
};
|
|
7497
7565
|
},
|
|
7498
7566
|
async getServices({ options }) {
|
|
7499
7567
|
if (!options.assets) {
|
|
7500
7568
|
return [];
|
|
7501
7569
|
}
|
|
7502
|
-
const assetsReverseMap = await createReverseMap(options.assets?.path);
|
|
7503
7570
|
const storageServiceName = `${ASSETS_PLUGIN_NAME}:storage`;
|
|
7504
7571
|
const storageService = {
|
|
7505
7572
|
name: storageServiceName,
|
|
7506
|
-
disk: { path: options.assets.
|
|
7573
|
+
disk: { path: options.assets.directory, writable: true }
|
|
7507
7574
|
};
|
|
7575
|
+
const { encodedAssetManifest, assetsReverseMap } = await buildAssetManifest(
|
|
7576
|
+
options.assets.directory
|
|
7577
|
+
);
|
|
7508
7578
|
const namespaceService = {
|
|
7509
7579
|
name: ASSETS_KV_SERVICE_NAME,
|
|
7510
7580
|
worker: {
|
|
@@ -7523,12 +7593,11 @@ var ASSETS_PLUGIN = {
|
|
|
7523
7593
|
},
|
|
7524
7594
|
{
|
|
7525
7595
|
name: "ASSETS_REVERSE_MAP",
|
|
7526
|
-
json: assetsReverseMap
|
|
7596
|
+
json: JSON.stringify(assetsReverseMap)
|
|
7527
7597
|
}
|
|
7528
7598
|
]
|
|
7529
7599
|
}
|
|
7530
7600
|
};
|
|
7531
|
-
const assetsManifest = await buildAssetsManifest(options.assets.path);
|
|
7532
7601
|
const assetService = {
|
|
7533
7602
|
name: ASSETS_SERVICE_NAME,
|
|
7534
7603
|
worker: {
|
|
@@ -7546,11 +7615,11 @@ var ASSETS_PLUGIN = {
|
|
|
7546
7615
|
},
|
|
7547
7616
|
{
|
|
7548
7617
|
name: "ASSETS_MANIFEST",
|
|
7549
|
-
data:
|
|
7618
|
+
data: encodedAssetManifest
|
|
7550
7619
|
},
|
|
7551
7620
|
{
|
|
7552
7621
|
name: "CONFIG",
|
|
7553
|
-
json: JSON.stringify(options.assets.assetConfig)
|
|
7622
|
+
json: JSON.stringify(options.assets.assetConfig ?? {})
|
|
7554
7623
|
}
|
|
7555
7624
|
]
|
|
7556
7625
|
}
|
|
@@ -7584,20 +7653,21 @@ var ASSETS_PLUGIN = {
|
|
|
7584
7653
|
return [storageService, namespaceService, assetService, routerService];
|
|
7585
7654
|
}
|
|
7586
7655
|
};
|
|
7587
|
-
var
|
|
7588
|
-
const manifest = await walk(dir);
|
|
7656
|
+
var buildAssetManifest = async (dir) => {
|
|
7657
|
+
const { manifest, assetsReverseMap } = await walk(dir);
|
|
7589
7658
|
const sortedAssetManifest = sortManifest(manifest);
|
|
7590
7659
|
const encodedAssetManifest = encodeManifest(sortedAssetManifest);
|
|
7591
|
-
return encodedAssetManifest;
|
|
7660
|
+
return { encodedAssetManifest, assetsReverseMap };
|
|
7592
7661
|
};
|
|
7593
7662
|
var walk = async (dir) => {
|
|
7594
7663
|
const files = await import_promises7.default.readdir(dir, { recursive: true });
|
|
7595
7664
|
const manifest = [];
|
|
7665
|
+
const assetsReverseMap = {};
|
|
7596
7666
|
let counter = 0;
|
|
7597
7667
|
await Promise.all(
|
|
7598
7668
|
files.map(async (file) => {
|
|
7599
|
-
const filepath =
|
|
7600
|
-
const relativeFilepath =
|
|
7669
|
+
const filepath = import_node_path2.default.join(dir, file);
|
|
7670
|
+
const relativeFilepath = import_node_path2.default.relative(dir, filepath);
|
|
7601
7671
|
const filestat = await import_promises7.default.stat(filepath);
|
|
7602
7672
|
if (filestat.isSymbolicLink() || filestat.isDirectory()) {
|
|
7603
7673
|
return;
|
|
@@ -7619,9 +7689,19 @@ Cloudflare Workers supports assets with sizes of up to ${prettyBytes(
|
|
|
7619
7689
|
Ensure all assets in your assets directory "${dir}" conform with the Workers maximum size requirement.`
|
|
7620
7690
|
);
|
|
7621
7691
|
}
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
7692
|
+
const [pathHash, contentHash] = await Promise.all([
|
|
7693
|
+
hashPath(normalizeFilePath(relativeFilepath)),
|
|
7694
|
+
// used absolute filepath here so that changes to the enclosing asset folder will be registered
|
|
7695
|
+
hashPath(filepath + filestat.mtimeMs.toString())
|
|
7696
|
+
]);
|
|
7697
|
+
manifest.push({
|
|
7698
|
+
pathHash,
|
|
7699
|
+
contentHash
|
|
7700
|
+
});
|
|
7701
|
+
assetsReverseMap[bytesToHex(contentHash)] = {
|
|
7702
|
+
filePath: relativeFilepath,
|
|
7703
|
+
contentType: getContentType(filepath)
|
|
7704
|
+
};
|
|
7625
7705
|
counter++;
|
|
7626
7706
|
}
|
|
7627
7707
|
})
|
|
@@ -7633,23 +7713,23 @@ Cloudflare Workers supports up to ${MAX_ASSET_COUNT.toLocaleString()} assets in
|
|
|
7633
7713
|
Ensure your assets directory contains a maximum of ${MAX_ASSET_COUNT.toLocaleString()} files, and that you have specified your assets directory correctly.`
|
|
7634
7714
|
);
|
|
7635
7715
|
}
|
|
7636
|
-
return manifest;
|
|
7716
|
+
return { manifest, assetsReverseMap };
|
|
7637
7717
|
};
|
|
7638
7718
|
var sortManifest = (manifest) => {
|
|
7639
7719
|
return manifest.sort(comparisonFn);
|
|
7640
7720
|
};
|
|
7641
7721
|
var comparisonFn = (a, b) => {
|
|
7642
|
-
if (a.length < b.length) {
|
|
7722
|
+
if (a.pathHash.length < b.pathHash.length) {
|
|
7643
7723
|
return -1;
|
|
7644
7724
|
}
|
|
7645
|
-
if (a.length > b.length) {
|
|
7725
|
+
if (a.pathHash.length > b.pathHash.length) {
|
|
7646
7726
|
return 1;
|
|
7647
7727
|
}
|
|
7648
|
-
for (const [i, v] of a.entries()) {
|
|
7649
|
-
if (v < b[i]) {
|
|
7728
|
+
for (const [i, v] of a.pathHash.entries()) {
|
|
7729
|
+
if (v < b.pathHash[i]) {
|
|
7650
7730
|
return -1;
|
|
7651
7731
|
}
|
|
7652
|
-
if (v > b[i]) {
|
|
7732
|
+
if (v > b.pathHash[i]) {
|
|
7653
7733
|
return 1;
|
|
7654
7734
|
}
|
|
7655
7735
|
}
|
|
@@ -7661,34 +7741,14 @@ var encodeManifest = (manifest) => {
|
|
|
7661
7741
|
);
|
|
7662
7742
|
for (const [i, entry] of manifest.entries()) {
|
|
7663
7743
|
const entryOffset = HEADER_SIZE + i * ENTRY_SIZE;
|
|
7664
|
-
assetManifestBytes.set(entry, entryOffset + PATH_HASH_OFFSET);
|
|
7665
|
-
assetManifestBytes.set(
|
|
7744
|
+
assetManifestBytes.set(entry.pathHash, entryOffset + PATH_HASH_OFFSET);
|
|
7745
|
+
assetManifestBytes.set(
|
|
7746
|
+
entry.contentHash,
|
|
7747
|
+
entryOffset + CONTENT_HASH_OFFSET
|
|
7748
|
+
);
|
|
7666
7749
|
}
|
|
7667
7750
|
return assetManifestBytes;
|
|
7668
7751
|
};
|
|
7669
|
-
var createReverseMap = async (dir) => {
|
|
7670
|
-
const files = await import_promises7.default.readdir(dir, { recursive: true });
|
|
7671
|
-
const assetsReverseMap = {};
|
|
7672
|
-
await Promise.all(
|
|
7673
|
-
files.map(async (file) => {
|
|
7674
|
-
const filepath = import_node_path.default.join(dir, file);
|
|
7675
|
-
const relativeFilepath = import_node_path.default.relative(dir, filepath);
|
|
7676
|
-
const filestat = await import_promises7.default.stat(filepath);
|
|
7677
|
-
if (filestat.isSymbolicLink() || filestat.isDirectory()) {
|
|
7678
|
-
return;
|
|
7679
|
-
} else {
|
|
7680
|
-
const pathHash = bytesToHex(
|
|
7681
|
-
await hashPath(encodeFilePath(relativeFilepath, import_node_path.default.sep))
|
|
7682
|
-
);
|
|
7683
|
-
assetsReverseMap[pathHash] = {
|
|
7684
|
-
filePath: relativeFilepath,
|
|
7685
|
-
contentType: getContentType(filepath)
|
|
7686
|
-
};
|
|
7687
|
-
}
|
|
7688
|
-
})
|
|
7689
|
-
);
|
|
7690
|
-
return JSON.stringify(assetsReverseMap);
|
|
7691
|
-
};
|
|
7692
7752
|
var bytesToHex = (buffer) => {
|
|
7693
7753
|
return [...new Uint8Array(buffer)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7694
7754
|
};
|
|
@@ -9084,8 +9144,15 @@ function getQueueProducers(allWorkerOpts) {
|
|
|
9084
9144
|
])
|
|
9085
9145
|
);
|
|
9086
9146
|
}
|
|
9087
|
-
|
|
9088
|
-
|
|
9147
|
+
const producersIterable = Object.entries(
|
|
9148
|
+
workerProducers
|
|
9149
|
+
);
|
|
9150
|
+
for (const [bindingName, opts] of producersIterable) {
|
|
9151
|
+
if (typeof opts === "string") {
|
|
9152
|
+
queueProducers.set(bindingName, { workerName, queueName: opts });
|
|
9153
|
+
} else {
|
|
9154
|
+
queueProducers.set(bindingName, { workerName, ...opts });
|
|
9155
|
+
}
|
|
9089
9156
|
}
|
|
9090
9157
|
}
|
|
9091
9158
|
}
|
|
@@ -9568,6 +9635,9 @@ var Miniflare2 = class {
|
|
|
9568
9635
|
const proxyBindings = [];
|
|
9569
9636
|
const allWorkerBindings = /* @__PURE__ */ new Map();
|
|
9570
9637
|
const wrappedBindingsToPopulate = [];
|
|
9638
|
+
if (this.#workerOpts[0].assets.assets) {
|
|
9639
|
+
this.#workerOpts[0].assets.assets.workerName = this.#workerOpts[0].core.name;
|
|
9640
|
+
}
|
|
9571
9641
|
for (let i = 0; i < allWorkerOpts.length; i++) {
|
|
9572
9642
|
const previousWorkerOpts = allPreviousWorkerOpts?.[i];
|
|
9573
9643
|
const workerOpts = allWorkerOpts[i];
|
|
@@ -9687,8 +9757,11 @@ var Miniflare2 = class {
|
|
|
9687
9757
|
const globalServices = getGlobalServices({
|
|
9688
9758
|
sharedOptions: sharedOpts.core,
|
|
9689
9759
|
allWorkerRoutes,
|
|
9690
|
-
// if Workers + Assets project, point to router Worker
|
|
9691
|
-
|
|
9760
|
+
// if Workers + Assets project but NOT Vitest, point to router Worker instead
|
|
9761
|
+
// if Vitest with assets, the self binding on the test runner will point to RW
|
|
9762
|
+
fallbackWorkerName: this.#workerOpts[0].assets.assets && !this.#workerOpts[0].core.name?.startsWith(
|
|
9763
|
+
"vitest-pool-workers-runner-"
|
|
9764
|
+
) ? ROUTER_SERVICE_NAME : getUserServiceName(this.#workerOpts[0].core.name),
|
|
9692
9765
|
loopbackPort,
|
|
9693
9766
|
log: this.#log,
|
|
9694
9767
|
proxyBindings
|
|
@@ -10195,7 +10268,7 @@ var Miniflare2 = class {
|
|
|
10195
10268
|
_transformsForContentEncodingAndContentType,
|
|
10196
10269
|
base64Decode,
|
|
10197
10270
|
base64Encode,
|
|
10198
|
-
|
|
10271
|
+
buildAssetManifest,
|
|
10199
10272
|
compileModuleRules,
|
|
10200
10273
|
coupleWebSocket,
|
|
10201
10274
|
createFetchMock,
|
|
@@ -10215,6 +10288,7 @@ var Miniflare2 = class {
|
|
|
10215
10288
|
getFreshSourceMapSupport,
|
|
10216
10289
|
getGlobalServices,
|
|
10217
10290
|
getMiniflareObjectBindings,
|
|
10291
|
+
getNodeCompat,
|
|
10218
10292
|
getPersistPath,
|
|
10219
10293
|
getRootPath,
|
|
10220
10294
|
globsToRegExps,
|