Skip to content

Commit 418ca46

Browse files
MegaManSecthymikee
andauthored
Build sourceMappingURL constructs with relative paths (#2737)
* Build sourceMappingURL constructs with relative paths Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com> * prettier --------- Signed-off-by: Joshua Rogers <MegaManSec@users.noreply.github.com> Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent dc848fd commit 418ca46

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

scripts/build.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,26 @@ function buildFile(file, silent) {
103103
} (copy)\n`,
104104
);
105105
} else {
106-
const options = Object.assign({}, transformOptions);
106+
const options = {
107+
...transformOptions,
108+
sourceMaps: true,
109+
sourceFileName: path.basename(file),
110+
};
107111

108112
let {code, map} = babel.transformFileSync(file, options);
109113

110-
if (!file.endsWith('.d.ts') && map.sources.length > 0) {
111-
code = `${code}\n\n//# sourceMappingURL=${destPath}.map`;
112-
map.sources = [path.relative(path.dirname(destPath), file)];
113-
fs.writeFileSync(`${destPath}.map`, JSON.stringify(map));
114+
if (!file.endsWith('.d.ts')) {
115+
const outDir = path.dirname(destPath);
116+
const outFile = path.basename(destPath);
117+
const mapFileName = `${outFile}.map`;
118+
const mapPath = path.join(outDir, mapFileName);
119+
120+
// Normalize/override key fields for consistency
121+
map.file = outFile;
122+
map.sources = [path.relative(outDir, file).replace(/\\/g, '/')];
123+
124+
code = `${code}\n\n//# sourceMappingURL=${mapFileName}`;
125+
fs.writeFileSync(mapPath, JSON.stringify(map));
114126
}
115127

116128
fs.writeFileSync(destPath, code);

0 commit comments

Comments
 (0)