Skip to content

Commit

Permalink
feat: support node: and file: protocols
Browse files Browse the repository at this point in the history
resolves #30
  • Loading branch information
pi0 committed Jul 26, 2021
1 parent 369c3ff commit bbb1cb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/jiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Module, builtinModules } from 'module'
import { dirname, join, basename, extname } from 'path'
import { tmpdir } from 'os'
import vm from 'vm'
import { fileURLToPath } from 'url'
import mkdirp from 'mkdirp'
import destr from 'destr'
import createRequire from 'create-require'
Expand Down Expand Up @@ -147,6 +148,13 @@ export default function createJITI (_filename: string = process.cwd(), opts: JIT
}

function jiti (id: string) {
// Check for node: and file: protocol
if (id.startsWith('node:')) {
id = id.substr(5)
} else if (id.startsWith('file:')) {
id = fileURLToPath(id)
}

// Check for builtin node module like fs
if (builtinModules.includes(id) || id === '.pnp.js' /* #24 */) {
return nativeRequire(id)
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/proto/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import _fs from 'node:fs'
// import 'file:///test.js'

0 comments on commit bbb1cb3

Please sign in to comment.