[ci] format
This commit is contained in:
parent
31ec847972
commit
e9c8e6a2c0
9 changed files with 24 additions and 22 deletions
|
@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';
|
||||||
|
|
||||||
const test = testFactory({
|
const test = testFactory({
|
||||||
experimentalErrorOverlay: true,
|
experimentalErrorOverlay: true,
|
||||||
root: './fixtures/error-cyclic/'
|
root: './fixtures/error-cyclic/',
|
||||||
});
|
});
|
||||||
|
|
||||||
let devServer;
|
let devServer;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';
|
||||||
|
|
||||||
const test = testFactory({
|
const test = testFactory({
|
||||||
experimentalErrorOverlay: true,
|
experimentalErrorOverlay: true,
|
||||||
root: './fixtures/error-react-spectrum/'
|
root: './fixtures/error-react-spectrum/',
|
||||||
});
|
});
|
||||||
|
|
||||||
let devServer;
|
let devServer;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';
|
||||||
|
|
||||||
const test = testFactory({
|
const test = testFactory({
|
||||||
experimentalErrorOverlay: true,
|
experimentalErrorOverlay: true,
|
||||||
root: './fixtures/error-sass/'
|
root: './fixtures/error-sass/',
|
||||||
});
|
});
|
||||||
|
|
||||||
let devServer;
|
let devServer;
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { getErrorOverlayContent, testFactory } from './test-utils.js';
|
||||||
|
|
||||||
const test = testFactory({
|
const test = testFactory({
|
||||||
experimentalErrorOverlay: true,
|
experimentalErrorOverlay: true,
|
||||||
root: './fixtures/errors/'
|
root: './fixtures/errors/',
|
||||||
});
|
});
|
||||||
|
|
||||||
let devServer;
|
let devServer;
|
||||||
|
|
|
@ -100,7 +100,10 @@ export function resolveFlags(flags: Partial<Flags>): CLIFlags {
|
||||||
host:
|
host:
|
||||||
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
|
typeof flags.host === 'string' || typeof flags.host === 'boolean' ? flags.host : undefined,
|
||||||
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined,
|
drafts: typeof flags.drafts === 'boolean' ? flags.drafts : undefined,
|
||||||
experimentalErrorOverlay: typeof flags.experimentalErrorOverlay === 'boolean' ? flags.experimentalErrorOverlay : undefined,
|
experimentalErrorOverlay:
|
||||||
|
typeof flags.experimentalErrorOverlay === 'boolean'
|
||||||
|
? flags.experimentalErrorOverlay
|
||||||
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@ import type * as Postcss from 'postcss';
|
||||||
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
||||||
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro';
|
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro';
|
||||||
|
|
||||||
|
import { OutgoingHttpHeaders } from 'http';
|
||||||
import postcssrc from 'postcss-load-config';
|
import postcssrc from 'postcss-load-config';
|
||||||
import { BUNDLED_THEMES } from 'shiki';
|
import { BUNDLED_THEMES } from 'shiki';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js';
|
import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js';
|
||||||
import { isObject } from '../util.js';
|
import { isObject } from '../util.js';
|
||||||
import { OutgoingHttpHeaders } from 'http';
|
|
||||||
|
|
||||||
const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
|
const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
|
||||||
root: '.',
|
root: '.',
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
|
import { escape } from 'html-escaper';
|
||||||
|
import { bold, underline } from 'kleur/colors';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import { isAbsolute, join } from 'node:path';
|
import { isAbsolute, join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import stripAnsi from 'strip-ansi';
|
import stripAnsi from 'strip-ansi';
|
||||||
import { escape } from 'html-escaper';
|
|
||||||
import type { BuildResult } from 'esbuild';
|
|
||||||
import type { ESBuildTransformResult } from 'vite';
|
import type { ESBuildTransformResult } from 'vite';
|
||||||
import type { SSRError } from '../../../@types/astro.js';
|
import type { SSRError } from '../../../@types/astro.js';
|
||||||
import { AggregateError, ErrorWithMetadata } from '../errors.js';
|
import { AggregateError, ErrorWithMetadata } from '../errors.js';
|
||||||
import { codeFrame } from '../printer.js';
|
import { codeFrame } from '../printer.js';
|
||||||
import { normalizeLF } from '../utils.js';
|
import { normalizeLF } from '../utils.js';
|
||||||
import { bold, underline } from 'kleur/colors';
|
|
||||||
|
|
||||||
type EsbuildMessage = ESBuildTransformResult['warnings'][number];
|
type EsbuildMessage = ESBuildTransformResult['warnings'][number];
|
||||||
|
|
||||||
|
|
|
@ -561,25 +561,25 @@ function getOverlayCode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patchOverlay(code: string, config: AstroConfig) {
|
export function patchOverlay(code: string, config: AstroConfig) {
|
||||||
if(config.experimentalErrorOverlay) {
|
if (config.experimentalErrorOverlay) {
|
||||||
return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay');
|
return code.replace('class ErrorOverlay', getOverlayCode() + '\nclass ViteErrorOverlay');
|
||||||
} else {
|
} else {
|
||||||
// Legacy overlay
|
// Legacy overlay
|
||||||
return (
|
return (
|
||||||
code
|
code
|
||||||
// Transform links in the message to clickable links
|
// Transform links in the message to clickable links
|
||||||
.replace(
|
.replace(
|
||||||
"this.text('.message-body', message.trim());",
|
"this.text('.message-body', message.trim());",
|
||||||
`const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim;
|
`const urlPattern = /(\\b(https?|ftp):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])/gim;
|
||||||
function escapeHtml(unsafe){return unsafe.replace(/</g, "<").replace(/>/g, ">");}
|
function escapeHtml(unsafe){return unsafe.replace(/</g, "<").replace(/>/g, ">");}
|
||||||
const escapedMessage = escapeHtml(message);
|
const escapedMessage = escapeHtml(message);
|
||||||
this.root.querySelector(".message-body").innerHTML = escapedMessage.trim().replace(urlPattern, '<a href="$1" target="_blank">$1</a>');`
|
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>')
|
.replace('</style>', '.message-body a {\n color: #ededed;\n}\n</style>')
|
||||||
// Hide `.tip` in Vite's ErrorOverlay
|
// Hide `.tip` in Vite's ErrorOverlay
|
||||||
.replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}')
|
.replace(/\.tip \{[^}]*\}/gm, '.tip {\n display: none;\n}')
|
||||||
// Replace [vite] messages with [astro]
|
// Replace [vite] messages with [astro]
|
||||||
.replace(/\[vite\]/g, '[astro]')
|
.replace(/\[vite\]/g, '[astro]')
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import type * as vite from 'vite';
|
||||||
import type { AstroSettings, ManifestData } from '../@types/astro';
|
import type { AstroSettings, ManifestData } from '../@types/astro';
|
||||||
|
|
||||||
import type fs from 'fs';
|
import type fs from 'fs';
|
||||||
|
import { patchOverlay } from '../core/errors/overlay.js';
|
||||||
import { LogOptions } from '../core/logger/core.js';
|
import { LogOptions } from '../core/logger/core.js';
|
||||||
import { createViteLoader } from '../core/module-loader/index.js';
|
import { createViteLoader } from '../core/module-loader/index.js';
|
||||||
import { createDevelopmentEnvironment } from '../core/render/dev/index.js';
|
import { createDevelopmentEnvironment } from '../core/render/dev/index.js';
|
||||||
|
@ -9,7 +10,6 @@ import { createRouteManifest } from '../core/routing/index.js';
|
||||||
import { baseMiddleware } from './base.js';
|
import { baseMiddleware } from './base.js';
|
||||||
import { createController } from './controller.js';
|
import { createController } from './controller.js';
|
||||||
import { handleRequest } from './request.js';
|
import { handleRequest } from './request.js';
|
||||||
import { patchOverlay } from '../core/errors/overlay.js';
|
|
||||||
|
|
||||||
export interface AstroPluginOptions {
|
export interface AstroPluginOptions {
|
||||||
settings: AstroSettings;
|
settings: AstroSettings;
|
||||||
|
|
Loading…
Reference in a new issue