Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node-resolve): Resolve local files if resolveOption is set #337

Conversation

JaviIG
Copy link
Contributor

@JaviIG JaviIG commented Apr 26, 2020

Rollup Plugin Name: node-resolve

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

This PR fixes the issue #209, where using the resolveOnly option at the node-resolve plugin prevented the resolution of local modules.

@shellscape
Copy link
Collaborator

Thanks for the PR!

I might be missing something here, entirely possible, but if this change were successful, wouldn't the deepEqual fail for the only test?

  t.deepEqual(imports, ['@scoped/foo', '@scoped/bar']);

@JaviIG
Copy link
Contributor Author

JaviIG commented Apr 26, 2020

Hello @shellscape. I'm the one probably missing something here. For what I understood about the issue #209 is that the resolveOnly option shouldn't prevent resolving local modules.

So in the only.js tests, as the only-local.js fixture is a local module, it should be resolved always, and never imported. If that assumption is right, shouldn't the node-resolve plugin configured either with the test string, or the /^@scoped\/.*$/ regex, never import the only-local.js file?

@shellscape
Copy link
Collaborator

Yeah I think I mistook the differences between imports and resolved.

I would like to try and get some test in place that has something we can check that asserts that the local file did resolve. It looks like the lack of warnings is the signal that it's successful but that feels brittle. Nothing to block this PR on but if you can think of anything that'd be cool.

I'd like @lukastaegert to put some quick eyes on this, but it looks good to me so far.

@JaviIG
Copy link
Contributor Author

JaviIG commented Apr 27, 2020

Great! I don´t have a deep understanding of the Rollup internal types and properties, so I might be wrong, but after a fast check, I thing we can use the ´PreRenderedChunk.modules´ property, and test if the modules that should be resolved are contained in that dictionary keys. If it works as I think, this might give the tests a little more confidence.

Other option I can think of is searching inside the generated code, but it is far more ugly and fragile than searching inside the imported or resolved modules.

If you have any more ideas I would be more than happy to try them.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Regarding the question of testing, a stable way to check if a module has been bundled would be to change in the test

const imports = await getImports(bundle);

to

const { output: [{imports, modules}]} = await bundle.generate({ format: 'esm' });

Then modules is an object the keys of which are the resolved included modules, so you could for instance

t.assert(Object.keys(modules).includes(path.resolve('only.js')))

@shellscape
Copy link
Collaborator

@JaviIG would you like to try Lukas' test suggestions before we merge?

@JaviIG
Copy link
Contributor Author

JaviIG commented May 1, 2020

Thank you both! I´ve just uploaded the improved tests. That was the idea I had, but I wasn´t 100% sure about the behavior of the modules property. If there is anything more you think I can improve just tell me :)

@shellscape
Copy link
Collaborator

thanks!

@shellscape shellscape merged commit 96e0900 into rollup:master May 1, 2020
LarsDenBakker pushed a commit to LarsDenBakker/plugins that referenced this pull request Sep 12, 2020
…lup#337)

* fix(node-resolve): Resolve local files if `resolveOption` is set

* format(node-resolve): Remove empty line in `fixtures/only.js`

* test(node-resolve): add assertion to 'resolveOnly' tests to check resolved modules

Co-authored-by: Javier Iglesias García <javieri@empathy.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants