refactor: Rename transform-module to static-module-record text
MODIFY
packages/ses/README.md
packages/ses/README.md
@@ -382,8 +382,10 @@ top-level await.
Instead of the `StaticModuleRecord` constructor specified for the SES language,
the SES shim uses compiled static module records as a stand-in.
-These can be created with a third-party `StaticModuleRecord` that we omitted
-from the SES shim because it entrains a heavy dependency on a JavaScript parser.
+These can be created with a `StaticModuleRecord` constructor from a package
+like `@endo/static-module-record`.
+We omitted `StaticModuleRecord` from the SES shim because it entrains a heavy
+dependency on a JavaScript parser.
The shim depends upon a `StaticModuleRecord` constructor to analyze and
transform the source of an ECMAScript module (known as an ESM or a `.mjs` file)
into a JavaScript program suitable for evaluation with `compartment.evaluate`

MODIFY
packages/ses/package.json
packages/ses/package.json
"@agoric/babel-standalone": "^7.9.5",
"@agoric/eslint-config": "^0.1.0",
"@agoric/test262-runner": "~0.1.0",
- "@agoric/transform-module": "^0.4.1",
+ "@endo/static-module-record": "^0.1.0",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^6.1.0",
"ava": "^3.12.1",

MODIFY
packages/ses/test/import-commons.js
packages/ses/test/import-commons.js
-import { StaticModuleRecord } from './static-module-record.js';
+import { StaticModuleRecord } from '@endo/static-module-record';
// q, to quote strings in error messages.
const q = JSON.stringify;

DELETE
packages/ses/test/static-module-record.js
-/* eslint no-underscore-dangle: ["off"] */
-
-import babel from '@agoric/babel-standalone';
-import { makeModuleAnalyzer } from '@agoric/transform-module';
-import { freeze, keys } from '../src/commons.js';
-
-const analyzeModule = makeModuleAnalyzer(babel);
-
-/*
- * StaticModuleRecord captures the effort of parsing and analyzing module text
- * so a cache of StaticModuleRecords may be shared by multiple Compartments.
- */
-export function StaticModuleRecord(string, url) {
- const {
- imports,
- functorSource,
- liveExportMap,
- fixedExportMap,
- exportAlls,
- } = analyzeModule({ string, url });
- return freeze({
- imports: freeze([...keys(imports)].sort()),
- exports: freeze([...keys(liveExportMap), ...keys(fixedExportMap)]),
- reexports: freeze([...exportAlls]),
- __syncModuleProgram__: functorSource,
- __liveExportMap__: liveExportMap,
- __fixedExportMap__: fixedExportMap,
- });
-}

MODIFY
packages/ses/test/test-compartment-transforms.js
packages/ses/test/test-compartment-transforms.js
// Importing StaticModuleRecord before lockdown is necessary because of an
// incompatibility in the Babel dependency: There is a conflict with the
// prototype override mistake.
-import { StaticModuleRecord } from './static-module-record.js';
+import { StaticModuleRecord } from '@endo/static-module-record';
import '../index.js';
import './lockdown-safe.js';
// Placing the ava import last demonstrates that ava itself is compatible with SES

MODIFY
packages/ses/test/test-import-cjs.js
packages/ses/test/test-import-cjs.js
import test from 'ava';
+import { StaticModuleRecord } from '@endo/static-module-record';
import { resolveNode } from './node.js';
import '../index.js';
import { freeze, keys } from '../src/commons.js';
-import { StaticModuleRecord } from './static-module-record.js';
function heuristicAnalysis(moduleSource) {
const dependsUpon = {};
@@ -200,7 +200,7 @@ test('ESM imports CommonJS module as default', async t => {
);
}
if (specifier === './odd') {
- return StaticModuleRecord(
+ return new StaticModuleRecord(
`
import even from './even';
export default n => !even(n);
@@ -234,7 +234,7 @@ test('ESM imports CommonJS module by name', async t => {
);
}
if (specifier === './odd') {
- return StaticModuleRecord(
+ return new StaticModuleRecord(
`
import { even } from './even';
export default n => !even(n);
@@ -260,7 +260,7 @@ test('CommonJS module imports ESM as default', async t => {
const resolveHook = resolveNode;
const importHook = async specifier => {
if (specifier === './even') {
- return StaticModuleRecord(
+ return new StaticModuleRecord(
`
export default n => n % 2 === 0;
`,
@@ -294,7 +294,7 @@ test('CommonJS module imports ESM by name', async t => {
const resolveHook = resolveNode;
const importHook = async specifier => {
if (specifier === './even') {
- return StaticModuleRecord(
+ return new StaticModuleRecord(
`
export function even(n) {
return n % 2 === 0;

MODIFY
packages/ses/test/test-module-static-record.js
packages/ses/test/test-module-static-record.js
import test from 'ava';
import '../index.js';
-import { StaticModuleRecord } from './static-module-record.js';
+import { StaticModuleRecord } from '@endo/static-module-record';
lockdown();

DELETE
packages/ses/test/test-static-module-record-unit.js
-import test from 'ava';
-import { StaticModuleRecord } from './static-module-record.js';
-
-test('static module record constructor', t => {
- t.plan(1);
-
- const smr = new StaticModuleRecord('export default 10');
- t.deepEqual(smr.imports, []);
-});
-
-test('static module record constructor without new', t => {
- t.plan(1);
-
- const smr = StaticModuleRecord('export default 10');
- t.deepEqual(smr.imports, []);
-});
-
-test('module imports list', t => {
- t.plan(1);
-
- const smr = new StaticModuleRecord(`
- import namedExport from 'namedModule';
- import otherName from 'namedModule';
- import yetAnother from 'otherModule';
- `);
- t.deepEqual(smr.imports, ['namedModule', 'otherModule']);
-});

MODIFY
packages/static-module-record/package.json
packages/static-module-record/package.json
"keywords": ["ses", "StaticModuleRecord", "modules", "ESM"],
"author": "Agoric",
"license": "Apache-2.0",
- "homepage": "https://github.com/endojs/endo/tree/master/packages/transform-module#readme",
+ "homepage": "https://github.com/endojs/endo/tree/master/packages/static-module-record#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/endojs/endo.git"
"parsers": {
"js": "mjs"
},
- "main": "./dist/transform-module.cjs",
+ "main": "./dist/static-module-record.cjs",
"module": "./index.js",
- "browser": "./dist/transform-module.umd.js",
- "unpkg": "./dist/transform-module.umd.js",
+ "browser": "./dist/static-module-record.umd.js",
+ "unpkg": "./dist/static-module-record.umd.js",
"types": "./index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./index.js",
- "require": "./dist/transform-module.cjs",
- "browser": "./dist/transform-module.umd.js"
+ "require": "./dist/static-module-record.cjs",
+ "browser": "./dist/static-module-record.umd.js"
}
},
"scripts": {

refactor: Rename transform-module to static-module-record text