Skip to content
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

Fix - mix ESM and CommonJS in shim/dynamic.js #145

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading