Skip to content

Commit 12b183d

Browse files
committed
fix: resolveModuleSpecifier
both `/` and `\` should be considered
1 parent 39aed29 commit 12b183d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from 'path'
22
import url from 'url'
33
import vm from 'vm'
44

5+
const VALID_PATH_REGEXP = /^[./\\]/
6+
57
export const isInESModuleScope = (): boolean => {
68
try {
79
return module === undefined
@@ -38,7 +40,5 @@ export const getCallerDirname = (): string => {
3840

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

0 commit comments

Comments
 (0)