Skip to content

Commit

Permalink
fix(compartment-mapper): bad types
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 14, 2024
1 parent 616219c commit 04f003b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion packages/compartment-mapper/src/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export const loadLocation = async (
moduleLocation,
options = {},
) => {
const { dev, tags, conditions = tags, commonDependencies, policy } = options;
const { dev, tags, commonDependencies, policy } = options;
// conditions are not present in SyncArchiveOptions
const conditions =
'conditions' in options ? options.conditions || tags : tags;
const compartmentMap = await mapNodeModules(readPowers, moduleLocation, {
dev,
conditions,
Expand Down
15 changes: 9 additions & 6 deletions packages/compartment-mapper/src/powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ const requiredSyncReadPowersProps = freeze(
/**
* Returns `true` if `value` is a {@link SyncReadPowers}
*
* @param {ReadPowers|ReadFn} value
* @param {ReadPowers|ReadFn|undefined} value
* @returns {value is SyncReadPowers}
*/
export const isSyncReadPowers = value =>
typeof value === 'object' &&
requiredSyncReadPowersProps.every(
prop => prop in value && typeof value[prop] === 'function',
Boolean(
value &&
typeof value === 'object' &&
requiredSyncReadPowersProps.every(
prop => prop in value && typeof value[prop] === 'function',
),
);

/**
Expand All @@ -83,11 +86,11 @@ export const isSyncReadPowers = value =>
*
* Used for human-friendly error messages
*
* @param {ReadPowers | ReadFn} value The value to check for missing properties.
* @param {ReadPowers | ReadFn} [value] The value to check for missing properties.
* @returns {SyncReadPowersProp[]}
*/
export const findInvalidSyncReadPowersProps = value => {
if (typeof value === 'function') {
if (!value || typeof value === 'function') {
return [...requiredSyncReadPowersProps];
}
return requiredSyncReadPowersProps.filter(
Expand Down
3 changes: 1 addition & 2 deletions packages/compartment-mapper/src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ const maybeReadDescriptorDefault = async (
* }>}
*/
export const search = async (readPowers, moduleLocation) => {
const { maybeRead } = unpackReadPowers(readPowers);
const { data, directory, location, packageDescriptorLocation } =
await searchDescriptor(moduleLocation, loc =>
maybeReadDescriptorDefault(maybeRead, loc),
maybeReadDescriptorDefault(readPowers, loc),
);

if (!data) {
Expand Down

0 comments on commit 04f003b

Please sign in to comment.