Skip to content

Commit

Permalink
fix: Restore Agoric SDK compatibility for sync (merge #2159)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored Mar 19, 2024
2 parents 4222776 + a1a3c3a commit 4fa8662
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions packages/bundle-source/src/bundle-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
const DEFAULT_MODULE_FORMAT = 'endoZipBase64';
const SUPPORTED_FORMATS = ['getExport', 'nestedEvaluate', 'endoZipBase64'];

/**
* @type {import('./types').BundleSourceGeneral}
*/
/** @type {import('./types').BundleSource} */
// @ts-ignore cast
const bundleSource = async (
startFilename,
options = {},
Expand All @@ -14,6 +13,8 @@ const bundleSource = async (
if (typeof options === 'string') {
options = { format: options };
}
/** @type {{ format: import('./types').ModuleFormat }} */
// @ts-expect-error cast (xxx params)
const { format: moduleFormat = DEFAULT_MODULE_FORMAT } = options;

switch (moduleFormat) {
Expand Down Expand Up @@ -51,6 +52,4 @@ const bundleSource = async (
}
};

export default /** @satisfies {import('./types').BundleSource} */ (
bundleSource
);
export default bundleSource;
9 changes: 5 additions & 4 deletions packages/bundle-source/src/nested-evaluate-and-get-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ function longestCommonPrefix(strings) {
}

/**
* @type {import('./types').BundleSourceWithFormat}
* @template {'nestedEvaluate' | 'getExport'} T
* @param {string} startFilename
* @param {T} moduleFormat
* @param {any} powers
*/
export async function bundleNestedEvaluateAndGetExports(
startFilename,
Expand All @@ -44,7 +47,7 @@ export async function bundleNestedEvaluateAndGetExports(
pathResolve = path.resolve,
pathToFileURL = url.pathToFileURL,
externals = [],
} = /** @type {any} */ (powers || {});
} = powers || {};
const resolvedPath = pathResolve(startFilename);
const bundle = await rollup({
input: resolvedPath,
Expand Down Expand Up @@ -157,7 +160,6 @@ ${sourceBundle[entrypoint]}
return module.exports;
}
${sourceMap}`;
// @ts-expect-error generic T not assignable to moduleFormat
return harden({ moduleFormat, source, sourceMap });
} else if (moduleFormat === 'nestedEvaluate') {
sourceMap = `//# sourceURL=${DEFAULT_FILE_PREFIX}-preamble.js\n`;
Expand Down Expand Up @@ -282,7 +284,6 @@ function getExportWithNestedEvaluate(filePrefix) {
return computeExports(entrypoint, { require: systemRequire, systemEval }, {});
}
${sourceMap}`;
// @ts-expect-error generic T not assignable to moduleFormat
return harden({ moduleFormat, source, sourceMap });
}

Expand Down
5 changes: 1 addition & 4 deletions packages/bundle-source/src/zip-base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
const readPowers = makeReadPowers({ fs, url, crypto });

/**
* @type {import('./types').BundleSourceWithOptions}
*/
export async function bundleZipBase64(
startFilename,
options,
options = {},
grantedPowers = {},
) {
const { dev = false, cacheSourceMaps = false, commonDependencies } = options;
Expand Down
4 changes: 3 additions & 1 deletion packages/ses-ava/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
"dependencies": {
"@endo/env-options": "^1.1.1",
"@endo/init": "^1.0.4",
"ava": "^6.1.2",
"ses": "^1.3.0"
},
"peerDependencies": {
"ava": "^5.3.0|^6.1.2"
},
"devDependencies": {
"babel-eslint": "^10.0.3",
"c8": "^7.14.0",
Expand Down

0 comments on commit 4fa8662

Please sign in to comment.