diff --git a/src/npm.ts b/src/npm.ts index 7b8a1e0d7..3fb9ae23b 100644 --- a/src/npm.ts +++ b/src/npm.ts @@ -36,7 +36,11 @@ export function formatNpmSpecifier({name, range, path}: NpmSpecifier): string { } /** Rewrites /npm/ import specifiers to be relative paths to /_npm/. */ -export function rewriteNpmImports(input: string, resolve: (specifier: string) => string = String): string { +export function rewriteNpmImports( + input: string, + resolve: (specifier: string) => string = String, + href?: string +): string { const body = parseProgram(input); const output = new Sourcemap(input); @@ -66,8 +70,9 @@ export function rewriteNpmImports(input: string, resolve: (specifier: string) => if (value !== resolved) output.replaceLeft(source.start, source.end, JSON.stringify(resolved)); } - // TODO Preserve the source map, but download it too. - return String(output).replace(/^\/\/# sourceMappingURL=.*$\n?/m, ""); + return String(output).replace(/^(\/\/# sourceMappingURL=)(.*)$\n?/m, (_, _1, _2) => + href ? `${_1}${new URL(_2, href)}` : "" + ); } const npmRequests = new Map>(); @@ -89,7 +94,7 @@ export async function populateNpmCache(root: string, path: string): Promise