From b7d7b2388308e23217dc7d126ba081c465cf4b1f Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Wed, 20 Nov 2024 15:39:03 -0800 Subject: [PATCH] fix(compartment-mapper): Development condition only implies devDependencies for entry package --- packages/compartment-mapper/src/node-modules.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/compartment-mapper/src/node-modules.js b/packages/compartment-mapper/src/node-modules.js index a3f41ace75..d2582a75a0 100644 --- a/packages/compartment-mapper/src/node-modules.js +++ b/packages/compartment-mapper/src/node-modules.js @@ -360,7 +360,7 @@ const graphPackage = async ( for (const name of Object.keys(optionalDependencies)) { optionals.add(name); } - if (dev !== undefined && dev !== null ? dev : conditions.has('development')) { + if (dev) { assign(allDependencies, devDependencies); } @@ -849,7 +849,7 @@ const makeLanguageOptions = ({ /** * @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers * @param {string} packageLocation - * @param {Set} conditions + * @param {Set} conditionsOption * @param {object} packageDescriptor * @param {string} moduleSpecifier * @param {CompartmentMapForNodeModulesOptions} [options] @@ -858,22 +858,29 @@ const makeLanguageOptions = ({ export const compartmentMapForNodeModules = async ( readPowers, packageLocation, - conditions, + conditionsOption, packageDescriptor, moduleSpecifier, options = {}, ) => { - const { dev = undefined, commonDependencies = {}, policy } = options; + const { dev = false, commonDependencies = {}, policy } = options; const { maybeRead, canonical } = unpackReadPowers(readPowers); const languageOptions = makeLanguageOptions(options); + const conditions = new Set(conditionsOption || []); + + // dev is only set for the entry package, and implied by the development + // condition. + // The dev option is deprecated in favor of using conditions, since that + // covers more intentional behaviors of the development mode. + const graph = await graphPackages( maybeRead, canonical, packageLocation, conditions, packageDescriptor, - dev, + dev || (conditions && conditions.has('development')), commonDependencies, languageOptions, );