Repository: withastro/astro
File: packages/astro/src/runtime.ts (TypeScript)

Code before:
import type { LogOptions } from './logger';
import type { AstroConfig, CollectionResult, CollectionRSS, CreateCollection, Params, RuntimeMode } from './@types/astro';
import type { CompileError as ICompileError } from 'astro-parser';

import resolve from 'resolve';
import { existsSync, promises as fs } from 'fs';
import { fileURLToPath, pathToFileURL } from 'url';
import { posix as path } from 'path';
import { performance } from 'perf_hooks';
import { SnowpackDevServer, ServerRuntime as SnowpackServerRuntime, SnowpackConfig, NotFoundError } from 'snowpack';
import parser from 'astro-parser';
const { CompileError } = parser;
import { loadConfiguration, logger as snowpackLogger, startServer as startSnowpackServer } from 'snowpack';
import { canonicalURL, getSrcPath, stopTimer } from './build/util.js';
import { debug, info } from './logger.js';
import { searchForPage } from './search.js';
import snowpackExternals from './external.js';

interface RuntimeConfig {
  astroConfig: AstroConfig;
  logging: LogOptions;
  mode: RuntimeMode;
  backendSnowpack: SnowpackDevServer;
  backendSnowpackRuntime: SnowpackServerRuntime;
  backendSnowpackConfig: SnowpackConfig;
  frontendSnowpack: SnowpackDevServer;
  frontendSnowpackRuntime: SnowpackServerRuntime;
  frontendSnowpackConfig: SnowpackConfig;
}

// info needed for collection generation
interface CollectionInfo {
  additionalURLs: Set<string>;
  rss?: { data: any[] & CollectionRSS };
}

type LoadResultSuccess = {
  statusCode: 200;
  contents: string | Buffer;
  contentType?: string | false;
};
type LoadResultNotFound = { statusCode: 404; error: Error; collectionInfo?: CollectionInfo };
type LoadResultRedirect = { statusCode: 301 | 302; location: string; collectionInfo?: CollectionInfo };
type LoadResultError = { statusCode: 500 } & ({ type: 'parse-error'; error: ICompileError } | { type: 'not-found'; error: ICompileError } | { type: 'unknown'; error: Error });


Review comment (suggestion):
`esbuild` didn't like the named import from a CJS package. I think it's actually fine and `esbuild` is being over-cautious, but whatever.

Code after:
import type { LogOptions } from './logger';
import type { AstroConfig, CollectionResult, CollectionRSS, CreateCollection, Params, RuntimeMode } from './@types/astro';
import type { CompileError as ICompileError } from '@astrojs/parser';

import resolve from 'resolve';
import { existsSync, promises as fs } from 'fs';
import { fileURLToPath } from 'url';
import { posix as path } from 'path';
import { performance } from 'perf_hooks';
import {
  loadConfiguration,
  logger as snowpackLogger,
  NotFoundError,
  SnowpackDevServer,
  ServerRuntime as SnowpackServerRuntime,
  SnowpackConfig,
  startServer as startSnowpackServer,
} from 'snowpack';
import parser from '@astrojs/parser';
const { CompileError } = parser;
import { canonicalURL, getSrcPath, stopTimer } from './build/util.js';
import { debug, info } from './logger.js';
import { configureSnowpackLogger } from './snowpack-logger.js';
import { searchForPage } from './search.js';
import snowpackExternals from './external.js';
import { nodeBuiltinsMap } from './node_builtins.js';
import { ConfigManager } from './config_manager.js';

interface RuntimeConfig {
  astroConfig: AstroConfig;
  logging: LogOptions;
  mode: RuntimeMode;
  snowpack: SnowpackDevServer;
  snowpackRuntime: SnowpackServerRuntime;
  snowpackConfig: SnowpackConfig;
  configManager: ConfigManager;
}

// info needed for collection generation
interface CollectionInfo {
  additionalURLs: Set<string>;
  rss?: { data: any[] & CollectionRSS };
}

type LoadResultSuccess = {