-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): inject __esModule marker into ES namespaces and add O…
…bject prototype (#552) * feat(commonjs): inject __esModule marker into ES namespaces * docs(commonjs): improve documentation and update types * feat(commonjs): Integrate into requireReturnsDefault option * refactor(commonjs): add early exit for namespace augmentation
- Loading branch information
1 parent
da12cf9
commit f11bc38
Showing
20 changed files
with
747 additions
and
204 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
8 changes: 1 addition & 7 deletions
8
packages/commonjs/test/fixtures/function/esm-externals-true/_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
4 changes: 0 additions & 4 deletions
4
packages/commonjs/test/fixtures/function/esm-externals-true/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 |
---|---|---|
@@ -1,11 +1,7 @@ | ||
const externalExports = require('external-cjs-exports'); | ||
const externalModuleExports = require('external-cjs-module-exports'); | ||
const externalNamed = require('external-esm-named'); | ||
const externalMixed = require('external-esm-mixed'); | ||
const externalDefault = require('external-esm-default'); | ||
|
||
t.deepEqual(externalExports, { foo: 'foo' }, 'external exports'); | ||
t.deepEqual(externalModuleExports, 'bar', 'external module exports'); | ||
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named'); | ||
t.deepEqual(externalMixed, { default: 'bar', foo: 'foo' }, 'external mixed'); | ||
t.deepEqual(externalDefault, { default: 'bar' }, 'external default'); |
11 changes: 11 additions & 0 deletions
11
...s/commonjs/test/fixtures/function/import-esm-require-returns-default-namespace/_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,11 @@ | ||
module.exports = { | ||
description: | ||
'returns the namespace when requiring an ES module and requireReturnsDefault is "namespace"', | ||
options: { | ||
external: ['external-esm-named', 'external-esm-mixed', 'external-esm-default'] | ||
}, | ||
pluginOptions: { | ||
requireReturnsDefault: 'namespace', | ||
esmExternals: true | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
...s/commonjs/test/fixtures/function/import-esm-require-returns-default-namespace/default.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 @@ | ||
export default 'bar'; |
16 changes: 16 additions & 0 deletions
16
...ages/commonjs/test/fixtures/function/import-esm-require-returns-default-namespace/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,16 @@ | ||
const externalNamed = require('external-esm-named'); | ||
const externalMixed = require('external-esm-mixed'); | ||
const externalDefault = require('external-esm-default'); | ||
|
||
const namedExports = require('./named.js'); | ||
const mixedExports = require('./mixed.js'); | ||
const defaultExport = require('./default.js'); | ||
const noExports = require('./none.js'); | ||
|
||
t.deepEqual(namedExports, { foo: 'foo' }, 'named exports'); | ||
t.deepEqual(mixedExports, { foo: 'foo', default: 'bar' }, 'mixed exports'); | ||
t.deepEqual(defaultExport, { default: 'bar' }, 'default export'); | ||
t.deepEqual(noExports, {}, 'no exports'); | ||
t.deepEqual(externalNamed, { foo: 'foo' }, 'external named'); | ||
t.deepEqual(externalMixed, { foo: 'foo', default: 'bar' }, 'external mixed'); | ||
t.deepEqual(externalDefault, { default: 'bar' }, 'external default'); |
2 changes: 2 additions & 0 deletions
2
...ges/commonjs/test/fixtures/function/import-esm-require-returns-default-namespace/mixed.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 @@ | ||
export const foo = 'foo'; | ||
export default 'bar'; |
1 change: 1 addition & 0 deletions
1
...ges/commonjs/test/fixtures/function/import-esm-require-returns-default-namespace/named.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 @@ | ||
export const foo = 'foo'; |
Empty file.
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/import-esm-with-interop/_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,3 @@ | ||
module.exports = { | ||
description: 'adds the __esModule property when requiring an ES module and support live-bindings' | ||
}; |
9 changes: 9 additions & 0 deletions
9
packages/commonjs/test/fixtures/function/import-esm-with-interop/lib.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 @@ | ||
/* eslint-disable import/no-mutable-exports */ | ||
let foo = 'foo'; | ||
let bar = 'bar'; | ||
export { foo as default, bar }; | ||
|
||
export function update(newFoo, newBar) { | ||
foo = newFoo; | ||
bar = newBar; | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/commonjs/test/fixtures/function/import-esm-with-interop/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,15 @@ | ||
/* eslint-disable */ | ||
var lib = require('./lib.js'); | ||
|
||
function _interopDefault(e) { | ||
return e && e.__esModule ? e : { default: e }; | ||
} | ||
|
||
var lib__default = /*#__PURE__*/_interopDefault(lib); | ||
t.is(lib__default['default'], 'foo') | ||
t.is(lib.bar, 'bar') | ||
|
||
lib.update('newFoo', 'newBar'); | ||
t.is(lib__default['default'], 'newFoo') | ||
t.is(lib.bar, 'newBar') | ||
|
Oops, something went wrong.