chore(compartment-mapper): Document introducing require.resolve support
MODIFY
packages/compartment-mapper/NEWS.md
packages/compartment-mapper/NEWS.md
User-visible changes to the compartment mapper:
+# Next release
+
+- Adds `require.resolve` support and provides its implementation from
+ `readPowers.requireResolve` if available.
# 0.7.6 (2022-06-10)

MODIFY
packages/compartment-mapper/README.md
packages/compartment-mapper/README.md
@@ -47,7 +47,22 @@ necessary).
The compartment mapper is also not coupled specifically to Node.js IO and does
not import any powerful modules like `fs`.
The user must provide `read` and `write` functions from whatever IO powers they
-have.
+have. These powers can be provided as individual functions or as objects
+carrying functions. `ReadPowers` has optional functions which can be used to
+unlock compatibility features. When `fileURLToPath` is available, `__dirname`
+and `__filename` will be provided to CJS modules. If `requireResolve` is
+available, it will be called whenever a CJS module calls `require.resolve()`.
+
+```js
+type ReadPowers = {
+ read: (location: string) => Promise<Uint8Array>,
+ canonical: (location: string) => Promise<string>,
+ computeSha512: { (bytes: Uint8Array) => string }?,
+ fileURLToPath: { (url: string | URL) => string }?,
+ pathToFileURL: { (path: string) => URL }?,
+ requireResolve: { (from: string, request: string, options?: {}) => string }?
+}
+```
> TODO
>

MODIFY
packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js
packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js
@@ -149,7 +149,7 @@ export const wrap = ({
} else {
require.resolve = freeze(specifier => {
const error = Error(
- `Cannot find module '${specifier}'\nPass ReadPowers with a requireResolve function to provide require.resolve`,
+ `Cannot find module '${specifier}'\nAdd requireResolve to Endo Compartment Mapper readPowers.`,
);
defineProperty(error, 'code', { value: 'MODULE_NOT_FOUND' });
throw error;

MODIFY
packages/compartment-mapper/test/test-cjs-compat.js
packages/compartment-mapper/test/test-cjs-compat.js
@@ -50,7 +50,7 @@ const assertFixture = (t, { namespace, testCategoryHint }) => {
"Cannot find module 'app'",
"Cannot find module 'fs'",
"Cannot find module 'nested-export/callBound'",
- 'Pass ReadPowers with a requireResolve function to provide require.resolve',
+ 'Add requireResolve to Endo Compartment Mapper readPowers.',
]);
}
t.pass();

chore(compartment-mapper): Document introducing require.resolve support