Skip to content

Commit

Permalink
fix(node-resolve): pass on isEntry flag (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert authored Oct 19, 2021
1 parent cfb4555 commit 12e1fee
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 114 deletions.
2 changes: 1 addition & 1 deletion packages/node-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-json": "^4.1.0",
"es5-ext": "^0.10.53",
"rollup": "^2.42.0",
"rollup": "^2.58.0",
"source-map": "^0.7.3",
"string-capitalize": "^1.0.1"
},
Expand Down
15 changes: 9 additions & 6 deletions packages/node-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function nodeResolve(opts = {}) {
const browserMapCache = new Map();
let preserveSymlinks;

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

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

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

async resolveId(importee, importer, opts) {
async resolveId(importee, importer, resolveOptions) {
if (importee === ES6_BROWSER_EMPTY) {
return importee;
}
Expand All @@ -261,9 +260,13 @@ export function nodeResolve(opts = {}) {
importer = undefined;
}

const resolved = await doResolveId(this, importee, importer, opts);
const resolved = await doResolveId(this, importee, importer, resolveOptions.custom);

This comment has been minimized.

Copy link
@jdalton

jdalton Dec 22, 2021

What if resolveOptions is undefined? Won't resolveOptions.custom be an undefined property access?

This comment has been minimized.

Copy link
@lukastaegert

lukastaegert Dec 22, 2021

Author Member

As Rollup itself calls resolveId, that should not be possible.

if (resolved) {
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true });
const resolvedResolved = await this.resolve(
resolved.id,
importer,
Object.assign({ skipSelf: true }, resolveOptions)
);
const isExternal = !!(resolvedResolved && resolvedResolved.external);
if (isExternal) {
return false;
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions packages/node-resolve/test/fixtures/entry/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './dep.js';

console.log('main');
1 change: 1 addition & 0 deletions packages/node-resolve/test/fixtures/entry/other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('other');
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import './side-effect.js';

console.log('main');
24 changes: 12 additions & 12 deletions packages/node-resolve/test/snapshots/dedupe.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ The actual snapshot is saved in `dedupe.js.snap`.

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

## dedupes deep imports by package name if dedupe is set
## single module version is bundled if dedupe is set

> Snapshot 1
{
React: 'react/deep.js:root',
ReactConsumer: 'react-consumer:react/deep.js:root',
React: 'react:root',
ReactConsumer: 'react-consumer:react:root',
}

## dedupes scoped deep imports by package name if dedupe is set
## dedupes deep imports by package name if dedupe is set

> Snapshot 1
{
ScopedDeduped: 'scoped-deduped:root',
ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root',
React: 'react/deep.js:root',
ReactConsumer: 'react-consumer:react/deep.js:root',
}

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

> Snapshot 1
{
React: 'react:root',
ReactConsumer: 'react-consumer:react:child',
ScopedDeduped: 'scoped-deduped:root',
ScopedDedupedConsumer: 'scoped-deduped-consumer:scoped-deduped:root',
}

## single module version is bundled if dedupe is set
## single module version is bundled if dedupe is set as a function

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

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

> Snapshot 1
{
React: 'react:root',
ReactConsumer: 'react-consumer:react:root',
ReactConsumer: 'react-consumer:react:child',
}
Binary file modified packages/node-resolve/test/snapshots/dedupe.js.snap
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/node-resolve/test/snapshots/only.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ The actual snapshot is saved in `only.js.snap`.

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

## handles nested entry modules
## specify the only packages to resolve

> Snapshot 1
[]

## regex
## handles nested entry modules

> Snapshot 1
[]

## specify the only packages to resolve
## regex

> Snapshot 1
Expand Down
Binary file modified packages/node-resolve/test/snapshots/only.js.snap
Binary file not shown.
99 changes: 51 additions & 48 deletions packages/node-resolve/test/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ The actual snapshot is saved in `test.js.snap`.

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

## throws error if local id is not resolved

> Snapshot 1
'Could not resolve \'./foo\' from unresolved-local.js'

## allows custom moduleDirectories with legacy customResolveOptions.moduleDirectory

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

## handles package side-effects

> Snapshot 1
[
'array-dep1',
'array-dep3',
'array-dep5',
'array-index',
'false-dep1',
'true-dep1',
'true-dep2',
'true-index',
]

## ignores deep-import non-modules

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

## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option
## respects the package.json sideEffects property for files in root package by default

> Snapshot 1
`'use strict';␊
console.log('side effect');␊
console.log('main');␊
`

## respects the package.json sideEffects property for files in root package by default
## ignores the package.json sideEffects property for files in root package with "ignoreSideEffectsForRoot" option

> Snapshot 1
`'use strict';␊
console.log('side effect');␊
console.log('main');␊
`

## throws error for removed customResolveOptions.basedir option
## handles package side-effects

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.',
}
[
'array-dep1',
'array-dep3',
'array-dep5',
'array-index',
'false-dep1',
'true-dep1',
'true-dep2',
'true-index',
]

## throws error for removed customResolveOptions.extensions option
## throws error for removed customResolveOptions.preserveSymlinks option

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

## throws error for removed customResolveOptions.includeCoreModules option
## throws error for removed customResolveOptions.basedir option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.basedir` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.isDirectory option
## throws error for removed customResolveOptions.package option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.isFile option
## throws error for removed customResolveOptions.extensions option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.extensions` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.package option
## throws error for removed customResolveOptions.includeCoreModules option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.package` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.includeCoreModules` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.packageFilter option
## throws error for removed customResolveOptions.readFile option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.packageFilter` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.packageIterator option
## throws error for removed customResolveOptions.isFile option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.isFile` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.pathFilter option
## throws error for removed customResolveOptions.isDirectory option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.isDirectory` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.paths option
## throws error for removed customResolveOptions.realpath option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.preserveSymlinks option
## throws error for removed customResolveOptions.packageFilter option

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

## throws error for removed customResolveOptions.readFile option
## throws error for removed customResolveOptions.pathFilter option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.readFile` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.pathFilter` is no longer an option. If you need this, please open an issue.',
}

## throws error for removed customResolveOptions.realpath option
## throws error for removed customResolveOptions.paths option

> Snapshot 1
Error {
message: 'node-resolve: `customResolveOptions.realpath` is no longer an option. If you need this, please open an issue.',
message: 'node-resolve: `customResolveOptions.paths` is no longer an option. If you need this, please open an issue.',
}

## throws error if local id is not resolved
## throws error for removed customResolveOptions.packageIterator option

> Snapshot 1
'Could not resolve \'./foo\' from unresolved-local.js'
Error {
message: 'node-resolve: `customResolveOptions.packageIterator` is no longer an option. If you need this, please open an issue.',
}
Binary file modified packages/node-resolve/test/snapshots/test.js.snap
Binary file not shown.
Loading

0 comments on commit 12e1fee

Please sign in to comment.