-
-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): support all styles of transpiled ES modules
BREAKING CHANGES: CJS entry points will always have a default export
- Loading branch information
1 parent
72f84a2
commit d8e3a6f
Showing
38 changed files
with
749 additions
and
91 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
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
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
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
3 changes: 0 additions & 3 deletions
3
packages/commonjs/test/fixtures/function/__esModule/answer.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/commonjs/test/fixtures/function/bare-import/_config.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/commonjs/test/fixtures/function/export-default-from/_config.js
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
packages/commonjs/test/fixtures/function/late-entry-dependency/_config.js
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,23 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
const ID_OTHER = path.join(__dirname, 'other.js'); | ||
|
||
module.exports = { | ||
options: { | ||
input: [ID_MAIN, ID_OTHER], | ||
plugins: [ | ||
{ | ||
load(id) { | ||
if (id === ID_MAIN) { | ||
return new Promise((resolve) => | ||
setTimeout(() => resolve(fs.readFileSync(ID_MAIN, 'utf8')), 100) | ||
); | ||
} | ||
return null; | ||
} | ||
} | ||
] | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/late-entry-dependency/main.js
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,3 @@ | ||
const foo = require('./other.js'); | ||
|
||
t.is(foo, 'foo'); |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/late-entry-dependency/other.js
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 @@ | ||
module.exports = 'foo'; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/no-exports-entry/dep.js
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 @@ | ||
module.exports = 42; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/no-exports-entry/main.js
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,3 @@ | ||
const dep = require('./dep.js'); | ||
|
||
t.is(dep, 42); |
2 changes: 2 additions & 0 deletions
2
packages/commonjs/test/fixtures/function/transpiled-esm-default/dep.js
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,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.default = 'default'; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-default/main.js
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,3 @@ | ||
import dep from './dep'; | ||
|
||
t.is(dep, 'default'); |
9 changes: 9 additions & 0 deletions
9
packages/commonjs/test/fixtures/function/transpiled-esm-entry-default/_config.js
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,9 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: | ||
'Creates correct exports if an ES module that was transpiled to CJS is used as entry point', | ||
options: { | ||
input: [path.join(__dirname, 'main.js'), path.join(__dirname, 'entry.js')] | ||
} | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/commonjs/test/fixtures/function/transpiled-esm-entry-default/entry.js
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,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.default = 'default'; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-entry-default/main.js
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,3 @@ | ||
import * as entry from './entry.js'; | ||
|
||
t.deepEqual(entry, { default: 'default' }); |
9 changes: 9 additions & 0 deletions
9
packages/commonjs/test/fixtures/function/transpiled-esm-entry-mixed/_config.js
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,9 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: | ||
'Creates correct exports if an ES module that was transpiled to CJS is used as entry point', | ||
options: { | ||
input: [path.join(__dirname, 'main.js'), path.join(__dirname, 'entry.js')] | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-entry-mixed/entry.js
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,3 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.default = 'default'; | ||
exports.named = 'named'; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-entry-mixed/main.js
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,3 @@ | ||
import * as entry from './entry.js'; | ||
|
||
t.deepEqual(entry, { default: 'default', named: 'named' }); |
9 changes: 9 additions & 0 deletions
9
packages/commonjs/test/fixtures/function/transpiled-esm-entry-named/_config.js
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,9 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
description: | ||
'Creates correct exports if an ES module that was transpiled to CJS is used as entry point', | ||
options: { | ||
input: [path.join(__dirname, 'main.js'), path.join(__dirname, 'entry.js')] | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
...res/samples/use-own-output/from-rollup.js → ...ction/transpiled-esm-entry-named/entry.js
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.x = 10; | ||
exports.named = 'named'; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/transpiled-esm-entry-named/main.js
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,11 @@ | ||
import * as entry from './entry.js'; | ||
|
||
t.deepEqual(entry, { | ||
// Technically, this should ideally not exist, or if we cannot avoid it due | ||
// to runtime default export detection, it should probably be undefined. We | ||
// return the namespace instead as this will fix | ||
// rollup/rollup-plugin-commonjs#224 until the remaining Rollup interop has | ||
// been updated | ||
default: { named: 'named' }, | ||
named: 'named' | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-mixed/dep.js
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,3 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.named = 'named'; | ||
exports.default = 'default'; |
4 changes: 4 additions & 0 deletions
4
packages/commonjs/test/fixtures/function/transpiled-esm-mixed/main.js
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,4 @@ | ||
import dep, { named } from './dep'; | ||
|
||
t.is(dep, 'default'); | ||
t.is(named, 'named'); |
2 changes: 2 additions & 0 deletions
2
packages/commonjs/test/fixtures/function/transpiled-esm-named/dep.js
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,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.named = 'named'; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-named/main.js
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,3 @@ | ||
import { named } from './dep'; | ||
|
||
t.is(named, 'named'); |
2 changes: 2 additions & 0 deletions
2
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-default/dep.js
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,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.default = 'default'; |
5 changes: 5 additions & 0 deletions
5
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-default/main.js
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,5 @@ | ||
import * as x from './dep'; | ||
|
||
t.deepEqual(x, { | ||
default: 'default' | ||
}); |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-mixed/dep.js
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,3 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.named = 'named'; | ||
exports.default = 'default'; |
6 changes: 6 additions & 0 deletions
6
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-mixed/main.js
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,6 @@ | ||
import * as x from './dep'; | ||
|
||
t.deepEqual(x, { | ||
default: 'default', | ||
named: 'named' | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-named/dep.js
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,2 @@ | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.named = 'named'; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/transpiled-esm-namespace-named/main.js
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,11 @@ | ||
import * as x from './dep'; | ||
|
||
t.deepEqual(x, { | ||
named: 'named', | ||
// Technically, this should ideally not exist, or if we cannot avoid it due | ||
// to runtime default export detection, it should probably be undefined. We | ||
// return the namespace instead as this will fix | ||
// rollup/rollup-plugin-commonjs#224 until the remaining Rollup interop has | ||
// been updated | ||
default: { named: 'named' } | ||
}); |
4 changes: 0 additions & 4 deletions
4
packages/commonjs/test/fixtures/samples/use-own-output/main.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.