Skip to content

Commit a54cf5f

Browse files
committed
chore: refactor package dependency filter, makePackagePolicy
1 parent a629cc9 commit a54cf5f

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

packages/compartment-mapper/src/hooks.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# Review of compartment-mapper hooks
22

3-
4-
5-
| Hook Name | Description |
6-
|-------------------------- | --- |
7-
| `packageDataHook` | Receives all found package descriptors data before graph translation. |
8-
| `packageDependenciesHook` | Allows dynamic mutation of dependencies during node_modules graph translation. |
9-
| `unknownCanonicalNameHook`| Called when the policy references unknown canonical names, can suggest typos/similar names. |
10-
| `moduleSourceHook` | Invoked when a module source is created. |
11-
| `packageConnectionsHook` | Surfaces connections during digest. (ignored in archiving) |
12-
13-
3+
| Hook Name | Description |
4+
| -------------------------- | ------------------------------------------------------------------------------------------- |
5+
| `packageDataHook` | Receives all found package descriptors data before graph translation. |
6+
| `packageDependenciesHook` | Allows dynamic mutation of dependencies during node_modules graph translation. |
7+
| `unknownCanonicalNameHook` | Called when the policy references unknown canonical names, can suggest typos/similar names. |
8+
| `moduleSourceHook` | Invoked when a module source is created. |
9+
| `packageConnectionsHook` | Surfaces connections during digest. (ignored in archiving) |
1410

1511
[Type declarations for the hooks](./types/external.ts)
1612

@@ -83,8 +79,6 @@ class note0,note1,note2,note3,note4,note5 note
8379
8480
```
8581

86-
87-
8882
<details>
8983
<summary>Bundle and Archive bits of the diagram that don't use hooks</summary>
9084

@@ -119,6 +113,3 @@ end
119113
```
120114

121115
</details>
122-
123-
124-

packages/compartment-mapper/src/node-modules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const defaultUnknownCanonicalNameHandler = ({
111111
* @param {SomePolicy} policy - The policy to check against
112112
* @returns {Partial<{ dependencies: Set<CanonicalName> }> | void}
113113
*/
114-
const defaultPackageDependenciesFilter = (
114+
const prePackageDependenciesFilter = (
115115
{ canonicalName, dependencies, log },
116116
policy,
117117
) => {
@@ -880,7 +880,7 @@ const translateGraph = (
880880
// Call default filter first if policy exists
881881
let packageDependenciesHookResult;
882882
if (policy) {
883-
packageDependenciesHookResult = defaultPackageDependenciesFilter(
883+
packageDependenciesHookResult = prePackageDependenciesFilter(
884884
packageDependenciesHookInput,
885885
policy,
886886
);

packages/compartment-mapper/src/policy.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,11 @@ export const dependencyAllowedByPolicy = (canonicalName, packagePolicy) => {
153153
* @param {CanonicalName | typeof ATTENUATORS_COMPARTMENT} label
154154
* @param {object} [options] Options
155155
* @param {SomePolicy} [options.policy] User-supplied policy
156-
* @param {SomePackagePolicy} [options.packagePolicy] Package policy, if already known
157156
* @returns {SomePackagePolicy|undefined} Package policy from `policy` or empty object; returns `params.packagePolicy` if provided
158157
*/
159-
export const makePackagePolicy = (
160-
label,
161-
{ policy, packagePolicy = undefined } = {},
162-
) => {
163-
if (packagePolicy !== undefined) {
164-
return packagePolicy;
165-
}
158+
export const makePackagePolicy = (label, { policy } = {}) => {
159+
/** @type {SomePackagePolicy|undefined} */
160+
let packagePolicy;
166161
if (policy) {
167162
if (label === ATTENUATORS_COMPARTMENT) {
168163
packagePolicy = {

0 commit comments

Comments
 (0)