Skip to content

Commit 1861fed

Browse files
authored
fix(build): entrypoint leak (#15887)
1 parent 7b4b254 commit 1861fed

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

.changeset/polite-poets-push.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes an issue where the build incorrectly leaked server entrypoint into the client environment, causing adapters to emit warnings during the build.

packages/astro/src/core/build/plugins/plugin-internals.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
import type { EnvironmentOptions, Plugin as VitePlugin } from 'vite';
1+
import type { EnvironmentOptions, Plugin as VitePlugin, Rollup } from 'vite';
22
import type { BuildInternals } from '../internal.js';
33
import type { StaticBuildOptions } from '../types.js';
44
import { normalizeEntryId } from './plugin-component-entry.js';
55
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../../constants.js';
66

7+
function getRollupInputAsSet(rollupInput: Rollup.InputOption | undefined): Set<string> {
8+
if (Array.isArray(rollupInput)) {
9+
return new Set(rollupInput);
10+
} else if (typeof rollupInput === 'string') {
11+
return new Set([rollupInput]);
12+
} else if (rollupInput && typeof rollupInput === 'object') {
13+
return new Set(Object.values(rollupInput) as string[]);
14+
} else {
15+
return new Set();
16+
}
17+
}
18+
719
export function pluginInternals(
820
options: StaticBuildOptions,
921
internals: BuildInternals,
1022
): VitePlugin {
11-
let input: Set<string>;
12-
1323
return {
1424
name: '@astro/plugin-build-internals',
1525

@@ -42,21 +52,15 @@ export function pluginInternals(
4252
}
4353
},
4454

45-
configResolved(config) {
46-
// Get input from rollupOptions
47-
const rollupInput = config.build?.rollupOptions?.input;
48-
if (Array.isArray(rollupInput)) {
49-
input = new Set(rollupInput);
50-
} else if (typeof rollupInput === 'string') {
51-
input = new Set([rollupInput]);
52-
} else if (rollupInput && typeof rollupInput === 'object') {
53-
input = new Set(Object.values(rollupInput) as string[]);
54-
} else {
55-
input = new Set();
56-
}
57-
},
58-
5955
async generateBundle(_options, bundle) {
56+
// Read the rollup input directly from the current environment's config rather than
57+
// relying on a closure variable from configResolved. With Vite's per-environment config
58+
// resolution, a shared closure variable would be overwritten by the last environment's
59+
// configResolved call, causing inputs from one environment (e.g. SSR) to leak into
60+
// another (e.g. client). This caused server-only modules like @astrojs/node/server.js
61+
// to be resolved in the client environment, triggering spurious "externalized for
62+
// browser compatibility" warnings.
63+
const input = getRollupInputAsSet(this.environment?.config.build.rollupOptions.input);
6064
const promises = [];
6165
const mapping = new Map<string, Set<string>>();
6266
const allInput = new Set([...input, ...internals.clientInput]);

0 commit comments

Comments
 (0)