Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to make type-module tolerant #1

Merged
merged 1 commit into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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