Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Soften range restriction in vm hook. [closes #369]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Apr 19, 2018
1 parent 437f581 commit 48f4a3e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/hook/module.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CHAR_CODE from "../constant/char-code.js"
import ENTRY from "../constant/entry.js"
import ENV from "../constant/env.js"
import PACKAGE from "../constant/package.js"
Expand Down Expand Up @@ -31,6 +32,14 @@ import { resolve } from "../safe/path.js"
import shared from "../shared.js"
import toOptInError from "../util/to-opt-in-error.js"

const {
DIGIT_0,
DIGIT_9,
EQUAL,
LOWERCASE_V,
TILDE
} = CHAR_CODE

const {
STATE_EXECUTION_STARTED
} = ENTRY
Expand Down Expand Up @@ -92,7 +101,20 @@ function hook(Mod, parent) {
function managerWrapper(manager, func, args) {
const [, filename] = args
const pkg = Package.from(filename)
const wrapped = Wrapper.find(_extensions, ".js", pkg.range)

let { range } = pkg

const code0 = range.charCodeAt(0)

if (code0 === TILDE ||
code0 === EQUAL ||
code0 === LOWERCASE_V) {
range = "^" + range.slice(1)
} else if (code0 >= DIGIT_0 && code0 <= DIGIT_9) {
range = "^" + range
}

const wrapped = Wrapper.find(_extensions, ".js", range)

return wrapped
? Reflect.apply(wrapped, this, [manager, func, args])
Expand Down

0 comments on commit 48f4a3e

Please sign in to comment.