-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to specify babel opts through babelrc or param. Fixes #5
- Loading branch information
1 parent
9dbb339
commit a3b6665
Showing
7 changed files
with
77 additions
and
13 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 |
---|---|---|
|
@@ -34,14 +34,16 @@ $ npm install --save-dev ts-babel-node [email protected] | |
|
||
Since `ts-babel-node` is a wrapper around `ts-node`, anything you can do with `ts-node` works with `ts-babel-node`. See [`ts-node`'s docs](https://github.com/TypeStrong/ts-node/#usage) for more details. | ||
|
||
To configure babel, you can pass in an options object to the appropriate register function or use a [babelrc](http://babeljs.io/docs/usage/babelrc/). All babelrc locations are supported. **Note**: if you use a babelrc, the default babel configuration provided by ts-babel-node will not be used. Simply include the `es2015` preset in your config (or don't, if you don't want it). | ||
|
||
### Library | ||
|
||
`ts-babel-node` exposes two APIs. The first is a wrapper around the `ts-node` API. | ||
|
||
```js | ||
// $ node this-file.js | ||
|
||
require('ts-babel-node').register(/* ts-node options */); | ||
require('ts-babel-node').register(tsNodeOpts, babelOpts); // both opts are optional | ||
// Or | ||
require('ts-babel-node/register'); | ||
``` | ||
|
@@ -57,7 +59,7 @@ The second API only adds the babel-compilation step. This is useful if your code | |
```js | ||
// $ ts-node this-file.js | ||
|
||
require('ts-babel-node').registerBabel(); | ||
require('ts-babel-node').registerBabel(babelOpts); // babelOpts is optional | ||
// Or | ||
require('ts-babel-node/register-babel'); | ||
``` | ||
|
@@ -83,4 +85,4 @@ import 'ts-babel-node/register-babel'; | |
// ... | ||
``` | ||
|
||
Then use `gulp` normally. Keep in mind that the babel traspiler won't be active in your `gulpfile.ts`, but will be running in all your imports. | ||
Then use `gulp` normally. Keep in mind that the babel traspiler won't be active in your `gulpfile.ts`, but will be running in all your imports. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
var exec = require('./exec'); | ||
var lab = exports.lab = require('lab').script(); | ||
var expect = require('code').expect; | ||
|
||
// the .babelrc in the custom-babel folder removes all console.* statements. | ||
// We selectively include this to demonstrate that the .babelrc is picked up. | ||
lab.experiment('When I have set a custom .babelrc', function () { | ||
var result; | ||
|
||
lab.before(function () { | ||
return exec('custom-babel/test.ts') | ||
.then(function (_result) { | ||
result = _result; | ||
}); | ||
}); | ||
|
||
lab.test('it runs successfully', function (done) { | ||
expect(result.code).to.equal(0); | ||
done(); | ||
}); | ||
|
||
lab.test('it prints the correct output', function (done) { | ||
expect(result.out).to.equal('this is the only thing that should appear\n'); | ||
done(); | ||
}); | ||
}); |
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,3 @@ | ||
{ | ||
"plugins": [ "transform-remove-console" ] | ||
} |
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,2 @@ | ||
console.log('this should not appear'); | ||
process.stdout.write('this is the only thing that should appear\n'); |
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