@endo/compartment-mapper 1.3.0 → 1.4.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.
Files changed (145) hide show
  1. package/README.md +50 -27
  2. package/archive-lite.d.ts +1 -0
  3. package/archive-lite.js +3 -0
  4. package/archive-parsers.d.ts +1 -0
  5. package/archive-parsers.js +3 -0
  6. package/archive.d.ts +1 -0
  7. package/archive.js +3 -0
  8. package/bundle.d.ts +1 -0
  9. package/bundle.js +3 -0
  10. package/capture-lite.d.ts +1 -0
  11. package/capture-lite.js +3 -0
  12. package/import-archive-lite.d.ts +1 -0
  13. package/import-archive-lite.js +3 -0
  14. package/import-archive-parsers.d.ts +1 -0
  15. package/import-archive-parsers.js +3 -0
  16. package/import-archive.d.ts +1 -0
  17. package/import-archive.js +3 -0
  18. package/import-lite.d.ts +1 -0
  19. package/import-lite.js +3 -0
  20. package/import-parsers.d.ts +1 -0
  21. package/import-parsers.js +3 -0
  22. package/import.d.ts +1 -0
  23. package/import.js +3 -0
  24. package/index.d.ts +1 -0
  25. package/index.js +3 -1
  26. package/node-modules.d.ts +1 -0
  27. package/node-modules.js +3 -0
  28. package/node-powers.d.ts +1 -0
  29. package/node-powers.js +3 -0
  30. package/package.json +10 -14
  31. package/src/archive-lite.d.ts +6 -6
  32. package/src/archive-lite.d.ts.map +1 -1
  33. package/src/archive-lite.js +35 -33
  34. package/src/archive.d.ts.map +1 -1
  35. package/src/archive.js +132 -28
  36. package/src/bundle.d.ts.map +1 -1
  37. package/src/bundle.js +54 -14
  38. package/src/capture-lite.d.ts +2 -2
  39. package/src/capture-lite.d.ts.map +1 -1
  40. package/src/capture-lite.js +21 -17
  41. package/src/compartment-map.d.ts +2 -1
  42. package/src/compartment-map.d.ts.map +1 -1
  43. package/src/compartment-map.js +11 -5
  44. package/src/extension.d.ts.map +1 -1
  45. package/src/extension.js +1 -3
  46. package/src/import-archive-lite.d.ts +3 -19
  47. package/src/import-archive-lite.d.ts.map +1 -1
  48. package/src/import-archive-lite.js +43 -57
  49. package/src/import-archive-parsers.d.ts.map +1 -1
  50. package/src/import-archive-parsers.js +1 -0
  51. package/src/import-archive.d.ts +2 -2
  52. package/src/import-archive.d.ts.map +1 -1
  53. package/src/import-archive.js +15 -12
  54. package/src/import-hook.d.ts +2 -1
  55. package/src/import-hook.d.ts.map +1 -1
  56. package/src/import-hook.js +87 -76
  57. package/src/import-lite.d.ts.map +1 -1
  58. package/src/import-lite.js +23 -23
  59. package/src/import.d.ts.map +1 -1
  60. package/src/import.js +47 -23
  61. package/src/infer-exports.d.ts.map +1 -1
  62. package/src/infer-exports.js +2 -3
  63. package/src/json.d.ts.map +1 -1
  64. package/src/json.js +1 -2
  65. package/src/link.d.ts.map +1 -1
  66. package/src/link.js +12 -29
  67. package/src/map-parser.d.ts.map +1 -1
  68. package/src/map-parser.js +21 -16
  69. package/src/node-module-specifier.d.ts.map +1 -1
  70. package/src/node-module-specifier.js +2 -3
  71. package/src/node-modules.d.ts +9 -7
  72. package/src/node-modules.d.ts.map +1 -1
  73. package/src/node-modules.js +176 -87
  74. package/src/node-powers.d.ts +8 -8
  75. package/src/node-powers.d.ts.map +1 -1
  76. package/src/node-powers.js +29 -24
  77. package/src/parse-archive-cjs.d.ts +3 -2
  78. package/src/parse-archive-cjs.d.ts.map +1 -1
  79. package/src/parse-archive-cjs.js +5 -4
  80. package/src/parse-archive-mjs.d.ts +3 -2
  81. package/src/parse-archive-mjs.d.ts.map +1 -1
  82. package/src/parse-archive-mjs.js +7 -5
  83. package/src/parse-bytes.d.ts +3 -2
  84. package/src/parse-bytes.d.ts.map +1 -1
  85. package/src/parse-bytes.js +7 -5
  86. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  87. package/src/parse-cjs-shared-export-wrapper.js +7 -6
  88. package/src/parse-cjs.d.ts +3 -2
  89. package/src/parse-cjs.d.ts.map +1 -1
  90. package/src/parse-cjs.js +14 -5
  91. package/src/parse-json.d.ts.map +1 -1
  92. package/src/parse-json.js +6 -6
  93. package/src/parse-mjs.d.ts +3 -2
  94. package/src/parse-mjs.d.ts.map +1 -1
  95. package/src/parse-mjs.js +3 -3
  96. package/src/parse-pre-cjs.d.ts +3 -2
  97. package/src/parse-pre-cjs.d.ts.map +1 -1
  98. package/src/parse-pre-cjs.js +14 -4
  99. package/src/parse-pre-mjs.d.ts +3 -2
  100. package/src/parse-pre-mjs.d.ts.map +1 -1
  101. package/src/parse-pre-mjs.js +4 -3
  102. package/src/parse-text.d.ts +3 -2
  103. package/src/parse-text.d.ts.map +1 -1
  104. package/src/parse-text.js +6 -5
  105. package/src/policy-format.d.ts +1 -1
  106. package/src/policy-format.d.ts.map +1 -1
  107. package/src/policy-format.js +5 -7
  108. package/src/policy.d.ts.map +1 -1
  109. package/src/policy.js +15 -10
  110. package/src/powers.d.ts.map +1 -1
  111. package/src/powers.js +15 -12
  112. package/src/search.d.ts.map +1 -1
  113. package/src/search.js +10 -7
  114. package/src/types/compartment-map-schema.d.ts +98 -0
  115. package/src/types/compartment-map-schema.d.ts.map +1 -0
  116. package/src/types/compartment-map-schema.ts +116 -0
  117. package/src/types/external.d.ts +256 -0
  118. package/src/types/external.d.ts.map +1 -0
  119. package/src/types/external.ts +379 -0
  120. package/src/types/internal.d.ts +161 -0
  121. package/src/types/internal.d.ts.map +1 -0
  122. package/src/types/internal.ts +216 -0
  123. package/src/types/node-powers.d.ts +46 -0
  124. package/src/types/node-powers.d.ts.map +1 -0
  125. package/src/types/node-powers.ts +52 -0
  126. package/src/types/policy-schema.d.ts +81 -0
  127. package/src/types/policy-schema.d.ts.map +1 -0
  128. package/src/types/policy-schema.ts +131 -0
  129. package/src/types/policy.d.ts +20 -0
  130. package/src/types/policy.d.ts.map +1 -0
  131. package/src/types/policy.ts +42 -0
  132. package/src/types/powers.d.ts +83 -0
  133. package/src/types/powers.d.ts.map +1 -0
  134. package/src/types/powers.ts +120 -0
  135. package/src/types/typescript.d.ts +28 -0
  136. package/src/types/typescript.d.ts.map +1 -0
  137. package/src/types/typescript.ts +41 -0
  138. package/src/types-external.d.ts +14 -0
  139. package/src/types-external.js +2 -0
  140. package/src/types.d.ts +9 -787
  141. package/src/url.d.ts.map +1 -1
  142. package/src/url.js +2 -3
  143. package/src/types.d.ts.map +0 -1
  144. package/src/types.js +0 -995
  145. package/types.d.ts +0 -19
