-
-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
350 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ dist/ | |
tsconfig.schema.json | ||
tsconfig.schemastore-schema.json | ||
.idea/ | ||
/.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Extracted from https://github.com/nodejs/node/blob/ec2ffd6b9d255e19818b6949d2f7dc7ac70faee9/lib/internal/modules/cjs/loader.js | ||
// then modified to suit our needs | ||
|
||
const path = require('path'); | ||
const Module = require('module'); | ||
|
||
exports.createRequireFromPath = createRequireFromPath; | ||
|
||
function createRequireFromPath(filename) { | ||
// Allow a directory to be passed as the filename | ||
const trailingSlash = | ||
filename.endsWith('/') || (isWindows && filename.endsWith('\\')); | ||
|
||
const proxyPath = trailingSlash ? | ||
path.join(filename, 'noop.js') : | ||
filename; | ||
|
||
const m = new Module(proxyPath); | ||
m.filename = proxyPath; | ||
|
||
m.paths = Module._nodeModulePaths(m.path); | ||
return makeRequireFunction(m, proxyPath); | ||
} | ||
|
||
// This trick is much smaller than copy-pasting from https://github.com/nodejs/node/blob/ec2ffd6b9d255e19818b6949d2f7dc7ac70faee9/lib/internal/modules/cjs/helpers.js#L32-L101 | ||
function makeRequireFunction(module, filename) { | ||
module._compile('module.exports = require;', filename) | ||
return mod.exports | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.