Merge pull request #435 from sivdead/fix/dev-assets-directory
Create missing Wrangler assets directories before development startup. Add regression coverage for creation before CLI invocation, preservation of existing assets, and non-dev command behavior. Validation: typecheck, typecheck:mobile, build:web, and all 2244 non-E2E tests passed.
This commit is contained in:
commit
509d523f00
3 files changed
+77
-3
No files matched your search
@@ -19,6 +19,7 @@ import {
|
||||
PLACEHOLDER_D1_ID,
|
||||
productionVersionIds,
|
||||
repositoryWranglerConfigError,
|
||||
resolveWranglerAssetsDirectory,
|
||||
runWranglerSync,
|
||||
shouldCaptureDeploymentTargets,
|
||||
} from "./wrangler-runner.mjs";
|
||||
@@ -166,8 +167,9 @@ const envValue = (name) => {
|
||||
const isRemoteCommand =
|
||||
wranglerArgs.includes("deploy") || wranglerArgs.includes("--remote");
|
||||
const isDeployCommand = wranglerArgs.includes("deploy");
|
||||
const isRemoteDevCommand = wranglerArgs.includes("dev") && wranglerArgs.includes("--remote");
|
||||
const isLocalDevCommand = wranglerArgs.includes("dev") && wranglerArgs.includes("--local");
|
||||
const isDevCommand = wranglerArgs.includes("dev");
|
||||
const isRemoteDevCommand = isDevCommand && wranglerArgs.includes("--remote");
|
||||
const isLocalDevCommand = isDevCommand && wranglerArgs.includes("--local");
|
||||
// Any --local command rewrites .wrangler.generated.toml. Keep local-only vars
|
||||
// (especially auth-free access) so `d1 migrations apply --local` cannot strip
|
||||
// them and leave a later wrangler reload requiring login mid-session.
|
||||
@@ -442,6 +444,12 @@ if (isDeployCommand && Object.keys(authSecrets).length === 0 && useExistingAuthS
|
||||
writeWranglerNotice("info", "using the authentication Secret provisioned by Cloudflare");
|
||||
}
|
||||
|
||||
if (isDevCommand) {
|
||||
// Local dev serves the web app from Vite, so an empty assets directory is enough.
|
||||
const assetsDirectory = resolveWranglerAssetsDirectory(config, dirname(configPath));
|
||||
if (assetsDirectory) mkdirSync(assetsDirectory, { recursive: true });
|
||||
}
|
||||
|
||||
if (isLocalDevCommand && !hasEnvFileArg) {
|
||||
writeFileSync(generatedLocalDevEnvPath, buildLocalDevEnvironmentFile());
|
||||
finalWranglerArgs.push("--env-file", generatedLocalDevEnvPath);
|
||||
|
||||
@@ -116,6 +116,13 @@ export const shouldCaptureDeploymentTargets = (env = process.env) =>
|
||||
export const LOCAL_DEV_CREDENTIALS_ENCRYPTION_KEY =
|
||||
"edgeever-local-development-credentials-key-v1";
|
||||
|
||||
// Wrangler refuses to start `dev` when the assets directory is missing and has no
|
||||
// option to create it. Like Wrangler, resolve `[assets].directory` from the config's directory.
|
||||
export const resolveWranglerAssetsDirectory = (config, configDirectory) => {
|
||||
const match = config.match(/^\s*\[assets\][^[]*?^\s*directory\s*=\s*["']([^"']+)["']/m);
|
||||
return match ? resolve(configDirectory, match[1]) : null;
|
||||
};
|
||||
|
||||
export const buildLocalDevEnvironmentFile = () => [
|
||||
"# Local-only values. Remote instance secrets are intentionally excluded.",
|
||||
`EDGE_EVER_CREDENTIALS_ENCRYPTION_KEY=${LOCAL_DEV_CREDENTIALS_ENCRYPTION_KEY}`,
|
||||
|
||||
Reference in new issue
Block a user