Skip to content

Commit 00260bb

Browse files
Merge pull request #9 from aui/patch-1
(fix): Fix 404 not being handled properly
2 parents 19c9522 + e293e3d commit 00260bb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/loader.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,17 @@ export const constructCachePath = ({
161161
* @param nextResolve callback
162162
* @returns string
163163
*/
164-
export const resolve = async (specifier: string, { parentURL }: Context, nextResolve: NextResolve, debug = false) => {
164+
export const resolve = async (specifier: string, { parentURL }: Context, nextResolve: NextResolve) => {
165165
const { nodeImportMapPath } = constructLoaderConfig()
166166
if (!parentURL || !nodeImportMapPath) return nextResolve(specifier);
167167

168-
try {
169168
const importmap = constructImportMap(nodeImportMapPath)
170169
const modulePath = importmap.resolve(
171170
specifier,
172171
cacheMap.get(parentURL) || parentURL
173172
);
174173
const moduleCachePath = await parseModule(specifier, modulePath);
175174
return nextResolve(moduleCachePath);
176-
} catch (error) {
177-
if (debug) console.log(error);
178-
return nextResolve(specifier);
179-
}
180175
};
181176

182177
/**
@@ -198,7 +193,12 @@ export const parseModule = async (specifier: string, modulePath: string) => {
198193

199194
cacheMap.set(`file://${cachePath}`, modulePath);
200195
if (existsSync(cachePath)) return cachePath
201-
const code = await (await fetch(modulePath)).text();
196+
const code = await (await fetch(modulePath).then(response => {
197+
if (!response.ok) {
198+
throw Error(`404: Module not found: ${modulePath}`);
199+
}
200+
return response;
201+
})).text();
202202

203203
ensureFileSync(cachePath);
204204
writeFileSync(cachePath, code);

0 commit comments

Comments
 (0)