fix: correct URL for entry points (#7490)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
57e603038f
commit
6014037441
10 changed files with 43 additions and 52 deletions
5
.changeset/brave-waves-battle.md
Normal file
5
.changeset/brave-waves-battle.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix the URL that belongs to `entryPoints` in the hook `astro:build:ssr`. The paths were created with the wrong output directory.
|
|
@ -36,6 +36,23 @@
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [#7220](https://github.com/withastro/astro/pull/7220) [`459b5bd05`](https://github.com/withastro/astro/commit/459b5bd05f562238f7250520efe3cf0fa156bb45) Thanks [@ematipico](https://github.com/ematipico)! - The Astro hook `astro:build:ssr` now receives a new option in their payload, called `entryPoints`.
|
||||||
|
|
||||||
|
`entryPoints` is defined as a `Map<RouteData, URL>`, where `RouteData` represents the information of a Astro route and `URL` is the path to the physical file emitted at the end of the build.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
export function integration(): AstroIntegration {
|
||||||
|
return {
|
||||||
|
name: "my-integration",
|
||||||
|
hooks: {
|
||||||
|
"astro:build:ssr": ({ entryPoints }) => {
|
||||||
|
// do something with `entryPoints`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
||||||
- [#7438](https://github.com/withastro/astro/pull/7438) [`30bb36371`](https://github.com/withastro/astro/commit/30bb363713e3d2c50d0d4816d970aa93b836a3b0) Thanks [@bluwy](https://github.com/bluwy)! - Fix `astro:build:setup` hook `updateConfig` utility, where the configuration wasn't correctly updated when the hook was fired.
|
- [#7438](https://github.com/withastro/astro/pull/7438) [`30bb36371`](https://github.com/withastro/astro/commit/30bb363713e3d2c50d0d4816d970aa93b836a3b0) Thanks [@bluwy](https://github.com/bluwy)! - Fix `astro:build:setup` hook `updateConfig` utility, where the configuration wasn't correctly updated when the hook was fired.
|
||||||
|
|
|
@ -111,21 +111,6 @@ export interface CLIFlags {
|
||||||
experimentalRedirects?: boolean;
|
experimentalRedirects?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BuildConfig {
|
|
||||||
/**
|
|
||||||
* @deprecated Use config.build.client instead.
|
|
||||||
*/
|
|
||||||
client: URL;
|
|
||||||
/**
|
|
||||||
* @deprecated Use config.build.server instead.
|
|
||||||
*/
|
|
||||||
server: URL;
|
|
||||||
/**
|
|
||||||
* @deprecated Use config.build.serverEntry instead.
|
|
||||||
*/
|
|
||||||
serverEntry: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Astro global available in all contexts in .astro files
|
* Astro global available in all contexts in .astro files
|
||||||
*
|
*
|
||||||
|
|
|
@ -133,8 +133,9 @@ export function chunkIsPage(
|
||||||
export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) {
|
export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) {
|
||||||
const timer = performance.now();
|
const timer = performance.now();
|
||||||
const ssr = isServerLikeOutput(opts.settings.config);
|
const ssr = isServerLikeOutput(opts.settings.config);
|
||||||
const serverEntry = opts.buildConfig.serverEntry;
|
const outFolder = ssr
|
||||||
const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
? opts.settings.config.build.server
|
||||||
|
: getOutDirWithinCwd(opts.settings.config.outDir);
|
||||||
|
|
||||||
if (ssr && !hasPrerenderedPages(internals)) return;
|
if (ssr && !hasPrerenderedPages(internals)) return;
|
||||||
|
|
||||||
|
@ -180,7 +181,6 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
||||||
|
|
||||||
await runHookBuildGenerated({
|
await runHookBuildGenerated({
|
||||||
config: opts.settings.config,
|
config: opts.settings.config,
|
||||||
buildConfig: opts.buildConfig,
|
|
||||||
logging: opts.logging,
|
logging: opts.logging,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
import type { AstroTelemetry } from '@astrojs/telemetry';
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
||||||
import type {
|
import type { AstroConfig, AstroSettings, ManifestData, RuntimeMode } from '../../@types/astro';
|
||||||
AstroConfig,
|
|
||||||
AstroSettings,
|
|
||||||
BuildConfig,
|
|
||||||
ManifestData,
|
|
||||||
RuntimeMode,
|
|
||||||
} from '../../@types/astro';
|
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as colors from 'kleur/colors';
|
import * as colors from 'kleur/colors';
|
||||||
|
@ -123,11 +117,6 @@ class AstroBuilder {
|
||||||
|
|
||||||
/** Run the build logic. build() is marked private because usage should go through ".run()" */
|
/** Run the build logic. build() is marked private because usage should go through ".run()" */
|
||||||
private async build({ viteConfig }: { viteConfig: vite.InlineConfig }) {
|
private async build({ viteConfig }: { viteConfig: vite.InlineConfig }) {
|
||||||
const buildConfig: BuildConfig = {
|
|
||||||
client: this.settings.config.build.client,
|
|
||||||
server: this.settings.config.build.server,
|
|
||||||
serverEntry: this.settings.config.build.serverEntry,
|
|
||||||
};
|
|
||||||
await runHookBuildStart({ config: this.settings.config, logging: this.logging });
|
await runHookBuildStart({ config: this.settings.config, logging: this.logging });
|
||||||
this.validateConfig();
|
this.validateConfig();
|
||||||
|
|
||||||
|
@ -168,7 +157,6 @@ class AstroBuilder {
|
||||||
routeCache: this.routeCache,
|
routeCache: this.routeCache,
|
||||||
teardownCompiler: this.teardownCompiler,
|
teardownCompiler: this.teardownCompiler,
|
||||||
viteConfig,
|
viteConfig,
|
||||||
buildConfig,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const { internals } = await viteBuild(opts);
|
const { internals } = await viteBuild(opts);
|
||||||
|
@ -188,7 +176,6 @@ class AstroBuilder {
|
||||||
// You're done! Time to clean up.
|
// You're done! Time to clean up.
|
||||||
await runHookBuildDone({
|
await runHookBuildDone({
|
||||||
config: this.settings.config,
|
config: this.settings.config,
|
||||||
buildConfig,
|
|
||||||
pages: pageNames,
|
pages: pageNames,
|
||||||
routes: Object.values(allPages).map((pd) => pd.route),
|
routes: Object.values(allPages).map((pd) => pd.route),
|
||||||
logging: this.logging,
|
logging: this.logging,
|
||||||
|
|
|
@ -382,7 +382,7 @@ function storeEntryPoint(
|
||||||
const componentPath = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, moduleKey);
|
const componentPath = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, moduleKey);
|
||||||
for (const [page, pageData] of Object.entries(options.allPages)) {
|
for (const [page, pageData] of Object.entries(options.allPages)) {
|
||||||
if (componentPath == page) {
|
if (componentPath == page) {
|
||||||
const publicPath = fileURLToPath(options.settings.config.outDir);
|
const publicPath = fileURLToPath(options.settings.config.build.server);
|
||||||
internals.entryPoints.set(pageData.route, pathToFileURL(join(publicPath, fileName)));
|
internals.entryPoints.set(pageData.route, pathToFileURL(join(publicPath, fileName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import * as eslexer from 'es-module-lexer';
|
||||||
import glob from 'fast-glob';
|
import glob from 'fast-glob';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { bgGreen, bgMagenta, black, dim } from 'kleur/colors';
|
import { bgGreen, bgMagenta, black, dim } from 'kleur/colors';
|
||||||
import { extname } from 'node:path';
|
import { extname, join } from 'node:path';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import * as vite from 'vite';
|
import * as vite from 'vite';
|
||||||
|
@ -146,7 +146,7 @@ async function ssrBuild(
|
||||||
) {
|
) {
|
||||||
const { allPages, settings, viteConfig } = opts;
|
const { allPages, settings, viteConfig } = opts;
|
||||||
const ssr = isServerLikeOutput(settings.config);
|
const ssr = isServerLikeOutput(settings.config);
|
||||||
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(settings.config.outDir);
|
const out = ssr ? settings.config.build.server : getOutDirWithinCwd(settings.config.outDir);
|
||||||
const routes = Object.values(allPages).map((pd) => pd.route);
|
const routes = Object.values(allPages).map((pd) => pd.route);
|
||||||
const { lastVitePlugins, vitePlugins } = container.runBeforeHook('ssr', input);
|
const { lastVitePlugins, vitePlugins } = container.runBeforeHook('ssr', input);
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ async function clientBuild(
|
||||||
const { settings, viteConfig } = opts;
|
const { settings, viteConfig } = opts;
|
||||||
const timer = performance.now();
|
const timer = performance.now();
|
||||||
const ssr = isServerLikeOutput(settings.config);
|
const ssr = isServerLikeOutput(settings.config);
|
||||||
const out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir);
|
const out = ssr ? settings.config.build.client : getOutDirWithinCwd(settings.config.outDir);
|
||||||
|
|
||||||
// Nothing to do if there is no client-side JS.
|
// Nothing to do if there is no client-side JS.
|
||||||
if (!input.size) {
|
if (!input.size) {
|
||||||
|
@ -289,12 +289,12 @@ async function runPostBuildHooks(
|
||||||
) {
|
) {
|
||||||
const mutations = await container.runPostHook(ssrReturn, clientReturn);
|
const mutations = await container.runPostHook(ssrReturn, clientReturn);
|
||||||
const config = container.options.settings.config;
|
const config = container.options.settings.config;
|
||||||
const buildConfig = container.options.settings.config.build;
|
const build = container.options.settings.config.build;
|
||||||
for (const [fileName, mutation] of mutations) {
|
for (const [fileName, mutation] of mutations) {
|
||||||
const root = isServerLikeOutput(config)
|
const root = isServerLikeOutput(config)
|
||||||
? mutation.build === 'server'
|
? mutation.build === 'server'
|
||||||
? buildConfig.server
|
? build.server
|
||||||
: buildConfig.client
|
: build.client
|
||||||
: config.outDir;
|
: config.outDir;
|
||||||
const fileURL = new URL(fileName, root);
|
const fileURL = new URL(fileName, root);
|
||||||
await fs.promises.mkdir(new URL('./', fileURL), { recursive: true });
|
await fs.promises.mkdir(new URL('./', fileURL), { recursive: true });
|
||||||
|
@ -313,7 +313,9 @@ async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInter
|
||||||
allStaticFiles.add(internals.pageToBundleMap.get(pageData.moduleSpecifier));
|
allStaticFiles.add(internals.pageToBundleMap.get(pageData.moduleSpecifier));
|
||||||
}
|
}
|
||||||
const ssr = isServerLikeOutput(opts.settings.config);
|
const ssr = isServerLikeOutput(opts.settings.config);
|
||||||
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
const out = ssr
|
||||||
|
? opts.settings.config.build.server
|
||||||
|
: getOutDirWithinCwd(opts.settings.config.outDir);
|
||||||
// The SSR output is all .mjs files, the client output is not.
|
// The SSR output is all .mjs files, the client output is not.
|
||||||
const files = await glob('**/*.mjs', {
|
const files = await glob('**/*.mjs', {
|
||||||
cwd: fileURLToPath(out),
|
cwd: fileURLToPath(out),
|
||||||
|
@ -394,8 +396,10 @@ async function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles = false
|
||||||
async function ssrMoveAssets(opts: StaticBuildOptions) {
|
async function ssrMoveAssets(opts: StaticBuildOptions) {
|
||||||
info(opts.logging, 'build', 'Rearranging server assets...');
|
info(opts.logging, 'build', 'Rearranging server assets...');
|
||||||
const serverRoot =
|
const serverRoot =
|
||||||
opts.settings.config.output === 'static' ? opts.buildConfig.client : opts.buildConfig.server;
|
opts.settings.config.output === 'static'
|
||||||
const clientRoot = opts.buildConfig.client;
|
? opts.settings.config.build.client
|
||||||
|
: opts.settings.config.build.server;
|
||||||
|
const clientRoot = opts.settings.config.build.client;
|
||||||
const assets = opts.settings.config.build.assets;
|
const assets = opts.settings.config.build.assets;
|
||||||
const serverAssets = new URL(`./${assets}/`, appendForwardSlash(serverRoot.toString()));
|
const serverAssets = new URL(`./${assets}/`, appendForwardSlash(serverRoot.toString()));
|
||||||
const clientAssets = new URL(`./${assets}/`, appendForwardSlash(clientRoot.toString()));
|
const clientAssets = new URL(`./${assets}/`, appendForwardSlash(clientRoot.toString()));
|
||||||
|
|
|
@ -2,7 +2,6 @@ import type { default as vite, InlineConfig } from 'vite';
|
||||||
import type {
|
import type {
|
||||||
AstroConfig,
|
AstroConfig,
|
||||||
AstroSettings,
|
AstroSettings,
|
||||||
BuildConfig,
|
|
||||||
ComponentInstance,
|
ComponentInstance,
|
||||||
ManifestData,
|
ManifestData,
|
||||||
MiddlewareHandler,
|
MiddlewareHandler,
|
||||||
|
@ -36,7 +35,6 @@ export type AllPagesData = Record<ComponentPath, PageBuildData>;
|
||||||
export interface StaticBuildOptions {
|
export interface StaticBuildOptions {
|
||||||
allPages: AllPagesData;
|
allPages: AllPagesData;
|
||||||
settings: AstroSettings;
|
settings: AstroSettings;
|
||||||
buildConfig: BuildConfig;
|
|
||||||
logging: LogOptions;
|
logging: LogOptions;
|
||||||
manifest: ManifestData;
|
manifest: ManifestData;
|
||||||
mode: RuntimeMode;
|
mode: RuntimeMode;
|
||||||
|
|
|
@ -7,7 +7,6 @@ import type {
|
||||||
AstroConfig,
|
AstroConfig,
|
||||||
AstroRenderer,
|
AstroRenderer,
|
||||||
AstroSettings,
|
AstroSettings,
|
||||||
BuildConfig,
|
|
||||||
ContentEntryType,
|
ContentEntryType,
|
||||||
DataEntryType,
|
DataEntryType,
|
||||||
HookParameters,
|
HookParameters,
|
||||||
|
@ -323,14 +322,12 @@ export async function runHookBuildSsr({
|
||||||
|
|
||||||
export async function runHookBuildGenerated({
|
export async function runHookBuildGenerated({
|
||||||
config,
|
config,
|
||||||
buildConfig,
|
|
||||||
logging,
|
logging,
|
||||||
}: {
|
}: {
|
||||||
config: AstroConfig;
|
config: AstroConfig;
|
||||||
buildConfig: BuildConfig;
|
|
||||||
logging: LogOptions;
|
logging: LogOptions;
|
||||||
}) {
|
}) {
|
||||||
const dir = isServerLikeOutput(config) ? buildConfig.client : config.outDir;
|
const dir = isServerLikeOutput(config) ? config.build.client : config.outDir;
|
||||||
|
|
||||||
for (const integration of config.integrations) {
|
for (const integration of config.integrations) {
|
||||||
if (integration?.hooks?.['astro:build:generated']) {
|
if (integration?.hooks?.['astro:build:generated']) {
|
||||||
|
@ -345,18 +342,16 @@ export async function runHookBuildGenerated({
|
||||||
|
|
||||||
export async function runHookBuildDone({
|
export async function runHookBuildDone({
|
||||||
config,
|
config,
|
||||||
buildConfig,
|
|
||||||
pages,
|
pages,
|
||||||
routes,
|
routes,
|
||||||
logging,
|
logging,
|
||||||
}: {
|
}: {
|
||||||
config: AstroConfig;
|
config: AstroConfig;
|
||||||
buildConfig: BuildConfig;
|
|
||||||
pages: string[];
|
pages: string[];
|
||||||
routes: RouteData[];
|
routes: RouteData[];
|
||||||
logging: LogOptions;
|
logging: LogOptions;
|
||||||
}) {
|
}) {
|
||||||
const dir = isServerLikeOutput(config) ? buildConfig.client : config.outDir;
|
const dir = isServerLikeOutput(config) ? config.build.client : config.outDir;
|
||||||
await fs.promises.mkdir(dir, { recursive: true });
|
await fs.promises.mkdir(dir, { recursive: true });
|
||||||
|
|
||||||
for (const integration of config.integrations) {
|
for (const integration of config.integrations) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe('astro:ssr-manifest, split', () => {
|
||||||
it('should give access to entry points that exists on file system', async () => {
|
it('should give access to entry points that exists on file system', async () => {
|
||||||
// number of the pages inside src/
|
// number of the pages inside src/
|
||||||
expect(entryPoints.size).to.equal(4);
|
expect(entryPoints.size).to.equal(4);
|
||||||
for (const fileUrl in entryPoints.values()) {
|
for (const fileUrl of entryPoints.values()) {
|
||||||
let filePath = fileURLToPath(fileUrl);
|
let filePath = fileURLToPath(fileUrl);
|
||||||
expect(existsSync(filePath)).to.be.true;
|
expect(existsSync(filePath)).to.be.true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue