Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading