Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 13a4ee4

Browse files
committed
Fix client transformer
1 parent fe24457 commit 13a4ee4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

server/transformer.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { transform } from "../compiler/mod.ts";
33
import type { TransformOptions } from "../compiler/types.ts";
44
import { readCode } from "../lib/fs.ts";
55
import { restoreUrl, toLocalPath } from "../lib/helpers.ts";
6+
import log from "../lib/log.ts";
67
import util from "../lib/util.ts";
78
import { bundleCSS } from "./bundle_css.ts";
89
import { getAlephPkgUri } from "./config.ts";
@@ -120,13 +121,18 @@ export default {
120121
}
121122
clientDependencyGraph.mark(specifier, { deps });
122123
if (map) {
123-
const m = JSON.parse(map);
124-
if (!util.isLikelyHttpURL(specifier)) {
125-
m.sources = [`file://source/${util.trimPrefix(specifier, ".")}`];
124+
try {
125+
const m = JSON.parse(map);
126+
if (!util.isLikelyHttpURL(specifier)) {
127+
m.sources = [`file://source/${util.trimPrefix(specifier, ".")}`];
128+
}
129+
m.sourcesContent = [rawCode];
130+
resBody = code +
131+
`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(JSON.stringify(m))}`;
132+
} catch {
133+
log.warn(`Failed to add source map for '${specifier}'`);
134+
resBody = code;
126135
}
127-
m.sourcesContent = [rawCode];
128-
resBody = code +
129-
`\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,${btoa(JSON.stringify(m))}`;
130136
} else {
131137
resBody = code;
132138
}

0 commit comments

Comments
 (0)