Merge "Remove check for referenced files" (#1196)

Co-authored-by: Fred K. Schott <fkschott@gmail.com>
This commit is contained in:
(none) 2021-08-22 18:49:34 -07:00 committed by Fred K. Schott
parent 97d37f8f49
commit d771dad669
6 changed files with 45 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': minor
---
Remove check for referenced files

View file

@ -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 shouldnt 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),

View file

@ -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();

View file

@ -0,0 +1,3 @@
{
"workspaceRoot": "../../../../../"
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<script src="/external-file.js" type="module"></script>
</head>
<body>
Check console for message.
</body>
</html>