Skip to content

Commit d59088e

Browse files
fix(commonjs): pass on isEntry and custom resolve options (#1018)
Co-authored-by: shellscape <[email protected]>
1 parent dbfb996 commit d59088e

File tree

11 files changed

+692
-616
lines changed

11 files changed

+692
-616
lines changed

packages/commonjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@rollup/plugin-node-resolve": "^8.4.0",
6464
"locate-character": "^2.0.5",
6565
"require-relative": "^0.8.7",
66-
"rollup": "^2.39.0",
66+
"rollup": "^2.58.0",
6767
"shx": "^0.3.2",
6868
"source-map": "^0.7.3",
6969
"source-map-support": "^0.5.19",

packages/commonjs/src/resolve-id.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function getResolveId(extensions) {
4949
return undefined;
5050
}
5151

52-
return function resolveId(importee, rawImporter) {
52+
return function resolveId(importee, rawImporter, resolveOptions) {
5353
if (isWrappedId(importee, MODULE_SUFFIX) || isWrappedId(importee, EXPORTS_SUFFIX)) {
5454
return importee;
5555
}
@@ -92,10 +92,16 @@ export default function getResolveId(extensions) {
9292
return null;
9393
}
9494

95-
return this.resolve(importee, importer, {
96-
skipSelf: true,
97-
custom: { 'node-resolve': { isRequire: isProxyModule || isRequiredModule } }
98-
}).then((resolved) => {
95+
return this.resolve(
96+
importee,
97+
importer,
98+
Object.assign({}, resolveOptions, {
99+
skipSelf: true,
100+
custom: Object.assign({}, resolveOptions.custom, {
101+
'node-resolve': { isRequire: isProxyModule || isRequiredModule }
102+
})
103+
})
104+
).then((resolved) => {
99105
if (!resolved) {
100106
resolved = resolveExtensions(importee, importer);
101107
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path');
2+
const assert = require('assert');
3+
4+
const ID_MAIN = path.join(__dirname, 'main.js');
5+
6+
const getLastPathFragment = (pathString) => pathString && pathString.split(/[\\/]/).slice(-1)[0];
7+
8+
const resolveIdArgs = [];
9+
10+
module.exports = {
11+
description: 'passes on isEntry and custom options when resolving via other plugins',
12+
options: {
13+
plugins: [
14+
{
15+
async buildStart() {
16+
await this.resolve('./other.js', ID_MAIN, { isEntry: true, custom: { test: 42 } });
17+
},
18+
buildEnd() {
19+
assert.deepStrictEqual(resolveIdArgs, [
20+
['other.js', 'main.js', { custom: { test: 42 }, isEntry: true }],
21+
[
22+
'other.js',
23+
'main.js',
24+
// This is the important one
25+
{ custom: { test: 42, 'node-resolve': { isRequire: false } }, isEntry: true }
26+
],
27+
['main.js', void 0, { custom: {}, isEntry: true }],
28+
['main.js', void 0, { custom: { 'node-resolve': { isRequire: false } }, isEntry: true }]
29+
]);
30+
},
31+
resolveId(source, importer, options) {
32+
resolveIdArgs.push([getLastPathFragment(source), getLastPathFragment(importer), options]);
33+
}
34+
}
35+
]
36+
}
37+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('main');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('other');

0 commit comments

Comments
 (0)