Skip to content

Commit

Permalink
feat: expose transform
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 14, 2021
1 parent e95220c commit 6b1ab5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function transform (opts: TransformOptions): string {
babelrc: false,
configFile: false,
compact: false,
retainLines: true,
retainLines: typeof opts.retainLines === 'boolean' ? opts.retainLines : true,
filename: '',
cwd: '/',
plugins: [
Expand Down
8 changes: 7 additions & 1 deletion src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function md5 (content: string, len = 8) {
return createHash('md5').update(content).digest('hex').substr(0, len)
}

export default function createJITI (_filename: string = process.cwd(), opts: JITIOptions = {}): typeof require {
type Require = typeof require
export interface JITI extends Require {
transform: (opts: TransformOptions) => string
}

export default function createJITI (_filename: string = process.cwd(), opts: JITIOptions = {}): JITI {
opts = { ...defaults, ...opts }

function debug (...args: string[]) {
Expand Down Expand Up @@ -206,6 +211,7 @@ export default function createJITI (_filename: string = process.cwd(), opts: JIT
jiti.cache = nativeRequire.cache
jiti.extensions = nativeRequire.extensions
jiti.main = nativeRequire.main
jiti.transform = opts.transform!

return jiti
}
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export type TransformOptions = {
source: string,
filename?: string,
ts?: Boolean
retainLines?: Boolean
}

0 comments on commit 6b1ab5e

Please sign in to comment.