package/src/archive.js CHANGED
@@ -1,4 +1,5 @@
1
- /* Provides mechanisms for creating archives (zip files with a
1
+ /**
2
+ * @module Provides mechanisms for creating archives (zip files with a
2
3
  * `compartmeent-map.json` and a file for every static dependency of an entry
3
4
  * module).
4
5
  *
@@ -13,7 +14,16 @@
13
14
  * for cases like XS native Compartments where pre-compilation is not
14
15
  * necessary or where the dependency on Babel can be dererred to runtime.
15
16
  */
16
- // @ts-check
17
+
18
+ /**
19
+ * @import {
20
+ * ArchiveOptions,
21
+ * ReadFn,
22
+ * ReadPowers,
23
+ * HashPowers,
24
+ * WriteFn,
25
+ * } from './types.js'
26
+ */
17
27
 
18
28
  import { defaultParserForLanguage } from './archive-parsers.js';
19
29
  import { mapNodeModules } from './node-modules.js';
@@ -27,12 +37,6 @@ import {
27
37
 
28
38
  const { assign, create, freeze } = Object;
29
39
 
30
- /** @import {ArchiveOptions} from './types.js' */
31
- /** @import {ReadFn} from './types.js' */
32
- /** @import {ReadPowers} from './types.js' */
33
- /** @import {HashPowers} from './types.js' */
34
- /** @import {WriteFn} from './types.js' */
35
-
36
40
  /**
37
41
  * Add the default parserForLanguage option.
38
42
  * @param {ArchiveOptions} [options]
@@ -43,7 +47,8 @@ const assignParserForLanguage = (options = {}) => {
43
47
  const parserForLanguage = freeze(
44
48
  assign(create(null), defaultParserForLanguage, parserForLanguageOption),
45
49
  );
46
- return { ...rest, parserForLanguage };
50
+ const languages = Object.keys(parserForLanguage);
51
+ return { ...rest, parserForLanguage, languages };
47
52
  };
48
53
 
49
54
  /**
@@ -57,12 +62,16 @@ export const makeAndHashArchive = async (
57
62
  moduleLocation,
58
63
  options = {},
59
64
  ) => {
60
- const compartmentMap = await mapNodeModules(powers, moduleLocation, options);
61
- return makeAndHashArchiveFromMap(
62
- powers,
63
- compartmentMap,
64
- assignParserForLanguage(options),
65
- );
65
+ const { parserForLanguage, languages, ...otherOptions } =
66
+ assignParserForLanguage(options);
67
+ const compartmentMap = await mapNodeModules(powers, moduleLocation, {
68
+ languages,
69
+ ...otherOptions,
70
+ });
71
+ return makeAndHashArchiveFromMap(powers, compartmentMap, {
72
+ parserForLanguage,
73
+ ...otherOptions,
74
+ });
66
75
  };
67
76
 
68
77
  /**
@@ -72,20 +81,41 @@ export const makeAndHashArchive = async (
72
81
  * @returns {Promise<Uint8Array>}
73
82
  */
74
83
  export const makeArchive = async (powers, moduleLocation, options = {}) => {
75
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
76
-
84
+ const {
85
+ dev,
86
+ tags,
87
+ conditions = tags,
88
+ commonDependencies,
89
+ policy,
90
+ languageForExtension,
91
+ commonjsLanguageForExtension,
92
+ moduleLanguageForExtension,
93
+ workspaceLanguageForExtension,
94
+ workspaceCommonjsLanguageForExtension,
95
+ workspaceModuleLanguageForExtension,
96
+ parserForLanguage,
97
+ languages,
98
+ ...otherOptions
99
+ } = assignParserForLanguage(options);
77
100
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
78
101
  dev,
79
102
  conditions,
80
103
  commonDependencies,
81
104
  policy,
105
+ languageForExtension,
106
+ commonjsLanguageForExtension,
107
+ moduleLanguageForExtension,
108
+ workspaceLanguageForExtension,
109
+ workspaceCommonjsLanguageForExtension,
110
+ workspaceModuleLanguageForExtension,
111
+ languages,
82
112
  });
