diff --git a/resources/build-npm.ts b/resources/build-npm.ts index a68ce9bbe7..c29747efb8 100644 --- a/resources/build-npm.ts +++ b/resources/build-npm.ts @@ -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, { diff --git a/tsconfig.json b/tsconfig.json index 7a2b32b927..1bd54781c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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,