@endo/compartment-mapper 0.7.14 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,35 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.8.0](https://github.com/endojs/endo/compare/@endo/compartment-mapper@0.7.15...@endo/compartment-mapper@0.8.0) (2022-11-14)
7
+
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * **compartment-mapper:** Remove support for globalLexicals
12
+
13
+ ### Features
14
+
15
+ * **compartment-mapper:** Bundles evaluate to entrypoint namespace ([85a69aa](https://github.com/endojs/endo/commit/85a69aaf8133fa84ec3548e8004777097cf7c326))
16
+ * **compartment-mapper:** Remove support for globalLexicals ([7d9603d](https://github.com/endojs/endo/commit/7d9603d0c838e02c1b052cf6e8f725ebf195aaf2))
17
+ * **compartment-mapper:** support peerDependencies and bundleDependencies ([3afd7c5](https://github.com/endojs/endo/commit/3afd7c5680813063a1ab7ff93af1a116e6af2f02))
18
+ * **compartment-mapper:** support various types of optional deps ([72fa6e7](https://github.com/endojs/endo/commit/72fa6e7a3089be31be97caee2616090ac842bb3e))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * assert touchups ([#1350](https://github.com/endojs/endo/issues/1350)) ([3fcb5b1](https://github.com/endojs/endo/commit/3fcb5b117eccb326c6c81339ae6a293a6bcaa9d4))
24
+
25
+
26
+
27
+ ### [0.7.15](https://github.com/endojs/endo/compare/@endo/compartment-mapper@0.7.14...@endo/compartment-mapper@0.7.15) (2022-10-24)
28
+
29
+ **Note:** Version bump only for package @endo/compartment-mapper
30
+
31
+
32
+
33
+
34
+
6
35
  ### [0.7.14](https://github.com/endojs/endo/compare/@endo/compartment-mapper@0.7.13...@endo/compartment-mapper@0.7.14) (2022-10-19)
7
36
 
8
37
  **Note:** Version bump only for package @endo/compartment-mapper
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/compartment-mapper",
3
- "version": "0.7.14",
3
+ "version": "0.8.0",
4
4
  "description": "The compartment mapper assembles Node applications in a sandbox",
5
5
  "keywords": [
6
6
  "node",
@@ -41,10 +41,10 @@
41
41
  "test": "ava"
42
42
  },
43
43
  "dependencies": {
44
- "@endo/cjs-module-analyzer": "^0.2.27",
45
- "@endo/static-module-record": "^0.7.13",
46
- "@endo/zip": "^0.2.27",
47
- "ses": "^0.16.0"
44
+ "@endo/cjs-module-analyzer": "^0.2.28",
45
+ "@endo/static-module-record": "^0.7.15",
46
+ "@endo/zip": "^0.2.28",
47
+ "ses": "^0.18.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@endo/eslint-config": "^0.5.1",
@@ -58,7 +58,7 @@
58
58
  "eslint-plugin-import": "^2.26.0",
59
59
  "eslint-plugin-prettier": "^3.4.1",
60
60
  "prettier": "^1.19.1",
61
- "typescript": "~4.6.2"
61
+ "typescript": "~4.8.4"
62
62
  },
63
63
  "files": [
64
64
  "LICENSE*",
@@ -93,5 +93,5 @@
93
93
  ],
94
94
  "timeout": "2m"
95
95
  },
96
- "gitHead": "8da6dc1002417c0f18cd43b351f8f62d7010260c"
96
+ "gitHead": "da16a94856482e36296b7cae16d715aa63344928"
97
97
  }
package/src/bundle.js CHANGED
@@ -337,6 +337,8 @@ ${importsCellSetter(__fixedExportMap__, index)}\
337
337
  `,
338
338
  ),
339
339
  )}\
340
+
341
+ return cells[cells.length - 1]['*'].get();
340
342
  })();
341
343
  `;
342
344
 
@@ -1,6 +1,10 @@
1
1
  // @ts-check
2
2
  /// <reference types="ses"/>
3
3
 
4
+ // TODO convert to the new `||` assert style.
5
+ // Deferred because this file pervasively uses simple template strings rather than
6
+ // template strings tagged with `assert.details` (aka `X`), and uses
7
+ // this definition of `q` rather than `assert.quote`
4
8
  const q = JSON.stringify;
5
9
 
6
10
  const moduleLanguages = [
@@ -29,7 +29,7 @@ import { assertCompartmentMap } from './compartment-map.js';
29
29
 
30
30
  const DefaultCompartment = Compartment;
31
31
 
32
- const { quote: q, details: d } = assert;
32
+ const { Fail, quote: q } = assert;
33
33
 
34
34
  const textDecoder = new TextDecoder();
35
35
 
@@ -207,12 +207,10 @@ export const parseArchive = async (
207
207
 
208
208
  // Track all modules that get loaded, all files that are used.
209
209
  const unseen = new Set(archive.files.keys());
210
- assert(
211
- unseen.size >= 2,
212
- `Archive failed sanity check: should contain at least a compartment map file and one module file in ${q(
210
+ unseen.size >= 2 ||
211
+ Fail`Archive failed sanity check: should contain at least a compartment map file and one module file in ${q(
213
212
  archiveLocation,
214
- )}`,
215
- );
213
+ )}`;
216
214
 
217
215
  /**
218
216
  * @param {string} path
@@ -280,24 +278,16 @@ export const parseArchive = async (
280
278
  });
281
279
 
282
280
  await compartment.load(moduleSpecifier);
283
- assert(
284
- unseen.size === 0,
285
- d`Archive contains extraneous files: ${q([...unseen])} in ${q(
281
+ unseen.size === 0 ||
282
+ Fail`Archive contains extraneous files: ${q([...unseen])} in ${q(
286
283
  archiveLocation,
287
- )}`,
288
- );
284
+ )}`;
289
285
  }
290
286
 
291
287
  /** @type {ExecuteFn} */
292
288
  const execute = options => {
293
- const {
294
- globals,
295
- globalLexicals,
296
- modules,
297
- transforms,
298
- __shimTransforms__,
299
- Compartment,
300
- } = options || {};
289
+ const { globals, modules, transforms, __shimTransforms__, Compartment } =
290
+ options || {};
301
291
  const makeImportHook = makeArchiveImportHookMaker(
302
292
  get,
303
293
  compartments,
@@ -309,13 +299,13 @@ export const parseArchive = async (
309
299
  makeImportHook,
310
300
  parserForLanguage,
311
301
  globals,
312
- globalLexicals,
313
302
  modules,
314
303
  transforms,
315
304
  __shimTransforms__,
316
305
  Compartment,
317
306
  });
318
- return compartment.import(moduleSpecifier);
307
+ // eslint-disable-next-line dot-notation
308
+ return compartment['import'](moduleSpecifier);
319
309
  };
320
310
 
321
311
  return { import: execute, sha512 };
package/src/import.js CHANGED
@@ -67,7 +67,6 @@ export const loadLocation = async (readPowers, moduleLocation, options) => {
67
67
  const execute = async (options = {}) => {
68
68
  const {
69
69
  globals,
70
- globalLexicals,
71
70
  modules,
72
71
  transforms,
73
72
  __shimTransforms__,
@@ -78,7 +77,6 @@ export const loadLocation = async (readPowers, moduleLocation, options) => {
78
77
  makeImportHook,
79
78
  parserForLanguage,
80
79
  globals,
81
- globalLexicals,
82
80
  modules,
83
81
  transforms,
84
82
  moduleTransforms,
package/src/link.js CHANGED
@@ -333,7 +333,6 @@ export const link = (
333
333
  makeImportHook,
334
334
  parserForLanguage,
335
335
  globals = {},
336
- globalLexicals = {},
337
336
  transforms = [],
338
337
  moduleTransforms = {},
339
338
  __shimTransforms__ = [],
@@ -401,7 +400,6 @@ export const link = (
401
400
  moduleMapHook,
402
401
  transforms,
403
402
  __shimTransforms__,
404
- globalLexicals,
405
403
  name: location,
406
404
  });
407
405
 
@@ -252,13 +252,37 @@ const graphPackage = async (
252
252
  graph[packageLocation] = /** @type {Node} */ (result);
253
253
 
254
254
  /** @type {Record<string, string>} */
255
- const dependencies = {};
255
+ const dependencyLocations = {};
256
256
  const children = [];
257
- const predicates = packageDescriptor.dependencies || {};
257
+ const optionals = new Set();
258
+ const {
259
+ dependencies = {},
260
+ peerDependencies = {},
261
+ peerDependenciesMeta = {},
262
+ bundleDependencies = {},
263
+ optionalDependencies = {},
264
+ devDependencies = {},
265
+ } = packageDescriptor;
266
+ const allDependencies = {};
267
+ assign(allDependencies, dependencies);
268
+ assign(allDependencies, peerDependencies);
269
+ for (const [name, { optional }] of Object.entries(peerDependenciesMeta)) {
270
+ if (optional) {
271
+ optionals.add(name);
272
+ }
273
+ }
274
+ assign(allDependencies, bundleDependencies);
275
+ assign(allDependencies, optionalDependencies);
276
+ Object.keys(optionalDependencies).forEach(name => {
277
+ optionals.add(name);
278
+ });
279
+
258
280
  if (dev) {
259
- assign(predicates, packageDescriptor.devDependencies || {});
281
+ assign(allDependencies, devDependencies);
260
282
  }
261
- for (const name of keys(predicates).sort()) {
283
+
284
+ for (const name of keys(allDependencies).sort()) {
285
+ const optional = optionals.has(name);
262
286
  children.push(
263
287
  // Mutual recursion ahead:
264
288
  // eslint-disable-next-line no-use-before-define
@@ -266,10 +290,11 @@ const graphPackage = async (
266
290
  readDescriptor,
267
291
  canonical,
268
292
  graph,
269
- dependencies,
293
+ dependencyLocations,
270
294
  packageLocation,
271
295
  name,
272
296
  tags,
297
+ optional,
273
298
  ),
274
299
  );
275
300
  }
@@ -291,7 +316,7 @@ const graphPackage = async (
291
316
  label: `${name}${version ? `-v${version}` : ''}`,
292
317
  explicit: exports !== undefined,
293
318
  exports: inferExports(packageDescriptor, tags, types),
294
- dependencies,
319
+ dependencies: dependencyLocations,
295
320
  types,
296
321
  parsers: inferParsers(packageDescriptor, packageLocation),
297
322
  });
@@ -317,6 +342,7 @@ const graphPackage = async (
317
342
  * @param {string} packageLocation - location of the package of interest.
318
343
  * @param {string} name - name of the package of interest.
319
344
  * @param {Set<string>} tags
345
+ * @param {boolean} optional - whether the dependency is optional
320
346
  */
321
347
  const gatherDependency = async (
322
348
  readDescriptor,
@@ -326,6 +352,7 @@ const gatherDependency = async (
326
352
  packageLocation,
327
353
  name,
328
354
  tags,
355
+ optional = false,
329
356
  ) => {
330
357
  const dependency = await findPackage(
331
358
  readDescriptor,
@@ -334,6 +361,10 @@ const gatherDependency = async (
334
361
  name,
335
362
  );
336
363
  if (dependency === undefined) {
364
+ // allow the dependency to be missing if optional
365
+ if (optional) {
366
+ return;
367
+ }
337
368
  throw new Error(`Cannot find dependency ${name} for ${packageLocation}`);
338
369
  }
339
370
  dependencies[name] = dependency.packageLocation;
package/src/types.js CHANGED
@@ -234,7 +234,6 @@ export {};
234
234
  /**
235
235
  * @typedef {Object} ExecuteOptions
236
236
  * @property {Object} [globals]
237
- * @property {Object} [globalLexicals]
238
237
  * @property {Array<Transform>} [transforms]
239
238
  * @property {Array<Transform>} [__shimTransforms__]
240
239
  * @property {Record<string, Object>} [modules]