Skip to content

Commit

Permalink
feat(bundle-source): Add dev mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Jun 21, 2021
1 parent 43dea96 commit 866b98a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 9 additions & 7 deletions packages/bundle-source/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,11 @@ async function transformSource(
return babelGenerate(ast, { retainLines: true });
}

async function bundleZipBase64(startFilename, powers = {}) {
// TODO endoZipBase64 format does not yet support the tildot transform, as
// Compartment Mapper does not yet reveal a pre-archive transform facility.
// Such a facility might be better served by a transform specified in
// individual package.jsons and driven by the compartment mapper.
async function bundleZipBase64(startFilename, dev, powers = {}) {
const base = new URL(`file://${process.cwd()}`).toString();
const entry = new URL(startFilename, base).toString();
const bytes = await makeArchive({ ...readPowers, ...powers }, entry, {
dev,
moduleTransforms: {
async mjs(sourceBytes) {
const source = textDecoder.decode(sourceBytes);
Expand Down Expand Up @@ -387,14 +384,19 @@ ${sourceMap}`;
/** @type {BundleSource} */
export default async function bundleSource(
startFilename,
moduleFormat = DEFAULT_MODULE_FORMAT,
options = {},
powers = undefined,
) {
if (typeof options === 'string') {
options = { format: options };
}
const { format: moduleFormat = DEFAULT_MODULE_FORMAT, dev = false } = options;

if (!SUPPORTED_FORMATS.includes(moduleFormat)) {
throw Error(`moduleFormat ${moduleFormat} is not implemented`);
}
if (moduleFormat === 'endoZipBase64') {
return bundleZipBase64(startFilename, powers);
return bundleZipBase64(startFilename, dev, powers);
}
return bundleNestedEvaluateAndGetExports(startFilename, moduleFormat, powers);
}
9 changes: 8 additions & 1 deletion packages/bundle-source/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
/**
* @callback BundleSource
* @param {string} startFilename - the filepath to start the bundling from
* @param {ModuleFormat=} moduleFormat
* @param {(ModuleFormat | BundleOptions)=} moduleFormat
* @param {Object=} powers
* @param {ReadFn=} powers.read
* @param {CanonicalFn=} powers.canonical
*/

/**
* @typedef {Object} BundleOptions
* @property {ModuleFormat} [format]
* @property {boolean} [dev] - development mode, for test bundles that need
* access to devDependencies of the entry package.
*/

/**
* @callback ReadFn
* @param {string} location
Expand Down

0 comments on commit 866b98a

Please sign in to comment.