Skip to content

Commit

Permalink
Don't cache entry or package instances in isSideloaded().
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 15, 2019
1 parent f326152 commit b77cf1a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/env/is-sideloaded.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { argv, cwd } from "../safe/process.js"

import Loader from "../loader.js"
import Package from "../package.js"

import hasLoaderArg from "./has-loader-arg.js"
Expand All @@ -24,15 +25,29 @@ function init() {
nodeModulesIndex = normalize(filename).lastIndexOf("/node_modules/")
}

const entryState = shared.entry
const entryCache = entryState.cache

const pkgState = Loader.state.package
const pkgCache = pkgState.cache

entryState.cache = new WeakMap
pkgState.cache = new Map

let result = false

// From a package like Mocha.
if (nodeModulesIndex !== -1 &&
hasLoaderArg(args) &&
(Package.get(cwd()) !== null ||
Package.get(filename.slice(0, nodeModulesIndex + 1)) !== null)) {
return true
result = true
}

return false
entryState.cache = entryCache
pkgState.cache = pkgCache

return result
}

return isSideloaded
Expand Down

0 comments on commit b77cf1a

Please sign in to comment.