mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
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
|
||||
|
||||
- [#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;
|
||||
}
|
||||
|
||||
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
|
||||
*
|
||||
|
|
|
@ -133,8 +133,9 @@ export function chunkIsPage(
|
|||
export async function generatePages(opts: StaticBuildOptions, internals: BuildInternals) {
|
||||
const timer = performance.now();
|
||||
const ssr = isServerLikeOutput(opts.settings.config);
|
||||
const serverEntry = opts.buildConfig.serverEntry;
|
||||
const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
||||
const outFolder = ssr
|
||||
? opts.settings.config.build.server
|
||||
: getOutDirWithinCwd(opts.settings.config.outDir);
|
||||
|
||||
if (ssr && !hasPrerenderedPages(internals)) return;
|
||||
|
||||
|
@ -180,7 +181,6 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
|
|||
|
||||
await runHookBuildGenerated({
|
||||
config: opts.settings.config,
|
||||
buildConfig: opts.buildConfig,
|
||||
logging: opts.logging,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
import type { AstroTelemetry } from '@astrojs/telemetry';
|
||||
import type {
|
||||
AstroConfig,
|
||||
AstroSettings,
|
||||
BuildConfig,
|
||||
ManifestData,
|
||||
RuntimeMode,
|
||||
} from '../../@types/astro';
|
||||
import type { AstroConfig, AstroSettings, ManifestData, RuntimeMode } from '../../@types/astro';
|
||||
|
||||
import fs from 'fs';
|
||||
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()" */
|
||||
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 });
|
||||
this.validateConfig();
|
||||
|
||||
|
@ -168,7 +157,6 @@ class AstroBuilder {
|
|||
routeCache: this.routeCache,
|
||||
teardownCompiler: this.teardownCompiler,
|
||||
viteConfig,
|
||||
buildConfig,
|
||||
};
|
||||
|
||||
const { internals } = await viteBuild(opts);
|
||||
|
@ -188,7 +176,6 @@ class AstroBuilder {
|
|||
// You're done! Time to clean up.
|
||||
await runHookBuildDone({
|
||||
config: this.settings.config,
|
||||
buildConfig,
|
||||
pages: pageNames,
|
||||
routes: Object.values(allPages).map((pd) => pd.route),
|
||||
logging: this.logging,
|
||||
|
|
|
@ -382,7 +382,7 @@ function storeEntryPoint(
|
|||
const componentPath = getPathFromVirtualModulePageName(RESOLVED_SPLIT_MODULE_ID, moduleKey);
|
||||
for (const [page, pageData] of Object.entries(options.allPages)) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as eslexer from 'es-module-lexer';
|
|||
import glob from 'fast-glob';
|
||||
import fs from 'fs';
|
||||
import { bgGreen, bgMagenta, black, dim } from 'kleur/colors';
|
||||
import { extname } from 'node:path';
|
||||
import { extname, join } from 'node:path';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import * as vite from 'vite';
|
||||
|
@ -146,7 +146,7 @@ async function ssrBuild(
|
|||
) {
|
||||
const { allPages, settings, viteConfig } = opts;
|
||||
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 { lastVitePlugins, vitePlugins } = container.runBeforeHook('ssr', input);
|
||||
|
||||
|
@ -227,7 +227,7 @@ async function clientBuild(
|
|||
const { settings, viteConfig } = opts;
|
||||
const timer = performance.now();
|
||||
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.
|
||||
if (!input.size) {
|
||||
|
@ -289,12 +289,12 @@ async function runPostBuildHooks(
|
|||
) {
|
||||
const mutations = await container.runPostHook(ssrReturn, clientReturn);
|
||||
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) {
|
||||
const root = isServerLikeOutput(config)
|
||||
? mutation.build === 'server'
|
||||
? buildConfig.server
|
||||
: buildConfig.client
|
||||
? build.server
|
||||
: build.client
|
||||
: config.outDir;
|
||||
const fileURL = new URL(fileName, root);
|
||||
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));
|
||||
}
|
||||
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.
|
||||
const files = await glob('**/*.mjs', {
|
||||
cwd: fileURLToPath(out),
|
||||
|
@ -394,8 +396,10 @@ async function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles = false
|
|||
async function ssrMoveAssets(opts: StaticBuildOptions) {
|
||||
info(opts.logging, 'build', 'Rearranging server assets...');
|
||||
const serverRoot =
|
||||
opts.settings.config.output === 'static' ? opts.buildConfig.client : opts.buildConfig.server;
|
||||
const clientRoot = opts.buildConfig.client;
|
||||
opts.settings.config.output === 'static'
|
||||
? 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 serverAssets = new URL(`./${assets}/`, appendForwardSlash(serverRoot.toString()));
|
||||
const clientAssets = new URL(`./${assets}/`, appendForwardSlash(clientRoot.toString()));
|
||||
|
|
|
@ -2,7 +2,6 @@ import type { default as vite, InlineConfig } from 'vite';
|
|||
import type {
|
||||
AstroConfig,
|
||||
AstroSettings,
|
||||
BuildConfig,
|
||||
ComponentInstance,
|
||||
ManifestData,
|
||||
MiddlewareHandler,
|
||||
|
@ -36,7 +35,6 @@ export type AllPagesData = Record<ComponentPath, PageBuildData>;
|
|||
export interface StaticBuildOptions {
|
||||
allPages: AllPagesData;
|
||||
settings: AstroSettings;
|
||||
buildConfig: BuildConfig;
|
||||
logging: LogOptions;
|
||||
manifest: ManifestData;
|
||||
mode: RuntimeMode;
|
||||
|
|
|
@ -7,7 +7,6 @@ import type {
|
|||
AstroConfig,
|
||||
AstroRenderer,
|
||||
AstroSettings,
|
||||
BuildConfig,
|
||||
ContentEntryType,
|
||||
DataEntryType,
|
||||
HookParameters,
|
||||
|
@ -323,14 +322,12 @@ export async function runHookBuildSsr({
|
|||
|
||||
export async function runHookBuildGenerated({
|
||||
config,
|
||||
buildConfig,
|
||||
logging,
|
||||
}: {
|
||||
config: AstroConfig;
|
||||
buildConfig: BuildConfig;
|
||||
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) {
|
||||
if (integration?.hooks?.['astro:build:generated']) {
|
||||
|
@ -345,18 +342,16 @@ export async function runHookBuildGenerated({
|
|||
|
||||
export async function runHookBuildDone({
|
||||
config,
|
||||
buildConfig,
|
||||
pages,
|
||||
routes,
|
||||
logging,
|
||||
}: {
|
||||
config: AstroConfig;
|
||||
buildConfig: BuildConfig;
|
||||
pages: string[];
|
||||
routes: RouteData[];
|
||||
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 });
|
||||
|
||||
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 () => {
|
||||
// number of the pages inside src/
|
||||
expect(entryPoints.size).to.equal(4);
|
||||
for (const fileUrl in entryPoints.values()) {
|
||||
for (const fileUrl of entryPoints.values()) {
|
||||
let filePath = fileURLToPath(fileUrl);
|
||||
expect(existsSync(filePath)).to.be.true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue