@cloudflare/vite-plugin 1.0.4 → 1.0.6
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 +61 -13
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -5832,14 +5832,14 @@ var AssetConfigSchema = z.object({
|
|
|
5832
5832
|
});
|
|
5833
5833
|
|
|
5834
5834
|
// src/asset-config.ts
|
|
5835
|
-
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig,
|
|
5835
|
+
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFilePath) {
|
|
5836
5836
|
if (!resolvedPluginConfig.experimental?.headersAndRedirectsDevModeSupport) {
|
|
5837
5837
|
return false;
|
|
5838
5838
|
}
|
|
5839
5839
|
return [
|
|
5840
5840
|
getRedirectsConfigPath(resolvedViteConfig),
|
|
5841
5841
|
getHeadersConfigPath(resolvedViteConfig)
|
|
5842
|
-
].includes(
|
|
5842
|
+
].includes(changedFilePath);
|
|
5843
5843
|
}
|
|
5844
5844
|
function getAssetsConfig(resolvedPluginConfig, entryWorkerConfig, resolvedConfig) {
|
|
5845
5845
|
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
@@ -12880,6 +12880,15 @@ function isNodeCompat(workerConfig) {
|
|
|
12880
12880
|
}
|
|
12881
12881
|
return false;
|
|
12882
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
|
+
}
|
|
12883
12892
|
function injectGlobalCode(id, code) {
|
|
12884
12893
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
12885
12894
|
if (typeof globalInject === "string") {
|
|
@@ -14181,12 +14190,15 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14181
14190
|
for (const envName of workersEnvironmentNames) {
|
|
14182
14191
|
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14183
14192
|
assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14184
|
-
const { optimizeDeps, resolve:
|
|
14193
|
+
const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
|
|
14185
14194
|
const disallowedConfig = {};
|
|
14186
14195
|
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14187
14196
|
if (cloudflareBuiltInModules.includes(entry)) {
|
|
14188
14197
|
return false;
|
|
14189
14198
|
}
|
|
14199
|
+
if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
|
|
14200
|
+
return false;
|
|
14201
|
+
}
|
|
14190
14202
|
if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
|
|
14191
14203
|
return false;
|
|
14192
14204
|
}
|
|
@@ -14195,8 +14207,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14195
14207
|
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14196
14208
|
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14197
14209
|
}
|
|
14198
|
-
if (
|
|
14199
|
-
disallowedConfig.resolveExternal =
|
|
14210
|
+
if (resolve7.external === true || resolve7.external.length > 0) {
|
|
14211
|
+
disallowedConfig.resolveExternal = resolve7.external;
|
|
14200
14212
|
}
|
|
14201
14213
|
if (Object.keys(disallowedConfig).length > 0) {
|
|
14202
14214
|
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
@@ -14402,14 +14414,12 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14402
14414
|
}
|
|
14403
14415
|
},
|
|
14404
14416
|
hotUpdate(options) {
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
resolvedPluginConfig
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
)
|
|
14412
|
-
) {
|
|
14417
|
+
const changedFilePath = path9.resolve(options.file);
|
|
14418
|
+
if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
|
|
14419
|
+
resolvedPluginConfig,
|
|
14420
|
+
resolvedViteConfig,
|
|
14421
|
+
changedFilePath
|
|
14422
|
+
)) {
|
|
14413
14423
|
options.server.restart();
|
|
14414
14424
|
return [];
|
|
14415
14425
|
}
|
|
@@ -14683,6 +14693,25 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14683
14693
|
);
|
|
14684
14694
|
}
|
|
14685
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
|
+
},
|
|
14686
14715
|
// Plugin that provides an __debug path for debugging the Cloudflare Workers.
|
|
14687
14716
|
{
|
|
14688
14717
|
name: "vite-plugin-cloudflare:debug",
|
|
@@ -14748,6 +14777,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14748
14777
|
build.onResolve(
|
|
14749
14778
|
{ filter: NODEJS_MODULES_RE },
|
|
14750
14779
|
({ path: path10, importer }) => {
|
|
14780
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
|
|
14781
|
+
return;
|
|
14782
|
+
}
|
|
14751
14783
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14752
14784
|
nodeJsCompatWarnings?.registerImport(path10, importer);
|
|
14753
14785
|
return { path: path10, external: true };
|
|
@@ -14777,6 +14809,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14777
14809
|
async resolveId(source, importer) {
|
|
14778
14810
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14779
14811
|
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14812
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
|
|
14813
|
+
return;
|
|
14814
|
+
}
|
|
14780
14815
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14781
14816
|
if (nodejsBuiltins.has(source)) {
|
|
14782
14817
|
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
@@ -14824,6 +14859,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
|
14824
14859
|
}
|
|
14825
14860
|
return null;
|
|
14826
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
|
+
}
|
|
14827
14875
|
export {
|
|
14828
14876
|
cloudflare2 as cloudflare
|
|
14829
14877
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"tinyglobby": "^0.2.12",
|
|
41
41
|
"unenv": "2.0.0-rc.15",
|
|
42
42
|
"ws": "8.18.0",
|
|
43
|
-
"miniflare": "4.20250408.0",
|
|
44
43
|
"@cloudflare/unenv-preset": "2.3.1",
|
|
45
|
-
"
|
|
44
|
+
"miniflare": "4.20250410.0",
|
|
45
|
+
"wrangler": "4.11.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@cloudflare/workers-types": "^4.
|
|
48
|
+
"@cloudflare/workers-types": "^4.20250410.0",
|
|
49
49
|
"@types/node": "^22.10.1",
|
|
50
50
|
"@types/ws": "^8.5.13",
|
|
51
51
|
"magic-string": "^0.30.12",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"vite": "^6.1.0",
|
|
57
57
|
"vitest": "~3.0.8",
|
|
58
58
|
"@cloudflare/mock-npm-registry": "0.0.0",
|
|
59
|
-
"@cloudflare/workers-
|
|
60
|
-
"@cloudflare/workers-
|
|
59
|
+
"@cloudflare/workers-shared": "0.17.1",
|
|
60
|
+
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"vite": "^6.1.0",
|