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

feat(ses): add SES version to lockdown shim #1854

Merged
merged 9 commits into from
Dec 5, 2023
37 changes: 26 additions & 11 deletions packages/ses/scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,44 @@ const write = async (target, content) => {
};

const main = async () => {
const text = await fs.promises.readFile(
fileURLToPath(`${root}/package.json`),
'utf8',
);
const packageJson = JSON.parse(text);
const version = packageJson.version;

const bundle = await makeBundle(
read,
pathToFileURL(resolve('../index.js', import.meta.url)).toString(),
);
const { code: terse } = await minify(bundle, {
const versionedBundle = `// ses@${version}\n${bundle}`;

const { code: terse } = await minify(versionedBundle, {
mangle: false,
keep_classnames: true,
});
assert.string(terse);

console.log(`Bundle size: ${bundle.length} bytes`);
console.log(`Bundle size: ${versionedBundle.length} bytes`);
console.log(`Minified bundle size: ${terse.length} bytes`);

await fs.promises.mkdir('dist', { recursive: true });
await write('dist/ses.cjs', bundle);
await write('dist/ses.mjs', bundle);
await write('dist/ses.umd.js', bundle);
await write('dist/ses.umd.min.js', terse);

await write('dist/lockdown.cjs', bundle);
await write('dist/lockdown.mjs', bundle);
await write('dist/lockdown.umd.js', bundle);
await write('dist/lockdown.umd.min.js', terse);

const bundleFilePaths = [
'dist/ses.cjs',
'dist/ses.mjs',
'dist/ses.umd.js',
'dist/lockdown.cjs',
'dist/lockdown.mjs',
'dist/lockdown.umd.js',
];
const terseFilePaths = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js'];

await Promise.all([
...bundleFilePaths.map(dest => write(dest, versionedBundle)),
...terseFilePaths.map(dest => write(dest, terse)),
]);
};

main().catch(err => {
Expand Down