Skip to content

Commit

Permalink
feat: support inline sourceMaps for easier debugging (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
  • Loading branch information
ast-pmykhailov and pi0 authored Feb 18, 2022
1 parent e8696c7 commit 888db00
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Using esm resolution algorithm to support `import` condition.

Transform function. See [src/babel](./src/babel.ts) for more details

### `sourceMaps`

- Type: Boolean
- Default `false`
- Environment Vriable: `JITI_SOURCE_MAPS`

Add inline source map to transformed source for better debugging.

## Development

- Clone Repo
Expand Down
11 changes: 11 additions & 0 deletions src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const _EnvDebug = destr(process.env.JITI_DEBUG)
const _EnvCache = destr(process.env.JITI_CACHE)
const _EnvESMReolve = destr(process.env.JITI_ESM_RESOLVE)
const _EnvRequireCache = destr(process.env.JITI_REQUIRE_CACHE)
const _EnvSourceMaps = destr(process.env.JITI_SOURCE_MAPS)

const isWindows = platform() === 'win32'

const defaults: JITIOptions = {
debug: _EnvDebug,
cache: _EnvCache !== undefined ? !!_EnvCache : true,
requireCache: _EnvRequireCache !== undefined ? !!_EnvRequireCache : true,
sourceMaps: _EnvSourceMaps !== undefined ? !!_EnvSourceMaps : false,
interopDefault: false,
esmResolve: _EnvESMReolve || false,
cacheVersion: '6',
Expand Down Expand Up @@ -162,6 +164,15 @@ export default function createJITI (_filename: string, opts: JITIOptions = {}, p
const res = opts.transform!({
legacy: opts.legacy,
...opts.transformOptions,
babel: {
...(opts.sourceMaps
? {
sourceFileName: topts.filename,
sourceMaps: 'inline'
}
: {}),
...opts.transformOptions?.babel
},
...topts
})
if (res.error && opts.debug) {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type JITIOptions = {
transform?: (opts: TransformOptions) => TRANSFORM_RESULT,
debug?: boolean,
cache?: boolean | string
sourceMaps?: boolean
requireCache?: boolean
v8cache?: boolean
interopDefault?: boolean
Expand Down

0 comments on commit 888db00

Please sign in to comment.