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

Commit 642a671

Browse files
fix: Fix non-top-level requires (#37)
revert @babel/plugin-transform-modules-commonjs to babel-plugin-add-module-exports
1 parent 29f4297 commit 642a671

File tree

7 files changed

+126
-72
lines changed

7 files changed

+126
-72
lines changed

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.2.1
1+
12.8.1

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const defaultOptions = {
2929
babelrc: false,
3030
plugins: [
3131
...[
32-
'@babel/plugin-transform-modules-commonjs',
32+
'babel-plugin-add-module-exports',
3333
'@babel/plugin-proposal-class-properties',
3434
'@babel/plugin-proposal-object-rest-spread',
3535
].map(require.resolve),

package-lock.json

Lines changed: 100 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@
5555
"semantic-release": "15.13.15",
5656
"sinon": "7.2.3",
5757
"sinon-chai": "3.3.0",
58-
"snap-shot-it": "6.2.9"
58+
"snap-shot-it": "7.9.2"
5959
},
6060
"dependencies": {
6161
"@babel/core": "7.4.5",
6262
"@babel/plugin-proposal-class-properties": "7.3.0",
6363
"@babel/plugin-proposal-object-rest-spread": "7.3.2",
64-
"@babel/plugin-transform-modules-commonjs": "7.8.3",
6564
"@babel/plugin-transform-runtime": "7.2.0",
6665
"@babel/preset-env": "7.4.5",
6766
"@babel/preset-react": "7.0.0",
6867
"@babel/runtime": "7.3.1",
68+
"babel-plugin-add-module-exports": "1.0.2",
6969
"babelify": "10.0.0",
7070
"bluebird": "3.5.3",
7171
"browserify": "16.2.3",

test/e2e/e2e_spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,11 @@ describe('imports and exports', () => {
7474
eval(output)
7575
})
7676
})
77+
78+
it('handles non-top-level require', () => {
79+
return bundle('require_spec.js').then((output) => {
80+
// check that bundled tests work
81+
eval(output)
82+
})
83+
})
7784
})

test/fixtures/dom_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const dom = require('./dom').default
1+
const dom = require('./dom')
22

33
context('imports default string', function () {
44
it('works', () => {

test/fixtures/require_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
context('non-top-level requires', function () {
2+
const math = require('./math')
3+
const dom = require('./dom')
4+
5+
it('imports proper types of values', () => {
6+
expect(math.add, 'add').to.be.a('function')
7+
expect(dom, 'dom').to.be.a('string')
8+
})
9+
10+
it('values are correct', function () {
11+
expect(math.add(1, 2)).to.eq(3)
12+
expect(dom, 'dom').to.equal('dom')
13+
})
14+
})

0 commit comments

Comments
 (0)