Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@endo/compartment-mapper

Package Overview
Dependencies
Maintainers
5
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endo/compartment-mapper - npm Package Compare versions

Comparing version 0.8.5 to 0.9.1

14

package.json
{
"name": "@endo/compartment-mapper",
"version": "0.8.5",
"version": "0.9.1",
"description": "The compartment mapper assembles Node applications in a sandbox",

@@ -46,6 +46,6 @@ "keywords": [

"dependencies": {
"@endo/cjs-module-analyzer": "^0.2.32",
"@endo/static-module-record": "^0.7.20",
"@endo/zip": "^0.2.32",
"ses": "^0.18.5"
"@endo/cjs-module-analyzer": "^0.2.34",
"@endo/static-module-record": "^0.8.1",
"@endo/zip": "^0.2.34",
"ses": "^0.18.7"
},

@@ -56,3 +56,3 @@ "devDependencies": {

"c8": "^7.14.0",
"eslint": "^8.44.0",
"eslint": "^8.46.0",
"eslint-config-airbnb-base": "^15.0.0",

@@ -98,3 +98,3 @@ "eslint-config-prettier": "^8.8.0",

},
"gitHead": "106da55b8bcea3067f70c29c357806f3f2e55c52"
"gitHead": "b38361616f968415291b089dcca75cc4a2672a35"
}

@@ -194,10 +194,2 @@ # Compartment mapper

>
> The absence of `exports` implies that _all_ of the modules in the package are
> valid entries.
> The compartment mapper does not yet support packages that do not name all of
> their exports in `package.json`, which is unfortunately a significant portion
> of packages in `npm`.
> TODO
>
> A future version may also respect the `imports` property.

@@ -309,2 +301,22 @@

# Source Maps
The `makeArchive`, `makeAndHashArchive`, and `writeArchive` tools can receive a
`sourceMapHook` as one of its options.
The `sourceMapHook` receives a source map `string` for every module it
archives, along with details `compartment`, `module`, `location`, and `sha512`.
The `compartment` is the fully-qualified file URL of the package root.
The `module` is the package-relative module specifier.
The `location` is the fully-qualified file URL of the module file.
The `sha512`, if present, was generated with the `computeSha512` power from the
generated module bytes.
The functions `importArchive`, `loadArchive`, and `parseArchive`
tools can receive a `computeSourceMapLocation` option that recives the same
details as above and must return a URL.
These will be appended to each module from the archive, for debugging purposes.
The `@endo/bundle-source` and `@endo/import-bundle` tools integrate source maps
for an end-to-end debugging experience.
# Design

@@ -566,2 +578,3 @@

[LavaMoat]: https://github.com/LavaMoat/lavamoat

@@ -568,0 +581,0 @@ [Compartments]: ../ses/README.md#compartment

@@ -305,2 +305,3 @@ // @ts-check

policy = undefined,
sourceMapHook = undefined,
} = options || {};

@@ -354,2 +355,3 @@ const { read, computeSha512 } = unpackReadPowers(powers);

exitModuleImportHook: consolidatedExitModuleImportHook,
sourceMapHook,
});

@@ -356,0 +358,0 @@ // Induce importHook to record all the necessary modules to import the given module specifier.

@@ -7,2 +7,3 @@ export function makeBundle(read: ReadFn, moduleLocation: string, options?: {

searchSuffixes?: string[] | undefined;
sourceMapHook?: import("./types.js").SourceMapHook | undefined;
} | undefined): Promise<string>;

@@ -9,0 +10,0 @@ export function writeBundle(write: WriteFn, read: ReadFn, bundleLocation: string, moduleLocation: string, options?: import("./types.js").ArchiveOptions | undefined): Promise<void>;

@@ -170,2 +170,3 @@ // @ts-check

* @param {Array<string>} [options.searchSuffixes]
* @param {import('./types.js').SourceMapHook} [options.sourceMapHook]
* @returns {Promise<string>}

@@ -180,2 +181,3 @@ */

commonDependencies,
sourceMapHook = undefined,
} = options || {};

@@ -217,2 +219,3 @@ const tags = new Set(tagsOption);

entryModuleSpecifier,
sourceMapHook,
});

@@ -219,0 +222,0 @@

@@ -8,22 +8,7 @@ export function parseArchive(archiveBytes: Uint8Array, archiveLocation?: string | undefined, options?: {

computeSourceLocation?: import("./types.js").ComputeSourceLocationHook | undefined;
} | undefined): Promise<Application>;
export function loadArchive(readPowers: ReadFn | ReadPowers, archiveLocation: string, options?: import("./types.js").LoadArchiveOptions | undefined): Promise<Application>;
export function importArchive(readPowers: ReadFn | ReadPowers, archiveLocation: string, options: ExecuteOptions & LoadArchiveOptions): Promise<object>;
export type ImportHook = import('ses').ImportHook;
export type ParserImplementation = import('./types.js').ParserImplementation;
export type CompartmentDescriptor = import('./types.js').CompartmentDescriptor;
export type Application = import('./types.js').Application;
export type CompartmentMapDescriptor = import('./types.js').CompartmentMapDescriptor;
export type ExecuteFn = import('./types.js').ExecuteFn;
export type ReadFn = import('./types.js').ReadFn;
export type ReadPowers = import('./types.js').ReadPowers;
export type HashFn = import('./types.js').HashFn;
export type StaticModuleType = import('./types.js').StaticModuleType;
export type ComputeSourceLocationHook = import('./types.js').ComputeSourceLocationHook;
export type LoadArchiveOptions = import('./types.js').LoadArchiveOptions;
export type ExecuteOptions = import('./types.js').ExecuteOptions;
export type ImportHookMaker = import('./types.js').ImportHookMaker;
export type ExitModuleImportHook = import('./types.js').ExitModuleImportHook;
export type DeferredAttenuatorsProvider = import('./types.js').DeferredAttenuatorsProvider;
computeSourceMapLocation?: import("./types.js").ComputeSourceMapLocationHook | undefined;
} | undefined): Promise<import('./types.js').Application>;
export function loadArchive(readPowers: import('./types.js').ReadFn | import('./types.js').ReadPowers, archiveLocation: string, options?: import("./types.js").LoadArchiveOptions | undefined): Promise<import('./types.js').Application>;
export function importArchive(readPowers: import('./types.js').ReadFn | import('./types.js').ReadPowers, archiveLocation: string, options: import('./types.js').ExecuteOptions & import('./types.js').LoadArchiveOptions): Promise<object>;
export type CompartmentConstructor = typeof Compartment;
//# sourceMappingURL=import-archive.d.ts.map
// @ts-check
/* eslint no-shadow: "off" */
/** @typedef {import('ses').ImportHook} ImportHook */
/** @typedef {import('./types.js').ParserImplementation} ParserImplementation */
/** @typedef {import('./types.js').CompartmentDescriptor} CompartmentDescriptor */
/** @typedef {import('./types.js').Application} Application */
/** @typedef {import('./types.js').CompartmentMapDescriptor} CompartmentMapDescriptor */
/** @typedef {import('./types.js').ExecuteFn} ExecuteFn */
/** @typedef {import('./types.js').ReadFn} ReadFn */
/** @typedef {import('./types.js').ReadPowers} ReadPowers */
/** @typedef {import('./types.js').HashFn} HashFn */
/** @typedef {import('./types.js').StaticModuleType} StaticModuleType */
/** @typedef {import('./types.js').ComputeSourceLocationHook} ComputeSourceLocationHook */
/** @typedef {import('./types.js').LoadArchiveOptions} LoadArchiveOptions */
/** @typedef {import('./types.js').ExecuteOptions} ExecuteOptions */
/** @typedef {import('./types.js').ImportHookMaker} ImportHookMaker */
/** @typedef {import('./types.js').ExitModuleImportHook} ExitModuleImportHook */
/** @typedef {import('./types.js').DeferredAttenuatorsProvider} DeferredAttenuatorsProvider */
import { ZipReader } from '@endo/zip';

