Skip to content

Commit

Permalink
Add sourcemaps to our published bundles (#4231)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored and erikwrede committed Oct 17, 2024
1 parent adafea8 commit dd1ed94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,23 @@ function emitTSFiles(options: {
});

const tsHost = ts.createCompilerHost(tsOptions);
tsHost.writeFile = (filepath, body) =>
writeGeneratedFile(filepath.replace(/.js$/, extension), body);
tsHost.writeFile = (filepath, body) => {
if (filepath.match(/.js$/) && extension === '.mjs') {
let bodyToWrite = body;
bodyToWrite = bodyToWrite.replace(
'//# sourceMappingURL=graphql.js.map',
'//# sourceMappingURL=graphql.mjs.map',
);
writeGeneratedFile(filepath.replace(/.js$/, extension), bodyToWrite);
} else if (filepath.match(/.js.map$/) && extension === '.mjs') {
writeGeneratedFile(
filepath.replace(/.js.map$/, extension + '.map'),
body,
);
} else {
writeGeneratedFile(filepath, body);
}
};

const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost);
const tsResult = tsProgram.emit(undefined, undefined, undefined, undefined, {
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dom" // Workaround for missing web-compatible globals in `@types/node`
],
"target": "es2021",
"sourceMap": true,
"inlineSources": true,
"module": "es2022",
"moduleResolution": "node",
"noEmit": true,
Expand Down

0 comments on commit dd1ed94

Please sign in to comment.