diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index aac1a90d69..3319a7b842 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -27,47 +27,51 @@ const writeBundle = async ({ buildType } = {}) => { const packageJson = JSON.parse(text); const version = packageJson.version; - const moduleTransforms = hermesTransforms; + const moduleTransforms = {}; + + let bundleFilePaths = [ + 'dist/ses.cjs', + 'dist/ses.mjs', + 'dist/ses.umd.js', + 'dist/lockdown.cjs', + 'dist/lockdown.mjs', + 'dist/lockdown.umd.js', + ]; + let terseFilePaths = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js']; + + if (buildType === 'hermes') { + bundleFilePaths = ['dist/ses-hermes.cjs']; + Object.assign(hermesTransforms, moduleTransforms); + terseFilePaths = []; + } const bundle = await makeBundle( read, pathToFileURL(resolve('../index.js', import.meta.url)).toString(), - buildType ? {} : { moduleTransforms }, + moduleTransforms, ); const versionedBundle = `// ses@${version}\n${bundle}`; - const { code: terse } = await minify(versionedBundle, { - mangle: false, - keep_classnames: true, - }); - assert.string(terse); - + buildType && console.log(`-- Building '${buildType}' version of SES --`); console.log(`Bundle size: ${versionedBundle.length} bytes`); - console.log(`Minified bundle size: ${terse.length} bytes`); + + let terse; + if (terseFilePaths.length) { + const { code } = await minify(versionedBundle, { + mangle: false, + keep_classnames: true, + }); + terse = code; + assert.string(terse); + console.log(`Minified bundle size: ${terse.length} bytes`); + } await fs.promises.mkdir('dist', { recursive: true }); - const bundleFilePaths = [ - 'dist/ses.cjs', - 'dist/ses.mjs', - 'dist/ses.umd.js', - 'dist/lockdown.cjs', - 'dist/lockdown.mjs', - 'dist/lockdown.umd.js', - ]; - const bundleFilePathsHermes = [ - `dist/ses${buildType ? `-${buildType}` : ''}.cjs`, - ]; - const terseFilePaths = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js']; - - await Promise.all( - buildType - ? [bundleFilePathsHermes] - : [ - ...bundleFilePaths.map(dest => write(dest, versionedBundle)), - ...terseFilePaths.map(dest => write(dest, terse)), - ], - ); + await Promise.all([ + ...bundleFilePaths.map(dest => write(dest, versionedBundle)), + ...terseFilePaths.map(dest => write(dest, terse)), + ]); // When importing types from a CJS package, TS v5.5+ considers the "module" // field in `ses`' `package.json`, so any .d.ts file is considered to be "ESM @@ -96,7 +100,7 @@ const writeBundle = async ({ buildType } = {}) => { }; const main = async () => { - await writeBundle({ buildType: process.env.SES_BUILD_TYPE || undefined }); + await writeBundle({ buildType: process.env.SES_BUILD_TYPE || 'vanilla' }); }; main().catch(err => {