diff --git a/packages/bundle-source/cache.js b/packages/bundle-source/cache.js index 5467ea43e5..f7715c7d68 100644 --- a/packages/bundle-source/cache.js +++ b/packages/bundle-source/cache.js @@ -284,7 +284,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { /** * @param {string} dest - * @param {{ format?: string, cacheOpts?: CacheOpts, cacheSourceMaps: boolean, dev?: boolean, log?: Logger }} options + * @param {{ format?: string, cacheOpts?: CacheOpts, cacheSourceMaps?: boolean, dev?: boolean, log?: Logger }} options * @param {(id: string) => Promise} loadModule * @param {number} [pid] * @param {number} [nonce] diff --git a/packages/bundle-source/src/bundle-source.js b/packages/bundle-source/src/bundle-source.js index a28c0c4463..24eea82dc3 100644 --- a/packages/bundle-source/src/bundle-source.js +++ b/packages/bundle-source/src/bundle-source.js @@ -2,8 +2,9 @@ const DEFAULT_MODULE_FORMAT = 'endoZipBase64'; const SUPPORTED_FORMATS = ['getExport', 'nestedEvaluate', 'endoZipBase64']; -/** @type {import('./types').BundleSource} */ -// @ts-ignore cast +/** + * @type {import('./types').BundleSourceGeneral} + */ const bundleSource = async ( startFilename, options = {}, @@ -13,8 +14,6 @@ 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) { @@ -52,4 +51,6 @@ const bundleSource = async ( } }; -export default bundleSource; +export default /** @satisfies {import('./types').BundleSource} */ ( + bundleSource +); diff --git a/packages/bundle-source/src/nested-evaluate-and-get-exports.js b/packages/bundle-source/src/nested-evaluate-and-get-exports.js index b2ae482e97..7b62072b3e 100644 --- a/packages/bundle-source/src/nested-evaluate-and-get-exports.js +++ b/packages/bundle-source/src/nested-evaluate-and-get-exports.js @@ -30,10 +30,7 @@ function longestCommonPrefix(strings) { } /** - * @template {'nestedEvaluate' | 'getExport'} T - * @param {string} startFilename - * @param {T} moduleFormat - * @param {any} powers + * @type {import('./types').BundleSourceWithFormat} */ export async function bundleNestedEvaluateAndGetExports( startFilename, @@ -47,7 +44,7 @@ export async function bundleNestedEvaluateAndGetExports( pathResolve = path.resolve, pathToFileURL = url.pathToFileURL, externals = [], - } = powers || {}; + } = /** @type {any} */ (powers || {}); const resolvedPath = pathResolve(startFilename); const bundle = await rollup({ input: resolvedPath, @@ -160,6 +157,7 @@ ${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`; @@ -284,6 +282,7 @@ function getExportWithNestedEvaluate(filePrefix) { return computeExports(entrypoint, { require: systemRequire, systemEval }, {}); } ${sourceMap}`; + // @ts-expect-error generic T not assignable to moduleFormat return harden({ moduleFormat, source, sourceMap }); } diff --git a/packages/bundle-source/src/zip-base64.js b/packages/bundle-source/src/zip-base64.js index b81102f497..e53e65b004 100644 --- a/packages/bundle-source/src/zip-base64.js +++ b/packages/bundle-source/src/zip-base64.js @@ -17,9 +17,12 @@ 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;