Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge output: hybrid and output: static #11824

Merged
merged 36 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a33f3ab
feat: merge hybrid and static
Princesseuh Aug 23, 2024
415a980
fix: linting
Princesseuh Aug 23, 2024
38fe245
fix: get a bunch of tests passing
Princesseuh Aug 23, 2024
032327d
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 23, 2024
00c0fd2
fix: make forceServerOutput optional
Princesseuh Aug 23, 2024
dcd3d4d
fix: more tests passing
Princesseuh Aug 24, 2024
2ae0754
fix: http2 test
Princesseuh Aug 24, 2024
84b6d23
fix: CCC
Princesseuh Aug 24, 2024
c9a003d
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 29, 2024
afc869b
fix: get unit tests passing
Princesseuh Aug 29, 2024
9fb39b8
fix: lint
Princesseuh Aug 29, 2024
a892e50
fix: vercel
Princesseuh Aug 29, 2024
a7ad179
fix: build
Princesseuh Aug 29, 2024
86923b1
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 29, 2024
cb8a7c2
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 29, 2024
6478ab4
fix: build
Princesseuh Aug 29, 2024
bcd8280
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 29, 2024
4bb31ff
fix: db tests
Princesseuh Aug 29, 2024
0fce869
fix: get all normal tests passing
Princesseuh Aug 30, 2024
485e305
fix: e2e tests
Princesseuh Aug 30, 2024
db0ead7
refactor: cleanup code
Princesseuh Aug 30, 2024
6c1ef55
fix: more tests
Princesseuh Aug 30, 2024
622d240
Merge branch 'next' into feat/remove-hybrid
Princesseuh Aug 30, 2024
5eab502
fix: windows
Princesseuh Aug 30, 2024
3614071
fix: apply feedback
Princesseuh Sep 3, 2024
b6f4db9
perf: do in parallel
Princesseuh Sep 3, 2024
122b9b7
Merge branch 'next' into feat/remove-hybrid
Princesseuh Sep 3, 2024
b5c1d11
Merge branch 'next' into feat/remove-hybrid
Princesseuh Sep 4, 2024
27cb9ac
fix: tests
Princesseuh Sep 4, 2024
2c4faa7
fix: tests, for real
Princesseuh Sep 4, 2024
ca0b570
fix: make server islands tests server-rendered
Princesseuh Sep 4, 2024
29b6d56
Merge branch 'next' into feat/remove-hybrid
Princesseuh Sep 6, 2024
c878836
fix: apply feedback
Princesseuh Sep 6, 2024
2cfe46d
nit: remove unnecessary file
Princesseuh Sep 6, 2024
e7bd25a
fix: test remove test that abuse prerender logic
Princesseuh Sep 6, 2024
ef10248
fix: ensure image endpoint is there on dev reload
Princesseuh Sep 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"editor.defaultFormatter": "biomejs.biome"
},
"editor.codeActionsOnSave": {
"quickFix.biome": true,
"source.fixAll.biome": true
}
"quickFix.biome": "explicit",
"source.fixAll.biome": "explicit"
}
}
8 changes: 7 additions & 1 deletion packages/astro/e2e/custom-client-directives.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ test.describe('Custom Client Directives - build server', () => {

test.beforeAll(async ({ astro }) => {
await astro.build({
adapter: testAdapter(),
adapter: testAdapter({
extendAdapter: {
adapterFeatures: {
forceServerOutput: false,
},
},
}),
});
previewServer = await astro.preview();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/fixtures/actions-blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import node from '@astrojs/node';
export default defineConfig({
site: 'https://example.com',
integrations: [db(), react()],
output: 'hybrid',
output: 'static',
adapter: node({
mode: 'standalone',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import node from '@astrojs/node';
export default defineConfig({
site: 'https://example.com',
integrations: [db(), react()],
output: 'hybrid',
output: 'static',
adapter: node({
mode: 'standalone',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import nodejs from '@astrojs/node';
// https://astro.build/config
export default defineConfig({
base: '/base',
output: 'hybrid',
output: 'static',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(), mdx()],
trailingSlash: process.env.TRAILING_SLASH ?? 'always',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import HTMLError from '../components/HTMLError.astro';
import { generateLongText } from '../lorem';

const content = generateLongText(5);

export const prerender = false;
---

<html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
output: 'hybrid',
output: 'static',
adapter: nodejs({ mode: 'standalone' }),
integrations: [react(),vue(),svelte()],
redirects: {
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
"test:e2e:chrome": "playwright test",
"test:e2e:firefox": "playwright test --config playwright.firefox.config.js",
"test:types": "tsc --project tsconfig.tests.json",
"test:node": "astro-scripts test \"test/**/*.test.js\""
"test:node": "astro-scripts test \"test/**/*.test.js\"",
"test:units": "astro-scripts test \"test/**/units/**/*.test.js\""
},
"dependencies": {
"@astrojs/compiler": "^2.10.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/src/actions/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionsWithoutServerOutputError } from '../core/errors/errors-data.js';
import { AstroError } from '../core/errors/errors.js';
import { isServerLikeOutput, viteID } from '../core/util.js';
import { viteID } from '../core/util.js';
import type { AstroSettings } from '../types/astro.js';
import type { AstroIntegration } from '../types/public/integrations.js';
import { ACTIONS_TYPES_FILE, VIRTUAL_MODULE_ID } from './consts.js';
Expand Down Expand Up @@ -30,7 +30,7 @@ export default function astroIntegrationActionsRouteHandler({
});
},
'astro:config:done': async (params) => {
if (!isServerLikeOutput(params.config)) {
if (params.buildOutput === 'static') {
const error = new AstroError(ActionsWithoutServerOutputError);
error.stack = undefined;
throw error;
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { AstroError } from '../../core/errors/errors.js';
import { AstroErrorData } from '../../core/errors/index.js';
import type { Logger } from '../../core/logger/core.js';
import { isRemotePath, removeLeadingForwardSlash } from '../../core/path.js';
import { isServerLikeOutput } from '../../core/util.js';
import type { MapValue } from '../../type-utils.js';
import type { AstroConfig } from '../../types/public/config.js';
import { getConfiguredImageService } from '../internal.js';
Expand Down Expand Up @@ -50,7 +49,7 @@ export async function prepareAssetsGenerationEnv(
pipeline: BuildPipeline,
totalCount: number,
): Promise<AssetEnv> {
const { config, logger } = pipeline;
const { config, logger, settings } = pipeline;
let useCache = true;
const assetsCacheDir = new URL('assets/', config.cacheDir);
const count = { total: totalCount, current: 1 };
Expand All @@ -66,8 +65,9 @@ export async function prepareAssetsGenerationEnv(
useCache = false;
}

const isServerOutput = settings.buildOutput === 'server';
let serverRoot: URL, clientRoot: URL;
if (isServerLikeOutput(config)) {
if (isServerOutput) {
serverRoot = config.build.server;
clientRoot = config.build.client;
} else {
Expand All @@ -77,7 +77,7 @@ export async function prepareAssetsGenerationEnv(

return {
logger,
isSSR: isServerLikeOutput(config),
isSSR: isServerOutput,
count,
useCache,
assetsCacheDir,
Expand Down
48 changes: 40 additions & 8 deletions packages/astro/src/assets/endpoint/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
import type { AstroSettings } from '../../types/astro.js';
import { resolveInjectedRoute } from '../../core/routing/manifest/create.js';
import type { AstroSettings, ManifestData } from '../../types/astro.js';
import type { RouteData } from '../../types/public/internal.js';

export function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build') {
export function injectImageEndpoint(
settings: AstroSettings,
manifest: ManifestData,
mode: 'dev' | 'build',
cwd?: string,
) {
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
}

export function ensureImageEndpointRoute(
settings: AstroSettings,
manifest: ManifestData,
mode: 'dev' | 'build',
cwd?: string,
) {
if (!manifest.routes.some((route) => route.route === '/_image')) {
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
}
}

function getImageEndpointData(
settings: AstroSettings,
mode: 'dev' | 'build',
cwd?: string,
): RouteData {
const endpointEntrypoint =
settings.config.image.endpoint ??
(mode === 'dev' ? 'astro/assets/endpoint/node' : 'astro/assets/endpoint/generic');

settings.injectedRoutes.push({
pattern: '/_image',
entrypoint: endpointEntrypoint,
return {
type: 'endpoint',
isIndex: false,
route: '/_image',
pattern: /^\/_image$/,
segments: [[{ content: '_image', dynamic: false, spread: false }]],
params: [],
component: resolveInjectedRoute(endpointEntrypoint, settings.config.root, cwd).component,
generate: () => '',
pathname: '/_image',
prerender: false,
});

return settings;
fallbackRoutes: [],
};
}
5 changes: 2 additions & 3 deletions packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
removeBase,
removeQueryString,
} from '../core/path.js';
import { isServerLikeOutput } from '../core/util.js';
import type { AstroPluginOptions, AstroSettings } from '../types/astro.js';
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js';
import type { ImageTransform } from './types.js';
Expand Down Expand Up @@ -131,7 +130,7 @@ export default function assets({
// so that it's tree-shaken away for all platforms that don't need it.
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
new URL(
isServerLikeOutput(settings.config)
settings.buildOutput === 'server'
? settings.config.build.client
: settings.config.outDir,
),
Expand Down Expand Up @@ -222,7 +221,7 @@ export default function assets({
if (options?.ssr) {
return `export default ${getProxyCode(
imageMetadata,
isServerLikeOutput(settings.config),
settings.buildOutput === 'server',
)}`;
} else {
globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { UserConfig as ViteUserConfig } from 'vite';
import { Logger } from '../core/logger/core.js';
import { createRouteManifest } from '../core/routing/index.js';
import type { AstroInlineConfig, AstroUserConfig } from '../types/public/config.js';

export function defineConfig(config: AstroUserConfig) {
Expand Down Expand Up @@ -40,6 +41,7 @@ export function getViteConfig(
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
let settings = await createSettings(config, userViteConfig.root);
settings = await runHookConfigSetup({ settings, command: cmd, logger });
const manifest = await createRouteManifest({ settings }, logger);
const viteConfig = await createVite(
{
mode,
Expand All @@ -48,7 +50,7 @@ export function getViteConfig(
astroContentListenPlugin({ settings, logger, fs }),
],
},
{ settings, logger, mode, sync: false },
{ settings, logger, mode, sync: false, manifest },
);
await runHookConfigDone({ settings, logger });
return mergeConfig(viteConfig, userViteConfig);
Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/content/vite-plugin-content-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getProxyCode } from '../assets/utils/proxy.js';
import { AstroError } from '../core/errors/errors.js';
import { AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js';
import { isServerLikeOutput } from '../core/util.js';
import type { AstroSettings } from '../types/astro.js';
import type { AstroConfig } from '../types/public/config.js';
import type {
Expand Down Expand Up @@ -115,7 +114,7 @@ export function astroContentImportPlugin({
const code = `
export const id = ${JSON.stringify(id)};
export const collection = ${JSON.stringify(collection)};
export const data = ${stringifyEntryData(data, isServerLikeOutput(settings.config))};
export const data = ${stringifyEntryData(data, settings.buildOutput === 'server')};
export const _internal = {
type: 'data',
filePath: ${JSON.stringify(_internal.filePath)},
Expand All @@ -140,7 +139,7 @@ export const _internal = {
export const collection = ${JSON.stringify(collection)};
export const slug = ${JSON.stringify(slug)};
export const body = ${JSON.stringify(body)};
export const data = ${stringifyEntryData(data, isServerLikeOutput(settings.config))};
export const data = ${stringifyEntryData(data, settings.buildOutput === 'server')};
export const _internal = {
type: 'content',
filePath: ${JSON.stringify(_internal.filePath)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { Plugin } from 'vite';
import { encodeName } from '../core/build/util.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js';
import { appendForwardSlash, removeFileExtension } from '../core/path.js';
import { isServerLikeOutput } from '../core/util.js';
import { rootRelativePath } from '../core/viteUtils.js';
import type { AstroSettings } from '../types/astro.js';
import type { AstroPluginMetadata } from '../vite-plugin-astro/index.js';
Expand Down Expand Up @@ -53,7 +52,7 @@ export function astroContentVirtualModPlugin({
fs,
}: AstroContentVirtualModPluginParams): Plugin {
let IS_DEV = false;
const IS_SERVER = isServerLikeOutput(settings.config);
const IS_SERVER = settings.buildOutput === 'server';
let dataStoreFile: URL;
return {
name: 'astro-content-virtual-mod-plugin',
Expand Down
15 changes: 8 additions & 7 deletions packages/astro/src/core/build/common.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import npath from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { appendForwardSlash } from '../../core/path.js';
import type { AstroSettings } from '../../types/astro.js';
import type { AstroConfig } from '../../types/public/config.js';
import type { RouteData } from '../../types/public/internal.js';

const STATUS_CODE_PAGES = new Set(['/404', '/500']);
const FALLBACK_OUT_DIR_NAME = './.astro/';

function getOutRoot(astroConfig: AstroConfig): URL {
if (astroConfig.output === 'static') {
return new URL('./', astroConfig.outDir);
function getOutRoot(astroSettings: AstroSettings): URL {
if (astroSettings.buildOutput === 'static') {
return new URL('./', astroSettings.config.outDir);
} else {
return new URL('./', astroConfig.build.client);
return new URL('./', astroSettings.config.build.client);
}
}

export function getOutFolder(
astroConfig: AstroConfig,
astroSettings: AstroSettings,
pathname: string,
routeData: RouteData,
): URL {
const outRoot = getOutRoot(astroConfig);
const outRoot = getOutRoot(astroSettings);
const routeType = routeData.type;

// This is the root folder to write to.
Expand All @@ -30,7 +31,7 @@ export function getOutFolder(
case 'fallback':
case 'page':
case 'redirect':
switch (astroConfig.build.format) {
switch (astroSettings.config.build.format) {
case 'directory': {
if (STATUS_CODE_PAGES.has(pathname)) {
return new URL('.' + appendForwardSlash(npath.dirname(pathname)), outRoot);
Expand Down
10 changes: 5 additions & 5 deletions packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { callGetStaticPaths } from '../render/route-cache.js';
import { createRequest } from '../request.js';
import { matchRoute } from '../routing/match.js';
import { stringifyParams } from '../routing/params.js';
import { getOutputFilename, isServerLikeOutput } from '../util.js';
import { getOutputFilename } from '../util.js';
import { getOutFile, getOutFolder } from './common.js';
import { cssOrder, mergeInlineCss } from './internal.js';
import { BuildPipeline } from './pipeline.js';
Expand All @@ -49,12 +49,12 @@ import { getTimeStat, shouldAppendForwardSlash } from './util.js';

export async function generatePages(options: StaticBuildOptions, internals: BuildInternals) {
const generatePagesTimer = performance.now();
const ssr = isServerLikeOutput(options.settings.config);
const ssr = options.settings.buildOutput === 'server';
let manifest: SSRManifest;
if (ssr) {
manifest = await BuildPipeline.retrieveManifest(options, internals);
} else {
const baseDirectory = getOutputDirectory(options.settings.config);
const baseDirectory = getOutputDirectory(options.settings);
const renderersEntryUrl = new URL('renderers.mjs', baseDirectory);
const renderers = await import(renderersEntryUrl.toString());
let middleware: MiddlewareHandler = (_, next) => next();
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function generatePages(options: StaticBuildOptions, internals: Buil
delete globalThis?.astroAsset?.addStaticImage;
}

await runHookBuildGenerated({ config, logger });
await runHookBuildGenerated({ settings: options.settings, logger });
}

const THRESHOLD_SLOW_RENDER_TIME_MS = 500;
Expand Down Expand Up @@ -466,7 +466,7 @@ async function generatePath(
body = Buffer.from(await response.arrayBuffer());
}

const outFolder = getOutFolder(config, pathname, route);
const outFolder = getOutFolder(pipeline.settings, pathname, route);
const outFile = getOutFile(config, outFolder, pathname, route);
route.distURL = outFile;

Expand Down
Loading
Loading