Skip to content

Commit

Permalink
chore: peer review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Sep 19, 2024
1 parent 7c9f54d commit 7386c8f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/compartment-mapper/src/import-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ const findRedirect = ({
compartmentDescriptors,
)) {
if (someDescriptorName !== ATTENUATORS_COMPARTMENT) {
const moduleSpecifierUrl = `${new URL(absoluteModuleSpecifier, packageLocation)}`;
const moduleSpecifierUrl = new URL(
absoluteModuleSpecifier,
packageLocation,
).href;
if (!compartmentDescriptor.location.startsWith(moduleSpecifierUrl)) {
if (moduleSpecifierUrl.startsWith(someDescriptor.location)) {
// compartmentDescriptor is a dependency of someDescriptor; we
// can use that compartment
if (someDescriptor.name in compartmentDescriptor.modules) {
return {
specifier: absoluteModuleSpecifier,
compartment: compartments[someDescriptorName],
};
}
// compartmentDescriptor is a dependent of someSomeDescriptor;
// this is more dubious but a common pattern
if (compartmentDescriptor.name in someDescriptor.modules) {
// similarly, if the relationship is true the other way around.
// We could allow requiring any compartment contents by absolute path, but requiring
// a relationship between compartments is a reasonable limitation.
if (
someDescriptor.name in compartmentDescriptor.modules ||
compartmentDescriptor.name in someDescriptor.modules
) {
return {
specifier: absoluteModuleSpecifier,
compartment: compartments[someDescriptorName],
Expand Down Expand Up @@ -637,8 +638,9 @@ export function makeImportNowHookMaker(
let { policy } = compartmentDescriptor;
policy = policy || create(null);

// associates modules with compartment descriptors based on policy
// which wouldn't otherwise be there
// Associates modules with compartment descriptors based on policy
// in cases where the association was not made when building the
// compartment map but is indicated by the policy.
if ('packages' in policy && typeof policy.packages === 'object') {
for (const [packageName, packagePolicyItem] of entries(policy.packages)) {
if (
Expand Down

0 comments on commit 7386c8f

Please sign in to comment.