Skip to content

Commit 1d5ef4c

Browse files
floatdropsindresorhus
authored andcommitted
Close #103 PR: Replace babel require hook with transformFileSync.
1 parent c2f4c9f commit 1d5ef4c

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/babel.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
'use strict';
22
var resolveFrom = require('resolve-from');
33
var createEspowerPlugin = require('babel-plugin-espower/create');
4+
var requireFromString = require('require-from-string');
45
var hasGenerators = parseInt(process.version.slice(1), 10) > 0;
56
var path = process.argv[2];
67

78
var options = {
8-
only: path,
99
blacklist: hasGenerators ? ['regenerator'] : [],
10-
optional: hasGenerators ? ['asyncToGenerator'] : [],
10+
optional: hasGenerators ? ['asyncToGenerator', 'runtime'] : ['runtime'],
1111
plugins: [
1212
createEspowerPlugin(require('babel-core'), {
1313
patterns: require('./enhance-assert').PATTERNS
1414
})
1515
]
1616
};
1717

18-
try {
19-
var localBabel = resolveFrom('.', 'babel-core/register') || resolveFrom('.', 'babel/register');
18+
var babel;
2019

21-
require(localBabel)(options);
20+
try {
21+
var localBabel = resolveFrom('.', 'babel-core') || resolveFrom('.', 'babel');
22+
babel = require(localBabel);
2223
} catch (err) {
23-
require('babel-core/register')(options);
24+
babel = require('babel-core');
2425
}
2526

26-
require(path);
27+
var transpiled = babel.transformFileSync(path, options);
28+
requireFromString(transpiled.code, path);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
"ava-init": "^0.1.0",
6565
"babel-core": "^5.8.23",
6666
"babel-plugin-espower": "^1.0.0",
67+
"babel-runtime": "^5.8.29",
6768
"bluebird": "^3.0.0",
6869
"chalk": "^1.0.0",
69-
"co": "^4.6.0",
70+
"co": "floatdrop/co#e6c2a50",
7071
"core-assert": "^0.1.0",
7172
"empower": "^1.0.2",
7273
"figures": "^1.4.0",
@@ -79,6 +80,7 @@
7980
"power-assert-formatter": "^1.1.0",
8081
"power-assert-renderers": "^0.1.0",
8182
"pretty-ms": "^2.0.0",
83+
"require-from-string": "^1.0.0",
8284
"resolve-from": "^1.0.0",
8385
"serialize-error": "^1.0.0",
8486
"set-immediate-shim": "^1.0.1",

test/fork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('rejects on error and streams output', function (t) {
3535
buffer += data;
3636
})
3737
.catch(function () {
38-
t.ok(/Cannot find module/.test(buffer));
38+
t.ok(/no such file or directory/.test(buffer));
3939
t.end();
4040
});
4141
});

0 commit comments

Comments
 (0)