-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9e06287
Showing
5 changed files
with
215 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Quick boot options | ||
sudo: false | ||
cache: | ||
directories: | ||
- node_modules | ||
|
||
# Ignore version tags | ||
branches: | ||
except: | ||
- /^v[0-9]/ | ||
|
||
# Language options | ||
language: node_js | ||
node_js: | ||
- '4.1.2' | ||
|
||
# Coverage report | ||
after_success: | ||
- export TRAVIS_PASSED=true | ||
- npm install codeclimate-test-reporter --global | ||
- codeclimate-test-reporter < coverage/lcov.info | ||
env: | ||
global: | ||
# CODECLIMATE_REPO_TOKEN | ||
- secure: BfmL4mRysi4/qUKuN9Hvx3QsbTRH6XtxfuXj3XXaIQiRNwYAU0FBiVjoJzzKk1AhXmLBzWco3jWFWGY0OpXCnzKLHYYZYB3L/UPGq5aqX004pk2ZaPFO8+nfdua15FP2/7vShB+4FbMTztQO4GZMdOi1QTXOdTJgjISQfIqZ7RIeWEaF3UlySt0Xety9Y2nN3YpdPUIPJW2TWP9dIA/XyMHa9knve7TdPzpXkJelpoi3+EnzEtEUWaPtDTMXwOq4zYM4E1bXeA5ZWPmbA1JlO4lDX1aeOz6MFTmBaPTt8K/TT2PLegh8u6JVyG45R1y8OTKyRPQR4+Dy5vp+NLlSMSugq2lxixcK4tuf17a7zPAAEQLNg7LSR9kg3/gyqjthXa5gMYEVI7kE0+mrJl5stVnkGCJaIBawxr4Miqot6qOkh3JSrv0YKh4q1f+XMgtJFlW4UhtJ5zqp/wRSaQpsWKmGqN6xPRMR//5vrTis7uFuCOvxsAN0wzmjelXuNc2nWLuZsP9A91sTghssdikm9maaiP+keAc4gMxy/GuNf0fqyylcaw+9cY9E4Fsg+0Qlv2p1TPOAmXdr0VIkVAuym8cQr+ULu9w4H1F2YrScYnwThTv9J9jhZXqmVh7Ysh9pTluZoTd9ymgkso0Av5xHN56ltHWF1Sku4FFGmnUdI+Q= | ||
|
||
# Npm publish options | ||
deploy: | ||
provider: npm | ||
email: i59naga@icloud.com | ||
api_key: | ||
secure: EuIsb55mziow6P8S+9X/BgWlMxy5LUKZUEQRqvoJRFnpR61hjIgO81JWm8MVZ0ajrC5zy9vyMQEnG0tVJlxxAYE4SpQPD8QLvXo2McUDwBtz0gwOf03j5SGovNEaBEnbUu9N7kYU+CtQXkKwIY1t9ioybS0tbFOLXnS1i4NDvF8aymTrl15GZUFvtVCcfftYRiZcZeXk9zh9KxkLOD2QwG52lzxOZ4n4sbnU09i89LsXZjf9HboOyPtMQxL4kMWRA5NGTEXG6zCP4JZu2iuaIQMuN5DM+nieT3RQAkgPEpHaQZGgo24lGNILdrrjEbMwFWgjaw6BdSit2+5RyuN0U3uzLJ6G8hx7NjT7WNjG8q8n5LTX4pqHHrn045trGuQZ7L7zbUSc5qDWEPrjEnK3tspIJBNbfloxRTCEv4mZR0FkYcEp6OtQV+fK3XKiRHYkIaXjVreEb+/1q3Hlj+lfrwH/vc9wAAhfuJh6MCykaTw4Imb4Eq8DtjDvcX+tzI9Kn96jjomqSU7ryKP1AcJ+ogTAA84iW0u8PJS96lS1yWXIBP04VO9N+OXywYIGggLw6qyRtA9um/cR2fYn09lm7phyyQKzCVGgjT9V8HoOSgEcYEUyVbyDDRodOUtXGRM5fvDFcpREQY8hTI+BZhjiphT6dNBVVcR5KcyRsGcXIGI= |
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,79 @@ | ||
BabelPlugin `Add module.exports` [![NPM version][npm-image]][npm] [![Build Status][travis-image]][travis] [![Coverage Status][cover-image]][cover] [![Climate Status][climate-image]][climate] | ||
--- | ||
|
||
> Fix [Kill CommonJS default export behaviour - babel/babel#2212](https://github.com/babel/babel/issues/2212) | ||
Installation | ||
--- | ||
|
||
```bash | ||
npm install babel-plugin-add-module-exports --save-dev | ||
``` | ||
|
||
Why? | ||
--- | ||
|
||
[babel-plugin-transform-es2015-modules-commonjs@6.1.3](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs) doesn't support the `module.exports`. | ||
|
||
```js | ||
// index.js | ||
export default 'foo' | ||
``` | ||
|
||
```bash | ||
npm install babel-core@6.1.2 --global | ||
npm install babel-preset-es2015 --save-dev | ||
npm install babel-plugin-transform-es2015-modules-commonjs --save-dev | ||
|
||
babel index.js --presets es2015 --plugins transform-es2015-modules-commonjs > bundle.js | ||
# 'use strict'; | ||
# | ||
# Object.defineProperty(exports, "__esModule", { | ||
# value: true | ||
# }); | ||
# exports.default = 'foo'; | ||
``` | ||
|
||
Therefore, need to use the `.default` at NodeJS. | ||
|
||
```js | ||
require('./bundle.js') // { default: 'foo' } | ||
require('./bundle.js').default // 'foo' | ||
``` | ||
|
||
This plugin add the `module.exports` to EOF. | ||
|
||
```bash | ||
npm install babel-plugin-add-module-exports --save-dev | ||
babel index.js --presets es2015 --plugins babel-plugin-add-module-exports > bundle.js | ||
# 'use strict'; | ||
# | ||
# Object.defineProperty(exports, "__esModule", { | ||
# value: true | ||
# }); | ||
# exports.default = 'foo'; | ||
# module.exports = exports.default; | ||
``` | ||
|
||
Therefore, `.default` is the unnecessary. | ||
|
||
```js | ||
require('./bundle.js') // 'foo' | ||
``` | ||
|
||
License | ||
--- | ||
[MIT][License] | ||
|
||
[License]: http://59naga.mit-license.org/ | ||
|
||
[sauce-image]: http://soysauce.berabou.me/u/59798/babel-plugin-add-module-exports.svg | ||
[sauce]: https://saucelabs.com/u/59798 | ||
[npm-image]:https://img.shields.io/npm/v/babel-plugin-add-module-exports.svg?style=flat-square | ||
[npm]: https://npmjs.org/package/babel-plugin-add-module-exports | ||
[travis-image]: http://img.shields.io/travis/59naga/babel-plugin-add-module-exports.svg?style=flat-square | ||
[travis]: https://travis-ci.org/59naga/babel-plugin-add-module-exports | ||
[cover-image]: https://img.shields.io/codeclimate/github/59naga/babel-plugin-add-module-exports.svg?style=flat-square | ||
[cover]: https://codeclimate.com/github/59naga/babel-plugin-add-module-exports/coverage | ||
[climate-image]: https://img.shields.io/codeclimate/coverage/github/59naga/babel-plugin-add-module-exports.svg?style=flat-square | ||
[climate]: https://codeclimate.com/github/59naga/babel-plugin-add-module-exports |
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,18 @@ | ||
// Dependencies | ||
var babelTemplate= require('babel-template') | ||
|
||
// Public | ||
module.exports= function(){ | ||
return { | ||
visitor: { | ||
Program: { | ||
exit: function(path){ | ||
var topNodes= [] | ||
topNodes.push(babelTemplate('module.exports = exports.default;')()) | ||
|
||
path.pushContainer('body',topNodes) | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
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,52 @@ | ||
{ | ||
"name": "babel-plugin-add-module-exports", | ||
"version": "0.0.0", | ||
"description": "Fix babel/babel#2212", | ||
|
||
"main": "lib", | ||
"files": [ | ||
"lib" | ||
], | ||
|
||
"scripts": { | ||
"start": "mocha --bail --watch --require intelli-espower-loader", | ||
"test": "istanbul cover _mocha --report text --report html --report lcov -- -R spec", | ||
"posttest": "npm run lint", | ||
"lint": "eslint lib test --config 59naga" | ||
}, | ||
"config": { | ||
"ghooks": { | ||
"pre-commit": "npm test" | ||
} | ||
}, | ||
|
||
"devDependencies": { | ||
"babel-core": "^6.1.2", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.3", | ||
"babel-preset-es2015": "^6.1.2", | ||
"babel-template": "^6.0.16", | ||
"eslint": "^1.9.0", | ||
"eslint-config-59naga": "0.0.5", | ||
"espower-loader": "^1.0.0", | ||
"ghooks": "^0.3.2", | ||
"intelli-espower-loader": "^1.0.0", | ||
"istanbul": "^0.4.0", | ||
"mocha": "^2.3.3", | ||
"power-assert": "^1.1.0" | ||
}, | ||
|
||
"keywords": [ | ||
"babel-plugin", | ||
"module.exports" | ||
], | ||
"author": "59naga <i59naga@icloud.com> (http://berabou.me)", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/59naga/babel-plugin-add-module-exports.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/59naga/babel-plugin-add-module-exports/issues" | ||
}, | ||
"homepage": "https://github.com/59naga/babel-plugin-add-module-exports#readme" | ||
} |
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,34 @@ | ||
// Dependencies | ||
var babel= require('babel-core') | ||
var assert= require('power-assert') | ||
|
||
// Fixture | ||
var str=`export default 'foo'` | ||
var out=`'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = 'foo'; | ||
module.exports = exports.default;` | ||
|
||
// Specs | ||
describe('babel-plugin-module-exports',()=>{ | ||
it('Nope.',()=>{ | ||
var result= babel.transform(str,{ | ||
presets: ['es2015'], | ||
plugins: ['transform-es2015-modules-commonjs'], | ||
}) | ||
assert(result.code.match('module.exports') === null) | ||
assert(result.code !== out) | ||
}) | ||
|
||
it('Add the `module.exports = exports.default;` to EOF.',()=>{ | ||
var result= babel.transform(str,{ | ||
presets: ['es2015'], | ||
plugins: ['../lib/index.js'], | ||
}) | ||
assert(result.code.match('module.exports') !== null) | ||
assert(result.code === out) | ||
}) | ||
}) |