-
-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commonjs): add esmExternals option
- Loading branch information
1 parent
61c1fc7
commit e4dc686
Showing
20 changed files
with
330 additions
and
17 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
15 changes: 15 additions & 0 deletions
15
packages/commonjs/test/fixtures/function/esm-externals-false/_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,15 @@ | ||
module.exports = { | ||
description: 'always uses the default export when esmExternals is not used', | ||
options: { | ||
external: [ | ||
'external-cjs-exports', | ||
'external-cjs-module-exports', | ||
'external-esm-named', | ||
'external-esm-mixed', | ||
'external-esm-default' | ||
] | ||
}, | ||
pluginOptions: { | ||
esmExternals: false | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/esm-externals-false/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 @@ | ||
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, 'bar', 'external mixed'); | ||
t.deepEqual(externalDefault, 'bar', 'external default'); |
36 changes: 36 additions & 0 deletions
36
packages/commonjs/test/fixtures/function/esm-externals-function/_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,36 @@ | ||
const assert = require('assert'); | ||
|
||
const called = {}; | ||
|
||
module.exports = { | ||
description: 'always uses the default export when esmExternals is not used', | ||
options: { | ||
external: [ | ||
'external-cjs-exports', | ||
'external-cjs-module-exports', | ||
'external-esm-named', | ||
'external-esm-mixed', | ||
'external-esm-default' | ||
], | ||
plugins: [ | ||
{ | ||
name: 'test-plugin', | ||
buildEnd() { | ||
assert.deepStrictEqual(called, { | ||
'external-cjs-exports': 1, | ||
'external-cjs-module-exports': 1, | ||
'external-esm-named': 1, | ||
'external-esm-mixed': 1, | ||
'external-esm-default': 1 | ||
}); | ||
} | ||
} | ||
] | ||
}, | ||
pluginOptions: { | ||
esmExternals: (id) => { | ||
called[id] = (called[id] || 0) + 1; | ||
return id === 'external-esm-default'; | ||
} | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/esm-externals-function/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 @@ | ||
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, 'bar', 'external mixed'); | ||
t.deepEqual(externalDefault, { default: 'bar' }, 'external default'); |
15 changes: 15 additions & 0 deletions
15
packages/commonjs/test/fixtures/function/esm-externals-list/_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,15 @@ | ||
module.exports = { | ||
description: 'always uses the default export when esmExternals is not used', | ||
options: { | ||
external: [ | ||
'external-cjs-exports', | ||
'external-cjs-module-exports', | ||
'external-esm-named', | ||
'external-esm-mixed', | ||
'external-esm-default' | ||
] | ||
}, | ||
pluginOptions: { | ||
esmExternals: ['external-esm-default'] | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/esm-externals-list/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 @@ | ||
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, 'bar', 'external mixed'); | ||
t.deepEqual(externalDefault, { default: 'bar' }, 'external default'); |
15 changes: 15 additions & 0 deletions
15
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
description: 'always uses the default export when esmExternals is not used', | ||
options: { | ||
external: [ | ||
'external-cjs-exports', | ||
'external-cjs-module-exports', | ||
'external-esm-named', | ||
'external-esm-mixed', | ||
'external-esm-default' | ||
] | ||
}, | ||
pluginOptions: { | ||
esmExternals: true | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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'); |
12 changes: 12 additions & 0 deletions
12
packages/commonjs/test/fixtures/function/esm-externals-undefined/_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,12 @@ | ||
module.exports = { | ||
description: 'always uses the default export when esmExternals is not used', | ||
options: { | ||
external: [ | ||
'external-cjs-exports', | ||
'external-cjs-module-exports', | ||
'external-esm-named', | ||
'external-esm-mixed', | ||
'external-esm-default' | ||
] | ||
} | ||
}; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/esm-externals-undefined/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 @@ | ||
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, 'bar', 'external mixed'); | ||
t.deepEqual(externalDefault, 'bar', 'external default'); |
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
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
Oops, something went wrong.