Skip to content

Commit 965ea6f

Browse files
committed
docs(compartment-mapper): add internal documentation of hooks wiring
1 parent b61c93f commit 965ea6f

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Review of compartment-mapper hooks
2+
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+
14+
15+
[Type declarations for the hooks](./types/external.ts)
16+
17+
```mermaid
18+
graph TB
19+
20+
exports((public exports))
21+
exports -.- compartmentMapForNodeModules
22+
exports -.- mapNodeModules
23+
exports -.- loadLocation
24+
exports -.- importLocation
25+
exports -.- captureFromMap
26+
exports -.- importFromMap
27+
exports -.- loadFromMap
28+
exports -.- digestCompartmentMap
29+
exports -.- makeFunctor
30+
exports -.- makeScript
31+
32+
33+
subgraph "import-hook.js"
34+
moduleSourceHook{{moduleSourceHook}} -.- note5["for all module sources read"]
35+
makeDeferError --> moduleSourceHook
36+
makeImportHookMaker --> makeDeferError
37+
makeImportNowHookMaker --> makeDeferError
38+
makeImportNowHookMaker -- via importNowHook --> chooseModuleDescriptor --> executeLocalModuleSourceHook--> moduleSourceHook
39+
makeImportHookMaker --via importHook exitModule logic--> moduleSourceHook
40+
makeImportHookMaker --via importHook call--> chooseModuleDescriptor
41+
end
42+
43+
subgraph "node-modules.js"
44+
compartmentMapForNodeModules --> packageDataHook{{packageDataHook}} -.- note0["called once"]
45+
compartmentMapForNodeModules --> unknownCanonicalNameHook{{unknownCanonicalNameHook}} -.- note1["for all issues from policy;<br>after defaultUnknownCanonicalNameHandler"]
46+
compartmentMapForNodeModules --> translateGraph --> packageDependenciesHook{{packageDependenciesHook}} -.-note3["for all locatons in graph<br>after defaultPackageDependenciesFilter"]
47+
mapNodeModules --> compartmentMapForNodeModules
48+
49+
end
50+
51+
subgraph "digest.js"
52+
digestCompartmentMap --> translateCompartmentMap --> packageConnectionsHook{{packageConnectionsHook}} -.- note4["for all retained compartments"]
53+
end
54+
55+
subgraph "bundle.js"
56+
makeFunctor -- options:can include hooks ----------> mapNodeModules
57+
makeScript -- options:can include hooks ----------> mapNodeModules
58+
end
59+
60+
61+
subgraph "import-lite.js"
62+
importFromMap --> loadFromMap ---> makeImportHookMaker
63+
loadFromMap ----> makeImportNowHookMaker
64+
end
65+
66+
67+
subgraph "capture-lite.js"
68+
captureFromMap -----> makeImportHookMaker
69+
captureFromMap --> captureCompartmentMap --> digestCompartmentMap
70+
end
71+
72+
73+
subgraph "import.js"
74+
loadLocation ----------> mapNodeModules
75+
importLocation --> loadLocation
76+
loadLocation --> loadFromMap
77+
end
78+
79+
80+
%% STYLING
81+
classDef note fill:#999, stroke:#ccb
82+
class note0,note1,note2,note3,note4,note5 note
83+
84+
```
85+
86+
87+
88+
<details>
89+
<summary>Bundle and Archive bits of the diagram that don't use hooks</summary>
90+
91+
These are calling the functions accepting hooks but don't pass them
92+
93+
> [TODO]
94+
> copy-paste this to the main diagram whenever the connections are made.
95+
96+
```mermaid
97+
98+
graph TB
99+
100+
subgraph "bundle.js"
101+
makeFunctor -- options:transparently ----------> mapNodeModules
102+
makeScript -- options:transparently ----------> mapNodeModules
103+
makeFunctorFromMap -- no moduleSourceHook ----x makeImportHookMaker
104+
end
105+
106+
subgraph "bundle-lite.js"
107+
makeFunctorFromMap2 --no moduleSourceHook -----x makeImportHookMaker
108+
end
109+
110+
subgraph "archive-lite.js"
111+
digestFromMap -- no moduleSourceHook -----x makeImportHookMaker
112+
makeArchiveCompartmentMap --no packageConnectionsHook----x digestCompartmentMap
113+
end
114+
115+
subgraph "archive.js"
116+
archive(("multiple <br> methods")) --no hooks passed-----------x mapNodeModules
117+
end
118+
119+
```
120+
121+
</details>
122+
123+
124+

0 commit comments

Comments
 (0)