Skip to content

Commit

Permalink
fix: implement standard-things#877
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed May 16, 2021
1 parent 511d672 commit 8db4b72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import staticResolveFilename from "./module/static/resolve-filename.js"
import staticResolveLookupPaths from "./module/static/resolve-lookup-paths.js"
import staticWrap from "./module/static/wrap.js"
import staticWrapper from "./module/static/wrapper.js"
import jsFileLoader from "./shim/module-js-file-loader"

const {
ELECTRON
Expand All @@ -51,6 +52,10 @@ const Module = maskFunction(function (id = "", parent) {
}
}, RealModule)

// Patch the loader for files with .js extension to prevent default
// behaviour of erroring on commonjs syntax in dependencies.
RealModule._extensions[".js"] = jsFileLoader

Module._cache = __non_webpack_require__.cache
Module._extensions = { __proto__: null }
Module._findPath = staticFindPath
Expand Down
8 changes: 8 additions & 0 deletions src/shim/module-js-file-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { readFileSync } from "fs"

function jsFileLoader(module, filename) {
const content = readFileSync(filename, "utf8")
module._compile(content, filename)
}

export default jsFileLoader

0 comments on commit 8db4b72

Please sign in to comment.