@cloudflare/vite-plugin 0.0.0-4c5ba3822 → 0.0.0-4cc036d46
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 +78 -15
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -490,6 +490,7 @@ import * as fs5 from "node:fs";
|
|
|
490
490
|
import * as fsp2 from "node:fs/promises";
|
|
491
491
|
import * as path9 from "node:path";
|
|
492
492
|
import { createMiddleware } from "@hattip/adapter-node";
|
|
493
|
+
import replace from "@rollup/plugin-replace";
|
|
493
494
|
|
|
494
495
|
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
495
496
|
var comma = ",".charCodeAt(0);
|
|
@@ -5831,14 +5832,14 @@ var AssetConfigSchema = z.object({
|
|
|
5831
5832
|
});
|
|
5832
5833
|
|
|
5833
5834
|
// src/asset-config.ts
|
|
5834
|
-
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig,
|
|
5835
|
+
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFilePath) {
|
|
5835
5836
|
if (!resolvedPluginConfig.experimental?.headersAndRedirectsDevModeSupport) {
|
|
5836
5837
|
return false;
|
|
5837
5838
|
}
|
|
5838
5839
|
return [
|
|
5839
5840
|
getRedirectsConfigPath(resolvedViteConfig),
|
|
5840
5841
|
getHeadersConfigPath(resolvedViteConfig)
|
|
5841
|
-
].includes(
|
|
5842
|
+
].includes(changedFilePath);
|
|
5842
5843
|
}
|
|
5843
5844
|
function getAssetsConfig(resolvedPluginConfig, entryWorkerConfig, resolvedConfig) {
|
|
5844
5845
|
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
@@ -12879,6 +12880,15 @@ function isNodeCompat(workerConfig) {
|
|
|
12879
12880
|
}
|
|
12880
12881
|
return false;
|
|
12881
12882
|
}
|
|
12883
|
+
function isNodeAls(workerConfig) {
|
|
12884
|
+
return workerConfig !== void 0 && getNodeCompat(
|
|
12885
|
+
workerConfig.compatibility_date,
|
|
12886
|
+
workerConfig.compatibility_flags ?? []
|
|
12887
|
+
).mode === "als";
|
|
12888
|
+
}
|
|
12889
|
+
function isNodeAlsModule(path10) {
|
|
12890
|
+
return /^(node:)?async_hooks$/.test(path10);
|
|
12891
|
+
}
|
|
12882
12892
|
function injectGlobalCode(id, code) {
|
|
12883
12893
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
12884
12894
|
if (typeof globalInject === "string") {
|
|
@@ -12909,7 +12919,7 @@ globalThis.${globalName} = var_${globalName}.${exportName};
|
|
|
12909
12919
|
}
|
|
12910
12920
|
function resolveNodeJSImport(source) {
|
|
12911
12921
|
const alias = env.alias[source];
|
|
12912
|
-
if (alias) {
|
|
12922
|
+
if (alias && !nodeCompatExternals.has(alias)) {
|
|
12913
12923
|
return {
|
|
12914
12924
|
unresolved: alias,
|
|
12915
12925
|
resolved: resolvePathSync(alias, { url: import.meta.url })
|
|
@@ -14180,12 +14190,15 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14180
14190
|
for (const envName of workersEnvironmentNames) {
|
|
14181
14191
|
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14182
14192
|
assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14183
|
-
const { optimizeDeps, resolve:
|
|
14193
|
+
const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
|
|
14184
14194
|
const disallowedConfig = {};
|
|
14185
14195
|
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14186
14196
|
if (cloudflareBuiltInModules.includes(entry)) {
|
|
14187
14197
|
return false;
|
|
14188
14198
|
}
|
|
14199
|
+
if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
|
|
14200
|
+
return false;
|
|
14201
|
+
}
|
|
14189
14202
|
if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
|
|
14190
14203
|
return false;
|
|
14191
14204
|
}
|
|
@@ -14194,8 +14207,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14194
14207
|
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14195
14208
|
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14196
14209
|
}
|
|
14197
|
-
if (
|
|
14198
|
-
disallowedConfig.resolveExternal =
|
|
14210
|
+
if (resolve7.external === true || resolve7.external.length > 0) {
|
|
14211
|
+
disallowedConfig.resolveExternal = resolve7.external;
|
|
14199
14212
|
}
|
|
14200
14213
|
if (Object.keys(disallowedConfig).length > 0) {
|
|
14201
14214
|
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
@@ -14401,14 +14414,12 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14401
14414
|
}
|
|
14402
14415
|
},
|
|
14403
14416
|
hotUpdate(options) {
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
resolvedPluginConfig
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
)
|
|
14411
|
-
) {
|
|
14417
|
+
const changedFilePath = path9.resolve(options.file);
|
|
14418
|
+
if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
|
|
14419
|
+
resolvedPluginConfig,
|
|
14420
|
+
resolvedViteConfig,
|
|
14421
|
+
changedFilePath
|
|
14422
|
+
)) {
|
|
14412
14423
|
options.server.restart();
|
|
14413
14424
|
return [];
|
|
14414
14425
|
}
|
|
@@ -14598,6 +14609,18 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14598
14609
|
configEnvironment(name) {
|
|
14599
14610
|
if (isNodeCompat(getWorkerConfig2(name))) {
|
|
14600
14611
|
return {
|
|
14612
|
+
build: {
|
|
14613
|
+
rollupOptions: {
|
|
14614
|
+
plugins: [
|
|
14615
|
+
replace({
|
|
14616
|
+
"process.env.NODE_ENV": JSON.stringify(
|
|
14617
|
+
process.env.NODE_ENV ?? "production"
|
|
14618
|
+
),
|
|
14619
|
+
preventAssignment: true
|
|
14620
|
+
})
|
|
14621
|
+
]
|
|
14622
|
+
}
|
|
14623
|
+
},
|
|
14601
14624
|
resolve: {
|
|
14602
14625
|
builtins: [...nodeCompatExternals]
|
|
14603
14626
|
},
|
|
@@ -14639,7 +14662,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14639
14662
|
},
|
|
14640
14663
|
async transform(code, id) {
|
|
14641
14664
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14642
|
-
|
|
14665
|
+
if (!workerConfig) {
|
|
14666
|
+
return;
|
|
14667
|
+
}
|
|
14643
14668
|
const resolvedId = await this.resolve(workerConfig.main);
|
|
14644
14669
|
if (id === resolvedId?.id) {
|
|
14645
14670
|
return injectGlobalCode(id, code);
|
|
@@ -14668,6 +14693,25 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14668
14693
|
);
|
|
14669
14694
|
}
|
|
14670
14695
|
},
|
|
14696
|
+
// Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
|
|
14697
|
+
{
|
|
14698
|
+
name: "vite-plugin-cloudflare:nodejs-als",
|
|
14699
|
+
apply(_config, env2) {
|
|
14700
|
+
return !env2.isPreview;
|
|
14701
|
+
},
|
|
14702
|
+
configEnvironment(name, config) {
|
|
14703
|
+
if (isNodeAls(getWorkerConfig2(name))) {
|
|
14704
|
+
return {
|
|
14705
|
+
resolve: {
|
|
14706
|
+
builtins: ["async_hooks", "node:async_hooks"]
|
|
14707
|
+
},
|
|
14708
|
+
optimizeDeps: {
|
|
14709
|
+
exclude: ["async_hooks", "node:async_hooks"]
|
|
14710
|
+
}
|
|
14711
|
+
};
|
|
14712
|
+
}
|
|
14713
|
+
}
|
|
14714
|
+
},
|
|
14671
14715
|
// Plugin that provides an __debug path for debugging the Cloudflare Workers.
|
|
14672
14716
|
{
|
|
14673
14717
|
name: "vite-plugin-cloudflare:debug",
|
|
@@ -14733,6 +14777,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14733
14777
|
build.onResolve(
|
|
14734
14778
|
{ filter: NODEJS_MODULES_RE },
|
|
14735
14779
|
({ path: path10, importer }) => {
|
|
14780
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
|
|
14781
|
+
return;
|
|
14782
|
+
}
|
|
14736
14783
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14737
14784
|
nodeJsCompatWarnings?.registerImport(path10, importer);
|
|
14738
14785
|
return { path: path10, external: true };
|
|
@@ -14762,6 +14809,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14762
14809
|
async resolveId(source, importer) {
|
|
14763
14810
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14764
14811
|
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14812
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
|
|
14813
|
+
return;
|
|
14814
|
+
}
|
|
14765
14815
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14766
14816
|
if (nodejsBuiltins.has(source)) {
|
|
14767
14817
|
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
@@ -14809,6 +14859,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
|
14809
14859
|
}
|
|
14810
14860
|
return null;
|
|
14811
14861
|
}
|
|
14862
|
+
function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
|
|
14863
|
+
return [...resolvedPluginConfig.configPaths].some((configPath) => {
|
|
14864
|
+
const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
|
|
14865
|
+
if (dotDevDotVars === changedFilePath) {
|
|
14866
|
+
return true;
|
|
14867
|
+
}
|
|
14868
|
+
if (resolvedPluginConfig.cloudflareEnv) {
|
|
14869
|
+
const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
|
|
14870
|
+
return dotDevDotVarsForEnv === changedFilePath;
|
|
14871
|
+
}
|
|
14872
|
+
return false;
|
|
14873
|
+
});
|
|
14874
|
+
}
|
|
14812
14875
|
export {
|
|
14813
14876
|
cloudflare2 as cloudflare
|
|
14814
14877
|
};
|
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-4cc036d46",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -34,17 +34,18 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@hattip/adapter-node": "^0.0.49",
|
|
37
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
37
38
|
"get-port": "^7.1.0",
|
|
38
39
|
"picocolors": "^1.1.1",
|
|
39
40
|
"tinyglobby": "^0.2.12",
|
|
40
41
|
"unenv": "2.0.0-rc.15",
|
|
41
42
|
"ws": "8.18.0",
|
|
42
|
-
"@cloudflare/unenv-preset": "0.0.0-
|
|
43
|
-
"wrangler": "0.0.0-
|
|
44
|
-
"miniflare": "0.0.0-
|
|
43
|
+
"@cloudflare/unenv-preset": "0.0.0-4cc036d46",
|
|
44
|
+
"wrangler": "0.0.0-4cc036d46",
|
|
45
|
+
"miniflare": "0.0.0-4cc036d46"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@cloudflare/workers-types": "^4.
|
|
48
|
+
"@cloudflare/workers-types": "^4.20250410.0",
|
|
48
49
|
"@types/node": "^22.10.1",
|
|
49
50
|
"@types/ws": "^8.5.13",
|
|
50
51
|
"magic-string": "^0.30.12",
|
|
@@ -54,8 +55,8 @@
|
|
|
54
55
|
"undici": "^5.28.5",
|
|
55
56
|
"vite": "^6.1.0",
|
|
56
57
|
"vitest": "~3.0.8",
|
|
57
|
-
"@cloudflare/workers-shared": "0.0.0-4c5ba3822",
|
|
58
58
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
59
|
+
"@cloudflare/workers-shared": "0.0.0-4cc036d46",
|
|
59
60
|
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|