Skip to content

Commit 774aece

Browse files
committed
fix: πŸ› log a warning if local external file is not found
βœ… Closes: #174
1 parent 98da4eb commit 774aece

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

Diff for: β€Žsrc/modules/parseFile.ts

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export const parseFile = async (
4242
if (await doesFileExist(path)) {
4343
content = await getSrcContent(path);
4444
dependencies.push(path);
45+
} else {
46+
console.warn(`[svelte-preprocess] The file "${path}" was not found.`);
4547
}
4648
}
4749
}

Diff for: β€Žtest/autoProcess/externalFiles.test.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ const {
1010
style: styleProcessor,
1111
} = getAutoPreprocess();
1212

13+
const REMOTE_JS = [
14+
'https://www.example.com/some/externally/delivered/content.js',
15+
'http://www.example.com/some/externally/delivered/content.js',
16+
'//www.example.com/some/externally/delivered/content.js',
17+
];
18+
1319
describe('external files', () => {
1420
let markup: Processed;
1521
let script: Processed;
@@ -48,15 +54,7 @@ describe('external files', () => {
4854
expect(style.dependencies).toContain(getFixturePath('style.css'));
4955
});
5056

51-
const EXTERNALJS = [
52-
'https://www.example.com/some/externally/delivered/content.js',
53-
'http://www.example.com/some/externally/delivered/content.js',
54-
'//www.example.com/some/externally/delivered/content.js',
55-
'some-file.js',
56-
'./some-not-local-file.js',
57-
];
58-
59-
EXTERNALJS.forEach((url) => {
57+
REMOTE_JS.forEach((url) => {
6058
it(`should not attempt to locally resolve ${url}`, async () => {
6159
const input = `<div></div><script src="${url}"></script>`;
6260

@@ -66,4 +64,15 @@ describe('external files', () => {
6664
expect(preprocessed.dependencies).toHaveLength(0);
6765
});
6866
});
67+
68+
it("should throw if local file don't exist", async () => {
69+
const spy = jest.spyOn(console, 'warn');
70+
const input = `<style src="./missing-potato"></style>`;
71+
72+
await preprocess(input, getAutoPreprocess());
73+
74+
expect(spy).toHaveBeenCalledWith(expect.stringContaining('was not found'));
75+
76+
spy.mockRestore();
77+
});
6978
});

Diff for: β€Žtest/autoProcess/style.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ STYLE_LANGS.forEach(([lang, ext]) => {
5555
});
5656

5757
it(`should return empty if content is empty`, async () => {
58-
const templateExternal = `<div></div><style src="./potato/style.${ext}"></style>`;
58+
const templateExternal = `<div></div><style lang="${lang}"></style>`;
5959
const opts = getAutoPreprocess({
6060
[lang]: {
6161
sourceMap: false,

0 commit comments

Comments
Β (0)