summaryrefslogtreecommitdiff
path: root/packages/astro/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/src')
-rw-r--r--packages/astro/src/build.ts29
-rw-r--r--packages/astro/src/build/page.ts8
-rw-r--r--packages/astro/src/compiler/codegen/index.ts2
3 files changed, 32 insertions, 7 deletions
diff --git a/packages/astro/src/build.ts b/packages/astro/src/build.ts
index fbe990169..81d86ddb4 100644
--- a/packages/astro/src/build.ts
+++ b/packages/astro/src/build.ts
@@ -9,7 +9,7 @@ import { performance } from 'perf_hooks';
import eslexer from 'es-module-lexer';
import cheerio from 'cheerio';
import del from 'del';
-import { bold, green, yellow } from 'kleur/colors';
+import { bold, green, yellow, red, dim, underline } from 'kleur/colors';
import mime from 'mime';
import glob from 'tiny-glob';
import { bundleCSS } from './build/bundle/css.js';
@@ -71,10 +71,11 @@ export async function build(astroConfig: AstroConfig, logging: LogOptions = defa
timer.build = performance.now();
const pages = await allPages(pagesRoot);
info(logging, 'build', yellow('! building pages...'));
- await Promise.all(
- pages.map(async (filepath) => {
+ try {
+ await Promise.all(
+ pages.map((filepath) => {
const buildPage = getPageType(filepath) === 'collection' ? buildCollectionPage : buildStaticPage;
- await buildPage({
+ return buildPage({
astroConfig,
buildState,
filepath,
@@ -85,7 +86,25 @@ export async function build(astroConfig: AstroConfig, logging: LogOptions = defa
site: astroConfig.buildOptions.site,
});
})
- );
+ )
+ } catch (e) {
+ if (e.filename) {
+ let stack = e.stack.replace(/Object\.__render \(/gm, '').replace(/\/_astro\/(.+)\.astro\.js\:\d+\:\d+\)/gm, (_: string, $1: string) => 'file://' + fileURLToPath(projectRoot) + $1 + '.astro').split('\n');
+ stack.splice(1, 0, ` at file://${e.filename}`)
+ stack = stack.join('\n')
+
+ error(logging, 'build', `${red(`Unable to render ${underline(e.filename.replace(fileURLToPath(projectRoot), ''))}`)}
+
+${stack}
+`);
+ } else {
+ error(logging, 'build', e);
+ }
+ error(logging, 'build', red('✕ building pages failed!'));
+
+ await runtime.shutdown();
+ return 1;
+ }
info(logging, 'build', green('✔'), 'pages built.');
debug(logging, 'build', `built pages [${stopTimer(timer.build)}]`);
diff --git a/packages/astro/src/build/page.ts b/packages/astro/src/build/page.ts
index e19cf097b..d7e8e276c 100644
--- a/packages/astro/src/build/page.ts
+++ b/packages/astro/src/build/page.ts
@@ -3,6 +3,7 @@ import type { AstroRuntime, LoadResult } from '../runtime';
import type { LogOptions } from '../logger';
import path from 'path';
import { generateRSS } from './rss.js';
+import { fileURLToPath } from 'url';
interface PageBuildOptions {
astroConfig: AstroConfig;
@@ -92,7 +93,12 @@ export async function buildStaticPage({ astroConfig, buildState, filepath, runti
const { pages: pagesRoot } = astroConfig;
const url = filepath.pathname.replace(pagesRoot.pathname, '/').replace(/(index)?\.(astro|md)$/, '');
const result = await runtime.load(url);
- if (result.statusCode !== 200) throw new Error((result as any).error);
+ if (result.statusCode !== 200) {
+ let err = (result as any).error;
+ if (!(err instanceof Error)) err = new Error(err);
+ err.filename = fileURLToPath(filepath);
+ throw err;
+ }
const outFile = path.posix.join(url, '/index.html');
buildState[outFile] = {
srcPath: filepath,
diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts
index 8e1edf763..843ecc428 100644
--- a/packages/astro/src/compiler/codegen/index.ts
+++ b/packages/astro/src/compiler/codegen/index.ts
@@ -277,7 +277,7 @@ function compileModule(module: Script, state: CodegenState, compileOptions: Comp
if (module) {
const parseOptions: babelParser.ParserOptions = {
sourceType: 'module',
- plugins: ['jsx', 'typescript', 'topLevelAwait'],
+ plugins: ['jsx', 'typescript', 'topLevelAwait', 'throwExpressions'],
};
let parseResult;
try {