Fix importing CJS, RESM, and ESM
MODIFY
package.json
package.json
"depcheck": "lerna run --no-bail depcheck",
"update": "lernaupdate --dedupe",
"prettier": "lerna run prettier",
- "lint": "lerna run lint",
+ "lint": "yes | yarn clean && lerna run lint",
"lint-fix": "lerna run --no-bail lint-fix",
"test": "lerna run test",
"test262": "lerna run test262",

MODIFY
packages/ses-integration-test/scaffolding/rollup/ses.js
packages/ses-integration-test/scaffolding/rollup/ses.js
+// eslint-disable-next-line import/no-unresolved
import SES from "ses";
export default SES;

MODIFY
packages/ses/package.json
packages/ses/package.json
"author": "Agoric",
"license": "Apache-2.0",
"type": "module",
- "main": "./src/lockdown-shim.js",
+ "main": "./dist/ses.cjs",
"exports": {
- "import": "./src/lockdown-shim.js",
- "require": "./dist/ses.cjs.js",
+ "import": "./src/main.js",
+ "require": "./dist/ses.cjs",
"browser": "./dist/ses.umd.js"
},
"scripts": {
"depcheck": "depcheck",
- "lint": "eslint '**/*.js'",
- "lint-fix": "eslint --fix '**/*.js'",
- "test": "tap --no-esm --no-coverage --reporter spec 'test/**/*.test.js'",
+ "clean": "rm -rf dist",
+ "lint": "yarn clean && eslint '**/*.js'",
+ "lint-fix": "yarn clean && eslint --fix '**/*.js' '**/*.mjs' '**/*.cjs'",
+ "test": "yarn build && tap --no-esm --no-coverage --reporter spec 'test/**/*.test.js'",
"test262": "tap --no-esm --no-coverage --reporter spec test262/*.js",
"build": "rollup --config rollup.config.js",
"demo": "http-server -o /demos"

MODIFY
packages/ses/rollup.config.js
packages/ses/rollup.config.js
@@ -6,11 +6,11 @@ export default [
input: 'src/main.js',
output: [
{
- file: 'dist/ses.esm.js',
+ file: 'dist/ses.mjs',
format: 'esm',
},
{
- file: 'dist/ses.cjs.js',
+ file: 'dist/ses.cjs',
format: 'cjs',
},
],

ADD
packages/ses/test/package.test.js
+import tap from 'tap';
+import { spawn } from 'child_process';
+import { dirname, join } from 'path';
+
+const { test } = tap;
+
+const cwd = join(dirname(new URL(import.meta.url).pathname), 'package');
+
+const table = {
+ cjs: {
+ args: ['test.cjs'],
+ code: 0,
+ },
+ resm: {
+ args: ['-r', 'esm', 'test.js'],
+ code: 0,
+ },
+ esm: {
+ args: ['test.mjs'],
+ code: 0,
+ },
+ 'who tests the tests': {
+ args: ['-e', 'throw "barff"'],
+ code: 1,
+ },
+};
+
+const stdio = ['ignore', 'ignore', 'ignore'];
+
+for (const [name, { args, code }] of Object.entries(table)) {
+ test(name, t => {
+ t.plan(1);
+ const child = spawn('node', args, { cwd, stdio });
+ child.on('close', actualCode => {
+ t.equals(actualCode, code);
+ });
+ });
+}

ADD
packages/ses/test/package/package.json
+{
+ "private": true,
+ "dependencies": {
+ "ses": "file:../.."
+ }
+}

ADD
packages/ses/test/package/test.cjs
+// node test.cjs
+
+const { lockdown } = require('ses');
+
+lockdown();
+console.log(Compartment);

ADD
packages/ses/test/package/test.js
+// node -r esm test.js
+
+// eslint-disable-next-line import/no-unresolved
+import { lockdown } from 'ses';
+
+lockdown();
+// eslint-disable-next-line no-undef
+console.log(Compartment);

ADD
packages/ses/test/package/test.mjs
+// node test.mjs
+
+import { lockdown } from 'ses';
+
+lockdown();
+console.log(Compartment);

Fix importing CJS, RESM, and ESM (#217)