refactor: make build dist/ directory portable#16826
Draft
ematipico wants to merge 7 commits into
Draft
Conversation
Replace absolute file:// URLs in the SSR manifest with relative paths computed from buildServerDir. At runtime, these are resolved against import.meta.url of the server entry to produce correct absolute URLs regardless of where dist/ is deployed. Changes: - plugin-manifest.ts: Compute directory paths relative to buildServerDir, relativize componentMetadata and entryModules keys, adjust paths for chunk nesting depth, keep absolute paths for prerender manifest - manifest.ts: Accept serverEntryUrl parameter in deserializeManifest to resolve relative paths against the runtime location - serialized.ts: Pass import.meta.url from the virtual module to deserializeManifest (build only, dev keeps absolute paths) - virtual-module.ts: Use already-resolved URL objects from manifest instead of redundant new URL() wrapping - default.ts: Use manifest.rootDir directly (already a URL object) - vite-plugin-astro: Normalize absolute paths to root-relative in compiled .astro output during build - vite-plugin-server-islands: Normalize resolvedPath during island discovery in build to match compiled output - mdx/vite-plugin-mdx-postprocess: Same normalization for MDX files Ref: withastro/roadmap#1286
- plugin-manifest.ts: Normalize inlinedScripts map keys from absolute to root-relative paths, matching the compiled output normalization - node/index.ts: Use relative paths (./client/, ./server/) instead of absolute file:// URLs for the baked-in adapter config - node/shared.ts: Simplify resolveClientDir to work with relative paths directly instead of parsing file:// URLs
Instead of baking an absolute filesystem path into the manifest for the
default fs-lite session driver, store just the subdirectory name
('sessions') and resolve it against manifest.cacheDir at server startup.
This makes the session config portable — moving dist/ to another machine
no longer breaks the default session storage path.
🦋 Changeset detectedLatest commit: 7dac3cf The changes in this PR will be included in the next version bump. This PR includes changesets to release 415 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will improve performance by 11.18%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | Build: hybrid site (static + server) |
10.7 s | 9.6 s | +11.18% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/self-contained-dist (7dac3cf) with main (ace96ba)
Instead of baking an absolute filesystem path into the manifest for the
default fs-lite session driver, store just the subdirectory name
('sessions') and resolve it against manifest.cacheDir at server startup.
This makes the session config portable — moving dist/ to another machine
no longer breaks the default session storage path.
- Fix no-shadow lint error: reuse outer normalizedRoot in componentMetadata - Fix serialized.test.ts: extract JSON with brace-counting instead of regex (the deserializeManifest call now has a second argument) - Fix Cloudflare Workers: use URL.canParse before constructing serverBaseUrl and resolveDir, falling back to a dummy URL on runtimes where import.meta.url is not a valid URL (workerd) - Remove accidental export from test file (biome no-export-from-test)
All portability changes are now gated behind the experimental.portableOutput config flag (default: false). When disabled, the build output is identical to the previous behavior — absolute file:// URLs in the manifest. When enabled: - Manifest directory paths are relative, resolved via import.meta.url at runtime - componentMetadata, entryModules, inlinedScripts keys are root-relative - Node adapter uses folder names and relative session storage paths - Compiled .astro and .mdx output uses root-relative module IDs The flag is checked at each gating point: - plugin-manifest.ts (directory paths, key normalization, chunk adjustment) - serialized.ts (import.meta.url argument) - vite-plugin-astro (path replacement in compiled output) - vite-plugin-server-islands (resolvedPath normalization) - mdx/vite-plugin-mdx-postprocess (path replacement in MDX output) - node/index.ts (config format, session base) - node/server.ts (session resolution) - node/shared.ts (auto-detects format via URL.canParse)
7a1e303 to
7dac3cf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
file://URLs in the SSR manifest with relative paths computed frombuildServerDir. At runtime,deserializeManifestresolves them againstimport.meta.urlof the server entry, producing correct absolute paths regardless of wheredist/is deployed.componentMetadata,entryModules,inlinedScripts, andserverIslandNameMapkeys from absolute paths to root-relative paths during build. Compiled.astroand.mdxoutput is normalized to match.file://URLs to plain folder names. Session storage base path is resolved againstmanifest.rootDirat server startup.Ref: Make build `dist/` directory portable. roadmap#1286
Testing
serializeManifest, SSR, server islands, and node adapter test suites cover the changed codepaths./tmp/hackernews/, moveddist/+node_modules/to/tmp/portable-app/, ran from there. SSR pages, prerendered static pages, sharp image optimization, and fs-lite sessions all work.Docs
No docs update needed — internal change to the build output format.