Skip to content

Commit

Permalink
migrate to Babel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolateboy committed Feb 20, 2018
1 parent 93e324e commit bc4595d
Show file tree
Hide file tree
Showing 19 changed files with 2,681 additions and 1,340 deletions.
21 changes: 10 additions & 11 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// vim:ft=javascript
{
sourceMaps: 'inline',
env: {
development: {
sourceMaps: 'inline',
}
},

presets: [
['env', {
['@babel/preset-env', {
// only include polyfills if they're used
useBuiltIns: 'usage',

/*
* add polyfills for Object.assign, Promise &c. to bring the supported
* target up to ES2015 compatibility.
*
* set debug to true to see what's added.
*/
useBuiltIns: true,
// set this to true to see the applied transforms and bundled polyfills
debug: false,

targets: { 'node': 4 },
loose: false,
targets: { node: 4 }, // same as Babel 7
}],
],
}
33 changes: 8 additions & 25 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# eslint-plugin-import \
# eslint-plugin-node \
# eslint-plugin-promise
#
# (eslint-plugin-import, eslint-plugin-node, and eslint-plugin-promise
# are peer dependencies of eslint-config-standard)

env:
browser: true
commonjs: true
jasmine: true
jquery: true
node: true
phantomjs: true
protractor: true

parser: babel-eslint

Expand All @@ -31,24 +31,19 @@ rules:
- error
- 4

# don't care either way about semi-colons
semi: 0

# don't care if multiple vars are initialised with
# a single statement
one-var: 0

# only allow trailing commas in arrays and objects
# (i.e. avoid using/keeping them in function parameters,
# which aren't supported prior to ES7)
# only allow trailing commas in multi-line expressions
comma-dangle:
- error
-
arrays: only-multiline
objects: only-multiline
functions: only-multiline
imports: never
exports: never
functions: never

# prefer
#
Expand All @@ -68,21 +63,9 @@ rules:
-
allowArrowFunctions: true

# prefer:
#
# foo ?
# bar :
# baz
#
# over:
#
# foo
# ? bar
# : baz
#
operator-linebreak:
- error
- after
# don't require operators to be consistently placed at the beginning/end
# of lines: it varies according to the lines
operator-linebreak: 0

# prohibit multiple spaces unless they're used to align requires, imports,
# or object literals
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_js:
- '4'
- '6'
- '8'
- '9'
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0 - TBC

* **breaking change**:
* add support for Babel >= 7.x
* remove support for Babel 6.x

## 1.0.0 - 2017-07-27 14:42:25

* **breaking change**:
Expand Down
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ A Babel plugin which automatically makes stack traces source-map aware
import foo from 'foo';
import bar from 'bar';

test();
foo(bar);
```

`$ babel --plugins source-map-support test.js`
Expand All @@ -39,7 +39,7 @@ import 'source-map-support/register';
import foo from 'foo';
import bar from 'bar';

test();
foo(bar);
```

# DESCRIPTION
Expand All @@ -62,6 +62,23 @@ though it's harmless in other environments.
The source-map-support module only needs to be registered in the top-level file(s) of an application,
but it no-ops if it has already been loaded, so there is no harm in registering it in every file.

You probably don't want to use this plugin when compiling code for the web because you probably don't
want to include inline source maps in minified code. An easy way to limit the plugin's use to
development/test builds, is to use Babel's [`env` option](https://babeljs.io/docs/usage/babelrc/#env-option) e.g.:

```javascript
{
env: {
development: {
sourceMaps: 'inline',
plugins: ['source-map-support', ...]
}
},

presets: [ ... ]
}
```

## CAVEATS

Source maps must currently be inline. While the source-map-support module provides a way
Expand All @@ -74,35 +91,35 @@ this plugin.

The following NPM scripts are available:

* build - compile the plugin and save it to the target directory
* test - compile the plugin and run the test suite
* test:debug - compile the plugin and run the test suite in debug mode (which dumps each transformed test case)
* release - run the test script in production mode, which compiles the plugin for release
* test - lint the codebase, compile the plugin, and run the test suite
* test:debug - run the test script in debug mode, which dumps each transformed test case

## Gulp Tasks

The following Gulp tasks are available:

* build - compile the plugin and save it to the target directory
* clean - remove the target directory and its contents
* default - alias for the `build` task
* default - run the `clean`, `lint` and `build` tasks
* lint - check and report style and usage errors in the gulpfile, source file(s) and test file(s)

# SEE ALSO

* [babel](https://www.npmjs.com/package/babel)
* [babel-plugin-transform-es2015-modules-commonjs-simple](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs-simple)
* [source-map-support](https://www.npmjs.com/package/source-map-support)

# VERSION

1.0.0
2.0.0

# AUTHOR

[chocolateboy](mailto:[email protected])

# COPYRIGHT AND LICENSE

Copyright © 2015-2017 by chocolateboy
Copyright © 2015-2018 by chocolateboy

This module is free software; you can redistribute it and/or modify it under the
terms of the [Artistic License 2.0](http:https://www.opensource.org/licenses/artistic-license-2.0.php).
41 changes: 22 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
const del = require('del')
const gulp = require('gulp')
const babel = require('gulp-babel')
const eslint = require('gulp-eslint')

const config = (function () {
const srcDir = 'src'

return {
isDev: process.env.NODE_ENV === 'development',
paths: {
srcDir,
destDir: 'dist',
src: {
js: `${srcDir}/**/*.js`
}
}
const config = {
isDev: process.env.NODE_ENV === 'development',
paths: {
destDir: 'dist',
src: `src/**/*.js`,
test: `test/*.js`,
}
})()
}

// compile the plugin and save it to the target directory
gulp.task('build', () => {
return gulp.src(config.paths.src)
.pipe(babel())
.pipe(gulp.dest(config.paths.destDir))
})

// delete the target directory
gulp.task('clean', () => {
return del(config.paths.destDir)
})

// compile the plugin and save it to the target directory
gulp.task('build', () => {
return gulp.src(config.paths.src.js)
.pipe(babel())
.pipe(gulp.dest(config.paths.destDir))
// check for violations of style and usage rules
gulp.task('lint', () => {
return gulp.src([__filename, config.paths.src, config.paths.test])
.pipe(eslint())
.pipe(eslint.format()) // dump invalid code
.pipe(eslint.failAfterError()) // exit with an error code on lint errors
})

gulp.task('default', gulp.task('build'))
gulp.task('default', gulp.series('clean', 'lint', 'build'))
38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
{
"name": "babel-plugin-source-map-support",
"version": "1.0.0",
"version": "2.0.0",
"description": "A Babel plugin which automatically makes stack traces source-map aware",
"repository": "chocolateboy/babel-plugin-source-map-support",
"license": "Artistic-2.0",
"main": "dist/plugin.js",
"main": "dist/index.js",
"files": [
"package.json",
"CHANGELOG.md",
"README.md",
"dist/plugin.js"
"dist/index.js"
],
"scripts": {
"build": "gulp build",
"release": "cross-env NODE_ENV=production npm run test",
"test:debug": "cross-env NODE_ENV=development npm run test",
"test": "gulp build && ava --verbose test/*.js"
"test": "gulp && ava --verbose test/*.js"
},
"dependencies": {
"babel-core": "^6.4.5",
"lodash.ismatch": "^4.4.0"
"@babel/core": "^7.0.0-beta.40",
"@babel/helper-module-imports": "^7.0.0-beta.40"
},
"devDependencies": {
"ava": "^0.21.0",
"babel-preset-env": "^1.6.0",
"@babel/preset-env": "^7.0.0-beta.40",
"ava": "^0.25.0",
"babel-eslint": "^8.2.1",
"cross-env": "^5.0.1",
"del": "^3.0.0",
"globby": "^6.1.0",
"grunt-babel": "^6.0.0",
"gulp": "gulpjs/gulp.git#4.0",
"gulp-babel": "^6.1.2",
"root-path": "^0.2.0"
"eslint": "^4.3.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^6.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"globby": "^8.0.1",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0-beta.1",
"gulp-eslint": "^4.0.2",
"root-path": "^0.2.1"
},
"keywords": [
"babel-plugin",
Expand Down
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { addSideEffect } from '@babel/helper-module-imports'

const IMPORT = 'source-map-support/register'

export default function babelPluginSourceMapSupport () {
return {
visitor: {
Program (path) {
addSideEffect(path, IMPORT)
}
}
}
}
Loading

0 comments on commit bc4595d

Please sign in to comment.