Skip to content

Commit cbe654d

Browse files
committedApr 5, 2022
New option "--no-sourcemap" to disable sourcemaps
1 parent 3039b14 commit cbe654d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed
 

‎.changeset/proud-grapes-shout.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'bob-tsm': patch
3+
---
4+
5+
New option "--no-sourcemap" to disable sourcemaps

‎packages/bob-tsm/src/bin.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ program
1515
.option('--tsmconfig <config>', 'Configuration file path', 'tsm.js')
1616
.option('--watch <patterns...>', 'Enable & specify watch mode')
1717
.option('--ignore <patterns...>', 'Ignore watch patterns')
18+
.option('--no-sourcemap', "Don't generate/enable source maps")
1819
.option('--keep-esm-loader', 'Keep ESM Loader for forks (It can break certain environments like Next.js custom server)')
1920
.addOption(
2021
new Option(
@@ -46,18 +47,22 @@ program
4647
quiet?: boolean;
4748
paths?: boolean;
4849
keepEsmLoader?: boolean;
50+
sourcemap?: boolean;
4951
}>();
5052

51-
const { watch, ignore, cjs, node_env, quiet, tsmconfig, paths, keepEsmLoader } = options;
53+
const { watch, ignore, cjs, node_env, quiet, tsmconfig, paths, keepEsmLoader, sourcemap } = options;
5254

5355
const binDirname = dirname(fileURLToPath(import.meta.url));
5456

5557
const spawnArgs = [
5658
'--require=' + join(binDirname, 'require.js'),
5759
'--loader=' + pathToFileURL(join(binDirname, 'loader.mjs')).href,
58-
'--enable-source-maps',
5960
];
6061

62+
if (sourcemap) {
63+
spawnArgs.push('--enable-source-maps');
64+
}
65+
6166
if (tsmconfig && existsSync(tsmconfig)) {
6267
spawnArgs.push('--tsmconfig', tsmconfig);
6368
}
@@ -76,6 +81,10 @@ program
7681
Object.assign((spawnEnv ||= { ...process.env }), { FORCE_CJS: '1' });
7782
}
7883

84+
if (!sourcemap) {
85+
Object.assign((spawnEnv ||= { ...process.env }), { DISABLE_SOURCEMAP: '1' });
86+
}
87+
7988
if (node_env) {
8089
const NODE_ENV = node_env === 'prod' ? 'production' : node_env === 'dev' ? 'development' : node_env;
8190
Object.assign((spawnEnv ||= { ...process.env }), {

‎packages/bob-tsm/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const defaults = function (format: Format): Defaults {
4444
options: {
4545
format,
4646
charset: 'utf8',
47-
sourcemap: 'inline',
47+
sourcemap: process.env.DISABLE_SOURCEMAP ? false : 'inline',
4848
target: 'node' + process.versions.node,
4949
logLevel: isQuiet ? 'silent' : 'warning',
5050
color: enabled,

0 commit comments

Comments
 (0)
Please sign in to comment.