diff --git a/packages/bundle-source/NEWS.md b/packages/bundle-source/NEWS.md index a110edc50f..f86e77ebef 100644 --- a/packages/bundle-source/NEWS.md +++ b/packages/bundle-source/NEWS.md @@ -11,8 +11,8 @@ - Adds a `-f,--format` command flag to specify other module formats. - Adds a new `endoScript` module format. - Adds a no-cache, bundle-to-stdout mode. -- Adds a `-t,--tag` command flag to specify export/import conditions like - `"browser"`. +- Adds a `-C,--condition` command flag to specify export/import conditions like + `"development"` or `"browser"`. # v3.2.1 (2024-03-20) diff --git a/packages/bundle-source/cache.js b/packages/bundle-source/cache.js index 6506dbfc7d..74220fa760 100644 --- a/packages/bundle-source/cache.js +++ b/packages/bundle-source/cache.js @@ -20,7 +20,7 @@ const { Fail, quote: q } = assert; * @property {number} bundleSize * @property {boolean} noTransforms * @property {ModuleFormat} format - * @property {string[]} tags + * @property {string[]} conditions * @property {{ relative: string, absolute: string }} moduleSource * @property {Array<{ relativePath: string, mtime: string, size: number }>} contents */ @@ -53,6 +53,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { * @param {object} [options] * @param {boolean} [options.noTransforms] * @param {string[]} [options.tags] + * @param {string[]} [options.conditions] * @param {ModuleFormat} [options.format] */ const add = async (rootPath, targetName, log = defaultLog, options = {}) => { @@ -61,10 +62,10 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { const { noTransforms = false, format = 'endoZipBase64', - tags = [], + conditions = [], } = options; - tags.sort(); + conditions.sort(); const statsByPath = new Map(); @@ -93,7 +94,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { const bundle = await bundleSource( rootPath, - { ...bundleOptions, noTransforms, format }, + { ...bundleOptions, noTransforms, format, conditions }, { ...readPowers, read: loggedRead, @@ -123,7 +124,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { ), noTransforms, format, - tags, + conditions, }; await metaWr.atomicWriteText(JSON.stringify(meta, null, 2)); @@ -154,6 +155,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { * @param {boolean} [options.noTransforms] * @param {ModuleFormat} [options.format] * @param {string[]} [options.tags] + * @param {string[]} [options.conditions] * @returns {Promise} */ const validate = async ( @@ -167,9 +169,9 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { const { noTransforms: expectedNoTransforms, format: expectedFormat, - tags: expectedTags = [], + conditions: expectedConditions = [], } = options; - expectedTags.sort(); + expectedConditions.sort(); if (!meta) { const metaJson = await loadMetaText(targetName, log); if (metaJson) { @@ -194,15 +196,15 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { moduleSource: { absolute: moduleSource }, format = 'endoZipBase64', noTransforms = false, - tags = [], + conditions = [], } = meta; - tags.sort(); + conditions.sort(); assert.equal(bundleFileName, toBundleName(targetName)); assert.equal(format, expectedFormat); assert.equal(noTransforms, expectedNoTransforms); - assert.equal(tags.length, expectedTags.length); - tags.forEach((tag, index) => { - assert.equal(tag, expectedTags[index]); + assert.equal(conditions.length, expectedConditions.length); + conditions.forEach((tag, index) => { + assert.equal(tag, expectedConditions[index]); }); if (rootOpt) { moduleSource === cwd.neighbor(rootOpt).absolute() || @@ -250,7 +252,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { * @param {object} [options] * @param {boolean} [options.noTransforms] * @param {ModuleFormat} [options.format] - * @param {string[]} [options.tags] + * @param {string[]} [options.conditions] * @returns {Promise} */ const validateOrAdd = async ( @@ -269,7 +271,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { meta = await validate(targetName, rootPath, log, meta, { format: options.format, noTransforms: options.noTransforms, - tags: options.tags, + conditions: options.conditions, }); const { bundleTime, @@ -277,7 +279,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { contents, noTransforms, format = 'endoZipBase64', - tags = [], + conditions = [], } = meta; log( `${wr}`, @@ -291,8 +293,8 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { noTransforms ? 'w/o transforms' : 'with transforms', 'with format', format, - 'and tags', - JSON.stringify(tags), + 'and conditions', + JSON.stringify(conditions), ); } catch (invalid) { meta = undefined; @@ -309,7 +311,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { contents, noTransforms, format = 'endoZipBase64', - tags = [], + conditions = [], } = meta; log( `${wr}`, @@ -322,8 +324,8 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { noTransforms ? 'w/o transforms' : 'with transforms', 'with format', format, - 'and tags', - JSON.stringify(tags), + 'and conditions', + JSON.stringify(conditions), ); } @@ -338,7 +340,7 @@ export const makeBundleCache = (wr, cwd, readPowers, opts) => { * @param {object} [options] * @param {boolean} [options.noTransforms] * @param {ModuleFormat} [options.format] - * @param {string[]} [options.tags] + * @param {string[]} [options.conditions] */ const load = async ( rootPath, diff --git a/packages/bundle-source/src/main.js b/packages/bundle-source/src/main.js index 4f31983c19..11bdd02c0e 100644 --- a/packages/bundle-source/src/main.js +++ b/packages/bundle-source/src/main.js @@ -11,7 +11,7 @@ const USAGE = `\ bundle-source [-Tft] bundle-source [-Tft] --cache-js|--cache-json ( )* -f,--format endoZipBase64*|nestedEvaluate|getExport - -t,--tag (browser, node, &c) + -C,--condition (browser, node, development, &c) -T,--no-transforms`; const options = /** @type {const} */ ({ @@ -33,9 +33,9 @@ const options = /** @type {const} */ ({ short: 'f', multiple: false, }, - tag: { + condition: { type: 'string', - short: 't', + short: 'C', multiple: true, }, // deprecated @@ -58,7 +58,7 @@ export const main = async (args, { loadModule, pid, log }) => { const { values: { format: moduleFormat = 'endoZipBase64', - tag: tags = [], + condition: conditions = [], 'no-transforms': noTransforms, 'cache-json': cacheJson, 'cache-js': cacheJs, @@ -94,7 +94,7 @@ export const main = async (args, { loadModule, pid, log }) => { const bundle = await bundleSource(entryPath, { noTransforms, format, - tags, + conditions, }); process.stdout.write(JSON.stringify(bundle)); process.stdout.write('\n'); @@ -125,7 +125,7 @@ export const main = async (args, { loadModule, pid, log }) => { await cache.validateOrAdd(bundleRoot, bundleName, undefined, { noTransforms, format, - tags, + conditions, }); } }; diff --git a/packages/bundle-source/src/script.js b/packages/bundle-source/src/script.js index 2e430927b9..3e08e8347b 100644 --- a/packages/bundle-source/src/script.js +++ b/packages/bundle-source/src/script.js @@ -37,7 +37,7 @@ export async function bundleScript( dev = false, cacheSourceMaps = false, noTransforms = false, - tags = [], + conditions = [], commonDependencies, } = options; const powers = { ...readPowers, ...grantedPowers }; @@ -70,7 +70,7 @@ export async function bundleScript( const source = await makeBundle(powers, entry, { dev, - tags, + conditions, commonDependencies, parserForLanguage, moduleTransforms, diff --git a/packages/bundle-source/src/types.js b/packages/bundle-source/src/types.js index 836f1b4326..087e0adab7 100644 --- a/packages/bundle-source/src/types.js +++ b/packages/bundle-source/src/types.js @@ -70,7 +70,7 @@ export {}; * @property {boolean} [noTransforms] - when true, generates a bundle with the * original sources instead of SES-shim specific ESM and CJS. This may become * default in a future major version. - * @property {string[]} [tags] - conditions for package.json conditional + * @property {string[]} [conditions] - conditions for package.json conditional * exports and imports. */ diff --git a/packages/bundle-source/src/zip-base64.js b/packages/bundle-source/src/zip-base64.js index e7bd1e29d8..dbf7cb0089 100644 --- a/packages/bundle-source/src/zip-base64.js +++ b/packages/bundle-source/src/zip-base64.js @@ -22,7 +22,7 @@ const readPowers = makeReadPowers({ fs, url, crypto }); * @param {boolean} [options.dev] * @param {boolean} [options.cacheSourceMaps] * @param {boolean} [options.noTransforms] - * @param {string[]} [options.tags] + * @param {string[]} [options.condditions] * @param {Record} [options.commonDependencies] * @param {object} [grantedPowers] * @param {(bytes: string | Uint8Array) => string} [grantedPowers.computeSha512] @@ -40,7 +40,7 @@ export async function bundleZipBase64( dev = false, cacheSourceMaps = false, noTransforms = false, - tags = [], + conditions = [], commonDependencies, } = options; const powers = { ...readPowers, ...grantedPowers }; @@ -73,7 +73,7 @@ export async function bundleZipBase64( const compartmentMap = await mapNodeModules(powers, entry, { dev, - tags, + conditions, commonDependencies, }); diff --git a/packages/bundle-source/test/tags-command.test.js b/packages/bundle-source/test/tags-command.test.js index ead4ccd88b..c0a4065ff8 100644 --- a/packages/bundle-source/test/tags-command.test.js +++ b/packages/bundle-source/test/tags-command.test.js @@ -40,11 +40,11 @@ const bundleSource = async (...args) => { return JSON.parse(bundleText); }; -test('bundle-source with --format and --tag', async t => { +test('bundle-source with --format and --condition', async t => { const compartment = new Compartment(); { const bundle = await bundleSource( - '--tag', + '--condition', 'b', '--format', 'endoScript', @@ -55,7 +55,7 @@ test('bundle-source with --format and --tag', async t => { } { const bundle = await bundleSource( - '--tag', + '--condition', 'a', '--format', 'endoScript',