fix(compartment-mapper): Switch from Syrup to JSON
MODIFY
packages/compartment-mapper/package.json
packages/compartment-mapper/package.json
"dependencies": {
"@endo/cjs-module-analyzer": "^0.1.0",
"@endo/static-module-record": "^0.4.1",
- "@endo/syrup": "^0.1.0",
"@endo/zip": "^0.1.0",
"ses": "^0.12.7"
},

MODIFY
packages/compartment-mapper/src/bundle.js
packages/compartment-mapper/src/bundle.js
@@ -185,7 +185,7 @@ export const makeBundle = async (read, moduleLocation, options) => {
// Only support mjs format.
const problems = modules
- .filter(module => module.parser !== 'premjs')
+ .filter(module => module.parser !== 'pre-mjs-json')
.map(
({ moduleSpecifier, compartmentName, parser }) =>
`module ${moduleSpecifier} in compartment ${compartmentName} in language ${parser}`,

MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
@@ -15,8 +15,8 @@ const textDecoder = new TextDecoder();
/** @type {Record<string, ParseFn>} */
const parserForLanguage = {
- precjs: parsePreCjs,
- premjs: parsePreMjs,
+ 'pre-cjs-json': parsePreCjs,
+ 'pre-mjs-json': parsePreMjs,
json: parseJson,
};

MODIFY
packages/compartment-mapper/src/parse-archive-cjs.js
packages/compartment-mapper/src/parse-archive-cjs.js
// @ts-check
import { analyzeCommonJS } from '@endo/cjs-module-analyzer';
-import { encodeSyrup } from '@endo/syrup/encode';
+const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
const { freeze } = Object;
@@ -27,15 +27,17 @@ export const parseArchiveCjs = async (
location,
);
- const pre = encodeSyrup({
+ const pre = textEncoder.encode(
+ JSON.stringify({
imports,
exports,
reexports,
source: `(function (require, exports, module, __filename, __dirname) { ${source} //*/\n})\n//# sourceURL=${location}`,
- });
+ }),
+ );
return {
- parser: 'precjs',
+ parser: 'pre-cjs-json',
bytes: pre,
record: freeze({ imports, exports, reexports }),
};

MODIFY
packages/compartment-mapper/src/parse-archive-mjs.js
packages/compartment-mapper/src/parse-archive-mjs.js
// @ts-check
import { StaticModuleRecord } from '@endo/static-module-record';
-import { encodeSyrup } from '@endo/syrup/encode';
+const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
/** @type {ParseFn} */
@@ -14,9 +14,9 @@ export const parseArchiveMjs = async (
) => {
const source = textDecoder.decode(bytes);
const record = new StaticModuleRecord(source);
- const pre = encodeSyrup(record);
+ const pre = textEncoder.encode(JSON.stringify(record));
return {
- parser: 'premjs',
+ parser: 'pre-mjs-json',
bytes: pre,
record,
};

MODIFY
packages/compartment-mapper/src/parse-pre-cjs.js
packages/compartment-mapper/src/parse-pre-cjs.js
// @ts-check
-import { decodeSyrup } from '@endo/syrup/decode';
+import { parseLocatedJson } from './json.js';
const { freeze } = Object;
+const textDecoder = new TextDecoder();
+
/** @type {ParseFn} */
export const parsePreCjs = async (
bytes,
@@ -11,9 +13,11 @@ export const parsePreCjs = async (
location,
_packageLocation,
) => {
- const { source, imports, exports, reexports } = decodeSyrup(bytes, {
- name: location,
- });
+ const text = textDecoder.decode(bytes);
+ const { source, imports, exports, reexports } = parseLocatedJson(
+ text,
+ location,
+ );
/**
* @param {Object} moduleExports
@@ -50,7 +54,7 @@ export const parsePreCjs = async (
};
return {
- parser: 'precjs',
+ parser: 'pre-cjs-json',
bytes,
record: {
imports,

MODIFY
packages/compartment-mapper/src/parse-pre-mjs.js
packages/compartment-mapper/src/parse-pre-mjs.js
// @ts-check
-import { decodeSyrup } from '@endo/syrup/decode';
+import { parseLocatedJson } from './json.js';
+
+const textDecoder = new TextDecoder();
/** @type {ParseFn} */
export const parsePreMjs = async (
@@ -9,9 +11,10 @@ export const parsePreMjs = async (
location,
_packageLocation,
) => {
- const record = decodeSyrup(bytes, { name: location });
+ const text = textDecoder.decode(bytes);
+ const record = parseLocatedJson(text, location);
return {
- parser: 'premjs',
+ parser: 'pre-mjs-json',
bytes,
record,
};

MODIFY
packages/compartment-mapper/src/types.js
packages/compartment-mapper/src/types.js
*/
/**
- * @typedef {'mjs' | 'cjs' | 'json' | 'premjs' | 'precjs'} Language
+ * @typedef {'mjs' | 'cjs' | 'json' | 'pre-mjs-json' | 'pre-cjs-json'} Language
*/
// /////////////////////////////////////////////////////////////////////////////

MODIFY
packages/compartment-mapper/test/app.agar
packages/compartment-mapper/test/app.agar
Binary files a/packages/compartment-mapper/test/app.agar and b/packages/compartment-mapper/test/app.agar differ

fix(compartment-mapper): Switch from Syrup to JSON