Closed mgol closed 2 months ago
CI is failing because pretest
now de facto depends on build:all
. This means core tests now require a build. I need to think how to approach this.
@timmywil the PR is ready for review now.
Very nice! I only have suggestions on the npm scripts
@timmywil I haven't addressed your feedback yet but I pushed 3 new commits that I had in progress (the first one is titled "Docs: Mention that the CommonJS module doesn't expose named exports"). The first one is a small docs update, the other two are adding more bundler/Node tests for our exports setup - for the slim build & both factory ones.
I contemplated simplifying the factory definitions by only exposing the ESM versions but I ultimately decided it's too breaking. People depending on factory behavior can update to our new entry points but they may not be able to switch to ESM. Funny enough, I hit it myself here as our Promises/A+ tests adapter uses the factory build but it's a CommonJS file and needs to expose the API synchronously...
The factory setup is still way simpler because there is no default export in ESM and the CommonJS version exports a similar object instead of just the API - and this means adapters are not needed, we can just expose the CommonJS version to Node and the ESM one to bundlers.
@timmywil I addressed your feedback now, please re-review.
@timmywil FYI, I added an explainer document to the wiki at https://github.com/jquery/jquery/wiki/jQuery-4-exports-explainer that should help understand the whole exports
definition. It can be helpful especially if we need to make more changes.
Summary
We cannot pass a single file via the
module
condition as thenrequire( "jquery" )
will not return jQuery but instead the module object withdefault
,$
&jQuery
as keys. Instead:node
condition:require
import
module
condition:import
require
node
ormodule
conditions`):require
import
The reasons for such definitions are as follows:
require
on an ESM file. This is possible since bundlers merge the files before they are passed to the browser to execute and the final bundles no longer contain async import code.In addition to the above changes, the
script
condition has been dropped. Only Webpack documents this condition and it's not clear when exactly it's triggered. Adding support for a new condition can be added later without a breaking change; removing is not so easy.The
production
&development
conditions have been removed as well. They were not really applied correctly; we'd need to provide both of them to each current leaf which would double the size of the definition for the.
&./slim
entry points. In jQuery, the only difference between development & production builds is minification; there are no logic changes so we can pass unminified versions to all the tooling, expecting minification down the line.For
./factory
&./factory-slim
entry points, only the ESM version is now supported. This was done to simplify the setup for this niche use case.Tests with Rollup (both pure ESM & with the CommonJS plugin) & Webpack have been added.
I added an explainer document to the wiki at https://github.com/jquery/jquery/wiki/jQuery-4-exports-explainer that should help understand the whole
exports
definition. It can be helpful especially if we need to make more changes.Fixes gh-5416
Checklist