Skip to content

Commit

Permalink
fix: implement standard-things#877
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoz committed Sep 17, 2021
1 parent 511d672 commit 18b1801
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "3.2.25",
"description": "Tomorrow's ECMAScript modules today!",
"keywords": "commonjs, ecmascript, export, import, modules, node, require",
"repository": "standard-things/esm",
"repository": "irls/esm",
"license": "MIT",
"author": "John-David Dalton <[email protected]>",
"author": "irls",
"main": "esm.js",
"private": true,
"runkitExample": "require = require(\"esm\")(module)\nrequire(\"lodash-es\")",
Expand Down
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 18b1801

Please sign in to comment.