Comparing version
53
index.js
@@ -5,25 +5,52 @@ const path = require('path'); | ||
const EXTRE = /^[.]?[^.]+([.].*)$/; | ||
function req (moduleName, cwd) { | ||
return require(resolve.sync(moduleName, {basedir: cwd})); | ||
} | ||
function handleLegacy (moduleName, legacyModuleName, cwd) { | ||
try { | ||
return req(moduleName, cwd); | ||
} catch (err) { | ||
try { | ||
return req(legacyModuleName, cwd); | ||
} catch (__) { | ||
// nice error messages | ||
err.message = err.message.replace(moduleName, moduleName + '\' or \'' + legacyModuleName); | ||
throw err; | ||
} | ||
} | ||
} | ||
exports.registerFor = function (filepath, cwd) { | ||
var ext = path.extname(filepath); | ||
var match = EXTRE.exec(path.basename(filepath)); | ||
if (!match) { | ||
return; | ||
} | ||
var ext = match[1]; | ||
if (Object.keys(require.extensions).indexOf(ext) !== -1) { | ||
return; | ||
} | ||
var moduleName = interpret.extensions[ext]; | ||
if (!moduleName) { | ||
return; | ||
} | ||
if (!cwd) { | ||
cwd = path.dirname(path.resolve(filepath)); | ||
} | ||
var moduleName = interpret.extensions[ext]; | ||
if (moduleName) { | ||
var compiler = require(resolve.sync(moduleName, {basedir: cwd})); | ||
var register = interpret.register[moduleName]; | ||
if (register) { | ||
register(compiler); | ||
} | ||
var legacyModuleName = interpret.legacy[ext]; | ||
var config = interpret.configurations[moduleName]; | ||
var compiler; | ||
if (legacyModuleName) { | ||
compiler = handleLegacy(moduleName, legacyModuleName, cwd); | ||
} else { | ||
compiler = req(moduleName, cwd); | ||
} | ||
} | ||
exports.load = function (filepath) { | ||
exports.registerFor(filepath); | ||
return require(filepath); | ||
var register = interpret.register[moduleName]; | ||
if (register) { | ||
register(compiler, config); | ||
} | ||
}; | ||
exports.interpret = interpret; |
{ | ||
"name": "rechoir", | ||
"description": "Require any supported file as a node module.", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/tkellen/node-rechoir", | ||
@@ -32,5 +32,6 @@ "author": { | ||
"resolve": "^0.6.1", | ||
"interpret": "^0.3.0" | ||
"interpret": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"6to5": "^2.9.4", | ||
"LiveScript": "^1.2.0", | ||
@@ -52,9 +53,27 @@ "chai": "^1.9.0", | ||
"require", | ||
"cjsx", | ||
"co", | ||
"coco", | ||
"coffee-script", | ||
"coffee", | ||
"coffee.md", | ||
"csv", | ||
"es", | ||
"es6", | ||
"iced", | ||
"iced.md", | ||
"iced-coffee-script", | ||
"ini", | ||
"js", | ||
"json", | ||
"json5", | ||
"jsx", | ||
"react", | ||
"litcoffee", | ||
"liticed", | ||
"ls", | ||
"livescript", | ||
"toml", | ||
"ts", | ||
"typescript", | ||
"xml", | ||
@@ -61,0 +80,0 @@ "yaml", |
@@ -35,14 +35,5 @@ # rechoir [](http://travis-ci.org/tkellen/node-rechoir) | ||
### load (filepath) | ||
Automatically call `requireFor`, then require the requested file and return the result. | ||
### interpret | ||
The underlying [interpret] module. | ||
#### Usage | ||
```js | ||
var rechoir = require('rechoir'); | ||
rechoir.load('file.coffee'); | ||
``` | ||
[interpret]: https://github.com/tkellen/node-interpret |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6423
20.94%50
100%1
-50%14
7.69%39
-18.75%1
Infinity%+ Added
- Removed
Updated