Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #31 plugin should export using module.exports #33

Merged
merged 3 commits into from
Apr 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"cover:test": "nyc --reporter=lcov --reporter=text npm test",
"cover:report": "npm-if TRAVIS \"codeclimate-test-reporter < coverage/lcov.info\"",
"lint": "eslint src test",
"version": "node changelog.js > CHANGELOG.md && git add CHANGELOG.md",
"postversion": "git push --follow-tags",
"postversion": "node changelog.js > CHANGELOG.md && git add CHANGELOG.md && echo ':wq' | git commit --amend && git push --follow-tags",
"build": "abby compile --log --env"
},
"nyc": {
Expand All @@ -40,8 +39,7 @@
}
},
"dependencies": {
"babel-template": "^6.5.0",
"lodash.get": "^4.2.1"
"babel-template": "^6.5.0"
},
"devDependencies": {
"abigail": "^1.6.1",
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import babelTemplate from 'babel-template'
import _get from 'lodash.get'

export default {
module.exports = {
visitor: {
Program: {
exit (path) {
Expand All @@ -18,7 +17,7 @@ export default {
}
if (path.isExportNamedDeclaration()) {
// HACK detect export-from statements for default
const specifiers = _get(path.get('declaration'), 'container.specifiers')
const specifiers = path.get('declaration').container.specifiers
const isDefaultExportDeclaration = specifiers.length === 1 && specifiers[0].exported.name === 'default'
if (isDefaultExportDeclaration) {
hasExportDefault = true
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ describe('babel-plugin-add-module-exports', () => {
assert(module.default === 'default-entry')
}))

it('plugin should export to module.exports(#31)', () => {
const plugin = require('../lib')
assert(typeof plugin === 'object')
assert(typeof plugin.visitor === 'object')
})

it('should handle duplicated plugin references (#1)', () =>
heplers.testPlugin(testCases[0].code, {
presets: ['es2015'],
Expand Down