Skip to content

Commit

Permalink
Use @babel/core (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo authored Oct 30, 2017
1 parent 6cb45a1 commit 984c9dc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const gutil = require('gulp-util');
const through = require('through2');
const applySourceMap = require('vinyl-sourcemaps-apply');
const replaceExt = require('replace-ext');
const babel = require('babel-core');
const babel = require('@babel/core');

function replaceExtension(fp) {
return path.extname(fp) ? replaceExt(fp, '.js') : fp;
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"vinyl-sourcemaps-apply": "^0.2.0"
},
"peerDependencies": {
"babel-core": "6 || 7 || ^7.0.0-alpha || ^7.0.0-beta || ^7.0.0-rc"
"@babel/core": "7 || ^7.0.0-beta || ^7.0.0-rc"
},
"devDependencies": {
"babel-core": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-arrow-functions": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-block-scoping": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-classes": "7.0.0-alpha.18",
"@babel/core": "7.0.0-beta.5",
"@babel/plugin-transform-arrow-functions": "7.0.0-beta.5",
"@babel/plugin-transform-block-scoping": "7.0.0-beta.5",
"@babel/plugin-transform-classes": "7.0.0-beta.5",
"gulp-sourcemaps": "^1.1.1",
"mocha": "*",
"xo": "*"
Expand Down
23 changes: 14 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Install

```
$ npm install --save-dev gulp-babel babel-core babel-preset-env
$ npm install --save-dev gulp-babel @babel/core @babel/preset-env
```


Expand All @@ -21,7 +21,7 @@ const babel = require('gulp-babel');
gulp.task('default', () =>
gulp.src('src/app.js')
.pipe(babel({
presets: ['env']
presets: ['@babel/env']
}))
.pipe(gulp.dest('dist'))
);
Expand Down Expand Up @@ -51,7 +51,7 @@ gulp.task('default', () =>
gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['env']
presets: ['@babel/env']
}))
.pipe(concat('all.js'))
.pipe(sourcemaps.write('.'))
Expand All @@ -71,19 +71,24 @@ const gulp = require('gulp');
const babel = require('gulp-babel');
const through = require('through2');

function logFileHelpers() {
function logBabelMetadata() {
return through.obj((file, enc, cb) => {
console.log(file.babel.usedHelpers);
console.log(file.babel.test); // 'metadata'
cb(null, file);
});
}

gulp.task('default', () =>
gulp.src('src/**/*.js')
.pipe(babel({
presets: ['env']
// plugin that sets some metadata
plugins: [{
post(file) {
file.metadata.test = 'metadata';
}
}]
}))
.pipe(logFileHelpers())
.pipe(logBabelMetadta())
)
```

Expand All @@ -95,7 +100,7 @@ If you're attempting to use features such as generators, you'll need to add `tra
Install the runtime:

```
$ npm install --save-dev babel-plugin-transform-runtime
$ npm install --save-dev @babel/plugin-transform-runtime
```

Use it as plugin:
Expand All @@ -107,7 +112,7 @@ const babel = require('gulp-babel');
gulp.task('default', () =>
gulp.src('src/app.js')
.pipe(babel({
plugins: ['transform-runtime']
plugins: ['@babel/transform-runtime']
}))
.pipe(gulp.dest('dist'))
);
Expand Down
16 changes: 10 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const babel = require('./');

it('should transpile with Babel', cb => {
const stream = babel({
plugins: ['transform-es2015-block-scoping']
plugins: ['@babel/transform-block-scoping']
});

stream.on('data', file => {
Expand All @@ -32,7 +32,7 @@ it('should generate source maps', cb => {
const write = sourceMaps.write();
init
.pipe(babel({
plugins: ['transform-es2015-arrow-functions']
plugins: ['@babel/transform-arrow-functions']
}))
.pipe(write);

Expand Down Expand Up @@ -61,7 +61,7 @@ it('should generate source maps for file in nested folder', cb => {
const write = sourceMaps.write();
init
.pipe(babel({
plugins: ['transform-es2015-arrow-functions']
plugins: ['@babel/transform-arrow-functions']
}))
.pipe(write);

Expand All @@ -85,13 +85,17 @@ it('should generate source maps for file in nested folder', cb => {
init.end();
});

it('should list used helpers in file.babel', cb => {
it('should pass the result of transform().metadata in file.babel', cb => {
const stream = babel({
plugins: ['transform-es2015-classes']
plugins: [{
post(file) {
file.metadata.test = 'metadata';
}
}]
});

stream.on('data', file => {
assert.deepEqual(file.babel.usedHelpers, ['classCallCheck']);
assert.deepEqual(file.babel, {test: 'metadata'});
});

stream.on('end', cb);
Expand Down

0 comments on commit 984c9dc

Please sign in to comment.