Skip to content

Commit 12e1fee

Browse files
authored
fix(node-resolve): pass on isEntry flag (#1016)
1 parent cfb4555 commit 12e1fee

14 files changed

Lines changed: 192 additions & 114 deletions

File tree

packages/node-resolve/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@rollup/plugin-commonjs": "^16.0.0",
6969
"@rollup/plugin-json": "^4.1.0",
7070
"es5-ext": "^0.10.53",
71-
"rollup": "^2.42.0",
71+
"rollup": "^2.58.0",
7272
"source-map": "^0.7.3",
7373
"string-capitalize": "^1.0.1"
7474
},

packages/node-resolve/src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function nodeResolve(opts = {}) {
7272
const browserMapCache = new Map();
7373
let preserveSymlinks;
7474

75-
const doResolveId = async (context, importee, importer, opts) => {
75+
const doResolveId = async (context, importee, importer, custom) => {
7676
// strip query params from import
7777
const [importPath, params] = importee.split('?');
7878
const importSuffix = `${params ? `?${params}` : ''}`;
@@ -142,8 +142,7 @@ export function nodeResolve(opts = {}) {
142142
}
143143

144144
const warn = (...args) => context.warn(...args);
145-
const isRequire =
146-
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire;
145+
const isRequire = custom && custom['node-resolve'] && custom['node-resolve'].isRequire;
147146
const exportConditions = isRequire ? conditionsCjs : conditionsEsm;
148147

149148
if (useBrowserOverrides && !exportConditions.includes('browser'))
@@ -250,7 +249,7 @@ export function nodeResolve(opts = {}) {
250249
isDirCached.clear();
251250
},
252251

253-
async resolveId(importee, importer, opts) {
252+
async resolveId(importee, importer, resolveOptions) {
254253
if (importee === ES6_BROWSER_EMPTY) {
255254
return importee;
256255
}
@@ -261,9 +260,13 @@ export function nodeResolve(opts = {}) {
261260
importer = undefined;
262261
}
263262

264-
const resolved = await doResolveId(this, importee, importer, opts);
263+
const resolved = await doResolveId(this, importee, importer, resolveOptions.custom);
265264
if (resolved) {
266-
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
265+
const resolvedResolved = await this.resolve(
266+
resolved.id,
267+
importer,
268+
Object.assign({ skipSelf: true }, resolveOptions)
269+
);
267270
const isExternal = !!(resolvedResolved && resolvedResolved.external);
268271
if (isExternal) {
269272
return false;

packages/node-resolve/test/fixtures/entry/dep.js

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './dep.js';
2+
3+
console.log('main');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('other');
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import './side-effect.js';
2+
3+
console.log('main');

packages/node-resolve/test/snapshots/dedupe.js.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ The actual snapshot is saved in `dedupe.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7-
## dedupes deep imports by package name if dedupe is set
7+
## single module version is bundled if dedupe is set
88

99
> Snapshot 1
1010
1111
{
12-
React: 'react/deep.js:root',
13-
ReactConsumer: 'react-consumer:react/deep.js:root',
12+
React: 'react:root',
13+
ReactConsumer: 'react-consumer:react:root',
1414
}
1515

16-
## dedupes scoped deep imports by package name if dedupe is set
16+
## dedupes deep imports by package name if dedupe is set
1717

1818
> Snapshot 1
1919
2020
{
21-
ScopedDeduped: 'scoped-deduped:root',
22-
ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root',
21+
React: 'react/deep.js:root',
22+
ReactConsumer: 'react-consumer:react/deep.js:root',
2323
}
2424

25-
## multiple module versions are bundled if dedupe is not set
25+
## dedupes scoped deep imports by package name if dedupe is set
2626

2727
> Snapshot 1
2828
2929
{
30-
React: 'react:root',
31-
ReactConsumer: 'react-consumer:react:child',
30+
ScopedDeduped: 'scoped-deduped:root',
31+
ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root',
3232
}
3333

34-
## single module version is bundled if dedupe is set
34+
## single module version is bundled if dedupe is set as a function
3535

3636
> Snapshot 1
3737
@@ -40,11 +40,11 @@ Generated by [AVA](https://avajs.dev).
4040
ReactConsumer: 'react-consumer:react:root',
4141
}
4242

43-
## single module version is bundled if dedupe is set as a function
43+
## multiple module versions are bundled if dedupe is not set
4444

4545
> Snapshot 1
4646
4747
{
4848
React: 'react:root',
49-
ReactConsumer: 'react-consumer:react:root',
49+
ReactConsumer: 'react-consumer:react:child',
5050
}
3 Bytes
Binary file not shown.

packages/node-resolve/test/snapshots/only.js.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ The actual snapshot is saved in `only.js.snap`.
44

55
Generated by [AVA](https://avajs.dev).
66

7-
## handles nested entry modules
7+
## specify the only packages to resolve
88

99
> Snapshot 1
1010
1111
[]
1212

13-
## regex
13+
## handles nested entry modules
1414

1515
> Snapshot 1
1616
1717
[]
1818

19-
## specify the only packages to resolve
19+
## regex
2020

2121
> Snapshot 1
2222
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)