Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically activate node source map when enabled in tsconfig.json #33

Merged
merged 4 commits into from
May 21, 2024
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
4 changes: 4 additions & 0 deletions fixtures/ts-esm-source-map/src/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function add (x: number, y: number): number {
return x + y
}
7 changes: 7 additions & 0 deletions fixtures/ts-esm-source-map/test/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import { add } from '../src/add.js'
import { strictEqual } from 'node:assert'

test('add', () => {
strictEqual(add(1, 2), 5)
})
24 changes: 24 additions & 0 deletions fixtures/ts-esm-source-map/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"sourceMap": true,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"resolveJsonModule": true,
"removeComments": true,
"newLine": "lf",
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"isolatedModules": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"lib": [
"ESNext"
],
"incremental": true
}
}
11 changes: 11 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ function deferred () {
return { resolve, reject, promise }
}

function enableSourceMapSupport (tsconfig) {
if (!tsconfig?.compilerOptions?.sourceMap) {
return
}

process.env.NODE_OPTIONS = (process.env.NODE_OPTIONS || '') + ' --enable-source-maps'
}
export default async function runWithTypeScript (config) {
// This is a hack to override
// https://github.com/nodejs/node/commit/d5c9adf3df
Expand Down Expand Up @@ -58,6 +65,8 @@ export default async function runWithTypeScript (config) {
prefix = join(dirname(tsconfigPath), outDir)
}

enableSourceMapSupport(tsconfig)

if (tscPath) {
// This will throw if we cannot find the `tsc` binary
await access(tscPath)
Expand Down Expand Up @@ -116,6 +125,8 @@ export default async function runWithTypeScript (config) {
if (config['post-compile'] && tsconfigPath) {
const tsconfig = JSON.parse(await readFile(tsconfigPath))
outDir = tsconfig.compilerOptions.outDir

enableSourceMapSupport(tsconfig)
}
let start = Date.now()
tscChild = execa('node', [tscPath, ...typescriptCliArgs], { cwd })
Expand Down
Loading
Loading