Merge "Remove check for referenced files" (#1196)
Co-authored-by: Fred K. Schott <fkschott@gmail.com>
This commit is contained in:
parent
97d37f8f49
commit
d771dad669
6 changed files with 45 additions and 6 deletions
5
.changeset/sweet-teachers-run.md
Normal file
5
.changeset/sweet-teachers-run.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': minor
|
||||
---
|
||||
|
||||
Remove check for referenced files
|
|
@ -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),
|
||||
|
|
19
packages/astro/test/astro-external-files.test.js
Normal file
19
packages/astro/test/astro-external-files.test.js
Normal 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();
|
0
packages/astro/test/fixtures/astro-external-files/public/.gitignore
vendored
Normal file
0
packages/astro/test/fixtures/astro-external-files/public/.gitignore
vendored
Normal file
3
packages/astro/test/fixtures/astro-external-files/snowpack.config.json
vendored
Normal file
3
packages/astro/test/fixtures/astro-external-files/snowpack.config.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"workspaceRoot": "../../../../../"
|
||||
}
|
8
packages/astro/test/fixtures/astro-external-files/src/pages/index.astro
vendored
Normal file
8
packages/astro/test/fixtures/astro-external-files/src/pages/index.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="/external-file.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
Check console for message.
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue