Skip to content

Commit 1cd1246

Browse files
committed
fix(compartment-mapper): remove unused type from ModuleSourceHookModuleSource
- Removes unused `ModuleSourceHook`'s "error" module source type. - Adds tests for specific behavior around exit modules - Fix a JSDoc import
1 parent 627352e commit 1cd1246

File tree

11 files changed

+154
-13
lines changed

11 files changed

+154
-13
lines changed

.changeset/whole-schools-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@endo/compartment-mapper': patch
3+
---
4+
5+
Remove unused "error" `ModuleSourceHookModuleSource` type.

packages/compartment-mapper/src/import-hook.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
* CompartmentModuleConfiguration,
4242
* LogOptions,
4343
* CanonicalName,
44-
* LocalModuleSource
44+
* LocalModuleSource,
45+
* ModuleSourceHook,
4546
* } from './types.js'
4647
*/
4748

@@ -262,7 +263,7 @@ const nominateCandidates = (moduleSpecifier, searchSuffixes) => {
262263
*
263264
* Preprocesses the fields for the hook.
264265
*
265-
* @param {import('./types.js').ModuleSourceHook | undefined} moduleSourceHook Hook function
266+
* @param {ModuleSourceHook | undefined} moduleSourceHook Hook function
266267
* @param {LocalModuleSource} moduleSource Original `LocalModuleSource` object
267268
* @param {CanonicalName} canonicalName Canonical name of the compartment/package
268269
* @param {LogOptions} options Options

packages/compartment-mapper/src/types/external.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,30 @@ export type PackageDependenciesHook = (params: {
9898
* The `moduleSource` property value for {@link ModuleSourceHook}
9999
*/
100100
export type ModuleSourceHookModuleSource =
101-
| {
102-
location: FileUrlString;
103-
language: Language;
104-
bytes: Uint8Array;
105-
imports?: string[] | undefined;
106-
exports?: string[] | undefined;
107-
reexports?: string[] | undefined;
108-
sha512?: string | undefined;
109-
}
110-
| { error: string }
111-
| { exit: string };
101+
| ModuleSourceHookFileModuleSource
102+
| ModuleSourceHookExitModuleSource;
103+
104+
/**
105+
* The `moduleSource` property value for {@link ModuleSourceHook} for a module
106+
* on disk
107+
*/
108+
export type ModuleSourceHookFileModuleSource = {
109+
location: FileUrlString;
110+
language: Language;
111+
bytes: Uint8Array;
112+
imports?: string[] | undefined;
113+
exports?: string[] | undefined;
114+
reexports?: string[] | undefined;
115+
sha512?: string | undefined;
116+
};
117+
118+
/**
119+
* The `moduleSource` property value for {@link ModuleSourceHook} for an exit
120+
* module (virtual)
121+
*/
122+
export type ModuleSourceHookExitModuleSource = {
123+
exit: string;
124+
};
112125

113126
/**
114127
* Hook executed when processing a module source.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# fixtures-module-source-hook
2+
3+
Fixtures for testing the behavior of `moduleSourceHook` when called against various project configurations.
4+
5+
## `app-implicit` — Implicit (Transitive) Dependency
6+
7+
Tests what happens when a package imports a dependency it does _not_ directly declare in its own `package.json`—a transitive dependency that's only reachable through an intermediary.
8+
9+
```mermaid
10+
graph TD
11+
app-implicit -- "declares dependency" --> dependency-a
12+
dependency-a -- "declares dependency" --> dependency-b
13+
app-implicit -. "imports (implicit)" .-> dependency-b
14+
```
15+
16+
`app-implicit` declares `dependency-a` as a direct dependency, and `dependency-a` in turn declares `dependency-b`. However, `app-implicit`'s `index.js` imports from `dependency-b` directly—a package it does not list in its own `dependencies`. In a flat `node_modules` layout (as used by these fixtures), `dependency-b` is resolvable despite not being a direct dependency.
17+
18+
The expectation is that `dependency-b` is loaded as an exit module from `app-implicit`.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/app-implicit/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/app-implicit/package.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/dependency-a/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/dependency-a/package.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/dependency-b/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compartment-mapper/test/fixtures-module-source-hook/node_modules/dependency-b/package.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)