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

@endo/compartment-mapper

Package Overview
Dependencies
Maintainers
4
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.5.6 to 0.6.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ # Change Log

## [0.6.0](https://github.com/endojs/endo/compare/@endo/compartment-mapper@0.5.6...@endo/compartment-mapper@0.6.0) (2021-12-08)
### Features
* **compartment-mapper:** Thread url into power makers for Windows support ([fedcc8c](https://github.com/endojs/endo/commit/fedcc8c2b1204a76af3ff8211ea7033411c657f8))
### Bug Fixes
* Avoid eslint globs for Windows ([4b4f3cc](https://github.com/endojs/endo/commit/4b4f3ccaf3f5e8d53faefb4264db343dd603bf80))
* **compartment-mapper:** prettier bundle code, with some reduction ([dc9ccaa](https://github.com/endojs/endo/commit/dc9ccaae184d6346d11d90df46a2ed46c3ad3480))
* **static-module-record:** cleaner Babel codegen ([6e22569](https://github.com/endojs/endo/commit/6e22569b0c3f56e9f78d59943235b97ba0429921))
### [0.5.6](https://github.com/endojs/endo/compare/@endo/compartment-mapper@0.5.5...@endo/compartment-mapper@0.5.6) (2021-11-16)

@@ -8,0 +24,0 @@

2

node-powers.js

@@ -0,1 +1,3 @@

export { makeReadPowers, makeWritePowers } from './src/node-powers.js';
// Deprecated:
export { makeNodeReadPowers, makeNodeWritePowers } from './src/node-powers.js';

18

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

@@ -37,4 +37,4 @@ "keywords": [

"lint": "yarn lint:types && yarn lint:js",
"lint-fix": "eslint --fix '**/*.js'",
"lint:js": "eslint '**/*.js'",
"lint-fix": "eslint --fix .",
"lint:js": "eslint .",
"lint:types": "tsc --build jsconfig.json",

@@ -44,9 +44,9 @@ "test": "ava"

"dependencies": {
"@endo/cjs-module-analyzer": "^0.2.11",
"@endo/static-module-record": "^0.6.6",
"@endo/zip": "^0.2.11",
"ses": "^0.15.1"
"@endo/cjs-module-analyzer": "^0.2.12",
"@endo/static-module-record": "^0.6.7",
"@endo/zip": "^0.2.12",
"ses": "^0.15.2"
},
"devDependencies": {
"@endo/eslint-config": "^0.3.18",
"@endo/eslint-config": "^0.3.19",
"ava": "^3.12.1",

@@ -93,3 +93,3 @@ "babel-eslint": "^10.0.3",

},
"gitHead": "f445a041c413195f29c2e929e28f87c62a80d943"
"gitHead": "26d991afb01cf824827db0c958c50970e038112f"
}

@@ -215,5 +215,34 @@ // @ts-check

const exportsCellRecord = exportMap =>
''.concat(
...Object.keys(exportMap).map(
exportName => `\
${exportName}: cell(${q(exportName)}),
`,
),
);
const importsCellSetter = (exportMap, index) =>
''.concat(
...Object.entries(exportMap).map(
([exportName, [importName]]) => `\
${importName}: cells[${index}].${exportName}.set,
`,
),
);
const bundle = `\
'use strict';
(functors => {
(() => {
const functors = [
${''.concat(
...modules.map(
({ record: { __syncModuleProgram__ } }, i) =>
`\
// === functors[${i}] ===
${__syncModuleProgram__},
`,
),
)}\
]; // functors end
function cell(name, value = undefined) {

@@ -237,28 +266,23 @@ const observers = [];

const cells = [${''.concat(
...modules.map(
({ record: { __fixedExportMap__, __liveExportMap__ } }) => `{
${''.concat(
...Object.keys(__fixedExportMap__).map(
exportName => `${exportName}: cell(${q(exportName)}),\n`,
),
)}
${''.concat(
...Object.keys(__liveExportMap__).map(
exportName => `${exportName}: cell(${q(exportName)}),\n`,
),
)}
},`,
),
)}];
const cells = [
${''.concat(
...modules.map(
({ record: { __fixedExportMap__, __liveExportMap__ } }) => `\
{
${exportsCellRecord(__fixedExportMap__)}${exportsCellRecord(__liveExportMap__)}\
},
`,
),
)}\
];
${''.concat(
...modules.flatMap(({ index, indexedImports, record: { reexports } }) =>
reexports.map(
(/* @type {string} */ importSpecifier) => `\
Object.defineProperties(cells[${index}], Object.getOwnPropertyDescriptors(cells[${indexedImports[importSpecifier]}]));
`,
),
${''.concat(
...modules.flatMap(({ index, indexedImports, record: { reexports } }) =>
reexports.map(
importSpecifier => `\
Object.defineProperties(cells[${index}], Object.getOwnPropertyDescriptors(cells[${indexedImports[importSpecifier]}]));
`,
),
)}
),
)}\

@@ -271,59 +295,43 @@ const namespaces = cells.map(cells => Object.create(null, cells));

${''.concat(
...modules.map(
({
index,
indexedImports,
record: { __liveExportMap__, __fixedExportMap__ },
}) => `\
functors[${index}]({
imports(entries) {
const map = new Map(entries);
${''.concat(
...Object.entries(indexedImports).map(
([importName, importIndex]) => `\
for (const [name, observers] of map.get(${q(importName)})) {
const cell = cells[${importIndex}][name];
if (cell === undefined) {
throw new ReferenceError(\`Cannot import name \${name}\`);
}
for (const observer of observers) {
cell.observe(observer);
}
}
`,
),
)}
},
liveVar: {
${''.concat(
...Object.entries(__liveExportMap__).map(
([exportName, [importName]]) => `\
${importName}: cells[${index}].${exportName}.set,
`,
),
)}
},
onceVar: {
${''.concat(
...Object.entries(__fixedExportMap__).map(
([exportName, [importName]]) => `\
${importName}: cells[${index}].${exportName}.set,
`,
),
)}
},
});
`,
),
)}
function observeImports(map, importName, importIndex) {
for (const [name, observers] of map.get(importName)) {
const cell = cells[importIndex][name];
if (cell === undefined) {
throw new ReferenceError(\`Cannot import name \${name}\`);
}
for (const observer of observers) {
cell.observe(observer);
}
}
}
})([
${''.concat(
...modules.map(
({ record: { __syncModuleProgram__ } }) =>
`${__syncModuleProgram__}\n,\n`,
),
)}
]);
${''.concat(
...modules.map(
({
index,
indexedImports,
record: { __liveExportMap__, __fixedExportMap__ },
}) => `\
functors[${index}]({
imports(entries) {
const map = new Map(entries);
${''.concat(
...Object.entries(indexedImports).map(
([importName, importIndex]) => `\
observeImports(map, ${q(importName)}, ${importIndex});
`,
),
)}\
},
liveVar: {
${importsCellSetter(__liveExportMap__, index)}\
},
onceVar: {
${importsCellSetter(__fixedExportMap__, index)}\
},
});
`,
),
)}\
})();
`;

@@ -330,0 +338,0 @@

@@ -52,3 +52,5 @@ // @ts-check

*/
const resolveLocation = (rel, abs) => new URL(rel, abs).toString();
const resolveLocation = (rel, abs) => {
return new URL(rel, abs).toString();
};

@@ -55,0 +57,0 @@ /**

@@ -8,7 +8,35 @@ // @ts-check

/**
* @param {typeof import('fs')} fs
* @param {typeof import('crypto')} [crypto]
* @returns {ReadPowers}
* @param {string} location
*/
export const makeNodeReadPowers = (fs, crypto = undefined) => {
const fakeFileURLToPath = location => {
const url = new URL(location);
if (url.protocol !== 'file:') {
throw new Error(`Cannot convert URL to file path: ${location}`);
}
return url.pathname;
};
/**
* @param {string} path
*/
const fakePathToFileURL = path => {
return new URL(path, 'file://').toString();
};
/**
* The implementation of `makeReadPowers` and the deprecated
* `makeNodeReadPowers` handles the case when the `url` power is not provided,
* but `makeReadPowers` presents a type that requires `url`.
*
* @param {Object} args
* @param {typeof import('fs')} args.fs
* @param {typeof import('url')} [args.url]
* @param {typeof import('crypto')} [args.crypto]
*/
const makeReadPowersSloppy = ({ fs, url = undefined, crypto = undefined }) => {
const fileURLToPath =
url === undefined ? fakeFileURLToPath : url.fileURLToPath;
const pathToFileURL =
url === undefined ? fakePathToFileURL : url.pathToFileURL;
/**

@@ -19,3 +47,4 @@ * @param {string} location

try {
return await fs.promises.readFile(new URL(location).pathname);
const path = fileURLToPath(location);
return await fs.promises.readFile(path);
} catch (error) {

@@ -45,8 +74,8 @@ throw new Error(error.message);

const realPath = await fs.promises.realpath(
new URL(location).pathname.replace(/\/$/, ''),
fileURLToPath(location).replace(/\/$/, ''),
);
return new URL(`${realPath}/`, location).toString();
return `${pathToFileURL(realPath)}/`;
} else {
const realPath = await fs.promises.realpath(new URL(location).pathname);
return new URL(realPath, location).toString();
const realPath = await fs.promises.realpath(fileURLToPath(location));
return pathToFileURL(realPath).toString();
}

@@ -71,6 +100,14 @@ } catch {

/**
* @param {typeof import('fs')} fs
* @returns {WritePowers}
* The implementation of `makeWritePowers` and the deprecated
* `makeNodeWritePowers` handles the case when the `url` power is not provided,
* but `makeWritePowers` presents a type that requires `url`.
*
* @param {Object} args
* @param {typeof import('fs')} args.fs
* @param {typeof import('url')} [args.url]
*/
export const makeNodeWritePowers = fs => {
const makeWritePowersSloppy = ({ fs, url = undefined }) => {
const fileURLToPath =
url === undefined ? fakeFileURLToPath : url.fileURLToPath;
/**

@@ -82,3 +119,3 @@ * @param {string} location

try {
return await fs.promises.writeFile(new URL(location).pathname, data);
return await fs.promises.writeFile(fileURLToPath(location), data);
} catch (error) {

@@ -91,1 +128,41 @@ throw new Error(error.message);

};
/**
* @param {Object} args
* @param {typeof import('fs')} args.fs
* @param {typeof import('url')} args.url
* @param {typeof import('crypto')} [args.crypto]
*/
export const makeReadPowers = makeReadPowersSloppy;
/**
* @param {Object} args
* @param {typeof import('fs')} args.fs
* @param {typeof import('url')} args.url
*/
export const makeWritePowers = makeWritePowersSloppy;
/**
* @deprecated in favor of makeReadPowers.
* It transpires that positional arguments needed to become an arguments bag to
* reasonably expand to multiple optional dependencies.
*
* @param {typeof import('fs')} fs
* @param {typeof import('crypto')} [crypto]
* @returns {ReadPowers}
*/
export const makeNodeReadPowers = (fs, crypto = undefined) => {
return makeReadPowersSloppy({ fs, crypto });
};
/**
* @deprecated in favor of makeWritePowers.
* It transpires that positional arguments needed to become an arguments bag to
* reasonably expand to multiple optional dependencies.
*
* @param {typeof import('fs')} fs
* @returns {WritePowers}
*/
export const makeNodeWritePowers = fs => {
return makeWritePowersSloppy({ fs });
};
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