summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar (none) <john@iamjohnhenry.com> 2021-08-22 18:49:34 -0700
committerGravatar Fred K. Schott <fkschott@gmail.com> 2021-09-14 16:47:54 -0700
commitd771dad66990f6436472b6ed185261da45be13f0 (patch)
tree71bc6dad45b4d1d984b0ebdf6dde2d9ba6303d8f
parent97d37f8f49981ad04dca01dad596846fd0725d41 (diff)
downloadastro-d771dad66990f6436472b6ed185261da45be13f0.tar.gz
astro-d771dad66990f6436472b6ed185261da45be13f0.tar.zst
astro-d771dad66990f6436472b6ed185261da45be13f0.zip
Merge "Remove check for referenced files" (#1196)
Co-authored-by: Fred K. Schott <fkschott@gmail.com>
-rw-r--r--.changeset/sweet-teachers-run.md5
-rw-r--r--packages/astro/src/build.ts16
-rw-r--r--packages/astro/test/astro-external-files.test.js19
-rw-r--r--packages/astro/test/fixtures/astro-external-files/public/.gitignore0
-rw-r--r--packages/astro/test/fixtures/astro-external-files/snowpack.config.json3
-rw-r--r--packages/astro/test/fixtures/astro-external-files/src/pages/index.astro8
6 files changed, 45 insertions, 6 deletions
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 = `<!DOCTYPE html><html><head><script src="/external-file.js" type="module"></script></head><body>
+ Check console for message.
+ </body></html>`;
+
+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
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-external-files/public/.gitignore
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 @@
+<html>
+ <head>
+ <script src="/external-file.js" type="module"></script>
+ </head>
+ <body>
+ Check console for message.
+ </body>
+</html> \ No newline at end of file