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

Commit

Permalink
Ensure .node extensions are stored on RealModule._cache. [closes #765]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 28, 2019
1 parent 208b3bb commit 4da4091
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import ENV from "./constant/env.js"

import GenericArray from "./generic/array.js"
import GenericObject from "./generic/object.js"
import OwnProxy from "./own/proxy.js"
import RealModule from "./real/module.js"
import SafeModule from "./safe/module.js"
import SafeObject from "./safe/object.js"

import assign from "./util/assign.js"
import builtinIds from "./builtin-ids.js"
import isExtNode from "./path/is-ext-node.js"
import maskFunction from "./util/mask-function.js"
import protoCompile from "./module/proto/compile.js"
import protoLoad from "./module/proto/load.js"
Expand Down Expand Up @@ -45,9 +48,10 @@ const Module = maskFunction(function (id, parent) {
}
}, RealModule)

const _cache = __non_webpack_require__.cache
const _extensions = { __proto__: null }

Module._cache = __non_webpack_require__.cache
Module._cache = _cache
Module._extensions = _extensions
Module._findPath = staticFindPath
Module._initPaths = staticInitPaths
Expand All @@ -61,6 +65,34 @@ Module.builtinModules = Object.freeze(GenericArray.from(builtinIds))
Module.createRequireFromPath = staticCreateRequireFromPath
Module.wrap = staticWrap

if (_cache !== RealModule._cache) {
Module._cache = new OwnProxy(_cache, {
defineProperty(target, name, descriptor) {
if (isExtNode(name)) {
Reflect.defineProperty(RealModule._cache, name, descriptor)
}

SafeObject.defineProperty(target, name, descriptor)

return true
},
deleteProperty(target, name) {
if (isExtNode(name)) {
Reflect.deleteProperty(RealModule._cache, name)
}

return Reflect.deleteProperty(target, name)
},
set(target, name, value, receiver) {
if (isExtNode(name)) {
Reflect.set(RealModule._cache, name, value)
}

return Reflect.set(target, name, value, receiver)
}
})
}

if (! ELECTRON ||
! Array.isArray(SafeModule.wrapper)) {
Module.wrapper = staticWrapper
Expand Down

0 comments on commit 4da4091

Please sign in to comment.