feat(astro): support Astro 6 and 7 - #670
Conversation
@astrojs/node@10 replaced the adapter `args` config with a `virtual:astro-node:config` module, so the installed major now selects the mechanism: v10+ gets a vendored config plugin and `entrypointResolution: "auto"`, v9 keeps the existing `args` export. Astro 5 support is unchanged. Also fixes two bugs that block repeat and multi-version use: - `.apphosting` was created with a non-recursive mkdir, so any second build in the same directory failed with EEXIST. - `frameworkVersion` came from `npm view astro version`, reporting the latest published release rather than the one installed. It now reads the installed package.json, which also drops a network call from the build. Verified against real App Hosting deployments on Astro 5, 6 and 7: SSR rendering, API routes and middleware all serve per-request.
Relocates @apphosting/astro-adapter to packages/@apphosting/experimental/, registering the new workspace glob and adding the directory to the CI build artifact paths. The community/ glob is dropped since adapter-astro was its only member. Pure rename, no source changes.
Wiz Scan Summary
To detect these findings earlier in the dev lifecycle, try the Wiz Code extension for VS Code, JetBrains, or Visual Studio. |
There was a problem hiding this comment.
Code Review
This pull request introduces experimental support for Astro (versions 5, 6, and 7) on Firebase App Hosting by adding a new @apphosting/astro-adapter package under packages/@apphosting/experimental/adapter-astro, along with integration updates in lerna.json, package.json, and the publishing scripts. The review feedback highlights several key improvements: resolving a critical syntax error in the virtual config generator when handling undefined values, adding the new package path to lerna.json for proper Lerna management, removing an invalid trailing comma in tsconfig.json, adopting optional chaining for safer configuration access, ensuring cross-platform path compatibility using path.join, refactoring synchronous file operations to asynchronous ones, and removing a redundant node:fs/promises import.
The move to packages/@apphosting/experimental/ updated the npm workspaces glob but not lerna.json, so lerna managed 8 packages and skipped the astro adapter entirely — `npm run build` never built it. The community/ glob is replaced rather than added to, since that directory no longer exists.
| env: | ||
| ADAPTER_NEXTJS_NPM_TOKEN: ${{ secrets.ADAPTER_NEXTJS_NPM_TOKEN }} | ||
| ADAPTER_ANGULAR_NPM_TOKEN: ${{ secrets.ADAPTER_ANGULAR_NPM_TOKEN }} | ||
| ADAPTER_COMMON_NPM_TOKEN: ${{ secrets.ADAPTER_COMMON_NPM_TOKEN }} |
There was a problem hiding this comment.
I think you need to define ADAPTER_ASTRO_NPM_TOKEN: ${{ secrets.ADAPTER_ASTRO_NPM_TOKEN }} here too and we need to set this up in the github as well
There was a problem hiding this comment.
I can help with setting it up on github
| const require = createRequire(import.meta.url); | ||
|
|
||
| try { | ||
| const packageJsonPath = require.resolve(join(packageName, "package.json"), { |
There was a problem hiding this comment.
I think this might cause some issues in windows with how the slashes are, probably want it to be const packageJsonPath = require.resolve(${packageName}/package.json) instead
Add the App Hosting Astro adapter, with Astro 5, 6 and 7 support
Lands
@apphosting/astro-adapterinpackages/@apphosting/experimental/and extendsit to Astro 6 and 7. Fixes #667.
The adapter has lived on this branch since
0.0.1was published to npm, and thatrelease only works on Astro 5.
@astrojs/node@10(Astro 6) replaced the adapterargsconfig with avirtual:astro-node:configvirtual module, so0.0.1fails tobuild on Astro 6+.
How version support works
The installed
@astrojs/nodemajor selects the config mechanism, since this adapterreuses that package's server entrypoint:
@astrojs/nodeargsexport (unchanged from0.0.1)virtual:astro-node:configmodule +entrypointResolution: "auto"usesVirtualConfig()resolves the installed major from the app's ownnode_modules,so no user configuration changes.
UserOptionsis untouched — still justmode.Bug fixes
.apphostingwas created with a non-recursivemkdir, so any second build inthe same directory failed with
EEXIST. Now usesensureDir.frameworkVersioncame fromnpm view astro version, reporting npm's latestrelease rather than the installed one — every non-latest app was mislabelled, and it
cost a network call per build. Now reads the installed
package.json, matching howfirebase-toolsresolves Astro's version.Testing
Verified against real App Hosting deployments on all three majors — no mocks or
synthetic fixtures. Each was deployed and exercised over HTTP:
@astrojs/node9)frameworkVersionin bundle.yaml5.18.26.4.87.1.3Each adapter option was toggled on real deployments to confirm it was load-bearing;
anything that worked without it was dropped.
createConfigPluginalso supplies@astrojs/node's own defaults forstaticHeaders,bodySizeLimitandexperimentalDisableStreaming— without them its server imports resolved toundefined, silently removing the 1 GiB request body limit and emitting buildwarnings in every user's project.
Also adds unit tests (
npm test) covering the virtual config plugin.Notes
experimental/; thecommunity/workspace glob is dropped since thiswas its only member.
astroand@astrojs/nodeare optional peer dependencies, matching the otheradapters.