Skip to content

Commit

Permalink
feat(ses): Add XS variant of shim
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 27, 2024
1 parent 8ddbfc3 commit b071135
Show file tree
Hide file tree
Showing 8 changed files with 526 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/ses/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
10 changes: 10 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ User-visible changes in `ses`:
- Node 18, Node 20, and all browsers have `structuredClone`
- Node <= 16 have neither, but are also no longer supported by Endo.
- Now exports separate layer for console shim: `ses/console-shim.js`.

Incubating: Please do not rely on these features as they are under development
and subject to breaking changes that will not be signaled by semver.

- Adds permits for `ModuleSource`, either the native implementation or from
`@endo/module-source/shim.js`.
- Adds support for an XS-specific variant of the SES shim that is triggered
with the `xs` package export condition.
This version of SES preserves all the features of `Compartment` provided
uniquely by the SES shim, but with the `__native__` constructor option,
loses support for importing precompiled module records and gains support
for native `ModuleSource`.

# v1.8.0 (2024-08-27)

Expand Down
13 changes: 10 additions & 3 deletions packages/ses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
".": {
"import": {
"types": "./types.d.ts",
"xs": "./src-xs/index.js",
"default": "./index.js"
},
"require": {
Expand All @@ -57,8 +58,14 @@
},
"./tools.js": "./tools.js",
"./assert-shim.js": "./assert-shim.js",
"./lockdown-shim.js": "./lockdown-shim.js",
"./compartment-shim.js": "./compartment-shim.js",
"./lockdown-shim.js": {
"xs": "./src-xs/shim.js",
"default": "./lockdown-shim.js"
},
"./compartment-shim.js": {
"xs": "./src-xs/shim.js",
"default": "./compartment-shim.js"
},
"./console-shim.js": "./console-shim.js",
"./package.json": "./package.json"
},
Expand All @@ -74,7 +81,7 @@
"prepare": "npm run clean && npm run build",
"qt": "ava",
"test": "tsd && ava",
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js",
"test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js && node scripts/generate-test-xs.js && xst tmp/test-xs.js",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'"
},
"dependencies": {
Expand Down
55 changes: 55 additions & 0 deletions packages/ses/scripts/generate-test-xs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global process */
import 'ses';

Check failure on line 2 in packages/ses/scripts/generate-test-xs.js

View workflow job for this annotation

GitHub Actions / lint (18.x, ubuntu-latest)

'ses' should be listed in the project's dependencies. Run 'npm i -S ses' to add it

Check failure on line 2 in packages/ses/scripts/generate-test-xs.js

View workflow job for this annotation

GitHub Actions / lint (20.x, ubuntu-latest)

'ses' should be listed in the project's dependencies. Run 'npm i -S ses' to add it
import { promises as fs } from 'fs';
// Lerna does not like dependency cycles.
// With an explicit devDependency from module-source to compartment-mapper,
// the build script stalls before running every package's build script.
// yarn lerna run build
// Omitting the dependency from package.json solves the problem and works
// by dint of shared workspace node_modules.
// eslint-disable-next-line import/no-extraneous-dependencies
import { makeBundle } from '@endo/compartment-mapper/bundle.js';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ModuleSource } from '@endo/module-source';
import { fileURLToPath } from 'url';

const read = async location => {
const path = fileURLToPath(location);
return fs.readFile(path);
};
const write = async (location, content) => {
const path = fileURLToPath(location);
await fs.writeFile(path, content);
};

const main = async () => {
const meaningText = await fs.readFile(
fileURLToPath(new URL('../test/_meaning.js', import.meta.url)),
'utf8',
);
const meaningModuleSource = new ModuleSource(meaningText);

await fs.writeFile(
fileURLToPath(new URL('../tmp/_meaning.pre-mjs.json', import.meta.url)),
JSON.stringify(meaningModuleSource),
);

const xsPrelude = await makeBundle(
read,
new URL('../test/_xs.js', import.meta.url).href,
{
tags: new Set(['xs']),
},
);

await fs.mkdir(fileURLToPath(new URL('../tmp', import.meta.url)), {
recursive: true,
});

await write(new URL('../tmp/test-xs.js', import.meta.url).href, xsPrelude);
};

main().catch(err => {
console.error('Error running main:', err);
process.exitCode = 1;
});
Loading

0 comments on commit b071135

Please sign in to comment.