-
-
Notifications
You must be signed in to change notification settings - Fork 591
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
Dynamic require #206
Dynamic require #206
Conversation
Thanks for reopening this PR here. Please fix the CI errors and we'll take a look once that's working. |
beafd7c
to
bff5b98
Compare
@shellscape Are the node-vxx-latest tests being done with latest version over PR tests? Some weird combination? |
Not sure I understand the question. Pretty standard setup: linting runs on the files in the PR and all tests for the plugin(s) changed run. |
I'm asking because the tests on Node 8/10 windows - pass. |
bff5b98
to
75aac84
Compare
Found a potential cause for this. In the two tests that fail intermittently there was usage of |
Well you should be leveraging @rollup/plugin-node-resolve (the old one is deprecated) and you should make sure it's added properly to the package's devDeps. Monorepos work a little differently. If we don't have this outlined in the README or CONTRIBUTING let me know and we'll add it to the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working to get this passing CI.
One big thing missing from the docs is a code example that might require using dynamicRequireTargets
. We get a lot of users from webpack and a lot of new users that are new to bundling and having a small code snippet in the docs to show what kind of code might require using the new option would be extremely helpful to users.
That aside I have several code quality comments I'd like to see fixed up along with some questions to be addressed.
@lukastaegert we'll need your eyes on this before we can merge it.
@shellscape Did some cleaning. I think it's ready as it already went through a lot of evolution (with the help of @lukastaegert), and it's a major part of what people are expecting when rolling up common js modules. |
There's only been one major change so far, and that was for the migration to the monorepo. You shouldn't see any tooling changes for a long while. We'll need resolution to #206 (comment) before we can move forward as well. I'm a stickler for making sure big changes are properly documented. An aside: We've both ESLint and Prettier setup in the repo. I'd very highly recommend a plugin for your editor of choice which will automatically correct formatting/style on document save. It takes a lot of headache out of complying with linting guidelines. |
86cd2ff
to
a5ddb46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went over the notes, cleaned up a bit, and added info to the PR.
Thanks. I'll bug @lukastaegert to take another look. |
Ok, this one is huge and I cannot promise when I will find time to look into this as my current stack of things to do is really long. One thing, I did not see any form tests that would allow me to inspect what the actually generated code is in the PR. Except deleted ones. Would it be possible to add some? I would not be too happy if the PR produced noticeably less efficient code for situations where we do not have dynamic requires. |
@lukastaegert So are you suggesting restoring the 3 deleted ones and updating the expected outputs? |
That would definitely help with the review and might also prevent regressions in code quality. Why were they deleted in the first place? |
Alternatively, I think it would be even more interesting to see what Rollup makes of it in the end. There are already some function tests that do that via |
Ok, here is a really simple change that will require little work of you but make the test much more powerful (and might even help us get rid of the explicit form tests eventually): Change |
Outlined in the PR description |
a5ddb46
to
6dd53c0
Compare
I am not that (or at all) familiar with Anyway I found the root of the issue, brought back the tests with only a minor modification, and I'm updating the PR description. |
6dd53c0
to
f6a936e
Compare
@shellscape Any news on this? |
@danielgindi Apologies that I did not get to merging this before a conflict happened. Please run the following commands in the project to resolve that conflict: git checkout master
git reset --hard origin && git pull
git checkout dynamic_require
git merge master
rm pnpm-lock.yaml
pnpm install --force
git add pnpm-lock.yaml
git commit --no-edit
git push And you should be good. Every now and then the pnpm lockfile gets out of sorts and that's the fix for a conflict. |
# Conflicts: # pnpm-lock.yaml
Done! |
@shellscape Don’t you want to merge it before breaking it again? 😂 |
Gah. Done. Our day care closed so things are a bit bananas around here now. Thank you very much for keeping steady on this one! |
Ours too, two weeks ago. It’s double bananas here. The girls are climbing on me all day, can’t do any serious work. |
Any link to how to use the master branch to use this plugin? Or any estimate on the publishing of the next version? |
I just got this error when trying to use a library of mine in which I use dynamic require:
Should this have already been resolved by this thread? I am on
|
@danielgindi Thank you very much!!! |
Ive been trying to get this going per your comment and have had no success? if i have a require statement like to: would i need to list each possibility for set and icon? Thanks |
@mjmnagy |
Sorry for the confusion - it was a translation error. The The function I have created to loop through the icons folders and create an array of strings of paths is::
No luck with this approach as I get |
|
Please just read the docs, also look at issues or open an issue. This PR is tested, merged, and working in production. |
@lukastaegert please lock the conversation... |
I have and I cannot get
to work hence why I'm asking |
* Implemented support for dynamic requires (transferred PR) Moved from rollup/rollup-plugin-commonjs#331 * Only add dynamic loader code when dynamic feature is enabled * test(commonjs): update snapshots for easier diffing * Automatically remove user paths * test(commonjs): Prepare tests to support code-splitting * test(commonjs): Try to add a code-splitting test * Fixed code-splitting support * Cleanup: avoid importing commonjs-proxy when we only need to register * Fixed test * Updated pnpm-lock * Updated snapshots * Satisfy linter Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
Rollup Plugin Name:
commonjs
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
rollup/rollup-plugin-commonjs#131
rollup/rollup-plugin-commonjs#331
This has already been through major refactoring and adjustments, and now has been rebased on this repo.
Json support has been fixed (and this will now required the json plugin when requiring a full module dynamically, as it needs to cache the
package.json
).Also the issue where the whole dynamic loader code was always added to any cjs project been rolled up is solved, it's now conditional on whether dynamic module loading is enabled or not.
Tests:
There are 3 tests (
unambiguous-with-default-export
,unambiguous-with-import
,unambiguous-with-named-export
) which were slightly modified.The reasoning is that prior to this PR, if a file was detected to be using static
import
/export
, then it was not processed for CJSrequire
statements.That situation was a nice optimization but not realistic, as users coming from webpack are used to have a JS file with static
import
/export
, whileimport
ing orrequire
a module which is essentially a CJS module. Such a module could have circular dependencies (i.elogform
) or dynamic dependencies (i.eknex
) which needs processing in the CJS realm.Now these 3 tests are using
require
, which means that there might be surprises hidden behind the scenes, so it must be processed for CJS. This means that the output code is a little more verbose (though not ending up adding the CJS boilerplate).