From 8db4b72678da47f5cfacd5607a2a0f04bde5c661 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Sat, 15 May 2021 19:12:22 -0600 Subject: [PATCH] fix: implement https://github.com/standard-things/esm/pull/877 --- src/module.js | 5 +++++ src/shim/module-js-file-loader.js | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/shim/module-js-file-loader.js diff --git a/src/module.js b/src/module.js index a543ac79a..867bfca2c 100644 --- a/src/module.js +++ b/src/module.js @@ -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 @@ -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 diff --git a/src/shim/module-js-file-loader.js b/src/shim/module-js-file-loader.js new file mode 100644 index 000000000..2be9cf533 --- /dev/null +++ b/src/shim/module-js-file-loader.js @@ -0,0 +1,8 @@ +import { readFileSync } from "fs" + +function jsFileLoader(module, filename) { + const content = readFileSync(filename, "utf8") + module._compile(content, filename) +} + +export default jsFileLoader