diff --git a/packages/astro/src/cli/index.ts b/packages/astro/src/cli/index.ts index 3a22bc3f3..2bbd3cdc2 100644 --- a/packages/astro/src/cli/index.ts +++ b/packages/astro/src/cli/index.ts @@ -1,24 +1,23 @@ /* eslint-disable no-console */ -import { LogOptions } from '../core/logger/core.js'; import * as colors from 'kleur/colors'; import yargs from 'yargs-parser'; import { z } from 'zod'; -import { telemetry } from '../events/index.js'; -import * as event from '../events/index.js'; import add from '../core/add/index.js'; import build from '../core/build/index.js'; import { openConfig } from '../core/config.js'; import devServer from '../core/dev/index.js'; +import { collectErrorMetadata } from '../core/errors.js'; +import { LogOptions } from '../core/logger/core.js'; import { enableVerboseLogging, nodeLogDestination } from '../core/logger/node.js'; import { formatConfigErrorMessage, formatErrorMessage, printHelp } from '../core/messages.js'; import preview from '../core/preview/index.js'; -import { createSafeError, ASTRO_VERSION } from '../core/util.js'; +import { ASTRO_VERSION, createSafeError } from '../core/util.js'; +import * as event from '../events/index.js'; +import { eventConfigError, eventError, telemetry } from '../events/index.js'; import { check } from './check.js'; import { openInBrowser } from './open.js'; import * as telemetryHandler from './telemetry.js'; -import { collectErrorMetadata } from '../core/errors.js'; -import { eventError, eventConfigError } from '../events/index.js'; type Arguments = yargs.Arguments; type CLICommand = diff --git a/packages/astro/src/core/messages.ts b/packages/astro/src/core/messages.ts index 1283708b2..aa29723c6 100644 --- a/packages/astro/src/core/messages.ts +++ b/packages/astro/src/core/messages.ts @@ -18,7 +18,7 @@ import type { AddressInfo } from 'net'; import os from 'os'; import { ZodError } from 'zod'; import type { AstroConfig } from '../@types/astro'; -import { cleanErrorStack, collectErrorMetadata, ErrorWithMetadata } from './errors.js'; +import { cleanErrorStack, ErrorWithMetadata } from './errors.js'; import { emoji, getLocalAddress, padMultilineString } from './util.js'; const PREFIX_PADDING = 6; diff --git a/packages/astro/src/events/index.ts b/packages/astro/src/events/index.ts index fa17490c3..784e7723f 100644 --- a/packages/astro/src/events/index.ts +++ b/packages/astro/src/events/index.ts @@ -1,6 +1,6 @@ import { AstroTelemetry } from '@astrojs/telemetry'; -import { ASTRO_VERSION } from '../core/util.js'; import { createRequire } from 'module'; +import { ASTRO_VERSION } from '../core/util.js'; const require = createRequire(import.meta.url); function getViteVersion() { @@ -11,8 +11,10 @@ function getViteVersion() { return undefined; } -export const telemetry = new AstroTelemetry({ astroVersion: ASTRO_VERSION, viteVersion: getViteVersion() }); +export const telemetry = new AstroTelemetry({ + astroVersion: ASTRO_VERSION, + viteVersion: getViteVersion(), +}); export * from './error.js'; export * from './session.js'; - diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index 2322d1627..7b8c6c7fd 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -5,10 +5,10 @@ import type { TransformHook } from './styles'; import { transform } from '@astrojs/compiler'; import { fileURLToPath } from 'url'; +import { AstroErrorCodes } from '../core/errors.js'; import { prependForwardSlash } from '../core/path.js'; import { viteID } from '../core/util.js'; import { transformWithVite } from './styles.js'; -import { AstroErrorCodes } from '../core/errors.js'; type CompilationCache = Map; type CompileResult = TransformResult & { rawCSSDeps: Set }; @@ -121,18 +121,21 @@ async function compile({ return null; } }, - }).catch((err) => { - // throw compiler errors here if encountered - err.code = err.code || AstroErrorCodes.UnknownCompilerError; - throw err; - }).then((result) => { - // throw CSS transform errors here if encountered - if (cssTransformError) { - (cssTransformError as any).code = (cssTransformError as any).code || AstroErrorCodes.UnknownCompilerCSSError; - throw cssTransformError; - } - return result; - }); + }) + .catch((err) => { + // throw compiler errors here if encountered + err.code = err.code || AstroErrorCodes.UnknownCompilerError; + throw err; + }) + .then((result) => { + // throw CSS transform errors here if encountered + if (cssTransformError) { + (cssTransformError as any).code = + (cssTransformError as any).code || AstroErrorCodes.UnknownCompilerCSSError; + throw cssTransformError; + } + return result; + }); const compileResult: CompileResult = Object.create(transformResult, { rawCSSDeps: { diff --git a/packages/astro/test/errors.test.js b/packages/astro/test/errors.test.js index fdf89a021..01fe61b9a 100644 --- a/packages/astro/test/errors.test.js +++ b/packages/astro/test/errors.test.js @@ -97,5 +97,4 @@ describe('Error display', () => { expect($('h1').text()).to.equal('No mismatch'); }); }); - }); diff --git a/packages/astro/test/events.test.js b/packages/astro/test/events.test.js index 42db3242e..f447d5d80 100644 --- a/packages/astro/test/events.test.js +++ b/packages/astro/test/events.test.js @@ -3,7 +3,6 @@ import { AstroErrorCodes } from '../dist/core/errors.js'; import * as events from '../dist/events/index.js'; describe('Events', () => { - describe('eventCliSession()', () => { it('All top-level keys added', () => { const config = { @@ -422,7 +421,7 @@ describe('Events', () => { const [event] = events.eventConfigError({ err: { issues: [{ path: ['a', 'b', 'c'] }, { path: ['d', 'e', 'f'] }] }, cmd: 'COMMAND_NAME', - isFatal: true + isFatal: true, }); expect(event).to.deep.equal({ eventName: 'ASTRO_CLI_ERROR', @@ -432,7 +431,7 @@ describe('Events', () => { isConfig: true, cliCommand: 'COMMAND_NAME', configErrorPaths: ['a.b.c', 'd.e.f'], - } + }, }); }); }); @@ -445,7 +444,7 @@ describe('Events', () => { const [event] = events.eventError({ err: errorWithFullMetadata, cmd: 'COMMAND_NAME', - isFatal: true + isFatal: true, }); expect(event).to.deep.equal({ eventName: 'ASTRO_CLI_ERROR', @@ -455,7 +454,7 @@ describe('Events', () => { isFatal: true, cliCommand: 'COMMAND_NAME', anonymousMessageHint: 'TEST ERROR MESSAGE', - } + }, }); }); @@ -463,7 +462,7 @@ describe('Events', () => { const [event] = events.eventError({ err: new Error('TEST ERROR MESSAGE'), cmd: 'COMMAND_NAME', - isFatal: false + isFatal: false, }); expect(event).to.deep.equal({ eventName: 'ASTRO_CLI_ERROR', @@ -473,7 +472,7 @@ describe('Events', () => { isFatal: false, cliCommand: 'COMMAND_NAME', anonymousMessageHint: 'TEST ERROR MESSAGE', - } + }, }); }); @@ -481,10 +480,9 @@ describe('Events', () => { const [event] = events.eventError({ err: new Error('TEST ERROR MESSAGE: Sensitive data is "/Users/MYNAME/foo.astro"'), cmd: 'COMMAND_NAME', - isFatal: true + isFatal: true, }); expect(event.payload.anonymousMessageHint).to.equal('TEST ERROR MESSAGE'); }); - }); }); diff --git a/packages/telemetry/src/system-info.ts b/packages/telemetry/src/system-info.ts index 5ff3b9559..77c735941 100644 --- a/packages/telemetry/src/system-info.ts +++ b/packages/telemetry/src/system-info.ts @@ -46,7 +46,7 @@ export type SystemInfo = { let meta: SystemInfo | undefined; -export function getSystemInfo(versions: {viteVersion: string, astroVersion: string}): SystemInfo { +export function getSystemInfo(versions: { viteVersion: string; astroVersion: string }): SystemInfo { if (meta) { return meta; } diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index b385e82a5..a3c49dc5c 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,5 +1,5 @@ export { pathToPosix } from './lib/utils'; -export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; +export { AbortController, AbortSignal, alert, atob, Blob, btoa, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter } from './mod.js'; export declare const polyfill: { (target: any, options?: PolyfillOptions): any; internals(target: any, name: string): any;