Core: Fix the exports setup to make bundlers work with ESM & CommonJS
[jquery.git] / test / bundler_smoke_tests / lib / run-rollup.js
blobd18c450ca55c41b0dad8b1c79fda6f4b211a655f
1 import { rollup } from "rollup";
3 import { loadConfigFile } from "rollup/loadConfigFile";
4 import path from "node:path";
5 import { fileURLToPath } from "node:url";
7 const dirname = path.dirname( fileURLToPath( import.meta.url ) );
8 const pureEsmConfigPath = path.resolve(
9         dirname, "..", "rollup-pure-esm.config.js" );
10 const commonJSConfigPath = path.resolve(
11         dirname, "..", "rollup-commonjs.config.js" );
13 // See https://rollupjs.org/javascript-api/#programmatically-loading-a-config-file
14 async function runRollup( name, configPath ) {
16         console.log( `Running Rollup, version: ${ name }` );
18         // options is an array of "inputOptions" objects with an additional
19         // "output" property that contains an array of "outputOptions".
20         // We generate a single output so the array only has one element.
21         const {
22                 options: [ optionsObj ],
23                 warnings
24         } = await loadConfigFile( configPath, {} );
26         // "warnings" wraps the default `onwarn` handler passed by the CLI.
27         // This prints all warnings up to this point:
28         warnings.flush();
30         const bundle = await rollup( optionsObj );
31         await Promise.all( optionsObj.output.map( bundle.write ) );
33         console.log( `Build completed: Rollup, version: ${ name }` );
36 export async function runRollupPureEsm() {
37         await runRollup( "pure ESM", pureEsmConfigPath );
40 export async function runRollupEsmAndCommonJs() {
41         await runRollup( "ESM + CommonJS", commonJSConfigPath );