-
Notifications
You must be signed in to change notification settings - Fork 126
Implemented support for dynamic require #331
Conversation
be5ca41
to
2929eb6
Compare
Yay, finally passed all tests! |
2929eb6
to
36ef5b8
Compare
c7accf2
to
4184389
Compare
78c0c67
to
8789e5c
Compare
@danielgindi Any update, when this feature will be released. I badly need this feature. |
@ansarizafar It's not up to me... I'll rebase on master as there are conflicts now |
@danielgindi will your implementation support complete dynamic path with require. Wepack does not support full dynamic path. |
8067ec4
to
b914b34
Compare
@ansarizafar Yes, but in case of fully dynamic path you'll have to tell the plugin to include those files so it can find it dynamically in runtime. You do that with the |
In my case path is fully dynamic and only known at runtime. It would be very useful If dynamicRequires option also allow a folder path from where to load files dynamically. |
It does. |
@guybedford are you going to consider merging this? |
I will take look, probably early next week. This looks really promising. From what I see from a first glance at the code: Maybe you want to split up some of the functions used. I know rollup-plugin-commonjs is some kind of a mess with this regard already so any works towards cleaning this up, at least as far as things are touched by this feature, is highly appreciated! This will also make the review a little faster :) |
419da73
to
490afd6
Compare
In order to correctly handle absolute paths
@lukastaegert As for the third if-case - that is resolved in my latest commits. I did some work on the path-module replicas there, as they had some bugs and broke a module that I'm compiling with this. Added tests for that too. As for local paths hardcoded into the module - I'm aware of that, and in my own code which calls the rollup I'm replacing it with a root path. It could probably be done automatically, but not 100% as if someone has I'm not sure that we have to handle all complex cases right away with this. As this already covers most situations (that I stumbled upon, at least), and without this you have no other options anyway. Btw there are many cases where dynamic requires are required that will be redundant in the future, as some modules are moving away from circular dependencies and dynamic requires. I posted quite a few issues in popular modules that do that, and most of them fixed it. |
Also what do you prefer - rebase on master or merge from master? As there are conflicts now |
Merging is ok as we will squash the PR anyway in the end |
@lukastaegert I've added a proposal commit for handling the test with Also I see that in many tests the output contains imports from |
cc907f4
to
bcd2aea
Compare
@lukastaegert since there were so many conflicts with each merge due to the heavy refactoring - I've rebased this on master, and compared to the merged version to make sure that it's exactly the same. I need you to look at the tests - I think that the ones that are failing need to adjust their expected outputs. But can't be sure. |
Hi @danielgindi, sorry for the wait. The last weeks, I was busy with some important private matters as well as trying to finally get the rollup 1.0 release going, which for me has some priority as I hope you will understand.
These tests make sure that a file that is already ESM (i.e. it contains import or export statements) is allowed to have a function named
Yes, the
But they do, it is the very first lines of
This was my hope with cherry-picking them to a separate PR. As for the future of this PR, this is why I am not happy to merge this in its current form:
So here is my suggested path forward:
Sorry this is quite a long list of things to do. Note that even if we drastically reduce the scope of this PR, it does not mean the things we skip cannot be re-added at some later point. So make sure you keep a copy of the branch in its current state for reference. |
Well a few points are already resolved AFAIK.
Overall the PR seems huge, but it's mainly tests... I understand your priorities and considerations, it's OK if this takes a little bit more time. |
@lukastaegert How can we get this moving? |
commonjs requires should still be processed in es modules, but the module should remain with its default exports (+1 squashed commits)
a92f44f
to
b347524
Compare
We do want to work on ES modules in case they have `require`s, But we do not want to touch `global` or mock an export for them.
@danielgindi First, apologies that this didn't get the attention it needed. We've got a great team of developers that have joined in on a Plugin Maintainers team and we're migrating all of the rollup plugins to a monorepo at https://github.com/rollup/plugins. I'd like to invite you to reopen your pull request on that repo once the move there is done. I fully recognize that it's a big ask. The unfortunate fact is that PR is just too large for us to get reviewed properly before we'd like to get the plugin moved. I also don't want to ask you to resolve any conflicts once again without a promise that it'll have eyes on it when it's done. I can tell you that a PR at the new plugins monorepo would have eyes on it. Does that sound good to you? |
@shellscape Yes, I'll try to get some time for it in the following days |
Thanks for replying, and no rush. I'll ping you again once we have the plugin moved to rollup/plugins. |
We've completed the move to the new repo. Please look for it in https://github.com/rollup/plugins |
This can handle cases of dynamic requires (
return require(modules[index])
/require(modulesPath + './test.js')
) and circular dependencies.Closes #131