83
113
 
84
- return makeArchiveFromMap(
85
- powers,
86
- compartmentMap,
87
- assignParserForLanguage(options),
88
- );
114
+ return makeArchiveFromMap(powers, compartmentMap, {
115
+ parserForLanguage,
116
+ policy,
117
+ ...otherOptions,
118
+ });
89
119
  };
90
120
 
91
121
  /**
@@ -95,16 +125,42 @@ export const makeArchive = async (powers, moduleLocation, options = {}) => {
95
125
  * @returns {Promise<Uint8Array>}
96
126
  */
97
127
  export const mapLocation = async (powers, moduleLocation, options = {}) => {
98
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
128
+ const {
129
+ dev,
130
+ tags,
131
+ conditions = tags,
132
+ commonDependencies,
133
+ policy,
134
+ parserForLanguage,
135
+ languages,
136
+ languageForExtension,
137
+ commonjsLanguageForExtension,
138
+ moduleLanguageForExtension,
139
+ workspaceLanguageForExtension,
140
+ workspaceCommonjsLanguageForExtension,
141
+ workspaceModuleLanguageForExtension,
142
+ ...otherOptions
143
+ } = assignParserForLanguage(options);
99
144
 
100
145
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
101
146
  dev,
102
147
  conditions,
103
148
  commonDependencies,
104
149
  policy,
150
+ languages,
151
+ languageForExtension,
152
+ commonjsLanguageForExtension,
153
+ moduleLanguageForExtension,
154
+ workspaceLanguageForExtension,
155
+ workspaceCommonjsLanguageForExtension,
156
+ workspaceModuleLanguageForExtension,
105
157
  });
106
158
 
107
- return mapFromMap(powers, compartmentMap, assignParserForLanguage(options));
159
+ return mapFromMap(powers, compartmentMap, {
160
+ parserForLanguage,
161
+ policy,
162
+ ...otherOptions,
163
+ });
108
164
  };
