0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

fix: docs and types (#13087)

This commit is contained in:
Emanuele Stoppa 2025-01-29 14:33:40 +00:00 committed by GitHub
parent 18a2699f53
commit c3ed9ee7b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 28 additions and 27 deletions

View file

@ -189,14 +189,14 @@ declare module 'astro:middleware' {
export * from 'astro/virtual-modules/middleware.js'; export * from 'astro/virtual-modules/middleware.js';
} }
declare module 'astro:manifest/server' { declare module 'astro:config/server' {
// biome-ignore format: bug // biome-ignore format: bug
type ServerConfigSerialized = import('./dist/types/public/manifest.js').ServerDeserializedManifest; type ServerConfigSerialized = import('./dist/types/public/manifest.js').ServerDeserializedManifest;
const manifest: ServerConfigSerialized; const manifest: ServerConfigSerialized;
export default manifest; export default manifest;
} }
declare module 'astro:manifest/client' { declare module 'astro:config/client' {
// biome-ignore format: bug // biome-ignore format: bug
type ClientConfigSerialized = import('./dist/types/public/manifest.js').ClientDeserializedManifest; type ClientConfigSerialized = import('./dist/types/public/manifest.js').ClientDeserializedManifest;
const manifest: ClientConfigSerialized; const manifest: ClientConfigSerialized;

View file

@ -17,6 +17,19 @@ export interface ErrorData {
* @name Astro Errors * @name Astro Errors
*/ */
// Astro Errors, most errors will go here! // Astro Errors, most errors will go here!
/**
* @docs
* @description
* Cannot use the module `astro:config` without enabling the experimental feature.
*/
export const CantUseAstroConfigModuleError = {
name: 'CantUseAstroConfigModuleError',
title: 'Cannot use the `astro:config` module without enabling the experimental feature.',
message: (moduleName) =>
`Cannot import the module "${moduleName}" because the experimental feature is disabled. Enable \`experimental.serializeManifest\` in your \`astro.config.mjs\` `,
} satisfies ErrorData;
/** /**
* @docs * @docs
* @message * @message
@ -1758,6 +1771,7 @@ export const UnsupportedConfigTransformError = {
hint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue', hint: 'See the devalue library for all supported types: https://github.com/rich-harris/devalue',
} satisfies ErrorData; } satisfies ErrorData;
/** /**
* @docs * @docs
* @kind heading * @kind heading
@ -1822,18 +1836,6 @@ export const ActionCalledFromServerError = {
hint: 'See the `Astro.callAction()` reference for usage examples: https://docs.astro.build/en/reference/api-reference/#callaction', hint: 'See the `Astro.callAction()` reference for usage examples: https://docs.astro.build/en/reference/api-reference/#callaction',
} satisfies ErrorData; } satisfies ErrorData;
/**
* @docs
* @description
* Cannot use the module `astro:config` without enabling the experimental feature.
*/
export const CantUseManifestModule = {
name: 'CantUseManifestModule',
title: 'Cannot use the `astro:config` module without enabling the experimental feature.',
message: (moduleName) =>
`Cannot import the module "${moduleName}" because the experimental feature is disabled. Enable \`experimental.serializeManifest\` in your \`astro.config.mjs\` `,
} satisfies ErrorData;
// Generic catch-all - Only use this in extreme cases, like if there was a cosmic ray bit flip. // Generic catch-all - Only use this in extreme cases, like if there was a cosmic ray bit flip.
export const UnknownError = { name: 'UnknownError', title: 'Unknown Error.' } satisfies ErrorData; export const UnknownError = { name: 'UnknownError', title: 'Unknown Error.' } satisfies ErrorData;

View file

@ -1,5 +1,5 @@
import type { Plugin } from 'vite'; import type { Plugin } from 'vite';
import { CantUseManifestModule } from '../core/errors/errors-data.js'; import { CantUseAstroConfigModuleError } from '../core/errors/errors-data.js';
import { AstroError, AstroErrorData } from '../core/errors/index.js'; import { AstroError, AstroErrorData } from '../core/errors/index.js';
import type { Logger } from '../core/logger/core.js'; import type { Logger } from '../core/logger/core.js';
import { fromRoutingStrategy } from '../i18n/utils.js'; import { fromRoutingStrategy } from '../i18n/utils.js';
@ -37,8 +37,8 @@ export default function virtualModulePlugin({
if (id === RESOLVED_VIRTUAL_CLIENT_ID) { if (id === RESOLVED_VIRTUAL_CLIENT_ID) {
if (!settings.config.experimental.serializeConfig) { if (!settings.config.experimental.serializeConfig) {
throw new AstroError({ throw new AstroError({
...CantUseManifestModule, ...CantUseAstroConfigModuleError,
message: CantUseManifestModule.message(VIRTUAL_CLIENT_ID), message: CantUseAstroConfigModuleError.message(VIRTUAL_CLIENT_ID),
}); });
} }
// There's nothing wrong about using `/client` on the server // There's nothing wrong about using `/client` on the server
@ -48,8 +48,8 @@ export default function virtualModulePlugin({
else if (id == RESOLVED_VIRTUAL_SERVER_ID) { else if (id == RESOLVED_VIRTUAL_SERVER_ID) {
if (!settings.config.experimental.serializeConfig) { if (!settings.config.experimental.serializeConfig) {
throw new AstroError({ throw new AstroError({
...CantUseManifestModule, ...CantUseAstroConfigModuleError,
message: CantUseManifestModule.message(VIRTUAL_SERVER_ID), message: CantUseAstroConfigModuleError.message(VIRTUAL_SERVER_ID),
}); });
} }
if (!opts?.ssr) { if (!opts?.ssr) {

View file

@ -271,12 +271,12 @@ export interface ViteUserConfig extends OriginalViteUserConfig {
* ```js * ```js
* export default defineConfig({ * export default defineConfig({
* redirects: { * redirects: {
* '/old': '/new', * '/old': '/new',
* '/blog/[...slug]': '/articles/[...slug]', * '/blog/[...slug]': '/articles/[...slug]',
* '/about': 'https://example.com/about', * '/about': 'https://example.com/about',
* '/news': { * '/news': {
* status: 302, * status: 302,
* destination: 'https://example.com/news' * destination: 'https://example.com/news'
* } * }
* } * }
* }) * })

View file

@ -6,7 +6,7 @@ import { AstroError } from '../dist/core/errors/index.js';
import testAdapter from './test-adapter.js'; import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
describe('astro:manifest/client', () => { describe('astro:config/client', () => {
/** @type {import('./test-utils').Fixture} */ /** @type {import('./test-utils').Fixture} */
let fixture; let fixture;
let devServer; let devServer;
@ -29,7 +29,7 @@ describe('astro:manifest/client', () => {
it('should throw an error when importing the module', async () => { it('should throw an error when importing the module', async () => {
const response = await fixture.fetch('/'); const response = await fixture.fetch('/');
const html = await response.text(); const html = await response.text();
assert.match(html, /CantUseManifestModule/); assert.match(html, /CantUseAstroConfigModuleError/);
}); });
}); });
@ -112,7 +112,7 @@ describe('astro:manifest/client', () => {
}); });
}); });
describe('astro:manifest/server', () => { describe('astro:config/server', () => {
/** @type {import('./test-utils').Fixture} */ /** @type {import('./test-utils').Fixture} */
let fixture; let fixture;
let devServer; let devServer;
@ -150,7 +150,7 @@ describe('astro:manifest/server', () => {
it('should throw an error when importing the module', async () => { it('should throw an error when importing the module', async () => {
const response = await fixture.fetch('/server'); const response = await fixture.fetch('/server');
const html = await response.text(); const html = await response.text();
assert.match(html, /CantUseManifestModule/); assert.match(html, /CantUseAstroConfigModuleError/);
}); });
}); });

1
pnpm-lock.yaml generated
View file

@ -8926,7 +8926,6 @@ packages:
libsql@0.4.5: libsql@0.4.5:
resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==} resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==}
cpu: [x64, arm64, wasm32]
os: [darwin, linux, win32] os: [darwin, linux, win32]
lightningcss-darwin-arm64@1.29.1: lightningcss-darwin-arm64@1.29.1: