Skip to content

Commit

Permalink
Fix - mix ESM and CommonJS in shim/dynamic.js
Browse files Browse the repository at this point in the history
  • Loading branch information
thim81 committed Nov 4, 2024
1 parent 15fb00b commit 646a44b
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/shim/dynamic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const faker = require('./faker.js');
import faker from './faker.js';
// import faker from "https://raw.githubusercontent.com/Marak/faker.js/9c65e5dd4902dbdf12088c36c098a9d7958afe09/dist/faker.min.js";

// locale list generated from: https://github.com/chromium/chromium/blob/master/ui/base/l10n/l10n_util.cc
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"lib": "lib"
},
"scripts": {
"bundle": "node scripts/bundle.js",
"bundle": "node scripts/bundle_esm.js",
"lint:fix": "yarn lint --fix",
"lint": "eslint .",
"format": "prettier -c ./lib/**/*.js ./test/**/*.js",
Expand Down Expand Up @@ -80,12 +80,16 @@
"@babel/preset-env": "^7.15.0",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.3",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"ava": "^2.4.0",
"cross-env": "^7.0.3",
"husky": "^7.0.4",
"jest": "^29.7.0",
"mock-require": "^3.0.3",
"npm-run-all": "^4.1.5",
"rollup": "^4.24.4",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^7.5.0",
"snazzy": "^8.0.0",
"standard": "^14.3.1"
Expand Down
55 changes: 55 additions & 0 deletions scripts/bundle_esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

const fs = require('fs-extra');
const rollup = require('rollup');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const { terser } = require('rollup-plugin-terser');

const dir = 'vendor';
const modules = [
'ajv',
'aws4',
'chai',
'cheerio',
'crypto-js',
'lodash',
'oauth-1.0a',
'papaparse',
'spo-gpo/polyfill',
'urijs',
'xml2js',
];

async function bundleModules() {
await fs.ensureDir(dir);
await fs.emptyDir(dir);

for (const module of modules) {
const name = module.split('/')[0];
const outputPath = `${dir}/${name}.js`;

try {
const bundle = await rollup.rollup({
input: require.resolve(module),
plugins: [
nodeResolve(), // Resolves modules in node_modules
commonjs(), // Converts CommonJS to ES6
terser(), // Minifies the output
],
});

await bundle.write({
file: outputPath,
format: 'es', // ESM output format
exports: 'auto',
});

console.log(`Bundled ${module} to ${outputPath}`);
} catch (error) {
console.error(`Error bundling ${module}:`, error);
}
}
}

bundleModules();
Loading

0 comments on commit 646a44b

Please sign in to comment.