Skip to content

Commit

Permalink
fix: resolveModuleSpecifier
Browse files Browse the repository at this point in the history
both `/` and `\` should be considered
  • Loading branch information
exuanbo committed Aug 28, 2021
1 parent 39aed29 commit 12b183d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import path from 'path'
import url from 'url'
import vm from 'vm'

const VALID_PATH_REGEXP = /^[./\\]/

export const isInESModuleScope = (): boolean => {
try {
return module === undefined
Expand Down Expand Up @@ -38,7 +40,5 @@ export const getCallerDirname = (): string => {

export const resolveModuleSpecifier = (specifier: string, dirname: string): string => {
const specifierPath = fileURLToPath(specifier)
return new RegExp(`^[.\\${path.sep}]`).test(specifierPath)
? path.resolve(dirname, specifierPath)
: specifier
return VALID_PATH_REGEXP.test(specifierPath) ? path.resolve(dirname, specifierPath) : specifier
}

0 comments on commit 12b183d

Please sign in to comment.