Skip to content

Commit

Permalink
feat(ses): add SES version to lockdown shim (merge #1854)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored Dec 5, 2023
2 parents 7e84765 + a3c3cc8 commit 8fd4295
Showing 1 changed file with 26 additions and 11 deletions.
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

0 comments on commit 8fd4295

Please sign in to comment.