Skip to content

Commit

Permalink
Further endo errata
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Aug 6, 2020
1 parent 06366f9 commit d73fdd1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/endo/src/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ export const makeArchive = async (read, moduleLocation) => {
return archive.data();
};

export const writeArchive = async (write, read, archiveLocation, moduleLocation) => {
export const writeArchive = async (
write,
read,
archiveLocation,
moduleLocation
) => {
const archiveBytes = await makeArchive(read, moduleLocation);
await write(archiveLocation, archiveBytes);
};
2 changes: 1 addition & 1 deletion packages/endo/src/compartmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const graphPackage = async (
const { name, version } = packageDescriptor;
result.label = `${name}@${version}`;
result.dependencies = dependencies;
result.exports = inferExports(packageDescriptor, tags);
result.exports = inferExports(packageDescriptor, tags, packageLocation);

return Promise.all(children);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/endo/src/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export const loadLocation = async (read, moduleLocation) => {
return { execute };
};

export const importLocation = async (read, moduleLocation, endowments, modules) => {
export const importLocation = async (
read,
moduleLocation,
endowments,
modules
) => {
const application = await loadLocation(read, moduleLocation);
return application.execute(endowments, modules);
};
9 changes: 5 additions & 4 deletions packages/endo/src/infer-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ function* interpretExports(name, exports, tags) {
// ascending priority order, and the caller should use the last one that exists.
export function* inferExportsEntries(
{ name, type, main, module, browser, exports },
tags
tags,
location
) {
// TODO support commonjs type packages.
if (type !== "module") {
throw new Error(
`Endo currently only supports packages with "type": "module" in package.json, got ${q(
type
)} in package ${q(name)}`
)} in package ${q(name)} at location ${q(location)}`
);
}
// From lowest to highest precedence, such that later entries override former
Expand Down Expand Up @@ -92,5 +93,5 @@ export function* inferExportsEntries(
// every package.
// That manifest will also prove useful for resolving aliases, like the
// implicit index.js modules within a package.
export const inferExports = (descriptor, tags) =>
fromEntries(inferExportsEntries(descriptor, tags));
export const inferExports = (descriptor, tags, location) =>
fromEntries(inferExportsEntries(descriptor, tags, location));
5 changes: 4 additions & 1 deletion packages/endo/src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const resolveLocation = (rel, abs) => new URL(rel, abs).toString();
export const search = async (read, moduleLocation) => {
let directory = resolveLocation("./", moduleLocation);
for (;;) {
const packageDescriptorLocation = resolveLocation("package.json", directory);
const packageDescriptorLocation = resolveLocation(
"package.json",
directory
);
// eslint-disable-next-line no-await-in-loop
const packageDescriptorBytes = await read(packageDescriptorLocation).catch(
() => undefined
Expand Down
7 changes: 6 additions & 1 deletion packages/endo/test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ test("loadLocation", async t => {
test("importLocation", async t => {
t.plan(fixtureAssertionCount);

const { namespace } = await importLocation(read, fixture, endowments, modules);
const { namespace } = await importLocation(
read,
fixture,
endowments,
modules
);
assertFixture(t, namespace);
});

Expand Down

0 comments on commit d73fdd1

Please sign in to comment.