-
-
Notifications
You must be signed in to change notification settings - Fork 591
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 ignore-dynamic-requires option (#819)
BREAKING CHANGES: When dynamicRequireTargets is specified, "require" will be default no longer be used as fallback
- Loading branch information
1 parent
8752c2f
commit 2d06c44
Showing
33 changed files
with
761 additions
and
466 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
9 changes: 0 additions & 9 deletions
9
packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/_config.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/main.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/commonjs/test/fixtures/function/dynamic-require-absolute-paths/submodule.js
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
packages/commonjs/test/fixtures/function/dynamic-require-fallback/_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,6 @@ | ||
module.exports = { | ||
description: 'keeps a require call as fallback when configured', | ||
pluginOptions: { | ||
ignoreDynamicRequires: true | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/dynamic-require-fallback/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 = 'dep'; |
8 changes: 8 additions & 0 deletions
8
packages/commonjs/test/fixtures/function/dynamic-require-fallback/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,8 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(withName) { | ||
return require(withName); | ||
} | ||
|
||
// The bundled code will run from test/helpers/util.js | ||
t.is(takeModule('../fixtures/function/dynamic-require-fallback/dep.js'), 'dep'); |
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: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/dynamic-require-no-fallback/_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: 'throws when there is no fallback for a dynamic require call' | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/commonjs/test/fixtures/function/dynamic-require-no-fallback/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,10 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(withName) { | ||
return require(withName); | ||
} | ||
|
||
t.throws(() => takeModule('./dep.js'), { | ||
message: | ||
'Could not dynamically require "./dep.js". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.' | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/commonjs/test/fixtures/function/dynamic-require-targets-fallback/_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,7 @@ | ||
module.exports = { | ||
description: 'keeps a require call as fallback when configured for dynamicRequireTargets', | ||
pluginOptions: { | ||
ignoreDynamicRequires: true, | ||
dynamicRequireTargets: ['fixtures/function/dynamic-require-targets-fallback/dep1.js'] | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/dynamic-require-targets-fallback/dep1.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 = 'dep'; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/dynamic-require-targets-fallback/dep2.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 = 'dep'; |
9 changes: 9 additions & 0 deletions
9
packages/commonjs/test/fixtures/function/dynamic-require-targets-fallback/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,9 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(withName) { | ||
return require(withName); | ||
} | ||
|
||
t.is(takeModule('./dep1.js'), 'dep'); | ||
// The bundled code will run from test/helpers/util.js | ||
t.is(takeModule('../fixtures/function/dynamic-require-targets-fallback/dep2.js'), 'dep'); |
7 changes: 7 additions & 0 deletions
7
packages/commonjs/test/fixtures/function/dynamic-require-targets-no-fallback/_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,7 @@ | ||
module.exports = { | ||
description: | ||
'throws when there is no require call configured as fallback for dynamicRequireTargets', | ||
pluginOptions: { | ||
dynamicRequireTargets: ['fixtures/function/dynamic-require-targets-no-fallback/dep1.js'] | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/dynamic-require-targets-no-fallback/dep1.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 = 'dep'; |
11 changes: 11 additions & 0 deletions
11
packages/commonjs/test/fixtures/function/dynamic-require-targets-no-fallback/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 @@ | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
|
||
function takeModule(withName) { | ||
return require(withName); | ||
} | ||
|
||
t.is(takeModule('./dep1.js'), 'dep'); | ||
t.throws(() => takeModule('./dep2.js'), { | ||
message: | ||
'Could not dynamically require "./dep2.js". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.' | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/global-not-overwritten/encode.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
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,4 +1,4 @@ | ||
/* eslint-disable global-require */ | ||
module.exports = function() { | ||
module.exports = function () { | ||
return require('./multiply')(2, require('./foo')); | ||
}; |
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,3 +1,3 @@ | ||
module.exports = function(a, b) { | ||
module.exports = function (a, b) { | ||
return a * b; | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/function/toplevel-return-complex/bar.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,3 +1,3 @@ | ||
module.exports = function() { | ||
module.exports = function () { | ||
return true; | ||
}; |
3 changes: 0 additions & 3 deletions
3
packages/commonjs/test/fixtures/function/unsupported-dynamic-require/_config.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
packages/commonjs/test/fixtures/function/unsupported-dynamic-require/main.js
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/commonjs/test/fixtures/samples/dynamic-require-different-loader/submodule2.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,3 +1,3 @@ | ||
module.exports = function() { | ||
module.exports = function () { | ||
return 'Hello there'; | ||
}; |
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,5 +1,5 @@ | ||
if (typeof require === 'function') { | ||
module.exports = (function(require) { | ||
module.exports = (function (require) { | ||
return typeof require; | ||
})({}); | ||
} |
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.