Skip to content

Commit 12e1fee

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

File tree

14 files changed

+192
-114
lines changed

14 files changed

+192
-114
lines changed

Diff for: packages/node-resolve/package.json

+1-1
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
},

Diff for: packages/node-resolve/src/index.js

+9-6
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;

Diff for: packages/node-resolve/test/fixtures/entry/dep.js

Whitespace-only changes.

Diff for: packages/node-resolve/test/fixtures/entry/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './dep.js';
2+
3+
console.log('main');

Diff for: packages/node-resolve/test/fixtures/entry/other.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('other');
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import './side-effect.js';
2+
3+
console.log('main');

Diff for: packages/node-resolve/test/snapshots/dedupe.js.md

+12-12
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
}

Diff for: packages/node-resolve/test/snapshots/dedupe.js.snap

3 Bytes
Binary file not shown.

Diff for: packages/node-resolve/test/snapshots/only.js.md

+3-3
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

Diff for: packages/node-resolve/test/snapshots/only.js.snap

0 Bytes
Binary file not shown.

Diff for: packages/node-resolve/test/snapshots/test.js.md

+51-48
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ The actual snapshot is saved in `test.js.snap`.
44

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

7+
## throws error if local id is not resolved
8+
9+
> Snapshot 1
10+
11+
'Could not resolve \'./foo\' from unresolved-local.js'
12+
713
## allows custom moduleDirectories with legacy customResolveOptions.moduleDirectory
814

915
> Snapshot 1
@@ -17,21 +23,6 @@ Generated by [AVA](https://avajs.dev).
1723
},
1824
]
1925

20-
## handles package side-effects
21-
22-
> Snapshot 1
23-
24-
[
25-
'array-dep1',
26-
'array-dep3',
27-
'array-dep5',
28-
'array-index',
29-
'false-dep1',
30-
'true-dep1',
31-
'true-dep2',
32-
'true-index',
33-
]
34-
3526
## ignores deep-import non-modules
3627

3728
> Snapshot 1
@@ -47,129 +38,141 @@ Generated by [AVA](https://avajs.dev).
4738
},
4839
]
4940

50-
## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option
41+
## respects the package.json sideEffects property for files in root package by default
5142

5243
> Snapshot 1
5344
5445
`'use strict';␊
5546
56-
console.log('side effect');␊
47+
console.log('main');␊
5748
`
5849

59-
## respects the package.json sideEffects property for files in root package by default
50+
## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option
6051

6152
> Snapshot 1
6253
6354
`'use strict';␊
6455
56+
console.log('side effect');␊
57+
58+
console.log('main');␊
6559
`
6660

67-
## throws error for removed customResolveOptions.basedir option
61+
## handles package side-effects
6862

6963
> Snapshot 1
7064
71-
Error {
72-
message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.',
73-
}
65+
[
66+
'array-dep1',
67+
'array-dep3',
68+
'array-dep5',
69+
'array-index',
70+
'false-dep1',
71+
'true-dep1',
72+
'true-dep2',
73+
'true-index',
74+
]
7475

75-
## throws error for removed customResolveOptions.extensions option
76+
## throws error for removed customResolveOptions.preserveSymlinks option
7677

7778
> Snapshot 1
7879
7980
Error {
80-
message: 'node-resolve: `customResolveOptions.extensions` is no longer an option. If you need this, please open an issue.',
81+
message: 'node-resolve: `customResolveOptions.preserveSymlinks` is no longer an option. We now always use the rollup `preserveSymlinks` option.',
8182
}
8283

83-
## throws error for removed customResolveOptions.includeCoreModules option
84+
## throws error for removed customResolveOptions.basedir option
8485

8586
> Snapshot 1
8687
8788
Error {
88-
message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.',
89+
message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.',
8990
}
9091

91-
## throws error for removed customResolveOptions.isDirectory option
92+
## throws error for removed customResolveOptions.package option
9293

9394
> Snapshot 1
9495
9596
Error {
96-
message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.',
97+
message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.',
9798
}
9899

99-
## throws error for removed customResolveOptions.isFile option
100+
## throws error for removed customResolveOptions.extensions option
100101

101102
> Snapshot 1
102103
103104
Error {
104-
message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.',
105+
message: 'node-resolve: `customResolveOptions.extensions` is no longer an option. If you need this, please open an issue.',
105106
}
106107

107-
## throws error for removed customResolveOptions.package option
108+
## throws error for removed customResolveOptions.includeCoreModules option
108109

109110
> Snapshot 1
110111
111112
Error {
112-
message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.',
113+
message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.',
113114
}
114115

115-
## throws error for removed customResolveOptions.packageFilter option
116+
## throws error for removed customResolveOptions.readFile option
116117

117118
> Snapshot 1
118119
119120
Error {
120-
message: 'node-resolve: `customResolveOptions.packageFilter` is no longer an option. If you need this, please open an issue.',
121+
message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.',
121122
}
122123

123-
## throws error for removed customResolveOptions.packageIterator option
124+
## throws error for removed customResolveOptions.isFile option
124125

125126
> Snapshot 1
126127
127128
Error {
128-
message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.',
129+
message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.',
129130
}
130131

131-
## throws error for removed customResolveOptions.pathFilter option
132+
## throws error for removed customResolveOptions.isDirectory option
132133

133134
> Snapshot 1
134135
135136
Error {
136-
message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.',
137+
message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.',
137138
}
138139

139-
## throws error for removed customResolveOptions.paths option
140+
## throws error for removed customResolveOptions.realpath option
140141

141142
> Snapshot 1
142143
143144
Error {
144-
message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.',
145+
message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.',
145146
}
146147

147-
## throws error for removed customResolveOptions.preserveSymlinks option
148+
## throws error for removed customResolveOptions.packageFilter option
148149

149150
> Snapshot 1
150151
151152
Error {
152-
message: 'node-resolve: `customResolveOptions.preserveSymlinks` is no longer an option. We now always use the rollup `preserveSymlinks` option.',
153+
message: 'node-resolve: `customResolveOptions.packageFilter` is no longer an option. If you need this, please open an issue.',
153154
}
154155

155-
## throws error for removed customResolveOptions.readFile option
156+
## throws error for removed customResolveOptions.pathFilter option
156157

157158
> Snapshot 1
158159
159160
Error {
160-
message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.',
161+
message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.',
161162
}
162163

163-
## throws error for removed customResolveOptions.realpath option
164+
## throws error for removed customResolveOptions.paths option
164165

165166
> Snapshot 1
166167
167168
Error {
168-
message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.',
169+
message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.',
169170
}
170171

171-
## throws error if local id is not resolved
172+
## throws error for removed customResolveOptions.packageIterator option
172173

173174
> Snapshot 1
174175
175-
'Could not resolve \'./foo\' from unresolved-local.js'
176+
Error {
177+
message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.',
178+
}

Diff for: packages/node-resolve/test/snapshots/test.js.snap

22 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)