pax_global_header00006660000000000000000000000064131421121420014501gustar00rootroot0000000000000052 comment=8e6fa78bab83f0d0eda65a281a1e4a39d119d262 gulp-babel-7.0.0/000077500000000000000000000000001314211214200135175ustar00rootroot00000000000000gulp-babel-7.0.0/.editorconfig000066400000000000000000000003471314211214200162000ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false gulp-babel-7.0.0/.gitattributes000066400000000000000000000000141314211214200164050ustar00rootroot00000000000000* text=auto gulp-babel-7.0.0/.gitignore000066400000000000000000000000151314211214200155030ustar00rootroot00000000000000node_modules gulp-babel-7.0.0/.travis.yml000066400000000000000000000001041314211214200156230ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'stable' - '6' - '4' gulp-babel-7.0.0/index.js000066400000000000000000000026661314211214200151760ustar00rootroot00000000000000'use strict'; const path = require('path'); 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'); function replaceExtension(fp) { return path.extname(fp) ? replaceExt(fp, '.js') : fp; } module.exports = function (opts) { opts = opts || {}; return through.obj(function (file, enc, cb) { if (file.isNull()) { cb(null, file); return; } if (file.isStream()) { cb(new gutil.PluginError('gulp-babel', 'Streaming not supported')); return; } try { const fileOpts = Object.assign({}, opts, { filename: file.path, filenameRelative: file.relative, sourceMap: Boolean(file.sourceMap), sourceFileName: file.relative, sourceMapTarget: file.relative }); const res = babel.transform(file.contents.toString(), fileOpts); if (res !== null) { if (file.sourceMap && res.map) { res.map.file = replaceExtension(res.map.file); applySourceMap(file, res.map); } if (!res.ignored) { file.contents = new Buffer(res.code); // eslint-disable-line unicorn/no-new-buffer file.path = replaceExtension(file.path); } file.babel = res.metadata; } this.push(file); } catch (err) { this.emit('error', new gutil.PluginError('gulp-babel', err, { fileName: file.path, showProperties: false })); } cb(); }); }; gulp-babel-7.0.0/license000066400000000000000000000021371314211214200150670ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) Sindre Sorhus (sindresorhus.com) 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. gulp-babel-7.0.0/package.json000066400000000000000000000023641314211214200160120ustar00rootroot00000000000000{ "name": "gulp-babel", "version": "7.0.0", "description": "Use next generation JavaScript, today", "license": "MIT", "repository": "babel/gulp-babel", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && mocha" }, "files": [ "index.js" ], "keywords": [ "gulpplugin", "babel", "transpiler", "es2015", "es2016", "es2017", "rewriting", "transformation", "syntax", "codegen", "desugaring", "javascript", "compiler" ], "dependencies": { "gulp-util": "^3.0.0", "replace-ext": "0.0.1", "through2": "^2.0.0", "vinyl-sourcemaps-apply": "^0.2.0" }, "peerDependencies": { "babel-core": "6 || 7 || ^7.0.0-alpha || ^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", "gulp-sourcemaps": "^1.1.1", "mocha": "*", "xo": "*" }, "xo": { "envs": [ "node", "mocha" ] } } gulp-babel-7.0.0/readme.md000066400000000000000000000045551314211214200153070ustar00rootroot00000000000000# gulp-babel [![Build Status](https://travis-ci.org/babel/gulp-babel.svg?branch=master)](https://travis-ci.org/babel/gulp-babel) > Use next generation JavaScript, today, with [Babel](https://babeljs.io) *Issues with the output should be reported on the Babel [issue tracker](https://phabricator.babeljs.io/).* ## Install ``` $ npm install --save-dev gulp-babel babel-preset-env ``` ## Usage ```js const gulp = require('gulp'); const babel = require('gulp-babel'); gulp.task('default', () => gulp.src('src/app.js') .pipe(babel({ presets: ['env'] })) .pipe(gulp.dest('dist')) ); ``` ## API ### babel([options]) #### options See the Babel [options](https://babeljs.io/docs/usage/options/), except for `sourceMap` and `filename` which is handled for you. ## Source Maps Use [gulp-sourcemaps](https://github.com/floridoo/gulp-sourcemaps) like this: ```js const gulp = require('gulp'); const sourcemaps = require('gulp-sourcemaps'); const babel = require('gulp-babel'); const concat = require('gulp-concat'); gulp.task('default', () => gulp.src('src/**/*.js') .pipe(sourcemaps.init()) .pipe(babel({ presets: ['env'] })) .pipe(concat('all.js')) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('dist')) ); ``` ## Babel Metadata Files in the stream are annotated with a `babel` property, which contains the metadata from [`babel.transform()`](https://babeljs.io/docs/usage/api/). #### Example ```js const gulp = require('gulp'); const babel = require('gulp-babel'); const through = require('through2'); function logFileHelpers() { return through.obj((file, enc, cb) => { console.log(file.babel.usedHelpers); cb(null, file); }); } gulp.task('default', () => gulp.src('src/**/*.js') .pipe(babel({ presets: ['env'] })) .pipe(logFileHelpers()) ) ``` ## Runtime If you're attempting to use features such as generators, you'll need to add `transform-runtime` as a plugin, to include the Babel runtime. Otherwise, you'll receive the error: `regeneratorRuntime is not defined`. Install the runtime: ``` $ npm install --save-dev babel-plugin-transform-runtime ``` Use it as plugin: ```js const gulp = require('gulp'); const babel = require('gulp-babel'); gulp.task('default', () => gulp.src('src/app.js') .pipe(babel({ plugins: ['transform-runtime'] })) .pipe(gulp.dest('dist')) ); ``` ## License MIT © [Sindre Sorhus](http://sindresorhus.com) gulp-babel-7.0.0/test.js000066400000000000000000000070201314211214200150330ustar00rootroot00000000000000'use strict'; const path = require('path'); const assert = require('assert'); const gutil = require('gulp-util'); const sourceMaps = require('gulp-sourcemaps'); const babel = require('./'); it('should transpile with Babel', cb => { const stream = babel({ plugins: ['transform-es2015-block-scoping'] }); stream.on('data', file => { assert(/var foo/.test(file.contents.toString()), file.contents.toString()); assert.equal(file.relative, 'fixture.js'); }); stream.on('end', cb); stream.write(new gutil.File({ cwd: __dirname, base: path.join(__dirname, 'fixture'), path: path.join(__dirname, 'fixture/fixture.jsx'), contents: Buffer.from('let foo;') })); stream.end(); }); it('should generate source maps', cb => { const init = sourceMaps.init(); const write = sourceMaps.write(); init .pipe(babel({ plugins: ['transform-es2015-arrow-functions'] })) .pipe(write); write.on('data', file => { assert.deepEqual(file.sourceMap.sources, ['fixture.es2015']); assert.strictEqual(file.sourceMap.file, 'fixture.js'); const contents = file.contents.toString(); assert(/function/.test(contents)); assert(/sourceMappingURL/.test(contents)); cb(); }); init.write(new gutil.File({ cwd: __dirname, base: path.join(__dirname, 'fixture'), path: path.join(__dirname, 'fixture/fixture.es2015'), contents: Buffer.from('[].map(v => v + 1)'), sourceMap: '' })); init.end(); }); it('should generate source maps for file in nested folder', cb => { const init = sourceMaps.init(); const write = sourceMaps.write(); init .pipe(babel({ plugins: ['transform-es2015-arrow-functions'] })) .pipe(write); write.on('data', file => { assert.deepEqual(file.sourceMap.sources, ['nested/fixture.es2015']); assert.strictEqual(file.sourceMap.file, 'nested/fixture.js'); const contents = file.contents.toString(); assert(/function/.test(contents)); assert(/sourceMappingURL/.test(contents)); cb(); }); init.write(new gutil.File({ cwd: __dirname, base: path.join(__dirname, 'fixture'), path: path.join(__dirname, 'fixture/nested/fixture.es2015'), contents: Buffer.from('[].map(v => v + 1)'), sourceMap: '' })); init.end(); }); it('should list used helpers in file.babel', cb => { const stream = babel({ plugins: ['transform-es2015-classes'] }); stream.on('data', file => { assert.deepEqual(file.babel.usedHelpers, ['classCallCheck']); }); stream.on('end', cb); stream.write(new gutil.File({ cwd: __dirname, base: path.join(__dirname, 'fixture'), path: path.join(__dirname, 'fixture/fixture.js'), contents: Buffer.from('class MyClass {};') })); stream.end(); }); it('should not rename ignored files', cb => { const stream = babel({ ignore: [/fixture/] }); const inputFile = { cwd: __dirname }; inputFile.base = path.join(inputFile.cwd, 'fixture'); inputFile.basename = 'fixture.jsx'; inputFile.path = path.join(inputFile.base, inputFile.basename); inputFile.contents = Buffer.from(';'); stream .on('data', file => { assert.equal(file.relative, inputFile.basename); }) .on('end', cb) .end(new gutil.File(inputFile)); }); it('should not rename files without an extension', cb => { const stream = babel(); const inputFile = { cwd: __dirname }; inputFile.base = path.join(inputFile.cwd, 'bin'); inputFile.basename = 'app'; inputFile.path = path.join(inputFile.base, inputFile.basename); inputFile.contents = Buffer.from(';'); stream .on('data', file => { assert.equal(file.relative, inputFile.basename); }) .on('end', cb) .end(new gutil.File(inputFile)); });