-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
JSM: Add Canonical Modules White List #15599
Conversation
… a module should be considered the canonical source
# Conflicts: # utils/modularize.js
@mrdoob This PR provides a way to consider some of the JSM scripts as canonical and rely on the rollup script to convert examples to UMD as opposed to relying on the modularize script. There have been a few PRs that have converted modules by hand (#15899, #15656) that can't be merged because they'll become out of date if the existing js scripts get updated. Other scripts such as EffectComposer.js will require hand changes that like separating I think it'll be important to have some process by which we consider the module versions of the example canonical as more get converted. |
I agree with creating a whitelist, so that some files can be graduated to JSM-as-source. But I'm not necessarily sure whether
These don't necessarily need to be separate files right, they could just have multiple exports? I'm tempted to argue an even more aggressive conversion for import { EffectComposer, Pass, BloomPass } from 'three/examples/jsm/postprocessing/';
const { EffectComposer, Pass, BloomPass } = require('three/examples/js/postprocessing.js'); |
Without refactoring EffectComposer.js that's not the case. I discussed it a bit in #15832 but EffectComposer.js currently defines
I don't really have strong feelings on this other than that it seems unnecessary to include a bunch of postprocessing pass code if it isn't being used and it's not backwards compatible, which has been mentioned as a desire previously. It is really inconvenient to have to include all the global scripts, though... |
Ah, ok yes we should split the file then.
How is Rollup going to create separate UMD files for ES modules that depend on one another? If it's easy enough get have it convert back In general these folders are things that would be separate NPM packages ( So yes, I'm suggesting we break back-compat for these specific cases (postprocessing, nodes, curves), but won't complain if others disagree. |
# Conflicts: # utils/modularize.js
It's actually not so bad and my previous module PR #14803 supported it by just marking every dependency as external in the rollup config which means the produced package will look on the global field ( I'll save the npm packages can of worms for another discussion but I've been operating under the assumption backwards compatibility is important when converting and if that's true then Rollup can support that when going from es6 -> umd. If that's not needed then even better! |
@gkjohnson what do you think of modifying this so it doesn't have an explicit whitelist, but instead:
I guess I'm looking for the simplest possible way to start converting a folder like |
Yeah I'm happy to simplify this however makes sense -- there is the caveat that there will have to be care taken to ensure that the modularize and rollup lists are mutually exclusive, otherwise we'll wind up with scripts overwriting each other. I can look into this a bit more either tonight or tomorrow.
Using either script from #14803 or #15832 could be a good starting point for this, but it's probably not so bad to do it by hand. And just for context I made PR #14795 awhile ago to address the cyclic dependency in the current EffectComposer to avoid this but it didn't gain much traction. After that change I was able to successfully convert the post processing files. Do you intend for the rollup-converted modules to be backwards compatible after the conversion? If so that will mean there have to be special settings for |
The conversion is easy enough, but unless it's 100% automated (and I don't think either PR above is there yet) I don't want to do it without a way to generate the Basically the rule should be for all files, either
I don't think that's a good idea or maintainable, personally. We should generate output that is consistent with Rollup best practice. |
Totally agree. I didn't intend to say that we should rely on the script entirely or that they wouldn't need hand fixes afterward. Just that they might serve as a good start to generating a module.
I'd like to keep things simple, too, but keep it in mind in case backwards compatibility winds up being a concern. The config would look something like this: var files = [{
path: 'jsm/postprocessing/EffectComposer.js',
include: ['jsm/postprocessing/Pass.js']
}]; What are you envisioning the converted files looking like after rollup is done with them? Will all postprocessing effects be separate UMD files as they are now? Or are you planning to create an index file so they will all be bundled into a single UMD file that encompasses all post processing effects? Edit: Just to note that the rollup script as it is right now will create a new UMD file for every module file processed. |
I'm fine with either, but I think I value a simple conversion and final result more than backward-compatibility in this case. |
@donmccurdy I've updated the rollup example config to be modeled a little more closely to modularize.js and removed the The big difference is that the rollup config specifies a regex for the file path while |
var dstFolder = __dirname + '/examples/js/'; | ||
|
||
var files = [ | ||
// { path: /postprocessing[\/\\].+\.js$/ }, |
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.
No files are converted at the moment (so rollup will throw an error) but they can be added in future PRs. You can use rollup to convert the files in the jsm/controls folder by changing this to:
var files = [
{ path: /controls[\/\\].+\.js$/ }
];
The changes look good to me, thanks! The regex should be fine. I'd like to test this on some files (maybe |
Closing in favor of #16920. |
As discussed here and here.
Adds a script to determine which example modules should be considered the canonical source. If it is considered the canonical source then a "do not edit" banner is added when generating a UMD module. If it is not then a "do not edit" banner is added when generating the jsm files.
The white list can consist of strings or regex. Here's an example banner: