pax_global_header 0000666 0000000 0000000 00000000064 12553725704 0014524 g ustar 00root root 0000000 0000000 52 comment=1aafd85aac487171be71891b916c9136c620ac0e
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/ 0000775 0000000 0000000 00000000000 12553725704 0020562 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.gitignore 0000664 0000000 0000000 00000000025 12553725704 0022547 0 ustar 00root root 0000000 0000000 node_modules
egcache
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.npmignore 0000664 0000000 0000000 00000000005 12553725704 0022554 0 ustar 00root root 0000000 0000000 test
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.travis.yml 0000664 0000000 0000000 00000001347 12553725704 0022700 0 ustar 00root root 0000000 0000000 sudo: false
language: node_js
node_js:
- "0.10"
- "0.12"
env:
global:
- REMOVE_DEPS=""
matrix:
- "CUSTOM_DEPS=coffee-script@~1.3"
- "CUSTOM_DEPS=coffee-script@~1.5"
- "CUSTOM_DEPS=coffee-script@~1.7"
- "CUSTOM_DEPS=coffee-script@latest"
- "CUSTOM_DEPS=iced-coffee-script@1.6.3-j"
- "CUSTOM_DEPS=iced-coffee-script@latest"
- "CUSTOM_DEPS=LiveScript@1.3.1 REMOVE_DEPS=livescript"
- "CUSTOM_DEPS=typescript-require REMOVE_DEPS=typescript-register"
matrix:
fast_finish: true
before_install:
- "npm install -g npm" # needs the newest version of npm
before_script:
- "[ \"${REMOVE_DEPS}\" == \"\" ] || npm rm $REMOVE_DEPS"
- "npm install $CUSTOM_DEPS" # install a specific version of dependencies
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/CHANGELOG 0000664 0000000 0000000 00000001600 12553725704 0021771 0 ustar 00root root 0000000 0000000 v0.6.2:
date: 2015-07-22
changes:
- Return `undefined` when an unknown extension is provided to prepare and
the `nothrow` option is specified.
v0.6.1:
date: 2015-05-22
changes:
- Add option for not throwing.
v0.6.0:
date: 2015-05-20
changes:
- Include module name when prepare is successful.
v0.5.0:
date: 2015-05-20
changes:
- Overhaul to support interpret 0.6.0.
v0.3.0:
date: 2015-01-10
changes:
- Breaking: `load` method removed.
- Improved extension recognition.
- No longer fails upon dots in filenames.
- Support confuration objects.
- Support and test ES6.
- Support legacy module loading.
v0.2.2:
date: 2014-12-17
changes:
- Expose interpret.
v0.2.0:
date: 2014-04-20
changes:
- Simplify loading of coffee-script and iced-coffee-script.
v0.1.0:
date: 2014-04-20
changes:
- Initial public release.
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/LICENSE 0000664 0000000 0000000 00000002040 12553725704 0021563 0 ustar 00root root 0000000 0000000 Copyright (c) 2015 Tyler Kellen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/README.md 0000664 0000000 0000000 00000003742 12553725704 0022047 0 ustar 00root root 0000000 0000000 # rechoir [](http://travis-ci.org/tkellen/js-rechoir)
> Require any supported file as a node module.
[](https://nodei.co/npm/rechoir/)
## What is it?
This module, in conjunction with [interpret]-like objects can register any file type the npm ecosystem has a module loader for. This library is a dependency of [Liftoff].
## API
### prepare(config, filepath, requireFrom)
Look for a module loader associated with the provided file and attempt require it. If necessary, run any setup required to inject it into [require.extensions](http://nodejs.org/api/globals.html#globals_require_extensions).
`config` An [interpret]-like configuration object.
`filepath` A file whose type you'd like to register a module loader for.
`requireFrom` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`.
If calling this method is successful (aka: it doesn't throw), you can now require files of the type you requested natively.
An error with a `failures` property will be thrown if the module loader(s) configured for a given extension cannot be registered.
If a loader is already registered, this will simply return `true`.
**Note:** While rechoir will automatically load and register transpilers like `coffee-script`, you must provide a local installation. The transpilers are **not** bundled with this module.
#### Usage
```js
const config = require('interpret').extensions;
const rechoir = require('rechoir');
rechoir.prepare(config, './test/fixtures/test.coffee');
rechoir.prepare(config, './test/fixtures/test.csv');
rechoir.prepare(config, './test/fixtures/test.toml');
console.log(require('./test/fixtures/test.coffee'));
console.log(require('./test/fixtures/test.csv'));
console.log(require('./test/fixtures/test.toml'));
```
[interpret]: http://github.com/tkellen/js-interpret
[Liftoff]: http://github.com/tkellen/js-liftoff
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/index.js 0000664 0000000 0000000 00000002546 12553725704 0022236 0 ustar 00root root 0000000 0000000 const path = require('path');
const extension = require('./lib/extension');
const normalize = require('./lib/normalize');
const register = require('./lib/register');
exports.prepare = function (extensions, filepath, cwd, nothrow) {
var option, attempt;
var attempts = [];
var err;
var onlyErrors = false;
var ext = extension(filepath);
if (Object.keys(require.extensions).indexOf(ext) !== -1) {
return true;
}
var config = normalize(extensions[ext]);
if (!config) {
if (nothrow) {
return;
} else {
throw new Error('No module loader found for "'+ext+'".');
}
}
if (!cwd) {
cwd = path.dirname(path.resolve(filepath));
}
if (!Array.isArray(config)) {
config = [config];
}
for (var i in config) {
option = config[i];
attempt = register(cwd, option.module, option.register);
error = (attempt instanceof Error) ? attempt : null;
if (error) {
attempt = null;
}
attempts.push({
moduleName: option.module,
module: attempt,
error: error
});
if (!error) {
onlyErrors = false;
break;
} else {
onlyErrors = true;
}
}
if (onlyErrors) {
err = new Error('Unable to use specified module loaders for "'+ext+'".');
err.failures = attempts;
if (nothrow) {
return err;
} else {
throw err;
}
}
return attempts;
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/ 0000775 0000000 0000000 00000000000 12553725704 0021330 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/extension.js 0000664 0000000 0000000 00000000332 12553725704 0023700 0 ustar 00root root 0000000 0000000 const path = require('path');
const EXTRE = /^[.]?[^.]+([.].*)$/;
module.exports = function (input) {
var extension = EXTRE.exec(path.basename(input));
if (!extension) {
return;
}
return extension[1];
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/normalize.js 0000664 0000000 0000000 00000000417 12553725704 0023670 0 ustar 00root root 0000000 0000000 function normalizer (config) {
if (typeof config === 'string') {
return {
module: config
}
}
return config;
};
module.exports = function (config) {
if (Array.isArray(config)) {
return config.map(normalizer);
}
return normalizer(config);
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/register.js 0000664 0000000 0000000 00000000550 12553725704 0023512 0 ustar 00root root 0000000 0000000 const path = require('path');
const resolve = require('resolve');
module.exports = function (cwd, moduleName, register) {
try {
var modulePath = resolve.sync(moduleName, {basedir: cwd});
var result = require(modulePath);
if (typeof register === 'function') {
register(result);
}
} catch (e) {
result = e;
}
return result;
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/package.json 0000664 0000000 0000000 00000003336 12553725704 0023055 0 ustar 00root root 0000000 0000000 {
"name": "rechoir",
"description": "Require any supported file as a node module.",
"version": "0.6.2",
"homepage": "https://github.com/tkellen/node-rechoir",
"author": {
"name": "Tyler Kellen",
"url": "http://goingslowly.com/"
},
"repository": {
"type": "git",
"url": "git://github.com/tkellen/node-rechoir.git"
},
"bugs": {
"url": "https://github.com/tkellen/node-rechoir/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/tkellen/node-rechoir/blob/master/LICENSE"
}
],
"main": "index.js",
"engines": {
"node": ">= 0.10"
},
"scripts": {
"test": "mocha -R spec test/index.js"
},
"dependencies": {
"resolve": "^1.1.6"
},
"devDependencies": {
"babel": "^5.4.3",
"chai": "^2.3.0",
"coco": "^0.9.1",
"coffee-script": "^1.9.2",
"earlgrey": "0.0.9",
"iced-coffee-script": "^1.8.0-d",
"interpret": "^0.6.1",
"json5": "^0.4.0",
"livescript": "^1.4.0",
"mocha": "^2.2.5",
"node-jsx": "^0.13.3",
"require-csv": "0.0.1",
"require-ini": "0.0.1",
"require-uncached": "^1.0.2",
"require-xml": "0.0.1",
"require-yaml": "0.0.1",
"rimraf": "^2.3.4",
"semver": "^4.3.4",
"sinon": "^1.14.1",
"toml-require": "^1.0.1",
"typescript-register": "^1.1.0"
},
"keywords": [
"require",
"cjsx",
"co",
"coco",
"coffee-script",
"coffee",
"coffee.md",
"csv",
"earlgrey",
"es",
"es6",
"iced",
"iced.md",
"iced-coffee-script",
"ini",
"js",
"json",
"json5",
"jsx",
"react",
"litcoffee",
"liticed",
"ls",
"livescript",
"toml",
"ts",
"typescript",
"xml",
"yaml",
"yml"
]
}
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/ 0000775 0000000 0000000 00000000000 12553725704 0021541 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/ 0000775 0000000 0000000 00000000000 12553725704 0023412 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/.testrc 0000664 0000000 0000000 00000000161 12553725704 0024715 0 ustar 00root root 0000000 0000000 module.exports = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/folder.with.dots/ 0000775 0000000 0000000 00000000000 12553725704 0026607 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/folder.with.dots/test.yaml 0000664 0000000 0000000 00000000101 12553725704 0030442 0 ustar 00root root 0000000 0000000 data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.babel.js 0000664 0000000 0000000 00000000355 12553725704 0025776 0 ustar 00root root 0000000 0000000 // Test ES6 arrow functions
var fn = () => {
var trueKey = true;
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
return { data: { trueKey, falseKey, subKey}};
};
module.exports = fn();
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.co 0000664 0000000 0000000 00000000156 12553725704 0024716 0 ustar 00root root 0000000 0000000 module.exports = {
data: {
trueKey: true
falseKey: false
subKey: {
subProp: 1
}
}
}
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.coffee 0000664 0000000 0000000 00000000134 12553725704 0025540 0 ustar 00root root 0000000 0000000 module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.coffee.md 0000664 0000000 0000000 00000000220 12553725704 0026133 0 ustar 00root root 0000000 0000000 Test Fixture
============
module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.csv 0000664 0000000 0000000 00000000034 12553725704 0025103 0 ustar 00root root 0000000 0000000 "r1c1","r1c2"
"r2c1","r2c2"
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.eg 0000664 0000000 0000000 00000000200 12553725704 0024676 0 ustar 00root root 0000000 0000000 module.exports = {
data = {
trueKey = true
falseKey = false
subKey = {
subProp = 1
}
}
}
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.iced 0000664 0000000 0000000 00000000134 12553725704 0025215 0 ustar 00root root 0000000 0000000 module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.iced.md 0000664 0000000 0000000 00000000217 12553725704 0025616 0 ustar 00root root 0000000 0000000 Test Fixture
============
module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ini 0000664 0000000 0000000 00000000053 12553725704 0025070 0 ustar 00root root 0000000 0000000 [data]
trueKey = true
falseKey = false
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.js 0000664 0000000 0000000 00000000161 12553725704 0024725 0 ustar 00root root 0000000 0000000 module.exports = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.json 0000664 0000000 0000000 00000000151 12553725704 0025261 0 ustar 00root root 0000000 0000000 {
"data": {
"trueKey": true,
"falseKey": false,
"subKey": {
"subProp": 1
}
}
}
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.json5 0000664 0000000 0000000 00000000212 12553725704 0025344 0 ustar 00root root 0000000 0000000 {
"data": {
"trueKey": true,
"falseKey": false,
"subKey": {
"subProp": 1
}
}
/* omg, a comment in json?? */
}
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.jsx 0000664 0000000 0000000 00000000554 12553725704 0025123 0 ustar 00root root 0000000 0000000 const React = {
createElement: function(Component){
return Component();
}
};
// Test harmony arrow functions
const Component = () => {
var trueKey = true;
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
return { data: { trueKey, falseKey, subKey}};
};
// Test JSX syntax
module.exports = ;
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.litcoffee 0000664 0000000 0000000 00000000177 12553725704 0026260 0 ustar 00root root 0000000 0000000 # comment
module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.liticed 0000664 0000000 0000000 00000000177 12553725704 0025735 0 ustar 00root root 0000000 0000000 # comment
module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ls 0000664 0000000 0000000 00000000134 12553725704 0024727 0 ustar 00root root 0000000 0000000 module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.toml 0000664 0000000 0000000 00000000106 12553725704 0025263 0 ustar 00root root 0000000 0000000 [data]
trueKey = true
falseKey = false
[data.subKey]
subProp = 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ts 0000664 0000000 0000000 00000000173 12553725704 0024742 0 ustar 00root root 0000000 0000000 var test = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};
export = test;
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.xml 0000664 0000000 0000000 00000000146 12553725704 0025114 0 ustar 00root root 0000000 0000000
true
false
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.yaml 0000664 0000000 0000000 00000000101 12553725704 0025245 0 ustar 00root root 0000000 0000000 data:
trueKey: true
falseKey: false
subKey:
subProp: 1
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/helpers.js 0000664 0000000 0000000 00000002575 12553725704 0023552 0 ustar 00root root 0000000 0000000 const Module = require('module');
const semver = require('semver');
const requireUncached = require('require-uncached');
// save the original Module._extensions
const originalExtensions = Object.keys(Module._extensions);
const original = originalExtensions.reduce(function (result, key) {
result[key] = require.extensions[key];
return result;
}, {});
// save the original cache keys
const originalCacheKeys = Object.keys(require.cache);
// save the original Module.prototype.load because coffee-script overwrites it
const originalModuleLoad = Module.prototype.load;
function cleanupCache(key) {
if (originalCacheKeys.indexOf(key) === -1) {
delete require.cache[key];
}
}
function cleanupExtensions(ext) {
if (originalExtensions.indexOf(ext) === -1) {
delete Module._extensions[ext];
} else {
Module._extensions[ext] = original[ext];
}
}
function cleanup() {
// restore the require.cache to startup state
Object.keys(require.cache).forEach(cleanupCache);
// restore the original Module.prototype.load
Module.prototype.load = originalModuleLoad;
// restore the original Module._extensions
Object.keys(Module._extensions).forEach(cleanupExtensions);
}
function skippable(module, minVersion, fn) {
if (semver.gte(requireUncached(module).VERSION, minVersion)) {
cleanup();
return fn;
}
}
module.exports = {
skippable: skippable,
cleanup: cleanup
};
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/index.js 0000664 0000000 0000000 00000016072 12553725704 0023214 0 ustar 00root root 0000000 0000000 const path = require('path');
const expect = require('chai').expect;
const extensions = require('interpret').extensions;
const rechoir = require('../');
const helpers = require('./helpers');
const cleanup = helpers.cleanup;
const skippable = helpers.skippable;
var expected = {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1
}
}
};
process.env.TYPESCRIPT_REGISTER_USE_CACHE = 'false';
describe('rechoir', function () {
require('./lib/extension');
require('./lib/normalize');
require('./lib/register');
describe('prepare', function () {
var testFilePath = path.join(__dirname, 'fixtures', 'test.coffee');
beforeEach(cleanup);
it('should throw if extension is unknown', function () {
expect(function () {
rechoir.prepare(extensions, './test/fixtures/test.whatever');
}).to.throw(/No module loader found for/);
});
it('should return undefined if an unknown extension is specified when nothrow is enabled', function () {
expect(rechoir.prepare(extensions, './test/fixtures/.testrc', null, true)).to.be.undefined;
});
it('should throw if a module loader cannot be found or loaded', function () {
expect(function () {
require(testFilePath);
}).to.throw;
});
it('should include errors for each module loader that was attempted if they failed to load', function () {
try {
rechoir.prepare({
'.coffee': [
'nothere',
'orhere'
]
}, testFilePath);
} catch (e) {
expect(e.failures).to.be.array;
expect(e.failures[0].error).to.be.instanceof(Error);
expect(e.failures[0].moduleName).to.equal('nothere');
expect(e.failures[0].module).to.be.null;
expect(e.failures[1].error).to.be.instanceof(Error);
expect(e.failures[1].moduleName).to.equal('orhere');
expect(e.failures[1].module).to.be.null;
}
});
it('should register a module loader for the specified extension', function () {
const result = rechoir.prepare({
'.coffee': [
'nothere',
'coffee-script/register',
'coffee-script'
]
}, testFilePath);
expect(function () {
require(testFilePath);
}).to.not.throw(Error);
});
it('should return true if the module loader for the specified extension is already available', function () {
rechoir.prepare({
'.coffee': [
'nothere',
'coffee-script/register',
'coffee-script'
]
}, testFilePath);
expect(rechoir.prepare({
'.coffee': [
'nothere',
'coffee-script/register',
'coffee-script'
]
}, testFilePath)).to.be.true;
});
it('should know babel.js', function () {
rechoir.prepare(extensions, './test/fixtures/test.babel.js');
expect(require('./fixtures/test.babel.js')).to.deep.equal(expected);
});
it('should know coco', function () {
rechoir.prepare(extensions, './test/fixtures/test.co');
expect(require('./fixtures/test.co')).to.deep.equal(expected);
});
it('should know coffee-script', function () {
rechoir.prepare(extensions, './test/fixtures/test.coffee');
expect(require('./fixtures/test.coffee')).to.deep.equal(expected);
});
it('should know csv', function () {
rechoir.prepare(extensions, './test/fixtures/test.csv');
expect(require('./fixtures/test.csv')).to.deep.equal([['r1c1','r1c2'],['r2c1','r2c2']]);
});
it('should know earl-grey', function () {
rechoir.prepare(extensions, './test/fixtures/test.eg');
expect(require('./fixtures/test.eg')).to.deep.equal(expected);
});
it('should know iced-coffee-script', function () {
rechoir.prepare(extensions, './test/fixtures/test.iced');
expect(require('./fixtures/test.iced')).to.deep.equal(expected);
});
it('should know ini', function () {
rechoir.prepare(extensions, './test/fixtures/test.ini');
expect(require('./fixtures/test.ini')).to.deep.equal({
data: {
trueKey: "true",
falseKey: "false"
}
});
});
it('should know .js', function () {
rechoir.prepare(extensions, './test/fixtures/test.js');
expect(require('./fixtures/test.js')).to.deep.equal(expected);
});
it('should know .json', function () {
rechoir.prepare(extensions, './test/fixtures/test.json');
expect(require('./fixtures/test.json')).to.deep.equal(expected);
});
it('should know .json5', function () {
rechoir.prepare(extensions, './test/fixtures/test.json5');
expect(require('./fixtures/test.json5')).to.deep.equal(expected);
});
it('should know jsx', function () {
rechoir.prepare(extensions, './test/fixtures/test.jsx');
expect(require('./fixtures/test.jsx')).to.deep.equal(expected);
});
it('should know livescript', function () {
rechoir.prepare(extensions, './test/fixtures/test.ls');
expect(require('./fixtures/test.ls')).to.deep.equal(expected);
});
it('should know literate coffee-script', skippable('coffee-script', '1.5.0', function () {
rechoir.prepare(extensions, './test/fixtures/test.litcoffee');
expect(require('./fixtures/test.litcoffee')).to.deep.equal(expected);
}));
it('should know literate coffee-script (.md)', skippable('coffee-script', '1.6.3', function () {
rechoir.prepare(extensions, './test/fixtures/test.coffee.md');
expect(require('./fixtures/test.coffee.md')).to.deep.equal(expected);
}));
it('should know literate iced-coffee-script', skippable('iced-coffee-script', '1.7.1', function () {
rechoir.prepare(extensions, './test/fixtures/test.liticed');
expect(require('./fixtures/test.liticed')).to.deep.equal(expected);
}));
it('should know literate iced-coffee-script (.md)', skippable('iced-coffee-script', '1.7.1', function () {
rechoir.prepare(extensions, './test/fixtures/test.iced.md');
expect(require('./fixtures/test.iced.md')).to.deep.equal(expected);
}));
it('should know ts', function () {
this.timeout(5000);
rechoir.prepare(extensions, './test/fixtures/test.ts');
expect(require('./fixtures/test.ts')).to.deep.equal(expected);
});
it('should know toml', function () {
rechoir.prepare(extensions, './test/fixtures/test.toml');
expect(require('./fixtures/test.toml')).to.deep.equal(expected);
});
it('should know xml', function () {
rechoir.prepare(extensions, './test/fixtures/test.xml');
expect(JSON.parse(require('./fixtures/test.xml'))).to.deep.equal(expected);
});
it('should know yaml', function () {
rechoir.prepare(extensions, './test/fixtures/test.yaml');
expect(require('./fixtures/test.yaml')).to.deep.equal(expected);
});
it('must not fail on folders with dots', function () {
delete require.cache[require.resolve('require-yaml')];
rechoir.prepare(extensions, './test/fixtures/folder.with.dots/test.yaml');
expect(require('./fixtures/folder.with.dots/test.yaml')).to.deep.equal(expected);
});
});
});
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/ 0000775 0000000 0000000 00000000000 12553725704 0022307 5 ustar 00root root 0000000 0000000 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/extension.js 0000664 0000000 0000000 00000000734 12553725704 0024665 0 ustar 00root root 0000000 0000000 const expect = require('chai').expect;
const extension = require('../../lib/extension');
describe('extension', function () {
it('should extract extension from filename/path from the first dot', function () {
expect(extension('file.js')).to.equal('.js');
expect(extension('file.dot.js')).to.equal('.dot.js');
expect(extension('relative/path/to/file.js')).to.equal('.js');
expect(extension('relative/path/to/file.dot.js')).to.equal('.dot.js');
});
});
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/normalize.js 0000664 0000000 0000000 00000001301 12553725704 0024640 0 ustar 00root root 0000000 0000000 const chai = require('chai');
const expect = chai.expect;
const normalize = require('../../lib/normalize');
describe('normalize', function () {
it('should convert a string input into array/object format', function () {
expect(normalize('foo')).to.deep.equal({module:'foo'});
});
it('should convert object input into array format', function () {
const input = {
module: 'foo'
};
expect(normalize(input)).to.equal(input);
});
it('should iterate an array, normalizing each item', function () {
const input = [
{ module: 'foo' },
'bar'
];
expect(normalize(input)).to.deep.equal([
{ module: 'foo' },
{ module: 'bar' }
]);
});
});
js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/register.js 0000664 0000000 0000000 00000001223 12553725704 0024467 0 ustar 00root root 0000000 0000000 const chai = require('chai');
const expect = chai.expect;
const register = require('../../lib/register');
describe('register', function () {
it('should return the specified module relative to the provided cwd', function () {
expect(register(__dirname, 'chai')).to.equal(chai);
});
it('should call a register function if provided, passing in the module', function () {
register(__dirname, 'chai', function (attempt) {
expect(attempt).to.equal(chai);
});
});
it('should return an error if the specified module cannot be registered', function () {
expect(register(__dirname, 'whatev')).to.be.an.instanceof(Error);
});
});