Unflag experimental features (#5728)

* feat: unflag `--experimental-error-overlay`

* feat: unflag `--experimental-prerender`

* chore: add changeset

* Update chilled-geese-worry.md

* test: update test to use `mjs`

* Update .changeset/chilled-geese-worry.md

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>

* Update chilled-geese-worry.md

Co-authored-by: Nate Moore <nate@astro.build>
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
This commit is contained in:
Nate Moore 2023-01-03 14:05:46 -05:00 committed by GitHub
parent f6cf92b483
commit 8fb28648f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 122 deletions

View file

@ -0,0 +1,13 @@
---
'astro': major
---
The previously experimental features `--experimental-error-overlay` and `--experimental-prerender`, both added in v1.7.0, are now the default.
You'll notice that the error overlay during `astro dev` has a refreshed visual design and provides more context for your errors.
The `prerender` feature is now enabled by default when using `output: 'server'`. To prerender a particular page, add `export const prerender = true` to your frontmatter.
> **Warning**
> Integration authors that previously relied on the exact structure of Astro's v1.0 build output may notice some changes to our output file structure. Please test your integrations to ensure compatability.
> Users that have configured a custom `vite.build.rollupOptions.output.chunkFileNames` should ensure that their Astro project is configured as an ESM Node project. Either include `"type": "module"` in your root `package.json` file or use the `.mjs` extension for `chunkFileNames`.

View file

@ -2,7 +2,6 @@ import { expect } from '@playwright/test';
import { testFactory, getErrorOverlayContent } from './test-utils.js';
const test = testFactory({
experimental: { errorOverlay: true },
root: './fixtures/error-cyclic/',
});

View file

@ -2,7 +2,6 @@ import { expect } from '@playwright/test';
import { testFactory, getErrorOverlayContent } from './test-utils.js';
const test = testFactory({
experimental: { errorOverlay: true },
root: './fixtures/error-sass/',
});

View file

@ -2,7 +2,6 @@ import { expect } from '@playwright/test';
import { getErrorOverlayContent, testFactory } from './test-utils.js';
const test = testFactory({
experimental: { errorOverlay: true },
root: './fixtures/errors/',
});

View file

@ -83,8 +83,6 @@ export interface CLIFlags {
port?: number;
config?: string;
drafts?: boolean;
experimentalErrorOverlay?: boolean;
experimentalPrerender?: boolean;
experimentalContentCollections?: boolean;
}
@ -927,46 +925,6 @@ export interface AstroUserConfig {
* These flags are not guaranteed to be stable.
*/
experimental?: {
/**
* @docs
* @name experimental.errorOverlay
* @type {boolean}
* @default `false`
* @version 1.7.0
* @description
* Turn on experimental support for the new error overlay component.
*
* To enable this feature, set `experimental.errorOverlay` to `true` in your Astro config:
*
* ```js
* {
* experimental: {
* errorOverlay: true,
* },
* }
* ```
*/
errorOverlay?: boolean;
/**
* @docs
* @name experimental.prerender
* @type {boolean}
* @default `false`
* @version 1.7.0
* @description
* Enable experimental support for prerendered pages when generating a server.
*
* To enable this feature, set `experimental.prerender` to `true` in your Astro config:
*
* ```js
* {
* experimental: {
* prerender: true,
* },
* }
* ```
*/
prerender?: boolean;
/**
* @docs
* @name experimental.contentCollections

View file

@ -81,7 +81,6 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.settings.config.outDir);
if (
opts.settings.config.experimental.prerender &&
opts.settings.config.output === 'server' &&
!hasPrerenderedPages(internals)
)
@ -94,7 +93,7 @@ export async function generatePages(opts: StaticBuildOptions, internals: BuildIn
const ssrEntry = await import(ssrEntryURL.toString());
const builtPaths = new Set<string>();
if (opts.settings.config.experimental.prerender && opts.settings.config.output === 'server') {
if (opts.settings.config.output === 'server') {
for (const pageData of eachPrerenderedPageData(internals)) {
await generatePage(opts, internals, pageData, ssrEntry, builtPaths);
}

View file

@ -95,32 +95,19 @@ export async function staticBuild(opts: StaticBuildOptions) {
await clientBuild(opts, internals, clientInput);
timer.generate = performance.now();
if (!settings.config.experimental.prerender) {
if (settings.config.output === 'static') {
switch (settings.config.output) {
case 'static': {
await generatePages(opts, internals);
await cleanServerOutput(opts);
} else {
// Inject the manifest
return;
}
case 'server': {
await injectManifest(opts, internals);
await generatePages(opts, internals);
await cleanStaticOutput(opts, internals);
info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`);
await ssrMoveAssets(opts);
}
} else {
switch (settings.config.output) {
case 'static': {
await generatePages(opts, internals);
await cleanServerOutput(opts);
return;
}
case 'server': {
await injectManifest(opts, internals);
await generatePages(opts, internals);
await cleanStaticOutput(opts, internals);
info(opts.logging, null, `\n${bgMagenta(black(' finalizing server assets '))}\n`);
await ssrMoveAssets(opts);
return;
}
return;
}
}
}
@ -197,12 +184,7 @@ async function clientBuild(
const { settings, viteConfig } = opts;
const timer = performance.now();
const ssr = settings.config.output === 'server';
let out;
if (!opts.settings.config.experimental.prerender) {
out = ssr ? opts.buildConfig.client : settings.config.outDir;
} else {
out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir);
}
const out = ssr ? opts.buildConfig.client : getOutDirWithinCwd(settings.config.outDir);
// Nothing to do if there is no client-side JS.
if (!input.size) {
@ -323,16 +305,6 @@ async function cleanStaticOutput(opts: StaticBuildOptions, internals: BuildInter
})
);
}
if (!opts.settings.config.experimental.prerender) {
// Clean out directly if the outDir is outside of root
if (out.toString() !== opts.settings.config.outDir.toString()) {
// Copy assets before cleaning directory if outside root
copyFiles(out, opts.settings.config.outDir);
await fs.promises.rm(out, { recursive: true });
return;
}
}
}
async function cleanServerOutput(opts: StaticBuildOptions) {

View file

@ -10,9 +10,6 @@ export function vitePluginPrerender(
name: 'astro:rollup-plugin-prerender',
outputOptions(outputOptions) {
// No-op if `prerender` is not enabled
if (!opts.settings.config.experimental.prerender) return;
const manualChunks = outputOptions.manualChunks || Function.prototype;
outputOptions.manualChunks = function (id, api, ...args) {
// Defer to user-provided `manualChunks`, if it was provided.

View file

@ -100,12 +100,6 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
host:
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined,
experimentalErrorOverlay:
typeof flags.experimentalErrorOverlay === 'boolean'
? flags.experimentalErrorOverlay
: undefined,
experimentalPrerender:
typeof flags.experimentalPrerender === 'boolean' ? flags.experimentalPrerender : undefined,
experimentalContentCollections:
typeof flags.experimentalContentCollections === 'boolean'
? flags.experimentalContentCollections
@ -138,8 +132,6 @@ function mergeCLIFlags(astroConfig: AstroUserConfig, flags: CLIFlags, cmd: strin
// TODO: Come back here and refactor to remove this expected error.
astroConfig.server.host = flags.host;
}
if (flags.experimentalErrorOverlay) astroConfig.experimental.errorOverlay = true;
if (flags.experimentalPrerender) astroConfig.experimental.prerender = true;
if (flags.experimentalContentCollections) astroConfig.experimental.contentCollections = true;
return astroConfig;
}

View file

@ -48,8 +48,6 @@ const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
astroFlavoredMarkdown: false,
},
experimental: {
errorOverlay: false,
prerender: false,
contentCollections: false,
},
};
@ -194,8 +192,6 @@ export const AstroConfigSchema = z.object({
.default(ASTRO_CONFIG_DEFAULTS.vite),
experimental: z
.object({
errorOverlay: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.errorOverlay),
prerender: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.prerender),
contentCollections: z
.boolean()
.optional()

View file

@ -119,7 +119,7 @@ export async function createVite(
astroIntegrationsContainerPlugin({ settings, logging }),
astroScriptsPageSSRPlugin({ settings }),
astroHeadPropagationPlugin({ settings }),
settings.config.experimental.prerender && astroScannerPlugin({ settings, logging }),
astroScannerPlugin({ settings, logging }),
...(settings.config.experimental.contentCollections
? [
astroContentVirtualModPlugin({ settings }),

View file

@ -561,25 +561,5 @@ function getOverlayCode() {
}
export function patchOverlay(code: string, config: AstroConfig) {
if (config.experimental.errorOverlay) {
return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay');
} else {
// Legacy overlay
return (
code
// Transform links in the message to clickable links
.replace(
"this.text('.message-body', message.trim());",
`const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim;
function escapeHtml(unsafe){return unsafe.replace(/</g, "&lt;").replace(/>/g, "&gt;");}
const escapedMessage = escapeHtml(message);
this.root.querySelector(".message-body").innerHTML = escapedMessage.trim().replace(urlPattern, '<a href="$1" target="_blank">$1</a>');`
)
.replace('</style>', '.message-body a {\n color: #ededed;\n}\n</style>')
// Hide `.tip` in Vite's ErrorOverlay
.replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}')
// Replace [vite] messages with [astro]
.replace(/\[vite\]/g, '[astro]')
);
}
return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay');
}

View file

@ -5,7 +5,7 @@ export default defineConfig({
build: {
rollupOptions: {
output: {
chunkFileNames: 'assets/testing-[name].js',
chunkFileNames: 'assets/testing-[name].mjs',
assetFileNames: 'assets/testing-[name].[ext]'
}
}