From d771dad66990f6436472b6ed185261da45be13f0 Mon Sep 17 00:00:00 2001 From: "(none)" Date: Sun, 22 Aug 2021 18:49:34 -0700 Subject: [PATCH] Merge "Remove check for referenced files" (#1196) Co-authored-by: Fred K. Schott --- .changeset/sweet-teachers-run.md | 5 +++++ packages/astro/src/build.ts | 16 ++++++++++------ .../astro/test/astro-external-files.test.js | 19 +++++++++++++++++++ .../astro-external-files/public/.gitignore | 0 .../astro-external-files/snowpack.config.json | 3 +++ .../src/pages/index.astro | 8 ++++++++ 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 .changeset/sweet-teachers-run.md create mode 100644 packages/astro/test/astro-external-files.test.js create mode 100644 packages/astro/test/fixtures/astro-external-files/public/.gitignore create mode 100644 packages/astro/test/fixtures/astro-external-files/snowpack.config.json create mode 100644 packages/astro/test/fixtures/astro-external-files/src/pages/index.astro diff --git a/.changeset/sweet-teachers-run.md b/.changeset/sweet-teachers-run.md new file mode 100644 index 000000000..dcf2cde3c --- /dev/null +++ b/.changeset/sweet-teachers-run.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Remove check for referenced files diff --git a/packages/astro/src/build.ts b/packages/astro/src/build.ts index 3ead6eca6..142e985df 100644 --- a/packages/astro/src/build.ts +++ b/packages/astro/src/build.ts @@ -18,7 +18,7 @@ import { collectBundleStats, logURLStats, mapBundleStatsToURLStats } from './bui import { getDistPath, stopTimer } from './build/util.js'; import type { LogOptions } from './logger'; import { debug, defaultLogDestination, defaultLogLevel, error, info, warn } from './logger.js'; -import { createRuntime } from './runtime.js'; +import { createRuntime, LoadResult } from './runtime.js'; const defaultLogging: LogOptions = { level: defaultLogLevel, @@ -148,13 +148,17 @@ ${stack} for (const url of [...pageDeps.js, ...pageDeps.css, ...pageDeps.images]) { if (!buildState[url]) scanPromises.push( - astroRuntime.load(url).then((result) => { - if (result.statusCode !== 200) { - if (result.statusCode === 404) { - throw new Error(`${buildState[id].srcPath.href}: could not find "${url}"`); + astroRuntime.load(url).then((result: LoadResult) => { + if (result.statusCode === 404) { + if (url.startsWith('/_astro/')) { + throw new Error(`${buildState[id].srcPath.href}: could not find file "${url}".`); } + warn(logging, 'build', `${buildState[id].srcPath.href}: could not find file "${url}". Marked as external.`); + return; + } + if (result.statusCode !== 200) { // there shouldn’t be a build error here - throw (result as any).error || new Error(`unexpected status ${result.statusCode} when loading ${url}`); + throw (result as any).error || new Error(`unexpected ${result.statusCode} response from "${url}".`); } buildState[url] = { srcPath: new URL(url, projectRoot), diff --git a/packages/astro/test/astro-external-files.test.js b/packages/astro/test/astro-external-files.test.js new file mode 100644 index 000000000..c1c177d1d --- /dev/null +++ b/packages/astro/test/astro-external-files.test.js @@ -0,0 +1,19 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { setupBuild } from './helpers.js'; + +const extRef = suite('Externeal file references'); + +setupBuild(extRef, './fixtures/astro-external-files'); + +const snapshot = ` + Check console for message. + `; + +extRef('Build with externeal reference', async (context) => { + await context.build(); + let rss = await context.readFile('/index.html'); + assert.equal(rss, snapshot); +}); + +extRef.run(); diff --git a/packages/astro/test/fixtures/astro-external-files/public/.gitignore b/packages/astro/test/fixtures/astro-external-files/public/.gitignore new file mode 100644 index 000000000..e69de29bb diff --git a/packages/astro/test/fixtures/astro-external-files/snowpack.config.json b/packages/astro/test/fixtures/astro-external-files/snowpack.config.json new file mode 100644 index 000000000..8f034781d --- /dev/null +++ b/packages/astro/test/fixtures/astro-external-files/snowpack.config.json @@ -0,0 +1,3 @@ +{ + "workspaceRoot": "../../../../../" +} diff --git a/packages/astro/test/fixtures/astro-external-files/src/pages/index.astro b/packages/astro/test/fixtures/astro-external-files/src/pages/index.astro new file mode 100644 index 000000000..cdd4545d4 --- /dev/null +++ b/packages/astro/test/fixtures/astro-external-files/src/pages/index.astro @@ -0,0 +1,8 @@ + + + + + + Check console for message. + + \ No newline at end of file