Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
fix: Fix non-top-level requires (#37)
Browse files Browse the repository at this point in the history
revert @babel/plugin-transform-modules-commonjs to babel-plugin-add-module-exports
  • Loading branch information
chrisbreiding committed Feb 11, 2020
1 parent 29f4297 commit 642a671
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2.1
12.8.1
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const defaultOptions = {
babelrc: false,
plugins: [
...[
'@babel/plugin-transform-modules-commonjs',
'babel-plugin-add-module-exports',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
].map(require.resolve),
Expand Down
167 changes: 100 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
"semantic-release": "15.13.15",
"sinon": "7.2.3",
"sinon-chai": "3.3.0",
"snap-shot-it": "6.2.9"
"snap-shot-it": "7.9.2"
},
"dependencies": {
"@babel/core": "7.4.5",
"@babel/plugin-proposal-class-properties": "7.3.0",
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
"@babel/plugin-transform-modules-commonjs": "7.8.3",
"@babel/plugin-transform-runtime": "7.2.0",
"@babel/preset-env": "7.4.5",
"@babel/preset-react": "7.0.0",
"@babel/runtime": "7.3.1",
"babel-plugin-add-module-exports": "1.0.2",
"babelify": "10.0.0",
"bluebird": "3.5.3",
"browserify": "16.2.3",
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/e2e_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ describe('imports and exports', () => {
eval(output)
})
})

it('handles non-top-level require', () => {
return bundle('require_spec.js').then((output) => {
// check that bundled tests work
eval(output)
})
})
})
2 changes: 1 addition & 1 deletion test/fixtures/dom_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const dom = require('./dom').default
const dom = require('./dom')

context('imports default string', function () {
it('works', () => {
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/require_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
context('non-top-level requires', function () {
const math = require('./math')
const dom = require('./dom')

it('imports proper types of values', () => {
expect(math.add, 'add').to.be.a('function')
expect(dom, 'dom').to.be.a('string')
})

it('values are correct', function () {
expect(math.add(1, 2)).to.eq(3)
expect(dom, 'dom').to.equal('dom')
})
})

0 comments on commit 642a671

Please sign in to comment.