109
165
 
110
166
  /**
@@ -114,16 +170,42 @@ export const mapLocation = async (powers, moduleLocation, options = {}) => {
114
170
  * @returns {Promise<string>}
115
171
  */
116
172
  export const hashLocation = async (powers, moduleLocation, options = {}) => {
117
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
173
+ const {
174
+ dev,
175
+ tags,
176
+ conditions = tags,
177
+ commonDependencies,
178
+ policy,
179
+ parserForLanguage,
180
+ languages,
181
+ languageForExtension,
182
+ commonjsLanguageForExtension,
183
+ moduleLanguageForExtension,
184
+ workspaceLanguageForExtension,
185
+ workspaceCommonjsLanguageForExtension,
186
+ workspaceModuleLanguageForExtension,
187
+ ...otherOptions
188
+ } = assignParserForLanguage(options);
118
189
 
119
190
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
120
191
  dev,
121
192
  conditions,
122
193
  commonDependencies,
123
194
  policy,
195
+ languages,
196
+ languageForExtension,
197
+ commonjsLanguageForExtension,
198
+ moduleLanguageForExtension,
199
+ workspaceLanguageForExtension,
200
+ workspaceCommonjsLanguageForExtension,
201
+ workspaceModuleLanguageForExtension,
124
202
  });
125
203
 
126
- return hashFromMap(powers, compartmentMap, assignParserForLanguage(options));
204
+ return hashFromMap(powers, compartmentMap, {
205
+ parserForLanguage,
206
+ policy,
207
+ ...otherOptions,
208
+ });
127
209
  };
128
210
 
129
211
  /**
@@ -140,18 +222,40 @@ export const writeArchive = async (
140
222
  moduleLocation,
141
223
  options = {},
142
224
  ) => {
143
- const { dev, tags, conditions = tags, commonDependencies, policy } = options;
225
+ const {
226
+ dev,
227
+ tags,
228
+ conditions = tags,
229
+ commonDependencies,
230
+ policy,
231
+ parserForLanguage,
232
+ languages,
233
+ languageForExtension,
234
+ commonjsLanguageForExtension,
235
+ moduleLanguageForExtension,
236
+ workspaceLanguageForExtension,
237
+ workspaceCommonjsLanguageForExtension,
238
+ workspaceModuleLanguageForExtension,
239
+ ...otherOptions
240
+ } = assignParserForLanguage(options);
144
241
  const compartmentMap = await mapNodeModules(readPowers, moduleLocation, {
145
242
  dev,
146
243
  conditions,
147
244
  commonDependencies,
148
245
  policy,
246
+ languageForExtension,
247
+ commonjsLanguageForExtension,
248
+ moduleLanguageForExtension,
249
+ workspaceLanguageForExtension,
250
+ workspaceCommonjsLanguageForExtension,
251
+ workspaceModuleLanguageForExtension,
252
+ languages,
149
253
  });
150
254
  return writeArchiveFromMap(
151
255
  write,
152
256
  readPowers,
153
257
  archiveLocation,
154
258
  compartmentMap,
155
- assignParserForLanguage(options),
259
+ { policy, parserForLanguage, ...otherOptions },
156
260
  );
157
261
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AA4NO,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CA4K3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,uDAahB;;;;;;;;;;;gBAxYa,MAAM,MAAM;;;;;;;cAOZ,MAAM,MAAM;;;;;;;oBAIZ,MAAM,MAAM;;;;;wBAIZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;qBACN,MAAM;qBACN,MAAM;YACN,MAAM;YACN,gBAAgB,GAAG,oBAAoB;qBACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;oBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;WACtB,UAAU;WACV,MAAM;gBACN,UAAU;;0BAID,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,KAChC,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BApDvB,YAAY;gCACR,YAAY;qCAHP,YAAY;oCAHb,YAAY;6BAQnB,YAAY;sCAVH,KAAK"}
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["bundle.js"],"names":[],"mappings":"AAgOO,uCALI,MAAM,GAAG,UAAU,GAAG,eAAe,kBACrC,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAgN3B;AASM,mCANI,OAAO,QACP,MAAM,kBACN,MAAM,kBACN,MAAM,uDAahB;;;;;;;;;;;gBA5aa,MAAM,MAAM;;;;;;;cAOZ,MAAM,MAAM;;;;;;;oBAIZ,MAAM,MAAM;;;;;wBAIZ,MAAM,MAAM;;yBAKH,oBAAoB,SAA9B,OAAS;SAER,MAAM;qBACN,MAAM;qBACN,MAAM;YACN,MAAM;YACN,gBAAgB,GAAG,oBAAoB;qBACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;oBACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;WACtB,UAAU;WACV,MAAM;gBACN,UAAU;;0BAID,oBAAoB,SAA9B,OAAS,aAEX,YAAY,CAAC,oBAAoB,CAAC,KAChC,UAAU;2BAIA,oBAAoB,SAA9B,OAAS;aAER,MAAM;mBACN,aAAa,CAAC,oBAAoB,CAAC;;4BAlDvC,YAAY;gCAAZ,YAAY;qCAAZ,YAAY;oCAAZ,YAAY;6BAAZ,YAAY;sCAVZ,KAAK"}
package/src/bundle.js CHANGED
@@ -1,17 +1,21 @@
1
- // @ts-check
2
1
  /* eslint no-shadow: 0 */
3
2
 
4
- /** @import {StaticModuleType} from 'ses' */
5
-
6
- /** @import {ArchiveOptions} from './types.js' */
7
- /** @import {CompartmentDescriptor} from './types.js' */
8
- /** @import {CompartmentSources} from './types.js' */
9
- /** @import {MaybeReadPowers} from './types.js' */
10
- /** @import {PrecompiledStaticModuleInterface} from 'ses' */
11
- /** @import {ReadFn} from './types.js' */
12
- /** @import {ReadPowers} from './types.js' */
13
- /** @import {Sources} from './types.js' */
14
- /** @import {WriteFn} from './types.js' */
3
+ /**
4
+ * @import {
5
+ * StaticModuleType,
6
+ * PrecompiledStaticModuleInterface
7
+ * } from 'ses'
8
+ * @import {
9
+ * ArchiveOptions,
10
+ * CompartmentDescriptor,
11
+ * CompartmentSources,
12
+ * MaybeReadPowers,
13
+ * ReadFn,
14
+ * ReadPowers,
15
+ * Sources,
16
+ * WriteFn,
17
+ * } from './types.js'
18
+ */
15
19
 
16
20
  /**
17
21
  * @typedef {object} BundlerKit
@@ -231,6 +235,13 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
231
235
  sourceMapHook = undefined,
232
236
  parserForLanguage: parserForLanguageOption = {},
233
237
  languageForExtension: languageForExtensionOption = {},
238
+ commonjsLanguageForExtension: commonjsLanguageForExtensionOption = {},
239
+ moduleLanguageForExtension: moduleLanguageForExtensionOption = {},
240
+ workspaceLanguageForExtension: workspaceLanguageForExtensionOption = {},
241
+ workspaceCommonjsLanguageForExtension:
242
+ workspaceCommonjsLanguageForExtensionOption = {},
243
+ workspaceModuleLanguageForExtension:
244
+ workspaceModuleLanguageForExtensionOption = {},
234
245
  } = options || {};
235
246
  const conditions = new Set(conditionsOption);
236
247
 
@@ -244,6 +255,27 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
244
255
  const languageForExtension = Object.freeze(
245
256
  Object.assign(Object.create(null), languageForExtensionOption),
246
257
  );
258
+ const commonjsLanguageForExtension = Object.freeze(
259
+ Object.assign(Object.create(null), commonjsLanguageForExtensionOption),
260
+ );
261
+ const moduleLanguageForExtension = Object.freeze(
262
+ Object.assign(Object.create(null), moduleLanguageForExtensionOption),
263
+ );
264
+ const workspaceLanguageForExtension = Object.freeze(
265
+ Object.assign(Object.create(null), workspaceLanguageForExtensionOption),
266
+ );
267
+ const workspaceCommonjsLanguageForExtension = Object.freeze(
268
+ Object.assign(
269
+ Object.create(null),
270
+ workspaceCommonjsLanguageForExtensionOption,
271
+ ),
272
+ );
273
+ const workspaceModuleLanguageForExtension = Object.freeze(
274
+ Object.assign(
275
+ Object.create(null),
276
+ workspaceModuleLanguageForExtensionOption,
277
+ ),
278
+ );
247
279
 
248
280
  const {
249
281
  packageLocation,
@@ -262,7 +294,16 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
262
294
  conditions,
263
295
  packageDescriptor,
264
296
  moduleSpecifier,
265
- { dev, commonDependencies },
297
+ {
298
+ dev,
299
+ commonDependencies,
300
+ languageForExtension,
301
+ commonjsLanguageForExtension,
302
+ moduleLanguageForExtension,
303
+ workspaceLanguageForExtension,
304
+ workspaceCommonjsLanguageForExtension,
305
+ workspaceModuleLanguageForExtension,
306
+ },
266
307
  );
267
308
 
268
309
  const {
@@ -287,7 +328,6 @@ export const makeBundle = async (readPowers, moduleLocation, options) => {
287
328
  makeImportHook,
288
329
  moduleTransforms,
289
330
  parserForLanguage,
290
- languageForExtension,
291
331
  });
292
332
  await compartment.load(entryModuleSpecifier);
293
333
 
@@ -1,7 +1,7 @@
1
- export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureOptions | undefined): Promise<CaptureResult>;
1
+ export function captureFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: CaptureLiteOptions | undefined): Promise<CaptureResult>;
2
2
  import type { ReadFn } from './types.js';
3
3
  import type { ReadPowers } from './types.js';
4
4
  import type { CompartmentMapDescriptor } from './types.js';
5
- import type { CaptureOptions } from './types.js';
5
+ import type { CaptureLiteOptions } from './types.js';
6
6
  import type { CaptureResult } from './types.js';
7
7
  //# sourceMappingURL=capture-lite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAkQO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,yCAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BAlSyB,YAAY;gCACR,YAAY;8CACE,YAAY;oCACtB,YAAY;mCAIb,YAAY"}
1
+ {"version":3,"file":"capture-lite.d.ts","sourceRoot":"","sources":["capture-lite.js"],"names":[],"mappings":"AAsQO,uCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,aAAa,CAAC,CAmElC;4BA9RS,YAAY;gCAAZ,YAAY;8CAAZ,YAAY;wCAAZ,YAAY;mCAAZ,YAAY"}
@@ -1,4 +1,5 @@
1
1
  /**
2
+ * @module
2
3
  * This module provides {@link captureFromMap}, which only "captures" the
3
4
  * compartment map descriptors and sources from a partially completed
4
5
  * compartment map--_without_ creating an archive. The resulting compartment map
@@ -24,21 +25,22 @@
24
25
  * contain original sources, so to import the archive with
25
26
  * `src/import-archive-lite.js`, you will need to provide the archive parsers
26
27
  * and entrain a runtime dependency on Babel.
27
- *
28
- * @module
29
28
  */
30
29
 
31
- // @ts-check
32
30
  /* eslint no-shadow: 0 */
33
31
 
34
- /** @import {ReadFn} from './types.js' */
35
- /** @import {ReadPowers} from './types.js' */
36
- /** @import {CompartmentMapDescriptor} from './types.js' */
37
- /** @import {CaptureOptions} from './types.js' */
38
- /** @import {Sources} from './types.js' */
39
- /** @import {CompartmentDescriptor} from './types.js' */
40
- /** @import {ModuleDescriptor} from './types.js' */
41
- /** @import {CaptureResult} from './types.js' */
32
+ /**
33
+ * @import {
34
+ * CaptureLiteOptions,
35
+ * CaptureResult,
36
+ * CompartmentDescriptor,
37
+ * CompartmentMapDescriptor,
38
+ * ModuleDescriptor,
39
+ * ReadFn,
40
+ * ReadPowers,
41
+ * Sources,
42
+ * } from './types.js'
43
+ */
42
44
 
43
45
  import {
44
46
  assertCompartmentMap,
@@ -56,6 +58,8 @@ import { unpackReadPowers } from './powers.js';
56
58
 
57
59
  const { freeze, assign, create, fromEntries, entries, keys } = Object;
58
60
 
61
+ const defaultCompartment = Compartment;
62
+
59
63
  /**
60
64
  * We attempt to produce compartment maps that are consistent regardless of
61
65
  * whether the packages were originally laid out on disk for development or
@@ -253,27 +257,25 @@ const captureCompartmentMap = (compartmentMap, sources) => {
253
257
  /**
254
258
  * @param {ReadFn | ReadPowers} powers
255
259
  * @param {CompartmentMapDescriptor} compartmentMap
256
- * @param {CaptureOptions} [options]
260
+ * @param {CaptureLiteOptions} [options]
257
261
  * @returns {Promise<CaptureResult>}
258
262
  */
259
263
  export const captureFromMap = async (powers, compartmentMap, options = {}) => {
260
264
  const {
261
265
  moduleTransforms,
266
+ syncModuleTransforms,
262
267
  modules: exitModules = {},
263
268
  searchSuffixes = undefined,
264
269
  importHook: exitModuleImportHook = undefined,
265
270
  policy = undefined,
266
271
  sourceMapHook = undefined,
267
272
  parserForLanguage: parserForLanguageOption = {},
268
- languageForExtension: languageForExtensionOption = {},
273
+ Compartment = defaultCompartment,
269
274
  } = options;
270
275
 
271
276
  const parserForLanguage = freeze(
272
277
  assign(create(null), parserForLanguageOption),
273
278
  );
274
- const languageForExtension = freeze(
275
- assign(create(null), languageForExtensionOption),
276
- );
277
279
 
278
280
  const { read, computeSha512 } = unpackReadPowers(powers);
279
281
 
@@ -288,6 +290,7 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
288
290
  const consolidatedExitModuleImportHook = exitModuleImportHookMaker({
289
291
  modules: exitModules,
290
292
  exitModuleImportHook,
293
+ entryCompartmentName,
291
294
  });
292
295
 
293
296
  const makeImportHook = makeImportHookMaker(read, entryCompartmentName, {
@@ -306,9 +309,10 @@ export const captureFromMap = async (powers, compartmentMap, options = {}) => {
306
309
  resolve,
307
310
  makeImportHook,
308
311
  moduleTransforms,
312
+ syncModuleTransforms,
309
313
  parserForLanguage,
310
- languageForExtension,
311
314
  archiveOnly: true,
315
+ Compartment,
312
316
  });
313
317
  await compartment.load(entryModuleSpecifier);
314
318
  if (policy) {
@@ -1,5 +1,6 @@
1
1
  /** @type {(a: string, b: string) => number} */
2
2
  export const stringCompare: (a: string, b: string) => number;
3
3
  export function pathCompare(a: Array<string> | undefined, b: Array<string> | undefined): number;
4
- export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is import("./types.js").CompartmentMapDescriptor;
4
+ export function assertCompartmentMap(allegedCompartmentMap: unknown, url?: string | undefined): asserts allegedCompartmentMap is CompartmentMapDescriptor;
5
+ import type { CompartmentMapDescriptor } from './types.js';
5
6
  //# sourceMappingURL=compartment-map.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"AAaA,+CAA+C;AAE/C,4BAFW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAE2B;AAc/D,+BAHI,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KACzB,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,UAqCnC;AAuZM,4DALI,OAAO,6BAEL,QAAQ,qBAAqB,IAAI,OAAO,YAAY,EAAE,wBAAwB,CA+B1F"}
1
+ {"version":3,"file":"compartment-map.d.ts","sourceRoot":"","sources":["compartment-map.js"],"names":[],"mappings":"AAYA,+CAA+C;AAE/C,4BAFW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAE2B;AAc/D,+BAHI,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,KACzB,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,UAqCnC;AA8ZM,4DALI,OAAO,6BAEL,QAAQ,qBAAqB,IAAI,wBAAwB,CA+BrE;8CArf2C,YAAY"}
@@ -1,10 +1,9 @@
1
1
  /* Validates a compartment map against its schema. */
2
2
 
3
- // @ts-check
4
- /// <reference types="ses"/>
5
-
6
3
  import { assertPackagePolicy } from './policy-format.js';
7
4
 
5
+ /** @import {CompartmentMapDescriptor} from './types.js' */
6
+
8
7
  // TODO convert to the new `||` assert style.
9
8
  // Deferred because this file pervasively uses simple template strings rather than
10
9
  // template strings tagged with `assert.details` (aka `X`), and uses
@@ -109,7 +108,7 @@ const assertConditions = (conditions, url) => {
109
108
  * @param {string} url
110
109
  */
111
110
  const assertCompartmentModule = (allegedModule, path, url) => {
112
- const { compartment, module, ...extra } = allegedModule;
111
+ const { compartment, module, retained, ...extra } = allegedModule;
113
112
  assertEmptyObject(
114
113
  extra,
115
114
  `${path} must not have extra properties, got ${q({
@@ -127,6 +126,13 @@ const assertCompartmentModule = (allegedModule, path, url) => {
127
126
  'string',
128
127
  `${path}.module must be a string, got ${q(module)} in ${q(url)}`,
129
128
  );
129
+ if (retained !== undefined) {
130
+ assert.typeof(
131
+ retained,
132
+ 'boolean',
133
+ `${path}.retained must be a boolean, got ${q(retained)} in ${q(url)}`,
134
+ );
135
+ }
130
136
  };
131
137
 
132
138
  /**
@@ -466,7 +472,7 @@ const assertEntry = (allegedEntry, url) => {
466
472
  /**
467
473
  * @param {unknown} allegedCompartmentMap
468
474
  * @param {string} [url]
469
- * @returns {asserts allegedCompartmentMap is import('./types.js').CompartmentMapDescriptor}
475
+ * @returns {asserts allegedCompartmentMap is CompartmentMapDescriptor}
470
476
  */
471
477
 
472
478
  export const assertCompartmentMap = (
@@ -1 +1 @@
1
- {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["extension.js"],"names":[],"mappings":"AAYO,yCAHI,MAAM,GACJ,MAAM,CAalB"}
1
+ {"version":3,"file":"extension.d.ts","sourceRoot":"","sources":["extension.js"],"names":[],"mappings":"AAUO,yCAHI,MAAM,GACJ,MAAM,CAalB"}
package/src/extension.js CHANGED
@@ -1,6 +1,4 @@
1
- /* Extracts the extension from a URL pathname. */
2
-
3
- // @ts-check
1
+ /** @module Extracts the extension from a URL pathname. */
4
2
 
5
3
  /**
6
4
  * `parseExtension` returns the file extension for the given URL, or an empty
@@ -1,23 +1,7 @@
1
- export function parseArchive(archiveBytes: Uint8Array, archiveLocation?: string | undefined, options?: {
2
- expectedSha512?: string | undefined;
3
- computeSha512?: HashFn | undefined;
4
- modules?: Record<string, unknown> | undefined;
5
- importHook?: ExitModuleImportHook | undefined;
6
- Compartment?: typeof Compartment | undefined;
7
- computeSourceLocation?: ComputeSourceLocationHook | undefined;
8
- computeSourceMapLocation?: ComputeSourceMapLocationHook | undefined;
9
- parserForLanguage?: ParserForLanguage | undefined;
10
- languageForExtension?: LanguageForExtension | undefined;
11
- } | undefined): Promise<Application>;
12
- export function loadArchive(readPowers: ReadFn | ReadPowers, archiveLocation: string, options?: LoadArchiveOptions | undefined): Promise<Application>;
1
+ export function parseArchive(archiveBytes: Uint8Array, archiveLocation?: string | undefined, options?: ParseArchiveOptions | undefined): Promise<Application>;
2
+ export function loadArchive(readPowers: ReadFn | ReadPowers, archiveLocation: string, options?: ParseArchiveOptions | undefined): Promise<Application>;
13
3
  export function importArchive(readPowers: ReadFn | ReadPowers, archiveLocation: string, options: LoadArchiveOptions): Promise<SomeObject>;
14
- export type CompartmentConstructor = typeof Compartment;
15
- import type { HashFn } from './types.js';
16
- import type { ExitModuleImportHook } from './types.js';
17
- import type { ComputeSourceLocationHook } from './types.js';
18
- import type { ComputeSourceMapLocationHook } from './types.js';
19
- import type { ParserForLanguage } from './types.js';
20
- import type { LanguageForExtension } from './types.js';
4
+ import type { ParseArchiveOptions } from './types.js';
21
5
  import type { Application } from './types.js';
22
6
  import type { ReadFn } from './types.js';
23
7
  import type { ReadPowers } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"import-archive-lite.d.ts","sourceRoot":"","sources":["import-archive-lite.js"],"names":[],"mappings":"AA4PO,2CAdI,UAAU;;;;;;;;;;gBAYR,OAAO,CAAC,WAAW,CAAC,CAiKhC;AAQM,wCALI,MAAM,GAAG,UAAU,mBACnB,MAAM,6CAEJ,OAAO,CAAC,WAAW,CAAC,CA0BhC;AAQM,0CALI,MAAM,GAAG,UAAU,mBACnB,MAAM,WACN,kBAAkB,GAChB,OAAO,CAAC,UAAU,CAAC,CAK/B;qCA3Na,OAAO,WAAW;4BAlNN,YAAY;0CADE,YAAY;+CAHP,YAAY;kDACT,YAAY;uCAOvB,YAAY;0CAFT,YAAY;iCARrB,YAAY;4BAWjB,YAAY;gCACR,YAAY;wCAHJ,YAAY;gCAIpB,YAAY"}
1
+ {"version":3,"file":"import-archive-lite.d.ts","sourceRoot":"","sources":["import-archive-lite.js"],"names":[],"mappings":"AAoPO,2CALI,UAAU,oFAGR,OAAO,CAAC,WAAW,CAAC,CA6JhC;AAQM,wCALI,MAAM,GAAG,UAAU,mBACnB,MAAM,8CAEJ,OAAO,CAAC,WAAW,CAAC,CAwBhC;AAQM,0CALI,MAAM,GAAG,UAAU,mBACnB,MAAM,WACN,kBAAkB,GAChB,OAAO,CAAC,UAAU,CAAC,CAK/B;yCApZS,YAAY;iCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;wCAAZ,YAAY;gCAAZ,YAAY"}