-
-
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.
fix(commonjs): Warn when plugins do not pass options to resolveId (#1038
- Loading branch information
1 parent
b1cd6a2
commit 4c34dd5
Showing
9 changed files
with
168 additions
and
71 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
29 changes: 29 additions & 0 deletions
29
packages/commonjs/test/fixtures/function/warn-this-resolve-without-options/_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,29 @@ | ||
const assert = require('assert'); | ||
|
||
const warnings = []; | ||
|
||
module.exports = { | ||
description: 'Warns when another plugin uses this.resolve without forwarding options', | ||
options: { | ||
onwarn(warning) { | ||
warnings.push(warning); | ||
}, | ||
plugins: [ | ||
{ | ||
name: 'test', | ||
resolveId(source, importer) { | ||
return this.resolve(source, importer, { skipSelf: true }); | ||
}, | ||
buildEnd() { | ||
assert.strictEqual(warnings.length, 1); | ||
assert.strictEqual( | ||
warnings[0].message, | ||
'It appears a plugin has implemented a "resolveId" hook that uses "this.resolve" without forwarding the third "options" parameter of "resolveId". This is problematic as it can lead to wrong module resolutions especially for the node-resolve plugin and in certain cases cause early exit errors for the commonjs plugin.\nIn rare cases, this warning can appear if the same file is both imported and required from the same mixed ES/CommonJS module, in which case it can be ignored.' | ||
); | ||
assert.strictEqual(warnings[0].pluginCode, 'THIS_RESOLVE_WITHOUT_OPTIONS'); | ||
assert.strictEqual(warnings[0].url, 'https://rollupjs.org/guide/en/#resolveid'); | ||
} | ||
} | ||
] | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/commonjs/test/fixtures/function/warn-this-resolve-without-options/foo.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 = 21; |
3 changes: 3 additions & 0 deletions
3
packages/commonjs/test/fixtures/function/warn-this-resolve-without-options/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('./foo'); | ||
|
||
module.exports = foo * 2; |
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
Binary file not shown.