@@ -43,3 +26,3 @@ import { link } from './link.js';

/** @type {Record<string, ParserImplementation>} */
/** @type {Record<string, import('./types.js').ParserImplementation>} */
const parserForLanguage = {

@@ -55,3 +38,3 @@ 'pre-cjs-json': parserPreCjs,

* @param {string} errorMessage - error to throw on execute
* @returns {StaticModuleType}
* @returns {import('./types.js').StaticModuleType}
*/

@@ -77,8 +60,9 @@ const postponeErrorToExecute = errorMessage => {

* @param {(path: string) => Uint8Array} get
* @param {Record<string, CompartmentDescriptor>} compartments
* @param {Record<string, import('./types.js').CompartmentDescriptor>} compartments
* @param {string} archiveLocation
* @param {HashFn} [computeSha512]
* @param {ComputeSourceLocationHook} [computeSourceLocation]
* @param {ExitModuleImportHook} [exitModuleImportHook]
* @returns {ImportHookMaker}
* @param {import('./types.js').HashFn} [computeSha512]
* @param {import('./types.js').ComputeSourceLocationHook} [computeSourceLocation]
* @param {import('./types.js').ExitModuleImportHook} [exitModuleImportHook]
* @param {import('./types.js').ComputeSourceMapLocationHook} [computeSourceMapLocation]
* @returns {import('./types.js').ImportHookMaker}
*/

@@ -92,5 +76,6 @@ const makeArchiveImportHookMaker = (

exitModuleImportHook = undefined,
computeSourceMapLocation = undefined,
) => {
// per-assembly:
/** @type {ImportHookMaker} */
/** @type {import('./types.js').ImportHookMaker} */
const makeImportHook = ({

@@ -106,3 +91,3 @@ packageLocation,

const { modules } = compartmentDescriptor;
/** @type {ImportHook} */
/** @type {import('ses').ImportHook} */
const importHook = async moduleSpecifier => {

@@ -198,2 +183,15 @@ // per-module:

let sourceMapUrl;
if (
computeSourceMapLocation !== undefined &&
module.sha512 !== undefined
) {
sourceMapUrl = computeSourceMapLocation({
compartment: packageLocation,
module: moduleSpecifier,
location: sourceLocation,
sha512: module.sha512,
});
}
// eslint-disable-next-line no-await-in-loop

@@ -205,2 +203,5 @@ const { record } = await parse(

packageLocation,
{
sourceMapUrl,
},
);

@@ -245,8 +246,9 @@ return { record, specifier: moduleSpecifier };

* @param {string} [options.expectedSha512]
* @param {HashFn} [options.computeSha512]
* @param {import('./types.js').HashFn} [options.computeSha512]
* @param {Record<string, unknown>} [options.modules]
* @param {ExitModuleImportHook} [options.importHook]
* @param {import('./types.js').ExitModuleImportHook} [options.importHook]
* @param {CompartmentConstructor} [options.Compartment]
* @param {ComputeSourceLocationHook} [options.computeSourceLocation]
* @returns {Promise<Application>}
* @param {import('./types.js').ComputeSourceLocationHook} [options.computeSourceLocation]
* @param {import('./types.js').ComputeSourceMapLocationHook} [options.computeSourceMapLocation]
* @returns {Promise<import('./types.js').Application>}
*/

@@ -262,2 +264,3 @@ export const parseArchive = async (

computeSourceLocation = undefined,
computeSourceMapLocation = undefined,
Compartment = DefaultCompartment,

@@ -331,2 +334,3 @@ modules = undefined,

compartmentExitModuleImportHook,
computeSourceMapLocation,
);

@@ -357,3 +361,3 @@ // A weakness of the current Compartment design is that the `modules` map

/** @type {ExecuteFn} */
/** @type {import('./types.js').ExecuteFn} */
const execute = async options => {

@@ -380,2 +384,3 @@ const {

compartmentExitModuleImportHook,
computeSourceMapLocation,
);

@@ -402,6 +407,6 @@ const { compartment, pendingJobsPromise } = link(compartmentMap, {

/**
* @param {ReadFn | ReadPowers} readPowers
* @param {import('./types.js').ReadFn | import('./types.js').ReadPowers} readPowers
* @param {string} archiveLocation
* @param {LoadArchiveOptions} [options]
* @returns {Promise<Application>}
* @param {import('./types.js').LoadArchiveOptions} [options]
* @returns {Promise<import('./types.js').Application>}
*/

@@ -414,3 +419,8 @@ export const loadArchive = async (

const { read, computeSha512 } = unpackReadPowers(readPowers);
const { expectedSha512, computeSourceLocation, modules } = options;
const {
expectedSha512,
computeSourceLocation,
modules,
computeSourceMapLocation,
} = options;
const archiveBytes = await read(archiveLocation);

@@ -422,2 +432,3 @@ return parseArchive(archiveBytes, archiveLocation, {

modules,
computeSourceMapLocation,
});

@@ -427,5 +438,5 @@ };

/**
* @param {ReadFn | ReadPowers} readPowers
* @param {import('./types.js').ReadFn | import('./types.js').ReadPowers} readPowers
* @param {string} archiveLocation
* @param {ExecuteOptions & LoadArchiveOptions} options
* @param {import('./types.js').ExecuteOptions & import('./types.js').LoadArchiveOptions} options
* @returns {Promise<object>}

@@ -432,0 +443,0 @@ */

@@ -5,3 +5,3 @@ export function exitModuleImportHookMaker({ modules, exitModuleImportHook, }: {

}): ExitModuleImportHook | undefined;
export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, entryCompartmentName, entryModuleSpecifier, exitModuleImportHook, }: {
export function makeImportHookMaker(readPowers: ReadFn | ReadPowers, baseLocation: string, { sources, compartmentDescriptors, archiveOnly, computeSha512, searchSuffixes, sourceMapHook, entryCompartmentName, entryModuleSpecifier, exitModuleImportHook, }: {
sources?: import("./types.js").Sources | undefined;

@@ -15,2 +15,3 @@ compartmentDescriptors?: Record<string, import("./types.js").CompartmentDescriptor> | undefined;

exitModuleImportHook?: import("./types.js").ExitModuleImportHook | undefined;
sourceMapHook?: import("./types.js").SourceMapHook | undefined;
}): ImportHookMaker;

@@ -17,0 +18,0 @@ export type ImportHook = import('ses').ImportHook;

@@ -116,2 +116,3 @@ // @ts-check

* @param {ExitModuleImportHook} [options.exitModuleImportHook]
* @param {import('./types.js').SourceMapHook} [options.sourceMapHook]
* @returns {ImportHookMaker}

@@ -128,2 +129,3 @@ */

searchSuffixes = nodejsConventionSearchSuffixes,
sourceMapHook = undefined,
entryCompartmentName,

@@ -260,3 +262,3 @@ entryModuleSpecifier,

const { read } = unpackReadPowers(readPowers);
const { maybeRead } = unpackReadPowers(readPowers);

@@ -302,6 +304,6 @@ for (const candidateSpecifier of candidates) {

// eslint-disable-next-line no-await-in-loop
const moduleBytes = await read(moduleLocation).catch(
_error => undefined,
);
const moduleBytes = await maybeRead(moduleLocation);
if (moduleBytes !== undefined) {
/** @type {string | undefined} */
let sourceMap;
// eslint-disable-next-line no-await-in-loop

@@ -315,2 +317,7 @@ const envelope = await parse(

readPowers,
sourceMapHook:
sourceMapHook &&
(nextSourceMapObject => {
sourceMap = JSON.stringify(nextSourceMapObject);
}),
},

@@ -342,2 +349,11 @@ );

sha512 = computeSha512(transformedBytes);
if (sourceMapHook !== undefined && sourceMap !== undefined) {
sourceMapHook(sourceMap, {
compartment: packageLocation,
module: candidateSpecifier,
location: moduleLocation,
sha512,
});
}
}

@@ -344,0 +360,0 @@

@@ -94,9 +94,21 @@ // @ts-check

let sourceMap;
if (has(moduleTransforms, language)) {
try {
({ bytes, parser: language } = await moduleTransforms[language](
({
bytes,
parser: language,
sourceMap,
} = await moduleTransforms[language](
bytes,
specifier,
location,
packageLocation,
{
// At time of writing, sourceMap is always undefined, but keeping
// it here is more resilient if the surrounding if block becomes a
// loop for multi-step transforms.
sourceMap,
},
));

@@ -119,3 +131,6 @@ } catch (err) {

const { parse } = parserForLanguage[language];
return parse(bytes, specifier, location, packageLocation, options);
return parse(bytes, specifier, location, packageLocation, {
sourceMap,
...options,
});
};

@@ -122,0 +137,0 @@ };

@@ -1,2 +0,2 @@

export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers, packageLocation: string, tags: Set<string>, packageDescriptor: object, moduleSpecifier: string, options?: {
export function compartmentMapForNodeModules(readPowers: ReadFn | ReadPowers | MaybeReadPowers, packageLocation: string, tags: Set<string>, packageDescriptor: object, moduleSpecifier: string, options?: {
dev?: boolean | undefined;

@@ -8,2 +8,3 @@ commonDependencies?: object;

export type ReadFn = import('./types.js').ReadFn;
export type MaybeReadFn = import('./types.js').MaybeReadFn;
export type CanonicalFn = import('./types.js').CanonicalFn;

@@ -15,2 +16,3 @@ export type CompartmentMapDescriptor = import('./types.js').CompartmentMapDescriptor;

export type ReadPowers = import('./types.js').ReadPowers;
export type MaybeReadPowers = import('./types.js').MaybeReadPowers;
/**

@@ -17,0 +19,0 @@ * The graph is an intermediate object model that the functions of this module

@@ -6,2 +6,3 @@ // @ts-check

/** @typedef {import('./types.js').ReadFn} ReadFn */
/** @typedef {import('./types.js').MaybeReadFn} MaybeReadFn */
/** @typedef {import('./types.js').CanonicalFn} CanonicalFn */

@@ -13,2 +14,3 @@ /** @typedef {import('./types.js').CompartmentMapDescriptor} CompartmentMapDescriptor */

/** @typedef {import('./types.js').ReadPowers} ReadPowers */
/** @typedef {import('./types.js').MaybeReadPowers} MaybeReadPowers */

@@ -88,11 +90,9 @@ /**

/**
* @param {ReadFn} read
* @param {MaybeReadFn} maybeRead
* @param {string} packageLocation
* @returns {Promise<object>}
*/
const readDescriptor = async (read, packageLocation) => {
const readDescriptor = async (maybeRead, packageLocation) => {
const descriptorLocation = resolveLocation('package.json', packageLocation);
const descriptorBytes = await read(descriptorLocation).catch(
_error => undefined,
);
const descriptorBytes = await maybeRead(descriptorLocation);
if (descriptorBytes === undefined) {

@@ -108,7 +108,7 @@ return undefined;

* @param {Record<string, object>} memo
* @param {ReadFn} read
* @param {MaybeReadFn} maybeRead
* @param {string} packageLocation
* @returns {Promise<object>}
*/
const readDescriptorWithMemo = async (memo, read, packageLocation) => {
const readDescriptorWithMemo = async (memo, maybeRead, packageLocation) => {
let promise = memo[packageLocation];

@@ -118,3 +118,3 @@ if (promise !== undefined) {

}
promise = readDescriptor(read, packageLocation);
promise = readDescriptor(maybeRead, packageLocation);
memo[packageLocation] = promise;

@@ -487,3 +487,3 @@ return promise;

*
* @param {ReadFn} read
* @param {MaybeReadFn} maybeRead
* @param {CanonicalFn} canonical

@@ -499,3 +499,3 @@ * @param {string} packageLocation - location of the main package.

const graphPackages = async (
read,
maybeRead,
canonical,

@@ -514,3 +514,3 @@ packageLocation,

const readDescriptor = packageLocation =>
readDescriptorWithMemo(memo, read, packageLocation);
readDescriptorWithMemo(memo, maybeRead, packageLocation);

@@ -708,3 +708,3 @@ if (mainPackageDescriptor !== undefined) {

/**
* @param {ReadFn | ReadPowers} readPowers
* @param {ReadFn | ReadPowers | MaybeReadPowers} readPowers
* @param {string} packageLocation

@@ -729,5 +729,5 @@ * @param {Set<string>} tags

const { dev = false, commonDependencies, policy } = options;
const { read, canonical } = unpackReadPowers(readPowers);
const { maybeRead, canonical } = unpackReadPowers(readPowers);
const graph = await graphPackages(
read,
maybeRead,
canonical,

@@ -734,0 +734,0 @@ packageLocation,

@@ -19,2 +19,3 @@ /// <reference types="node" />

read: (location: string) => Promise<Buffer>;
maybeRead: (location: string) => Promise<Buffer | undefined>;
fileURLToPath: (location: string) => string;

@@ -21,0 +22,0 @@ pathToFileURL: ((path: string) => string) | typeof import("url").pathToFileURL;

@@ -43,2 +43,4 @@ // @ts-check

let readMutex = Promise.resolve(undefined);
/**

@@ -48,10 +50,33 @@ * @param {string} location

const read = async location => {
const promise = readMutex;
let release = Function.prototype;
readMutex = new Promise(resolve => {
release = resolve;
});
await promise;
const path = fileURLToPath(location);
try {
const path = fileURLToPath(location);
// We await here to ensure that we release the mutex only after
// completing the read.
return await fs.promises.readFile(path);
} catch (error) {
throw Error(error.message);
} finally {
release(undefined);
}
};
/**
* @param {string} location
*/
const maybeRead = location =>
read(location).catch(error => {
if (
error.message.startsWith('ENOENT: ') ||
error.message.startsWith('EISDIR: ')
) {
return undefined;
}
throw error;
});
const requireResolve = (from, specifier, options) =>

@@ -102,2 +127,3 @@ createRequire(from).resolve(specifier, options);

read,
maybeRead,
fileURLToPath,

@@ -104,0 +130,0 @@ pathToFileURL,

@@ -11,8 +11,14 @@ // @ts-check

bytes,
_specifier,
_location,
_packageLocation,
specifier,
sourceUrl,
packageLocation,
options = {},
) => {
const { sourceMap, sourceMapHook } = options;
const source = textDecoder.decode(bytes);
const record = new StaticModuleRecord(source);
const record = new StaticModuleRecord(source, {
sourceMap,
sourceMapUrl: sourceUrl,
sourceMapHook,
});
const pre = textEncoder.encode(JSON.stringify(record));

@@ -19,0 +25,0 @@ return {

@@ -11,7 +11,14 @@ // @ts-check

_specifier,
location,
sourceUrl,
_packageLocation,
options = {},
) => {
const { sourceMap, sourceMapHook } = options;
const source = textDecoder.decode(bytes);
const record = new StaticModuleRecord(source, location);
const record = new StaticModuleRecord(source, {
sourceUrl,
sourceMap,
sourceMapUrl: sourceUrl,
sourceMapHook,
});
return {

@@ -18,0 +25,0 @@ parser: 'mjs',

@@ -13,7 +13,13 @@ // @ts-check

_packageLocation,
{ sourceMapUrl },
) => {
const text = textDecoder.decode(bytes);
const record = parseLocatedJson(text, location);
// eslint-disable-next-line no-underscore-dangle
record.__syncModuleProgram__ += `//# sourceURL=${location}\n`;
if (sourceMapUrl) {
// eslint-disable-next-line no-underscore-dangle
record.__syncModuleProgram__ += `//# sourceMappingURL=${sourceMapUrl}\n`;
} else {
// eslint-disable-next-line no-underscore-dangle
record.__syncModuleProgram__ += `//# sourceURL=${location}\n`;
}
return {

@@ -20,0 +26,0 @@ parser: 'pre-mjs-json',

@@ -1,5 +0,2 @@

export function unpackReadPowers(powers: ReadFn | ReadPowers): ReadPowers;
export type ReadFn = import('./types.js').ReadFn;
export type CanonicalFn = import('./types.js').CanonicalFn;
export type ReadPowers = import('./types.js').ReadPowers;
export function unpackReadPowers(powers: import('./types.js').ReadFn | import('./types.js').ReadPowers | import('./types.js').MaybeReadPowers): import('./types.js').MaybeReadPowers;
//# sourceMappingURL=powers.d.ts.map
// @ts-check
/** @typedef {import('./types.js').ReadFn} ReadFn */
/** @typedef {import('./types.js').CanonicalFn} CanonicalFn */
/** @typedef {import('./types.js').ReadPowers} ReadPowers */
/** @type {CanonicalFn} */
/** @type {import('./types.js').CanonicalFn} */
const canonicalShim = async path => path;
/**
* @param {ReadFn | ReadPowers} powers
* @returns {ReadPowers}
* @param {import('./types.js').ReadFn | import('./types.js').ReadPowers | import('./types.js').MaybeReadPowers} powers
* @returns {import('./types.js').MaybeReadPowers}
*/
export const unpackReadPowers = powers => {
/** @type {import('./types.js').ReadFn | undefined} */
let read;
/** @type {import('./types.js').MaybeReadFn | undefined} */
let maybeRead;
/** @type {import('./types.js').CanonicalFn | undefined} */
let canonical;
if (typeof powers === 'function') {
return {
read: powers,
canonical: canonicalShim,
};
read = powers;
} else {
({ read, maybeRead, canonical } = powers);
}
return powers;
if (canonical === undefined) {
canonical = canonicalShim;
}
if (maybeRead === undefined) {
/** @param {string} path */
maybeRead = path =>
/** @type {import('./types.js').ReadFn} */ (read)(path).catch(
_error => undefined,
);
}
return {
...powers,
read,
maybeRead,
canonical,
};
};

@@ -101,2 +101,6 @@ export type FinalStaticModuleType = import('ses').FinalStaticModuleType;

/**
* A resolution of `undefined` indicates `ENOENT` or the equivalent.
*/
export type MaybeReadFn = (location: string) => Promise<Uint8Array | undefined>;
/**
* Returns a canonical URL for a given URL, following redirects or symbolic

@@ -122,2 +126,3 @@ * links if any exist along the path.

};
export type MaybeReadPowers = ReadPowers | object;
export type HashPowers = {

@@ -142,6 +147,21 @@ read: ReadFn;

export type ImportHookMaker = (options: ImportHookMakerOptions) => ImportHook;
export type ParseFn = (bytes: Uint8Array, specifier: string, location: string, packageLocation: string, options?: object, readPowers?: ReadFn | ReadPowers | undefined) => Promise<{
export type SourceMapHookDetails = {
compartment: string;
module: string;
location: string;
sha512: string;
};
export type SourceMapHook = (sourceMap: string, details: SourceMapHookDetails) => any;
export type ComputeSourceMapLocationDetails = {
compartment: string;
module: string;
location: string;
sha512: string;
};
export type ComputeSourceMapLocationHook = (details: ComputeSourceMapLocationDetails) => string;
export type ParseFn = (bytes: Uint8Array, specifier: string, location: string, packageLocation: string, options?: object, sourceMap?: string | undefined, sourceMapUrl?: string | undefined, readPowers?: ReadFn | ReadPowers | undefined) => Promise<{
bytes: Uint8Array;
parser: Language;
record: FinalStaticModuleType;
sourceMap?: string;
}>;

@@ -163,2 +183,3 @@ /**

computeSourceLocation?: ComputeSourceLocationHook | undefined;
computeSourceMapLocation?: ComputeSourceMapLocationHook | undefined;
};

@@ -184,5 +205,6 @@ export type ExecuteOptions = {

export type ModuleTransforms = Record<string, ModuleTransform>;
export type ModuleTransform = (bytes: Uint8Array, specifier: string, location: string, packageLocation: string) => Promise<{
export type ModuleTransform = (bytes: Uint8Array, specifier: string, location: string, packageLocation: string, options?: object, sourceMap?: string | undefined) => Promise<{
bytes: Uint8Array;
parser: Language;
sourceMap?: string;
}>;

@@ -228,2 +250,3 @@ export type Sources = Record<string, CompartmentSources>;

commonDependencies?: Record<string, string> | undefined;
sourceMapHook?: SourceMapHook | undefined;
};

@@ -230,0 +253,0 @@ export type PackageNamingKit = {

@@ -117,2 +117,10 @@ // @ts-check

/**
* A resolution of `undefined` indicates `ENOENT` or the equivalent.
*
* @callback MaybeReadFn
* @param {string} location
* @returns {Promise<Uint8Array | undefined>} bytes
*/
/**
* Returns a canonical URL for a given URL, following redirects or symbolic

@@ -161,2 +169,7 @@ * links if any exist along the path.

/**
* @typedef {ReadPowers | object} MaybeReadPowers
* @property {MaybeReadFn} maybeRead
*/
/**
* @typedef {object} HashPowers

@@ -199,2 +212,3 @@ * @property {ReadFn} read

*/
/**

@@ -207,2 +221,30 @@ * @callback ImportHookMaker

/**
* @typedef {object} SourceMapHookDetails
* @property {string} compartment
* @property {string} module
* @property {string} location
* @property {string} sha512
*/
/**
* @callback SourceMapHook
* @param {string} sourceMap
* @param {SourceMapHookDetails} details
*/
/**
* @typedef {object} ComputeSourceMapLocationDetails
* @property {string} compartment
* @property {string} module
* @property {string} location
* @property {string} sha512
*/
/**
* @callback ComputeSourceMapLocationHook
* @param {ComputeSourceMapLocationDetails} details
* @returns {string}
*/
/**
* @callback ParseFn

@@ -214,2 +256,4 @@ * @param {Uint8Array} bytes

* @param {object} [options]
* @param {string} [options.sourceMap]
* @param {string} [options.sourceMapUrl]
* @param {ReadFn | ReadPowers} [options.readPowers]

@@ -220,2 +264,3 @@ * @returns {Promise<{

* record: FinalStaticModuleType,
* sourceMap?: string,
* }>}

@@ -252,2 +297,3 @@ */

* @property {ComputeSourceLocationHook} [computeSourceLocation]
* @property {ComputeSourceMapLocationHook} [computeSourceMapLocation]
*/

@@ -293,3 +339,5 @@

* @param {string} packageLocation
* @returns {Promise<{bytes: Uint8Array, parser: Language}>}
* @param {object} [options]
* @param {string} [options.sourceMap]
* @returns {Promise<{bytes: Uint8Array, parser: Language, sourceMap?: string}>}
*/

@@ -346,2 +394,3 @@

* @property {Record<string, string>} [commonDependencies]
* @property {SourceMapHook} [sourceMapHook]
*/

@@ -348,0 +397,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc