Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Dec 14, 2022
1 parent 31ec847 commit e9c8e6a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/astro/e2e/error-cyclic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';

const test = testFactory({
experimentalErrorOverlay: true,
root: './fixtures/error-cyclic/'
root: './fixtures/error-cyclic/',
});

let devServer;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/error-react-spectrum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';

const test = testFactory({
experimentalErrorOverlay: true,
root: './fixtures/error-react-spectrum/'
root: './fixtures/error-react-spectrum/',
});

let devServer;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/error-sass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { testFactory, getErrorOverlayContent } from './test-utils.js';

const test = testFactory({
experimentalErrorOverlay: true,
root: './fixtures/error-sass/'
root: './fixtures/error-sass/',
});

let devServer;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/e2e/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getErrorOverlayContent, testFactory } from './test-utils.js';

const test = testFactory({
experimentalErrorOverlay: true,
root: './fixtures/errors/'
root: './fixtures/errors/',
});

let devServer;
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/src/core/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ 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,
experimentalErrorOverlay:
typeof flags.experimentalErrorOverlay === 'boolean'
? flags.experimentalErrorOverlay
: undefined,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type * as Postcss from 'postcss';
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro';

import { OutgoingHttpHeaders } from 'http';
import postcssrc from 'postcss-load-config';
import { BUNDLED_THEMES } from 'shiki';
import { fileURLToPath } from 'url';
import { z } from 'zod';
import { appendForwardSlash, prependForwardSlash, trimSlashes } from '../path.js';
import { isObject } from '../util.js';
import { OutgoingHttpHeaders } from 'http';

const ASTRO_CONFIG_DEFAULTS: AstroUserConfig & any = {
root: '.',
Expand Down
5 changes: 2 additions & 3 deletions packages/astro/src/core/errors/dev/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { escape } from 'html-escaper';
import { bold, underline } from 'kleur/colors';
import * as fs from 'node:fs';
import { isAbsolute, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import stripAnsi from 'strip-ansi';
import { escape } from 'html-escaper';
import type { BuildResult } from 'esbuild';
import type { ESBuildTransformResult } from 'vite';
import type { SSRError } from '../../../@types/astro.js';
import { AggregateError, ErrorWithMetadata } from '../errors.js';
import { codeFrame } from '../printer.js';
import { normalizeLF } from '../utils.js';
import { bold, underline } from 'kleur/colors';

type EsbuildMessage = ESBuildTransformResult['warnings'][number];

Expand Down
24 changes: 12 additions & 12 deletions packages/astro/src/core/errors/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,25 @@ function getOverlayCode() {
}

export function patchOverlay(code: string, config: AstroConfig) {
if(config.experimentalErrorOverlay) {
if (config.experimentalErrorOverlay) {
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;
// 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]')
)
)
.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]')
);
}
}
2 changes: 1 addition & 1 deletion packages/astro/src/vite-plugin-astro-server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type * as vite from 'vite';
import type { AstroSettings, ManifestData } from '../@types/astro';

import type fs from 'fs';
import { patchOverlay } from '../core/errors/overlay.js';
import { LogOptions } from '../core/logger/core.js';
import { createViteLoader } from '../core/module-loader/index.js';
import { createDevelopmentEnvironment } from '../core/render/dev/index.js';
import { createRouteManifest } from '../core/routing/index.js';
import { baseMiddleware } from './base.js';
import { createController } from './controller.js';
import { handleRequest } from './request.js';
import { patchOverlay } from '../core/errors/overlay.js';

export interface AstroPluginOptions {
settings: AstroSettings;
Expand Down

0 comments on commit e9c8e6a

Please sign in to comment.