Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Feature: default exports as an array #40

Closed
wants to merge 8 commits into from
Closed

Conversation

arshaw
Copy link

@arshaw arshaw commented Jun 22, 2019

I needed to make a new module that took a wildcard-generated list of other modules, take their default exports, and export them as an array in the resulting bundled module.

To make the usecase more concrete, in my project FullCalendar, I needed to take all the locale files and turn them into a "locales-all.js" file. Does that make sense?

Your module was a great starting point for this! I contemplated simply forking your code and making a new plugin, but ultimately decided it'd be best as a new feature. I've added a exports: 'array' option. I've also added a test and I've update the README.

I also had to refactor the tests a bit. The previous tests were doing string comparisons on the generated code, which is rather brittle of Rollup decides to mangle variable names in the future. While not that big of a deal for existing features, it was absolutely necessary for my new feature. Thus, the tests now primarily try to execute the resulting module by dumping it to the temp file and requiring it, and looking at the export object. Fingers crossed you are okay with this.

Please let me know what you think! I am open to any feedback.

@@ -12,7 +12,7 @@ const entry = '\0rollup-plugin-multi-entry:entry-point';
export default function multiEntry(config: ?Config = null) {
let include = [];
let exclude = [];
let exporter = path => `export * from ${JSON.stringify(path)};`;
let exporter = buildNamedExports;
Copy link
Author

Choose a reason for hiding this comment

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

the exporter now operates on an array of paths rather than just a single path

@arshaw
Copy link
Author

arshaw commented Jun 22, 2019

The CI situation for Node 6 is failing for some reason. Doesn't seem related to my stuff.

error resolve-pkg@2.0.0: The engine "node" is incompatible with this module. Expected version ">=8".
error Found incompatible module

@eventualbuddha
Copy link
Contributor

@arshaw I fixed the issue on master and rebased.

@eventualbuddha
Copy link
Contributor

Can we guarantee the ordering of the array? Do we know that matched is returning them in a known order?

@arshaw
Copy link
Author

arshaw commented Jun 25, 2019

Thanks @eventualbuddha . It looks like matched mostly defers to node-glob, and I doesn't document anything nor expose anything about ordering.

However, I would say this is also an issue for the default behavior of rollup-plugin-multi-entry. When your modules have side effects, those side effects will be executed in an arbitrary order.

We can decide to force an order, via Array#sort for example, but I think that should be for the default behavior of this plugin as well.

Please let me know if you'd like me to write code to force an order for either my new feature, for the plugin as a whole, or not at all.

@eventualbuddha
Copy link
Contributor

Sorry for taking so long to get back to you. I think doing Array#sort on the files returned to us is the least likely thing to surprise people. If people need to specify an order in the future then maybe we can add a comparator option or something.

@arshaw
Copy link
Author

arshaw commented Jul 9, 2019

Okay, would you like me to do the sorting regardless of what kind of exports settings is specified. So, in all cases?

@eventualbuddha
Copy link
Contributor

Yep, I think that’s best.

@arshaw
Copy link
Author

arshaw commented Aug 1, 2019

Sorry for the delay!

I've made it so that the ordering of the array results as well as the execution-order of the name-exported-modules is now sorted and deterministic.

BTW, here's more supporting evidence that the matched lib doesn't return in a particular order: jonschlinkert/matched#10

Let me know if there's anything else I should do!

PS- test in the node 6 environment are failing. chokes on the es6 async keyword.

test/test.js Outdated
include: ['test/fixtures/default-1.js', 'test/fixtures/default-0.js'],
exports: 'array'
}).then(moduleExports => {
deepStrictEqual(moduleExports, [0, 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't feel right to me. I think what should happen is that globs get expanded in place in sorted order, but everything else remains as it was. So in this case as there are no globs, each entry stays where it is in the list. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

I agree. I changed it to honor your recommendation.

I originally implemented it how I implemented to be defensive... if you upgrade to the latest matched (4.0.0), the order becomes unpredictable. Solution: just don't upgrade. Stay at ^1.0.2.

Sound okay?

@shellscape
Copy link
Contributor

@eventualbuddha @arshaw I'd like to begin the process of moving this plugin to our new monorepo. To do that we have to get the outstanding PRs resolved. Any chance you all can wrap this one up this week?

@arshaw
Copy link
Author

arshaw commented Dec 1, 2019

sure. the ball is in @eventualbuddha 's court to review my latest changes

@eventualbuddha
Copy link
Contributor

I'm unlikely to get to this as I am not a user of this package anymore.

@shellscape
Copy link
Contributor

@lukastaegert I'm consumed with the migration of a few plugins at the moment. Could you take a look at this one?

@shellscape
Copy link
Contributor

After discussing at length with other plugin contributors we've come to the conclusion that your use case is absolutely valid, but the likelihood that this would be a widely used feature is pretty slim. The good news is that none of your work has been wasted at all, and this can easily be made a separate third party plugin. We feel that'd be the best route to get the function you're after. Because of that, were going to close the PR, but please don't take that as a rejection of your work.

Thank you for your work on this PR and for keeping with it through the delays. Consider me at your service for any assistance in getting this PR turned into a plugin, I'm happy to help in any way I can.

@shellscape shellscape closed this Dec 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants