@endo/compartment-mapper 1.1.5 → 1.2.1

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.
Files changed (130) hide show
  1. package/README.md +17 -28
  2. package/archive-lite.d.ts +2 -0
  3. package/archive-lite.js +7 -0
  4. package/archive-parsers.d.ts +2 -0
  5. package/archive-parsers.js +1 -0
  6. package/capture-lite.d.ts +2 -0
  7. package/capture-lite.js +1 -0
  8. package/import-archive-lite.d.ts +2 -0
  9. package/import-archive-lite.js +5 -0
  10. package/import-archive-parsers.d.ts +2 -0
  11. package/import-archive-parsers.js +1 -0
  12. package/import-lite.d.ts +2 -0
  13. package/import-lite.js +1 -0
  14. package/import-parsers.d.ts +2 -0
  15. package/import-parsers.js +1 -0
  16. package/node-modules.d.ts +2 -0
  17. package/node-modules.js +1 -0
  18. package/package.json +23 -14
  19. package/src/archive-lite.d.ts +20 -0
  20. package/src/archive-lite.d.ts.map +1 -0
  21. package/src/archive-lite.js +495 -0
  22. package/src/archive-parsers.d.ts +11 -0
  23. package/src/archive-parsers.d.ts.map +1 -0
  24. package/src/archive-parsers.js +26 -0
  25. package/src/archive.d.ts +0 -6
  26. package/src/archive.d.ts.map +1 -1
  27. package/src/archive.js +94 -420
  28. package/src/bundle-cjs.d.ts +6 -17
  29. package/src/bundle-cjs.d.ts.map +1 -1
  30. package/src/bundle-cjs.js +11 -3
  31. package/src/bundle-json.d.ts +15 -0
  32. package/src/bundle-json.d.ts.map +1 -0
  33. package/src/bundle-json.js +24 -0
  34. package/src/bundle-mjs.d.ts +3 -19
  35. package/src/bundle-mjs.d.ts.map +1 -1
  36. package/src/bundle-mjs.js +6 -0
  37. package/src/bundle.d.ts +53 -10
  38. package/src/bundle.d.ts.map +1 -1
  39. package/src/bundle.js +118 -56
  40. package/src/capture-lite.d.ts +7 -0
  41. package/src/capture-lite.d.ts.map +1 -0
  42. package/src/capture-lite.js +324 -0
  43. package/src/compartment-map.d.ts +1 -1
  44. package/src/compartment-map.d.ts.map +1 -1
  45. package/src/compartment-map.js +18 -37
  46. package/src/extension.d.ts.map +1 -1
  47. package/src/extension.js +2 -0
  48. package/src/import-archive-lite.d.ts +26 -0
  49. package/src/import-archive-lite.d.ts.map +1 -0
  50. package/src/import-archive-lite.js +455 -0
  51. package/src/import-archive-parsers.d.ts +9 -0
  52. package/src/import-archive-parsers.d.ts.map +1 -0
  53. package/src/import-archive-parsers.js +24 -0
  54. package/src/import-archive.d.ts +12 -9
  55. package/src/import-archive.d.ts.map +1 -1
  56. package/src/import-archive.js +74 -406
  57. package/src/import-hook.d.ts.map +1 -1
  58. package/src/import-hook.js +10 -3
  59. package/src/import-lite.d.ts +9 -0
  60. package/src/import-lite.d.ts.map +1 -0
  61. package/src/import-lite.js +121 -0
  62. package/src/import-parsers.d.ts +9 -0
  63. package/src/import-parsers.d.ts.map +1 -0
  64. package/src/import-parsers.js +24 -0
  65. package/src/import.d.ts +1 -4
  66. package/src/import.d.ts.map +1 -1
  67. package/src/import.js +44 -97
  68. package/src/infer-exports.d.ts +4 -4
  69. package/src/infer-exports.d.ts.map +1 -1
  70. package/src/infer-exports.js +29 -20
  71. package/src/json.d.ts.map +1 -1
  72. package/src/json.js +1 -0
  73. package/src/link.d.ts +4 -4
  74. package/src/link.d.ts.map +1 -1
  75. package/src/link.js +62 -19
  76. package/src/node-module-specifier.d.ts.map +1 -1
  77. package/src/node-module-specifier.js +5 -0
  78. package/src/node-modules.d.ts +13 -2
  79. package/src/node-modules.d.ts.map +1 -1
  80. package/src/node-modules.js +127 -40
  81. package/src/node-powers.d.ts +4 -4
  82. package/src/node-powers.d.ts.map +1 -1
  83. package/src/node-powers.js +10 -0
  84. package/src/parse-archive-cjs.d.ts +2 -2
  85. package/src/parse-archive-cjs.d.ts.map +1 -1
  86. package/src/parse-archive-cjs.js +4 -0
  87. package/src/parse-archive-mjs.d.ts +2 -2
  88. package/src/parse-archive-mjs.d.ts.map +1 -1
  89. package/src/parse-archive-mjs.js +5 -2
  90. package/src/parse-bytes.d.ts +2 -2
  91. package/src/parse-bytes.d.ts.map +1 -1
  92. package/src/parse-bytes.js +4 -0
  93. package/src/parse-cjs-shared-export-wrapper.d.ts +2 -2
  94. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  95. package/src/parse-cjs-shared-export-wrapper.js +16 -1
  96. package/src/parse-cjs.d.ts +2 -2
  97. package/src/parse-cjs.d.ts.map +1 -1
  98. package/src/parse-cjs.js +4 -0
  99. package/src/parse-json.d.ts +2 -2
  100. package/src/parse-json.d.ts.map +1 -1
  101. package/src/parse-json.js +2 -0
  102. package/src/parse-mjs.d.ts +2 -2
  103. package/src/parse-mjs.d.ts.map +1 -1
  104. package/src/parse-mjs.js +4 -2
  105. package/src/parse-pre-cjs.d.ts +2 -2
  106. package/src/parse-pre-cjs.d.ts.map +1 -1
  107. package/src/parse-pre-cjs.js +6 -0
  108. package/src/parse-pre-mjs.d.ts +2 -2
  109. package/src/parse-pre-mjs.d.ts.map +1 -1
  110. package/src/parse-pre-mjs.js +6 -0
  111. package/src/parse-text.d.ts +2 -2
  112. package/src/parse-text.d.ts.map +1 -1
  113. package/src/parse-text.js +5 -0
  114. package/src/policy-format.d.ts +8 -6
  115. package/src/policy-format.d.ts.map +1 -1
  116. package/src/policy-format.js +12 -3
  117. package/src/policy.d.ts +9 -9
  118. package/src/policy.d.ts.map +1 -1
  119. package/src/policy.js +3 -0
  120. package/src/powers.d.ts +1 -1
  121. package/src/powers.d.ts.map +1 -1
  122. package/src/powers.js +7 -0
  123. package/src/search.d.ts +4 -2
  124. package/src/search.d.ts.map +1 -1
  125. package/src/search.js +22 -16
  126. package/src/types.d.ts +121 -15
  127. package/src/types.d.ts.map +1 -1
  128. package/src/types.js +161 -19
  129. package/src/url.d.ts.map +1 -1
  130. package/src/url.js +5 -0
package/README.md CHANGED
@@ -164,27 +164,15 @@ in a parent directory, under `node_modules`.
164
164
  The `main`, `browser`, and `exports` properties determine the modules each
165
165
  package exports to other compartments.
166
166
 
167
- The `exports` property describes [package entry points] and can be influenced
168
- by build _tags_.
169
- Currently, the only tag supported by the compartment mapper is `import`, which
170
- indicates that the module map should use ESM modules over CommonJS modules or
171
- other variants.
172
-
173
- > TODO
174
- >
175
- > A future version may reveal other tags like `browser` to prepare an
176
- > application for use in a web client.
177
- > For this case, the compartment mapper would prepare a JSON manifest like an
178
- > `importmap` (if not precisely an `importmap`).
179
- > The "compartment map" would be consistent except when the dependency graph
180
- > changes so updates could be automated with a `postinstall` script.
181
- > Preparing a web application for production would follow a process similar to
182
- > creating an archive, but with the `browser` build tag.
183
-
184
- The `browser` and `require` tags are well-known but not yet supported.
185
- The `browser` tag will apply for compartment maps generated for use on the web.
186
- The `require` tag is a fallback for environments that do not support ESM and
187
- will never apply.
167
+ The `exports` property describes [package entry points][] and can be influenced
168
+ by build _conditions_.
169
+ Currently, the only conditions supported by the compartment mapper are
170
+ `import`, `browser`, and `endo`.
171
+ The `imports` condition indicates that the module map should use ESM modules
172
+ over CommonJS modules or other variants, and `endo`.
173
+ The `browser` condition also draws in the `browser` property from
174
+ `package.json` instead of `main`.
175
+ The `endo` condition only indicates that this tool is in use.
188
176
 
189
177
  If no `exports` apply to the root of the compartment namespace (`"."`),
190
178
  the `main` property serves as a default.
@@ -284,7 +272,7 @@ Node.js platform.
284
272
  > For browser applications, the compartment mapper would use the translator
285
273
  > modules in two modes.
286
274
  > During development, the compartment mapper would be able to load the
287
- > translator in the client, with the `browser` tag.
275
+ > translator in the client, with the `browser` condition.
288
276
  > The compartment mapper would also be able to run the translator in a separate
289
277
  > non-browser compartment during bundling, so the translator can be excluded
290
278
  > from the production application and archived applications.
@@ -392,18 +380,19 @@ The compartment map shape:
392
380
  // CompartmentMap describes how to prepare compartments
393
381
  // to run an application.
394
382
  type CompartmentMap = {
395
- tags: Tags,
383
+ tags: Conditions,
396
384
  entry: Entry,
397
385
  compartments: Record<CompartmentName, Compartment>,
398
386
  realms: Record<RealmName, Realm>, // TODO
399
387
  };
400
388
 
401
- // Tags are the build tags for the compartment.
389
+ // Conditions influence which modules are selected
390
+ // to represent the implementation of various modules.
402
391
  // These may include terms like "browser", meaning
403
392
  // each compartment uses the implementation of each
404
393
  // module suitable for use in a browser environment.
405
- type Tags = Array<Tag>;
406
- type Tag = string;
394
+ type Conditions = Array<Condition>;
395
+ type Condition = string;
407
396
 
408
397
  // Entry is a reference to the module that is the module to initially import.
409
398
  type Entry = CompartmentModule;
@@ -485,7 +474,7 @@ type InternalModuleSpecifier = string;
485
474
  // in the namespace of the foreign compartment.
486
475
  type ExternalModuleSpecifier = string;
487
476
 
488
- // ParserMap indicates which parser to use to construct static module records
477
+ // ParserMap indicates which parser to use to construct module sources
489
478
  // from sources, for each supported file extension.
490
479
  // For parity with Node.js, a package with `"type": "module"` in its
491
480
  // `package.json` would have a parser map of `{"js": "mjs", "cjs": "cjs",
@@ -500,7 +489,7 @@ type ParserMap = Record<Extension, Parser>;
500
489
  // Extension is a file extension such as "js" for "main.js" or "" for "README".
501
490
  type Extension = string;
502
491
 
503
- // Parser is a union of built-in parsers for static module records.
492
+ // Parser is a union of built-in parsers for module sources.
504
493
  // "mjs" corresponds to ECMAScript modules.
505
494
  // "cjs" corresponds to CommonJS modules.
506
495
  // "json" corresponds to JSON.
@@ -0,0 +1,2 @@
1
+ export { makeArchiveFromMap, makeAndHashArchiveFromMap, writeArchiveFromMap, mapFromMap, hashFromMap } from "./src/archive-lite.js";
2
+ //# sourceMappingURL=archive-lite.d.ts.map
@@ -0,0 +1,7 @@
1
+ export {
2
+ makeArchiveFromMap,
3
+ makeAndHashArchiveFromMap,
4
+ writeArchiveFromMap,
5
+ mapFromMap,
6
+ hashFromMap,
7
+ } from './src/archive-lite.js';
@@ -0,0 +1,2 @@
1
+ export { defaultParserForLanguage } from "./src/archive-parsers.js";
2
+ //# sourceMappingURL=archive-parsers.d.ts.map
@@ -0,0 +1 @@
1
+ export { defaultParserForLanguage } from './src/archive-parsers.js';
@@ -0,0 +1,2 @@
1
+ export { captureFromMap } from "./src/capture-lite.js";
2
+ //# sourceMappingURL=capture-lite.d.ts.map
@@ -0,0 +1 @@
1
+ export { captureFromMap } from './src/capture-lite.js';
@@ -0,0 +1,2 @@
1
+ export { parseArchive, loadArchive, importArchive } from "./src/import-archive-lite.js";
2
+ //# sourceMappingURL=import-archive-lite.d.ts.map
@@ -0,0 +1,5 @@
1
+ export {
2
+ parseArchive,
3
+ loadArchive,
4
+ importArchive,
5
+ } from './src/import-archive-lite.js';
@@ -0,0 +1,2 @@
1
+ export { defaultParserForLanguage } from "./src/import-archive-parsers.js";
2
+ //# sourceMappingURL=import-archive-parsers.d.ts.map
@@ -0,0 +1 @@
1
+ export { defaultParserForLanguage } from './src/import-archive-parsers.js';
@@ -0,0 +1,2 @@
1
+ export { loadFromMap, importFromMap } from "./src/import-lite.js";
2
+ //# sourceMappingURL=import-lite.d.ts.map
package/import-lite.js ADDED
@@ -0,0 +1 @@
1
+ export { loadFromMap, importFromMap } from './src/import-lite.js';
@@ -0,0 +1,2 @@
1
+ export { defaultParserForLanguage } from "./src/import-parsers.js";
2
+ //# sourceMappingURL=import-parsers.d.ts.map
@@ -0,0 +1 @@
1
+ export { defaultParserForLanguage } from './src/import-parsers.js';
@@ -0,0 +1,2 @@
1
+ export { mapNodeModules } from "./src/node-modules.js";
2
+ //# sourceMappingURL=node-modules.d.ts.map
@@ -0,0 +1 @@
1
+ export { mapNodeModules } from './src/node-modules.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/compartment-mapper",
3
- "version": "1.1.5",
3
+ "version": "1.2.1",
4
4
  "description": "The compartment mapper assembles Node applications in a sandbox",
5
5
  "keywords": [
6
6
  "node",
@@ -28,16 +28,24 @@
28
28
  "default": "./index.js"
29
29
  },
30
30
  "./import.js": "./import.js",
31
+ "./import-lite.js": "./import-lite.js",
32
+ "./import-parsers.js": "./import-parsers.js",
31
33
  "./archive.js": "./archive.js",
34
+ "./archive-lite.js": "./archive-lite.js",
35
+ "./archive-parsers.js": "./archive-parsers.js",
36
+ "./capture-lite.js": "./capture-lite.js",
32
37
  "./import-archive.js": "./import-archive.js",
38
+ "./import-archive-lite.js": "./import-archive-lite.js",
39
+ "./import-archive-parsers.js": "./import-archive-parsers.js",
33
40
  "./bundle.js": "./bundle.js",
34
41
  "./node-powers.js": "./node-powers.js",
42
+ "./node-modules.js": "./node-modules.js",
35
43
  "./package.json": "./package.json"
36
44
  },
37
45
  "scripts": {
38
46
  "build": "exit 0",
39
- "build:types": "tsc --build tsconfig.build.json",
40
- "clean:types": "git clean -f '*.d.ts*'",
47
+ "prepack": "tsc --build tsconfig.build.json",
48
+ "postpack": "git clean -f '*.d.ts*'",
41
49
  "cover": "c8 ava",
42
50
  "lint": "yarn lint:types && yarn lint:eslint",
43
51
  "lint-fix": "eslint --fix .",
@@ -47,22 +55,22 @@
47
55
  "test": "ava"
48
56
  },
49
57
  "dependencies": {
50
- "@endo/cjs-module-analyzer": "^1.0.5",
51
- "@endo/static-module-record": "^1.1.2",
52
- "@endo/zip": "^1.0.5",
53
- "ses": "^1.5.0"
58
+ "@endo/cjs-module-analyzer": "^1.0.6",
59
+ "@endo/module-source": "^1.0.1",
60
+ "@endo/zip": "^1.0.6",
61
+ "ses": "^1.7.0"
54
62
  },
55
63
  "devDependencies": {
56
- "ava": "^6.1.2",
57
- "babel-eslint": "^10.0.3",
64
+ "ava": "^6.1.3",
65
+ "babel-eslint": "^10.1.0",
58
66
  "c8": "^7.14.0",
59
67
  "eslint": "^8.57.0",
60
68
  "eslint-config-airbnb-base": "^15.0.0",
61
69
  "eslint-config-prettier": "^9.1.0",
62
- "eslint-plugin-eslint-comments": "^3.1.2",
63
- "eslint-plugin-import": "^2.29.0",
70
+ "eslint-plugin-eslint-comments": "^3.2.0",
71
+ "eslint-plugin-import": "^2.29.1",
64
72
  "prettier": "^3.2.5",
65
- "typescript": "~5.5.0-dev.20240327"
73
+ "typescript": "5.5.2"
66
74
  },
67
75
  "files": [
68
76
  "LICENSE*",
@@ -93,12 +101,13 @@
93
101
  },
94
102
  "ava": {
95
103
  "files": [
96
- "test/**/test-*.js"
104
+ "test/**/test-*.*",
105
+ "test/**/*.test.*"
97
106
  ],
98
107
  "timeout": "2m"
99
108
  },
100
109
  "typeCoverage": {
101
110
  "atLeast": 86.14
102
111
  },
103
- "gitHead": "08e59bc0d262565165636c2e3875bbe3dcb91cf8"
112
+ "gitHead": "444c81ad3ecc1b0a449023a9c65e9be2fa17db21"
104
113
  }
@@ -0,0 +1,20 @@
1
+ export function makeArchiveCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): {
2
+ archiveCompartmentMap: CompartmentMapDescriptor;
3
+ archiveSources: Sources;
4
+ };
5
+ export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<{
6
+ bytes: Uint8Array;
7
+ sha512?: string;
8
+ }>;
9
+ export function makeArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
10
+ export function mapFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<Uint8Array>;
11
+ export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<string>;
12
+ export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveOptions | undefined): Promise<void>;
13
+ import type { CompartmentMapDescriptor } from './types.js';
14
+ import type { Sources } from './types.js';
15
+ import type { ReadFn } from './types.js';
16
+ import type { ReadPowers } from './types.js';
17
+ import type { ArchiveOptions } from './types.js';
18
+ import type { HashPowers } from './types.js';
19
+ import type { WriteFn } from './types.js';
20
+ //# sourceMappingURL=archive-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AA2QO,0DAJI,wBAAwB,WACxB,OAAO,GACL;IAAC,qBAAqB,EAAE,wBAAwB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAC,CAmCtF;AA6GM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAmBzD;AAQM,2CALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,mCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,oCALI,UAAU,kBACV,wBAAwB,yCAEtB,OAAO,CAAC,MAAM,CAAC,CAU3B;AASM,2CANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,wBAAwB,uDAgBlC;8CA1c2C,YAAY;6BAM7B,YAAY;4BAJb,YAAY;gCAER,YAAY;oCAPR,YAAY;gCAQhB,YAAY;6BAEf,YAAY"}