@cloudflare/vite-plugin 0.0.0-ca3cbc42a → 0.0.0-ca6001066
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/asset-workers/asset-worker.js +1252 -1676
- package/dist/asset-workers/router-worker.js +1182 -1565
- package/dist/index.js +139 -102
- package/dist/runner-worker/index.js +1 -1
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import assert9 from "node:assert";
|
|
3
3
|
import * as fs5 from "node:fs";
|
|
4
|
+
import { builtinModules as builtinModules2 } from "node:module";
|
|
4
5
|
import * as path7 from "node:path";
|
|
5
6
|
import { createMiddleware } from "@hattip/adapter-node";
|
|
6
7
|
|
|
@@ -1074,7 +1075,6 @@ import * as vite6 from "vite";
|
|
|
1074
1075
|
|
|
1075
1076
|
// src/cloudflare-environment.ts
|
|
1076
1077
|
import assert from "node:assert";
|
|
1077
|
-
import { builtinModules } from "node:module";
|
|
1078
1078
|
import * as vite2 from "vite";
|
|
1079
1079
|
|
|
1080
1080
|
// src/constants.ts
|
|
@@ -1207,7 +1207,9 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
1207
1207
|
// dependencies as not external
|
|
1208
1208
|
noExternal: true,
|
|
1209
1209
|
// We want to use `workerd` package exports if available (e.g. for postgres).
|
|
1210
|
-
conditions: [...defaultConditions, "development|production"]
|
|
1210
|
+
conditions: [...defaultConditions, "development|production"],
|
|
1211
|
+
// The Cloudflare ones are proper builtins in the environment
|
|
1212
|
+
builtins: [...cloudflareBuiltInModules]
|
|
1211
1213
|
},
|
|
1212
1214
|
dev: {
|
|
1213
1215
|
createEnvironment(name2, config) {
|
|
@@ -1229,19 +1231,14 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
1229
1231
|
// so the input value here serves both as the build input as well as the starting point for
|
|
1230
1232
|
// dev pre-bundling crawling (were we not to set this input field we'd have to appropriately set
|
|
1231
1233
|
// optimizeDeps.entries in the dev config)
|
|
1232
|
-
input: workerConfig.main
|
|
1233
|
-
external: [...cloudflareBuiltInModules]
|
|
1234
|
+
input: workerConfig.main
|
|
1234
1235
|
}
|
|
1235
1236
|
},
|
|
1236
1237
|
optimizeDeps: {
|
|
1237
1238
|
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
1238
1239
|
noDiscovery: false,
|
|
1239
1240
|
entries: workerConfig.main,
|
|
1240
|
-
exclude: [
|
|
1241
|
-
...cloudflareBuiltInModules,
|
|
1242
|
-
// we have to exclude all node modules to work in dev-mode not just the unenv externals...
|
|
1243
|
-
...builtinModules.concat(builtinModules.map((m) => `node:${m}`))
|
|
1244
|
-
],
|
|
1241
|
+
exclude: [...cloudflareBuiltInModules],
|
|
1245
1242
|
esbuildOptions: {
|
|
1246
1243
|
platform: "neutral",
|
|
1247
1244
|
conditions: [...defaultConditions, "development"],
|
|
@@ -1367,7 +1364,13 @@ import * as fs2 from "node:fs";
|
|
|
1367
1364
|
import * as fsp from "node:fs/promises";
|
|
1368
1365
|
import * as path3 from "node:path";
|
|
1369
1366
|
import { fileURLToPath } from "node:url";
|
|
1370
|
-
import {
|
|
1367
|
+
import {
|
|
1368
|
+
kCurrentWorker,
|
|
1369
|
+
Log,
|
|
1370
|
+
LogLevel,
|
|
1371
|
+
Response as MiniflareResponse
|
|
1372
|
+
} from "miniflare";
|
|
1373
|
+
import { globSync } from "tinyglobby";
|
|
1371
1374
|
import "vite";
|
|
1372
1375
|
import {
|
|
1373
1376
|
unstable_getMiniflareWorkerOptions,
|
|
@@ -1401,11 +1404,10 @@ function getWorkerToWorkerEntrypointNamesMap(workers) {
|
|
|
1401
1404
|
);
|
|
1402
1405
|
for (const worker of workers) {
|
|
1403
1406
|
for (const value of Object.values(worker.serviceBindings ?? {})) {
|
|
1404
|
-
if (typeof value === "object" && "name" in value &&
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1407
|
-
);
|
|
1408
|
-
assert4(entrypointNames, missingWorkerErrorMessage(value.name));
|
|
1407
|
+
if (typeof value === "object" && "name" in value && value.entrypoint !== void 0 && value.entrypoint !== "default") {
|
|
1408
|
+
const targetWorkerName = value.name === kCurrentWorker ? worker.name : value.name;
|
|
1409
|
+
const entrypointNames = workerToWorkerEntrypointNamesMap.get(targetWorkerName);
|
|
1410
|
+
assert4(entrypointNames, missingWorkerErrorMessage(targetWorkerName));
|
|
1409
1411
|
entrypointNames.add(value.entrypoint);
|
|
1410
1412
|
}
|
|
1411
1413
|
}
|
|
@@ -1585,20 +1587,17 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1585
1587
|
);
|
|
1586
1588
|
const [moduleId] = invokePayloadData.data;
|
|
1587
1589
|
const moduleRE = new RegExp(MODULE_PATTERN);
|
|
1588
|
-
|
|
1590
|
+
const shouldExternalize = (
|
|
1591
|
+
// Worker modules (CompiledWasm, Text, Data)
|
|
1592
|
+
moduleRE.test(moduleId)
|
|
1593
|
+
);
|
|
1594
|
+
if (shouldExternalize) {
|
|
1589
1595
|
const result2 = {
|
|
1590
1596
|
externalize: moduleId,
|
|
1591
1597
|
type: "module"
|
|
1592
1598
|
};
|
|
1593
1599
|
return MiniflareResponse.json({ result: result2 });
|
|
1594
1600
|
}
|
|
1595
|
-
if (moduleId.startsWith("cloudflare:")) {
|
|
1596
|
-
const result2 = {
|
|
1597
|
-
externalize: moduleId,
|
|
1598
|
-
type: "builtin"
|
|
1599
|
-
};
|
|
1600
|
-
return MiniflareResponse.json({ result: result2 });
|
|
1601
|
-
}
|
|
1602
1601
|
const devEnvironment = viteDevServer.environments[environmentName];
|
|
1603
1602
|
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
1604
1603
|
return MiniflareResponse.json(result);
|
|
@@ -1658,7 +1657,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1658
1657
|
const workflowEntrypointClassNames = workerToWorkflowEntrypointClassNamesMap.get(workerOptions.name);
|
|
1659
1658
|
assert4(
|
|
1660
1659
|
workflowEntrypointClassNames,
|
|
1661
|
-
`WorkflowEntrypoint class names not found for worker ${workerOptions.name}`
|
|
1660
|
+
`WorkflowEntrypoint class names not found for worker: ${workerOptions.name}`
|
|
1662
1661
|
);
|
|
1663
1662
|
for (const className of [...workflowEntrypointClassNames].sort()) {
|
|
1664
1663
|
wrappers.push(
|
|
@@ -1694,17 +1693,19 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1694
1693
|
);
|
|
1695
1694
|
const moduleRE = new RegExp(MODULE_PATTERN);
|
|
1696
1695
|
const match = moduleRE.exec(rawSpecifier);
|
|
1697
|
-
assert4(match, `Unexpected error: no match for module ${rawSpecifier}.`);
|
|
1696
|
+
assert4(match, `Unexpected error: no match for module: ${rawSpecifier}.`);
|
|
1698
1697
|
const [full, moduleType, modulePath] = match;
|
|
1699
1698
|
assert4(
|
|
1700
1699
|
modulePath,
|
|
1701
|
-
`Unexpected error: module path not found in reference ${full}.`
|
|
1700
|
+
`Unexpected error: module path not found in reference: ${full}.`
|
|
1702
1701
|
);
|
|
1703
1702
|
let source;
|
|
1704
1703
|
try {
|
|
1705
1704
|
source = fs2.readFileSync(modulePath);
|
|
1706
1705
|
} catch (error) {
|
|
1707
|
-
throw new Error(
|
|
1706
|
+
throw new Error(
|
|
1707
|
+
`Import "${modulePath}" not found. Does the file exist?`
|
|
1708
|
+
);
|
|
1708
1709
|
}
|
|
1709
1710
|
return MiniflareResponse.json({
|
|
1710
1711
|
// Cap'n Proto expects byte arrays for `:Data` typed fields from JSON
|
|
@@ -1713,6 +1714,26 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer) {
|
|
|
1713
1714
|
}
|
|
1714
1715
|
};
|
|
1715
1716
|
}
|
|
1717
|
+
function getPreviewModules(main, modulesRules) {
|
|
1718
|
+
assert4(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
1719
|
+
const rootPath = path3.dirname(main);
|
|
1720
|
+
const entryPath = path3.basename(main);
|
|
1721
|
+
return {
|
|
1722
|
+
rootPath,
|
|
1723
|
+
modules: [
|
|
1724
|
+
{
|
|
1725
|
+
type: "ESModule",
|
|
1726
|
+
path: entryPath
|
|
1727
|
+
},
|
|
1728
|
+
...modulesRules.flatMap(
|
|
1729
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path8) => ({
|
|
1730
|
+
type,
|
|
1731
|
+
path: path8
|
|
1732
|
+
}))
|
|
1733
|
+
)
|
|
1734
|
+
]
|
|
1735
|
+
};
|
|
1736
|
+
}
|
|
1716
1737
|
function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
|
|
1717
1738
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
1718
1739
|
const configPaths = getWorkerConfigPaths(resolvedViteConfig.root);
|
|
@@ -1721,13 +1742,12 @@ function getPreviewMiniflareOptions(vitePreviewServer, persistState) {
|
|
|
1721
1742
|
);
|
|
1722
1743
|
const workers = workerConfigs.map((config) => {
|
|
1723
1744
|
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(config);
|
|
1724
|
-
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1745
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
1725
1746
|
return {
|
|
1726
1747
|
...workerOptions,
|
|
1727
1748
|
// We have to add the name again because `unstable_getMiniflareWorkerOptions` sets it to `undefined`
|
|
1728
1749
|
name: config.name,
|
|
1729
|
-
modules: true,
|
|
1730
|
-
...miniflareWorkerOptions.main ? { scriptPath: miniflareWorkerOptions.main } : { script: "" }
|
|
1750
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
1731
1751
|
};
|
|
1732
1752
|
});
|
|
1733
1753
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
@@ -7310,7 +7330,7 @@ Parser.acorn = {
|
|
|
7310
7330
|
};
|
|
7311
7331
|
|
|
7312
7332
|
// ../../node_modules/.pnpm/mlly@1.7.4/node_modules/mlly/dist/index.mjs
|
|
7313
|
-
import { builtinModules
|
|
7333
|
+
import { builtinModules, createRequire } from "node:module";
|
|
7314
7334
|
import fs3, { realpathSync, statSync as statSync2, promises } from "node:fs";
|
|
7315
7335
|
|
|
7316
7336
|
// ../../node_modules/.pnpm/ufo@1.5.4/node_modules/ufo/dist/index.mjs
|
|
@@ -7370,10 +7390,10 @@ var isAbsolute = function(p) {
|
|
|
7370
7390
|
import { fileURLToPath as fileURLToPath$1, URL as URL$1, pathToFileURL as pathToFileURL$1 } from "node:url";
|
|
7371
7391
|
import assert5 from "node:assert";
|
|
7372
7392
|
import process$1 from "node:process";
|
|
7373
|
-
import path4, { dirname as
|
|
7393
|
+
import path4, { dirname as dirname4 } from "node:path";
|
|
7374
7394
|
import v8 from "node:v8";
|
|
7375
7395
|
import { format as format2, inspect } from "node:util";
|
|
7376
|
-
var BUILTIN_MODULES = new Set(
|
|
7396
|
+
var BUILTIN_MODULES = new Set(builtinModules);
|
|
7377
7397
|
function normalizeSlash(path8) {
|
|
7378
7398
|
return path8.replace(/\\/g, "/");
|
|
7379
7399
|
}
|
|
@@ -8487,7 +8507,7 @@ function parsePackageName(specifier, base) {
|
|
|
8487
8507
|
return { packageName, packageSubpath, isScoped };
|
|
8488
8508
|
}
|
|
8489
8509
|
function packageResolve(specifier, base, conditions) {
|
|
8490
|
-
if (
|
|
8510
|
+
if (builtinModules.includes(specifier)) {
|
|
8491
8511
|
return new URL$1("node:" + specifier);
|
|
8492
8512
|
}
|
|
8493
8513
|
const { packageName, packageSubpath, isScoped } = parsePackageName(
|
|
@@ -8574,7 +8594,7 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
|
8574
8594
|
try {
|
|
8575
8595
|
resolved = new URL$1(specifier);
|
|
8576
8596
|
} catch (error_) {
|
|
8577
|
-
if (isRemote && !
|
|
8597
|
+
if (isRemote && !builtinModules.includes(specifier)) {
|
|
8578
8598
|
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
8579
8599
|
error.cause = error_;
|
|
8580
8600
|
throw error;
|
|
@@ -8719,7 +8739,8 @@ var { env } = defineEnv({
|
|
|
8719
8739
|
nodeCompat: true,
|
|
8720
8740
|
presets: [cloudflare]
|
|
8721
8741
|
});
|
|
8722
|
-
var
|
|
8742
|
+
var nodeCompatExternals = new Set(env.external);
|
|
8743
|
+
var nodeCompatEntries = getNodeCompatEntries();
|
|
8723
8744
|
function isNodeCompat(workerConfig) {
|
|
8724
8745
|
if (workerConfig === void 0) {
|
|
8725
8746
|
return false;
|
|
@@ -8747,12 +8768,17 @@ function injectGlobalCode(id, code) {
|
|
|
8747
8768
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
8748
8769
|
if (typeof globalInject === "string") {
|
|
8749
8770
|
const moduleSpecifier2 = globalInject;
|
|
8750
|
-
return `import var_${globalName} from "${
|
|
8771
|
+
return `import var_${globalName} from "${moduleSpecifier2}";
|
|
8751
8772
|
globalThis.${globalName} = var_${globalName};
|
|
8752
8773
|
`;
|
|
8753
8774
|
}
|
|
8754
8775
|
const [moduleSpecifier, exportName] = globalInject;
|
|
8755
|
-
|
|
8776
|
+
assert6(
|
|
8777
|
+
moduleSpecifier !== void 0,
|
|
8778
|
+
"Expected moduleSpecifier to be defined"
|
|
8779
|
+
);
|
|
8780
|
+
assert6(exportName !== void 0, "Expected exportName to be defined");
|
|
8781
|
+
return `import var_${globalName} from "${moduleSpecifier}";
|
|
8756
8782
|
globalThis.${globalName} = var_${globalName}.${exportName};
|
|
8757
8783
|
`;
|
|
8758
8784
|
}).join("\n");
|
|
@@ -8763,37 +8789,36 @@ globalThis.${globalName} = var_${globalName}.${exportName};
|
|
|
8763
8789
|
map: modified.generateMap({ hires: "boundary", source: id })
|
|
8764
8790
|
};
|
|
8765
8791
|
}
|
|
8766
|
-
function getNodeCompatAliases() {
|
|
8767
|
-
const aliases = {};
|
|
8768
|
-
Object.keys(env.alias).forEach((key) => {
|
|
8769
|
-
if (!env.external.includes(key)) {
|
|
8770
|
-
aliases[key] = CLOUDFLARE_VIRTUAL_PREFIX + key;
|
|
8771
|
-
}
|
|
8772
|
-
});
|
|
8773
|
-
return aliases;
|
|
8774
|
-
}
|
|
8775
|
-
function getNodeCompatExternals() {
|
|
8776
|
-
return env.external;
|
|
8777
|
-
}
|
|
8778
|
-
function maybeStripNodeJsVirtualPrefix(source) {
|
|
8779
|
-
return source.startsWith(CLOUDFLARE_VIRTUAL_PREFIX) ? source.slice(CLOUDFLARE_VIRTUAL_PREFIX.length) : void 0;
|
|
8780
|
-
}
|
|
8781
8792
|
function resolveNodeJSImport(source) {
|
|
8782
8793
|
const alias = env.alias[source];
|
|
8783
8794
|
if (alias) {
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
source = alias;
|
|
8795
|
+
return {
|
|
8796
|
+
unresolved: alias,
|
|
8797
|
+
resolved: resolvePathSync(alias, { url: import.meta.url })
|
|
8798
|
+
};
|
|
8789
8799
|
}
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8800
|
+
if (nodeCompatEntries.has(source)) {
|
|
8801
|
+
return {
|
|
8802
|
+
unresolved: source,
|
|
8803
|
+
resolved: resolvePathSync(source, { url: import.meta.url })
|
|
8804
|
+
};
|
|
8805
|
+
}
|
|
8806
|
+
}
|
|
8807
|
+
function getNodeCompatEntries() {
|
|
8808
|
+
const entries = new Set(Object.values(env.alias));
|
|
8809
|
+
for (const globalInject of Object.values(env.inject)) {
|
|
8810
|
+
if (typeof globalInject === "string") {
|
|
8811
|
+
entries.add(globalInject);
|
|
8812
|
+
} else {
|
|
8813
|
+
assert6(
|
|
8814
|
+
globalInject[0] !== void 0,
|
|
8815
|
+
"Expected first element of globalInject to be defined"
|
|
8816
|
+
);
|
|
8817
|
+
entries.add(globalInject[0]);
|
|
8818
|
+
}
|
|
8819
|
+
}
|
|
8820
|
+
nodeCompatExternals.forEach((external) => entries.delete(external));
|
|
8821
|
+
return entries;
|
|
8797
8822
|
}
|
|
8798
8823
|
|
|
8799
8824
|
// src/plugin-config.ts
|
|
@@ -9106,9 +9131,9 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
9106
9131
|
}
|
|
9107
9132
|
|
|
9108
9133
|
// src/websockets.ts
|
|
9109
|
-
import
|
|
9134
|
+
import { WebSocketServer } from "ws";
|
|
9110
9135
|
function handleWebSocket(httpServer, fetcher, logger) {
|
|
9111
|
-
const nodeWebSocket = new
|
|
9136
|
+
const nodeWebSocket = new WebSocketServer({ noServer: true });
|
|
9112
9137
|
httpServer.on(
|
|
9113
9138
|
"upgrade",
|
|
9114
9139
|
async (request, socket, head) => {
|
|
@@ -9217,7 +9242,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9217
9242
|
}
|
|
9218
9243
|
} : void 0,
|
|
9219
9244
|
builder: {
|
|
9220
|
-
|
|
9245
|
+
buildApp: userConfig.builder?.buildApp ?? (async (builder) => {
|
|
9221
9246
|
const clientEnvironment = builder.environments.client;
|
|
9222
9247
|
const defaultHtmlPath = path7.resolve(
|
|
9223
9248
|
builder.config.root,
|
|
@@ -9243,7 +9268,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9243
9268
|
)
|
|
9244
9269
|
);
|
|
9245
9270
|
}
|
|
9246
|
-
}
|
|
9271
|
+
})
|
|
9247
9272
|
}
|
|
9248
9273
|
};
|
|
9249
9274
|
},
|
|
@@ -9304,7 +9329,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9304
9329
|
return;
|
|
9305
9330
|
}
|
|
9306
9331
|
config.no_bundle = true;
|
|
9307
|
-
config.rules = [{ type: "ESModule", globs: ["**/*.js"] }];
|
|
9332
|
+
config.rules = [{ type: "ESModule", globs: ["**/*.js", "**/*.mjs"] }];
|
|
9308
9333
|
if (config.unsafe && Object.keys(config.unsafe).length === 0) {
|
|
9309
9334
|
config.unsafe = void 0;
|
|
9310
9335
|
}
|
|
@@ -9462,49 +9487,61 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
9462
9487
|
apply(_config, env2) {
|
|
9463
9488
|
return !env2.isPreview;
|
|
9464
9489
|
},
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
resolve: {
|
|
9468
|
-
alias: getNodeCompatAliases()
|
|
9469
|
-
}
|
|
9470
|
-
};
|
|
9471
|
-
},
|
|
9472
|
-
configEnvironment(environmentName) {
|
|
9473
|
-
const workerConfig = getWorkerConfig2(environmentName);
|
|
9474
|
-
if (isNodeCompat(workerConfig)) {
|
|
9490
|
+
configEnvironment(name2) {
|
|
9491
|
+
if (isNodeCompat(getWorkerConfig2(name2))) {
|
|
9475
9492
|
return {
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9493
|
+
resolve: {
|
|
9494
|
+
builtins: [...nodeCompatExternals]
|
|
9495
|
+
},
|
|
9496
|
+
optimizeDeps: {
|
|
9497
|
+
// This is a list of dependency entry-points that should be pre-bundled.
|
|
9498
|
+
// In this case we provide a list of all the possible polyfills so that they are pre-bundled,
|
|
9499
|
+
// ready ahead the first request to the dev server.
|
|
9500
|
+
// Without this the dependency optimizer will try to bundle them on-the-fly in the middle of the first request,
|
|
9501
|
+
// which can potentially cause problems if it leads to previous pre-bundling to become stale and needing to be reloaded.
|
|
9502
|
+
// TODO: work out how to re-enable pre-bundling of these
|
|
9503
|
+
// include: [...getNodeCompatEntries()],
|
|
9504
|
+
// This is a list of module specifiers that the dependency optimizer should not follow when doing import analysis.
|
|
9505
|
+
// In this case we provide a list of all the Node.js modules, both those built-in to workerd and those that will be polyfilled.
|
|
9506
|
+
// Obviously we don't want/need the optimizer to try to process modules that are built-in;
|
|
9507
|
+
// But also we want to avoid following the ones that are polyfilled since the dependency-optimizer import analyzer does not
|
|
9508
|
+
// resolve these imports using our `resolveId()` hook causing the optimization step to fail.
|
|
9509
|
+
exclude: [
|
|
9510
|
+
...builtinModules2,
|
|
9511
|
+
...builtinModules2.map((m) => `node:${m}`)
|
|
9512
|
+
]
|
|
9480
9513
|
}
|
|
9481
9514
|
};
|
|
9482
9515
|
}
|
|
9483
9516
|
},
|
|
9517
|
+
applyToEnvironment(environment) {
|
|
9518
|
+
return isNodeCompat(getWorkerConfig2(environment.name));
|
|
9519
|
+
},
|
|
9520
|
+
// We need the resolver from this plugin to run before built-in ones, otherwise Vite's built-in
|
|
9521
|
+
// resolver will try to externalize the Node.js module imports (e.g. `perf_hooks` and `node:tty`)
|
|
9522
|
+
// rather than allowing the resolve hook here to alias then to polyfills.
|
|
9523
|
+
enforce: "pre",
|
|
9484
9524
|
async resolveId(source, importer, options) {
|
|
9485
|
-
const
|
|
9486
|
-
if (!
|
|
9487
|
-
return;
|
|
9525
|
+
const result = resolveNodeJSImport(source);
|
|
9526
|
+
if (!result) {
|
|
9527
|
+
return this.resolve(source, importer, options);
|
|
9488
9528
|
}
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9499
|
-
return this.resolve(optimized, importer, options);
|
|
9529
|
+
if (this.environment.mode === "dev") {
|
|
9530
|
+
assert9(
|
|
9531
|
+
this.environment.depsOptimizer,
|
|
9532
|
+
"depsOptimizer is required in dev mode"
|
|
9533
|
+
);
|
|
9534
|
+
const { id } = this.environment.depsOptimizer.registerMissingImport(
|
|
9535
|
+
result.unresolved,
|
|
9536
|
+
result.resolved
|
|
9537
|
+
);
|
|
9538
|
+
return this.resolve(id, importer, options);
|
|
9500
9539
|
}
|
|
9501
|
-
return this.resolve(resolved, importer, options);
|
|
9540
|
+
return this.resolve(result.resolved, importer, options);
|
|
9502
9541
|
},
|
|
9503
9542
|
async transform(code, id) {
|
|
9504
9543
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
9505
|
-
|
|
9506
|
-
return;
|
|
9507
|
-
}
|
|
9544
|
+
assert9(workerConfig, "Expected a worker config");
|
|
9508
9545
|
const resolvedId = await this.resolve(workerConfig.main);
|
|
9509
9546
|
if (id === resolvedId?.id) {
|
|
9510
9547
|
return injectGlobalCode(id, code);
|
|
@@ -25,7 +25,7 @@ function stripInternalEnv(internalEnv) {
|
|
|
25
25
|
return userEnv;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
// ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.
|
|
28
|
+
// ../../node_modules/.pnpm/vite@6.1.0_@types+node@18.19.76_jiti@2.4.2/node_modules/vite/dist/node/module-runner.js
|
|
29
29
|
var VALID_ID_PREFIX = "/@id/";
|
|
30
30
|
var NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
31
31
|
var SOURCEMAPPING_URL = "sourceMa";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-ca6001066",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -35,25 +35,26 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@cloudflare/unenv-preset": "1.1.1",
|
|
37
37
|
"@hattip/adapter-node": "^0.0.49",
|
|
38
|
+
"tinyglobby": "^0.2.12",
|
|
38
39
|
"unenv": "2.0.0-rc.1",
|
|
39
|
-
"ws": "
|
|
40
|
-
"miniflare": "0.0.0-
|
|
40
|
+
"ws": "8.18.0",
|
|
41
|
+
"miniflare": "0.0.0-ca6001066"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@cloudflare/workers-types": "^4.
|
|
44
|
+
"@cloudflare/workers-types": "^4.20250224.0",
|
|
44
45
|
"@types/node": "^22.10.1",
|
|
45
46
|
"@types/ws": "^8.5.13",
|
|
46
47
|
"magic-string": "^0.30.12",
|
|
47
48
|
"mlly": "^1.7.4",
|
|
48
49
|
"tsup": "8.3.0",
|
|
49
50
|
"typescript": "^5.7.2",
|
|
50
|
-
"undici": "^5.28.
|
|
51
|
+
"undici": "^5.28.5",
|
|
51
52
|
"vite": "^6.1.0",
|
|
52
|
-
"vitest": "~
|
|
53
|
+
"vitest": "~3.0.5",
|
|
54
|
+
"@cloudflare/workers-shared": "0.0.0-ca6001066",
|
|
53
55
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
54
|
-
"@cloudflare/workers-shared": "0.0.0-ca3cbc42a",
|
|
55
56
|
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
56
|
-
"wrangler": "0.0.0-
|
|
57
|
+
"wrangler": "0.0.0-ca6001066"
|
|
57
58
|
},
|
|
58
59
|
"peerDependencies": {
|
|
59
60
|
"vite": "^6.1.0",
|