@cloudflare/vite-plugin 1.7.4 → 1.8.0
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/index.js +41 -53
- package/dist/runner-worker/index.js +437 -574
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -13361,7 +13361,8 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13361
13361
|
optimizeDeps: {
|
|
13362
13362
|
// Note: ssr pre-bundling is opt-in and we need to enable it by setting `noDiscovery` to false
|
|
13363
13363
|
noDiscovery: false,
|
|
13364
|
-
|
|
13364
|
+
// We need to normalize the path as it is treated as a glob and backslashes are therefore treated as escape characters.
|
|
13365
|
+
entries: vite2.normalizePath(workerConfig.main),
|
|
13365
13366
|
exclude: [...cloudflareBuiltInModules],
|
|
13366
13367
|
esbuildOptions: {
|
|
13367
13368
|
platform: "neutral",
|
|
@@ -14611,6 +14612,44 @@ function assertIsPreview(resolvedPluginConfig) {
|
|
|
14611
14612
|
);
|
|
14612
14613
|
}
|
|
14613
14614
|
|
|
14615
|
+
// src/vite-config.ts
|
|
14616
|
+
import assert10 from "node:assert";
|
|
14617
|
+
function validateWorkerEnvironmentOptions(resolvedPluginConfig, resolvedViteConfig) {
|
|
14618
|
+
const workerEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
14619
|
+
const disallowedEnvironmentOptionsMap = /* @__PURE__ */ new Map();
|
|
14620
|
+
for (const environmentName of workerEnvironmentNames) {
|
|
14621
|
+
const environmentOptions = resolvedViteConfig.environments[environmentName];
|
|
14622
|
+
assert10(
|
|
14623
|
+
environmentOptions,
|
|
14624
|
+
`Missing environment config for "${environmentName}"`
|
|
14625
|
+
);
|
|
14626
|
+
const { resolve: resolve8 } = environmentOptions;
|
|
14627
|
+
const disallowedEnvironmentOptions = {};
|
|
14628
|
+
if (resolve8.external === true || resolve8.external.length) {
|
|
14629
|
+
disallowedEnvironmentOptions.resolveExternal = resolve8.external;
|
|
14630
|
+
}
|
|
14631
|
+
if (Object.keys(disallowedEnvironmentOptions).length) {
|
|
14632
|
+
disallowedEnvironmentOptionsMap.set(
|
|
14633
|
+
environmentName,
|
|
14634
|
+
disallowedEnvironmentOptions
|
|
14635
|
+
);
|
|
14636
|
+
}
|
|
14637
|
+
}
|
|
14638
|
+
if (disallowedEnvironmentOptionsMap.size) {
|
|
14639
|
+
const errorMessage = `The following environment options are incompatible with the Cloudflare Vite plugin:
|
|
14640
|
+
${[
|
|
14641
|
+
...disallowedEnvironmentOptionsMap
|
|
14642
|
+
].map(
|
|
14643
|
+
([environmentName, disallowedEnvironmentOptions]) => disallowedEnvironmentOptions.resolveExternal && ` - "${environmentName}" environment: \`resolve.external\`: ${JSON.stringify(disallowedEnvironmentOptions.resolveExternal)}
|
|
14644
|
+
`
|
|
14645
|
+
).join(
|
|
14646
|
+
""
|
|
14647
|
+
)}To resolve this issue, avoid setting \`resolve.external\` in your Cloudflare Worker environments.
|
|
14648
|
+
`;
|
|
14649
|
+
throw new Error(errorMessage);
|
|
14650
|
+
}
|
|
14651
|
+
}
|
|
14652
|
+
|
|
14614
14653
|
// src/websockets.ts
|
|
14615
14654
|
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14616
14655
|
import { coupleWebSocket } from "miniflare";
|
|
@@ -14648,57 +14687,6 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14648
14687
|
);
|
|
14649
14688
|
}
|
|
14650
14689
|
|
|
14651
|
-
// src/worker-environments-validation.ts
|
|
14652
|
-
import assert10 from "node:assert";
|
|
14653
|
-
function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolvedViteConfig) {
|
|
14654
|
-
const workersEnvironmentNames = Object.keys(resolvedPluginConfig.workers);
|
|
14655
|
-
const disallowedEnvsConfigs = /* @__PURE__ */ new Map();
|
|
14656
|
-
for (const envName of workersEnvironmentNames) {
|
|
14657
|
-
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14658
|
-
assert10(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14659
|
-
const { optimizeDeps, resolve: resolve8 } = workerEnvConfig;
|
|
14660
|
-
const disallowedConfig = {};
|
|
14661
|
-
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14662
|
-
if (cloudflareBuiltInModules.includes(entry)) {
|
|
14663
|
-
return false;
|
|
14664
|
-
}
|
|
14665
|
-
if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
|
|
14666
|
-
return false;
|
|
14667
|
-
}
|
|
14668
|
-
if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
|
|
14669
|
-
return false;
|
|
14670
|
-
}
|
|
14671
|
-
return true;
|
|
14672
|
-
});
|
|
14673
|
-
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14674
|
-
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14675
|
-
}
|
|
14676
|
-
if (resolve8.external === true || resolve8.external.length > 0) {
|
|
14677
|
-
disallowedConfig.resolveExternal = resolve8.external;
|
|
14678
|
-
}
|
|
14679
|
-
if (Object.keys(disallowedConfig).length > 0) {
|
|
14680
|
-
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
14681
|
-
}
|
|
14682
|
-
}
|
|
14683
|
-
if (disallowedEnvsConfigs.size > 0) {
|
|
14684
|
-
const errorMessage = `The following environment configurations are incompatible with the Cloudflare Vite plugin:
|
|
14685
|
-
${[
|
|
14686
|
-
...disallowedEnvsConfigs
|
|
14687
|
-
].map(
|
|
14688
|
-
([envName, disallowedConfig]) => [
|
|
14689
|
-
disallowedConfig.optimizeDepsExclude ? ` - "${envName}" environment: \`optimizeDeps.exclude\`: ${JSON.stringify(disallowedConfig.optimizeDepsExclude)}
|
|
14690
|
-
` : null,
|
|
14691
|
-
disallowedConfig.resolveExternal ? ` - "${envName}" environment: \`resolve.external\`: ${JSON.stringify(disallowedConfig.resolveExternal)}
|
|
14692
|
-
` : null
|
|
14693
|
-
].join("")
|
|
14694
|
-
).join(
|
|
14695
|
-
""
|
|
14696
|
-
)}To resolve this issue, avoid setting \`optimizeDeps.exclude\` and \`resolve.external\` in your Cloudflare Worker environments.
|
|
14697
|
-
`;
|
|
14698
|
-
throw new Error(errorMessage);
|
|
14699
|
-
}
|
|
14700
|
-
}
|
|
14701
|
-
|
|
14702
14690
|
// src/index.ts
|
|
14703
14691
|
var workersConfigsWarningShown = false;
|
|
14704
14692
|
var miniflare;
|
|
@@ -14778,7 +14766,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14778
14766
|
configResolved(config) {
|
|
14779
14767
|
resolvedViteConfig = config;
|
|
14780
14768
|
if (resolvedPluginConfig.type === "workers") {
|
|
14781
|
-
|
|
14769
|
+
validateWorkerEnvironmentOptions(
|
|
14782
14770
|
resolvedPluginConfig,
|
|
14783
14771
|
resolvedViteConfig
|
|
14784
14772
|
);
|