Skip to content

Commit a9b18b9

Browse files
authored
Add sourcemaps to our published bundles (#4231)
Fixes #2470
1 parent 0254e5f commit a9b18b9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

resources/build-npm.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,23 @@ function emitTSFiles(options: {
140140
});
141141

142142
const tsHost = ts.createCompilerHost(tsOptions);
143-
tsHost.writeFile = (filepath, body) =>
144-
writeGeneratedFile(filepath.replace(/.js$/, extension), body);
143+
tsHost.writeFile = (filepath, body) => {
144+
if (filepath.match(/.js$/) && extension === '.mjs') {
145+
let bodyToWrite = body;
146+
bodyToWrite = bodyToWrite.replace(
147+
'//# sourceMappingURL=graphql.js.map',
148+
'//# sourceMappingURL=graphql.mjs.map',
149+
);
150+
writeGeneratedFile(filepath.replace(/.js$/, extension), bodyToWrite);
151+
} else if (filepath.match(/.js.map$/) && extension === '.mjs') {
152+
writeGeneratedFile(
153+
filepath.replace(/.js.map$/, extension + '.map'),
154+
body,
155+
);
156+
} else {
157+
writeGeneratedFile(filepath, body);
158+
}
159+
};
145160

146161
const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
147162
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"dom" // Workaround for missing web-compatible globals in `@types/node`
1212
],
1313
"target": "es2021",
14+
"sourceMap": true,
15+
"inlineSources": true,
1416
"module": "es2022",
1517
"moduleResolution": "node",
1618
"noEmit": true,

0 commit comments

Comments
 (0)