feat(ses): Replace Rollup with Endo bundler
MODIFY
packages/ses/package.json
packages/ses/package.json
"test": "yarn build && yarn ava",
"qt": "yarn ava",
"test:platform-compatability": "node test/package/test.cjs",
- "build": "rollup --config rollup.config.js && (cd dist; cp ses.cjs lockdown.cjs; cp ses.mjs lockdown.mjs; cp ses.umd.js lockdown.umd.js; cp ses.umd.min.js lockdown.umd.min.js)",
+ "build": "mkdir -p dist && node scripts/bundle.js",
"demo": "http-server -o /demos"
},
"dependencies": {
},
"devDependencies": {
"@agoric/babel-standalone": "^7.9.5",
+ "@agoric/compartment-mapper": "^0.2.4",
"@agoric/eslint-config": "^0.1.0",
"@agoric/test262-runner": "~0.1.0",
"@endo/static-module-record": "^0.1.0",
"http-server": "^0.12.1",
"prettier": "^1.19.1",
"rollup-plugin-terser": "^5.1.3",
- "sinon": "8.0.4"
+ "sinon": "8.0.4",
+ "terser": "^4.8.0"
},
"ava": {
"files": [

DELETE
packages/ses/rollup.config.js
-import resolve from '@rollup/plugin-node-resolve';
-import commonjs from '@rollup/plugin-commonjs';
-import { terser } from 'rollup-plugin-terser';
-
-export default [
- {
- input: 'index.js',
- output: [
- {
- file: 'dist/ses.mjs',
- format: 'esm',
- },
- {
- file: 'dist/ses.cjs',
- format: 'cjs',
- },
- ],
- plugins: [resolve(), commonjs()],
- },
- {
- input: 'index.js',
- output: {
- file: 'dist/ses.umd.js',
- format: 'umd',
- name: 'SES',
- },
- plugins: [resolve(), commonjs()],
- },
- {
- input: 'index.js',
- output: {
- file: 'dist/ses.umd.min.js',
- format: 'umd',
- name: 'SES',
- },
- plugins: [resolve(), commonjs(), terser()],
- },
-];

ADD
packages/ses/scripts/bundle.js
+import '../index.js';
+import fs from 'fs';
+import { makeBundle } from '@agoric/compartment-mapper';
+import prettier from 'prettier';
+import terser from 'terser';
+
+const resolve = (rel, abs) => new URL(rel, abs).toString();
+const root = resolve('..', import.meta.url);
+
+const read = async location => fs.promises.readFile(new URL(location).pathname);
+const write = async (target, content) => {
+ const location = resolve(target, root);
+ await fs.promises.writeFile(new URL(location).pathname, content);
+};
+
+(async () => {
+ const bundle = await makeBundle(
+ read,
+ resolve('../index.js', import.meta.url),
+ );
+ const pretty = prettier.format(bundle);
+ const { code: terse } = terser.minify(bundle);
+
+ console.log(`Bundle size: ${pretty.length} bytes`);
+ console.log(`Minified bundle size: ${terse.length} bytes`);
+
+ await write('dist/ses.cjs', pretty);
+ await write('dist/ses.mjs', pretty);
+ await write('dist/ses.umd.js', pretty);
+ await write('dist/ses.umd.min.js', terse);
+
+ await write('dist/lockdown.cjs', pretty);
+ await write('dist/lockdown.mjs', pretty);
+ await write('dist/lockdown.umd.js', pretty);
+ await write('dist/lockdown.umd.min.js', terse);
+})();

feat(ses): Replace Rollup with Endo bundler