From db17743885e7a221eaf3f6cf5e811a1a1d97788f Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Wed, 8 Nov 2023 19:33:17 +0000 Subject: [PATCH 1/9] feat(ses): add SES version Tested - `npm run build` - `head dist/ses.cjs` --- packages/ses/scripts/bundle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index c1e77dfdf7..aeb4c4a1da 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -4,6 +4,7 @@ import fs from 'fs'; import { makeBundle } from '@endo/compartment-mapper/bundle.js'; import { minify } from 'terser'; import { fileURLToPath, pathToFileURL } from 'url'; +import packageJson from '../package.json' assert { type: 'json' }; const resolve = (rel, abs) => fileURLToPath(new URL(rel, abs).toString()); const root = new URL('..', import.meta.url).toString(); @@ -15,10 +16,11 @@ const write = async (target, content) => { }; const main = async () => { - const bundle = await makeBundle( + const version = packageJson.version; + const bundle = `// v${version}\n${await makeBundle( read, pathToFileURL(resolve('../index.js', import.meta.url)).toString(), - ); + )}`; const { code: terse } = await minify(bundle, { mangle: false, keep_classnames: true, From d5741a44450bb31150cf90e9a0d12eecc836503a Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:22:22 +0000 Subject: [PATCH 2/9] fix(ses): refactor import assert {type: json} to fs --- packages/ses/scripts/bundle.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index aeb4c4a1da..34cd9fef65 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -4,7 +4,8 @@ import fs from 'fs'; import { makeBundle } from '@endo/compartment-mapper/bundle.js'; import { minify } from 'terser'; import { fileURLToPath, pathToFileURL } from 'url'; -import packageJson from '../package.json' assert { type: 'json' }; + +const textDecoder = new TextDecoder(); const resolve = (rel, abs) => fileURLToPath(new URL(rel, abs).toString()); const root = new URL('..', import.meta.url).toString(); @@ -16,7 +17,13 @@ const write = async (target, content) => { }; const main = async () => { + const bytes = await fs.promises.readFile( + fileURLToPath(`${root}/package.json`), + ); + const text = textDecoder.decode(bytes); + const packageJson = JSON.parse(text); const version = packageJson.version; + const bundle = `// v${version}\n${await makeBundle( read, pathToFileURL(resolve('../index.js', import.meta.url)).toString(), From 44f9de6508c88b54180a59c9c2e58200f260c116 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:39:30 +0000 Subject: [PATCH 3/9] refactor(ses): format 'v' prefix to git/npm tag style --- packages/ses/scripts/bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index 34cd9fef65..c19519eb8e 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -24,7 +24,7 @@ const main = async () => { const packageJson = JSON.parse(text); const version = packageJson.version; - const bundle = `// v${version}\n${await makeBundle( + const bundle = `// ses@${version}\n${await makeBundle( read, pathToFileURL(resolve('../index.js', import.meta.url)).toString(), )}`; From 651fbee8cc8de97ee6c7f9913e9c0b59ac420fe8 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:09:02 +0000 Subject: [PATCH 4/9] refactor(ses): split bundle variable (bundle, version) Resolve: https://github.com/endojs/endo/pull/1854#discussion_r1388392602 --- packages/ses/scripts/bundle.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index c19519eb8e..dc061cb304 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -24,28 +24,30 @@ const main = async () => { const packageJson = JSON.parse(text); const version = packageJson.version; - const bundle = `// ses@${version}\n${await makeBundle( + 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.cjs', versionedBundle); + await write('dist/ses.mjs', versionedBundle); + await write('dist/ses.umd.js', versionedBundle); 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.cjs', versionedBundle); + await write('dist/lockdown.mjs', versionedBundle); + await write('dist/lockdown.umd.js', versionedBundle); await write('dist/lockdown.umd.min.js', terse); }; From 37c65e46777b6a4f3d75a35753d3ae75f296cc5b Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:20:31 +0000 Subject: [PATCH 5/9] refactor(ses): remove TextDecoder global Co-authored-by: Christopher Hiller --- packages/ses/scripts/bundle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index dc061cb304..57109977f7 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -17,10 +17,10 @@ const write = async (target, content) => { }; const main = async () => { - const bytes = await fs.promises.readFile( + const text = await fs.promises.readFile( fileURLToPath(`${root}/package.json`), + 'utf8' ); - const text = textDecoder.decode(bytes); const packageJson = JSON.parse(text); const version = packageJson.version; From 70a48299a2649008e07c28de684667d3a810a6dc Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:27:49 +0000 Subject: [PATCH 6/9] refactor(ses): format bundle file --- packages/ses/scripts/bundle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index 57109977f7..2374ebc374 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -19,7 +19,7 @@ const write = async (target, content) => { const main = async () => { const text = await fs.promises.readFile( fileURLToPath(`${root}/package.json`), - 'utf8' + 'utf8', ); const packageJson = JSON.parse(text); const version = packageJson.version; From ececb6fb63755063000781d71c7924336e76e3e9 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:29:50 +0000 Subject: [PATCH 7/9] refactor(ses): remove stale var instance of TextDecoder global class --- packages/ses/scripts/bundle.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index 2374ebc374..61cd72682b 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -5,8 +5,6 @@ import { makeBundle } from '@endo/compartment-mapper/bundle.js'; import { minify } from 'terser'; import { fileURLToPath, pathToFileURL } from 'url'; -const textDecoder = new TextDecoder(); - const resolve = (rel, abs) => fileURLToPath(new URL(rel, abs).toString()); const root = new URL('..', import.meta.url).toString(); From 0a649b88d12528a17032cb55f4ac2e0018baa828 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:06:17 +0000 Subject: [PATCH 8/9] refactor(ses): make go vroom faster --- packages/ses/scripts/bundle.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index 61cd72682b..8ca86a0479 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -38,15 +38,21 @@ const main = async () => { console.log(`Minified bundle size: ${terse.length} bytes`); await fs.promises.mkdir('dist', { recursive: true }); - await write('dist/ses.cjs', versionedBundle); - await write('dist/ses.mjs', versionedBundle); - await write('dist/ses.umd.js', versionedBundle); - await write('dist/ses.umd.min.js', terse); - - await write('dist/lockdown.cjs', versionedBundle); - await write('dist/lockdown.mjs', versionedBundle); - await write('dist/lockdown.umd.js', versionedBundle); - await write('dist/lockdown.umd.min.js', terse); + + const bundles = [ + 'dist/ses.cjs', + 'dist/ses.mjs', + 'dist/ses.umd.js', + 'dist/lockdown.cjs', + 'dist/lockdown.mjs', + 'dist/lockdown.umd.js', + ]; + const terses = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js']; + + await Promise.all([ + ...bundles.map(dest => write(dest, versionedBundle)), + ...terses.map(dest => write(dest, terse)), + ]); }; main().catch(err => { From a3c3cc8ac8cc461b50b05c3d40071574d88b9799 Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:06:39 +0000 Subject: [PATCH 9/9] refactor(ses): rename vars --- packages/ses/scripts/bundle.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ses/scripts/bundle.js b/packages/ses/scripts/bundle.js index 8ca86a0479..d34fe238f2 100644 --- a/packages/ses/scripts/bundle.js +++ b/packages/ses/scripts/bundle.js @@ -39,7 +39,7 @@ const main = async () => { await fs.promises.mkdir('dist', { recursive: true }); - const bundles = [ + const bundleFilePaths = [ 'dist/ses.cjs', 'dist/ses.mjs', 'dist/ses.umd.js', @@ -47,11 +47,11 @@ const main = async () => { 'dist/lockdown.mjs', 'dist/lockdown.umd.js', ]; - const terses = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js']; + const terseFilePaths = ['dist/ses.umd.min.js', 'dist/lockdown.umd.min.js']; await Promise.all([ - ...bundles.map(dest => write(dest, versionedBundle)), - ...terses.map(dest => write(dest, terse)), + ...bundleFilePaths.map(dest => write(dest, versionedBundle)), + ...terseFilePaths.map(dest => write(dest, terse)), ]); };