@endo/compartment-mapper 1.4.0 → 1.6.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 (93) hide show
  1. package/README.md +292 -111
  2. package/bundle.d.ts +1 -1
  3. package/bundle.js +4 -1
  4. package/functor-lite.d.ts +3 -0
  5. package/functor-lite.d.ts.map +1 -0
  6. package/functor-lite.js +4 -0
  7. package/functor.d.ts +3 -0
  8. package/functor.d.ts.map +1 -0
  9. package/functor.js +4 -0
  10. package/import-archive-all-parsers.d.ts +2 -0
  11. package/import-archive-all-parsers.d.ts.map +1 -0
  12. package/import-archive-all-parsers.js +1 -0
  13. package/index.d.ts +1 -1
  14. package/index.js +4 -1
  15. package/package.json +14 -5
  16. package/script-lite.d.ts +3 -0
  17. package/script-lite.d.ts.map +1 -0
  18. package/script-lite.js +4 -0
  19. package/script.d.ts +3 -0
  20. package/script.d.ts.map +1 -0
  21. package/script.js +4 -0
  22. package/src/archive-lite.d.ts +2 -4
  23. package/src/archive-lite.d.ts.map +1 -1
  24. package/src/archive-lite.js +16 -192
  25. package/src/archive.d.ts.map +1 -1
  26. package/src/archive.js +8 -0
  27. package/src/bundle-cjs.d.ts +1 -1
  28. package/src/bundle-cjs.d.ts.map +1 -1
  29. package/src/bundle-cjs.js +57 -28
  30. package/src/bundle-json.d.ts.map +1 -1
  31. package/src/bundle-json.js +2 -3
  32. package/src/bundle-lite.d.ts +91 -0
  33. package/src/bundle-lite.d.ts.map +1 -0
  34. package/src/bundle-lite.js +668 -0
  35. package/src/bundle-mjs.d.ts +2 -2
  36. package/src/bundle-mjs.d.ts.map +1 -1
  37. package/src/bundle-mjs.js +36 -19
  38. package/src/bundle.d.ts +48 -10
  39. package/src/bundle.d.ts.map +1 -1
  40. package/src/bundle.js +399 -127
  41. package/src/capture-lite.d.ts.map +1 -1
  42. package/src/capture-lite.js +10 -188
  43. package/src/digest.d.ts +5 -0
  44. package/src/digest.d.ts.map +1 -0
  45. package/src/digest.js +235 -0
  46. package/src/import-archive-all-parsers.d.ts +11 -0
  47. package/src/import-archive-all-parsers.d.ts.map +1 -0
  48. package/src/import-archive-all-parsers.js +29 -0
  49. package/src/import-archive-lite.d.ts.map +1 -1
  50. package/src/import-archive-lite.js +4 -0
  51. package/src/import-hook.d.ts +3 -16
  52. package/src/import-hook.d.ts.map +1 -1
  53. package/src/import-hook.js +11 -18
  54. package/src/import-lite.d.ts.map +1 -1
  55. package/src/import-lite.js +7 -2
  56. package/src/import.d.ts.map +1 -1
  57. package/src/import.js +2 -0
  58. package/src/link.d.ts.map +1 -1
  59. package/src/link.js +2 -0
  60. package/src/map-parser.d.ts.map +1 -1
  61. package/src/map-parser.js +4 -1
  62. package/src/node-modules.d.ts +4 -47
  63. package/src/node-modules.d.ts.map +1 -1
  64. package/src/node-modules.js +157 -131
  65. package/src/parse-archive-cjs.d.ts.map +1 -1
  66. package/src/parse-archive-cjs.js +8 -3
  67. package/src/parse-cjs-shared-export-wrapper.d.ts.map +1 -1
  68. package/src/parse-cjs-shared-export-wrapper.js +2 -10
  69. package/src/parse-cjs.js +1 -1
  70. package/src/parse-mjs.js +2 -2
  71. package/src/policy.d.ts.map +1 -1
  72. package/src/policy.js +4 -7
  73. package/src/search.d.ts +6 -12
  74. package/src/search.d.ts.map +1 -1
  75. package/src/search.js +29 -12
  76. package/src/types/compartment-map-schema.d.ts +5 -0
  77. package/src/types/compartment-map-schema.d.ts.map +1 -1
  78. package/src/types/compartment-map-schema.ts +5 -0
  79. package/src/types/external.d.ts +159 -12
  80. package/src/types/external.d.ts.map +1 -1
  81. package/src/types/external.ts +180 -12
  82. package/src/types/internal.d.ts +86 -13
  83. package/src/types/internal.d.ts.map +1 -1
  84. package/src/types/internal.ts +107 -13
  85. package/src/types/node-modules.d.ts +79 -0
  86. package/src/types/node-modules.d.ts.map +1 -0
  87. package/src/types/node-modules.ts +89 -0
  88. package/src/types/node-powers.d.ts +4 -4
  89. package/src/types/node-powers.d.ts.map +1 -1
  90. package/src/types/node-powers.ts +4 -4
  91. package/src/types/powers.d.ts +2 -2
  92. package/src/types/powers.d.ts.map +1 -1
  93. package/src/types/powers.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/compartment-mapper",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "The compartment mapper assembles Node applications in a sandbox",
5
5
  "keywords": [
6
6
  "node",
@@ -32,8 +32,17 @@
32
32
  "./capture-lite.js": "./capture-lite.js",
33
33
  "./import-archive.js": "./import-archive.js",
34
34
  "./import-archive-lite.js": "./import-archive-lite.js",
35
- "./import-archive-parsers.js": "./import-archive-parsers.js",
35
+ "./import-archive-parsers.js": {
36
+ "xs": "./import-archive-all-parsers.js",
37
+ "node": "./import-archive-all-parsers.js",
38
+ "default": "./import-archive-parsers.js"
39
+ },
40
+ "./import-archive-all-parsers.js": "./import-archive-all-parsers.js",
36
41
  "./bundle.js": "./bundle.js",
42
+ "./functor.js": "./functor.js",
43
+ "./functor-lite.js": "./functor-lite.js",
44
+ "./script.js": "./script.js",
45
+ "./script-lite.js": "./script-lite.js",
37
46
  "./node-powers.js": "./node-powers.js",
38
47
  "./node-modules.js": "./node-modules.js",
39
48
  "./package.json": "./package.json"
@@ -52,10 +61,10 @@
52
61
  },
53
62
  "dependencies": {
54
63
  "@endo/cjs-module-analyzer": "^1.0.9",
55
- "@endo/module-source": "^1.1.2",
64
+ "@endo/module-source": "^1.3.0",
56
65
  "@endo/trampoline": "^1.0.3",
57
66
  "@endo/zip": "^1.0.9",
58
- "ses": "^1.10.0"
67
+ "ses": "^1.12.0"
59
68
  },
60
69
  "devDependencies": {
61
70
  "ava": "^6.1.3",
@@ -109,5 +118,5 @@
109
118
  "typeCoverage": {
110
119
  "atLeast": 86.14
111
120
  },
112
- "gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
121
+ "gitHead": "9b6784831d37db948cdd61f6da1f3489e8f97906"
113
122
  }
@@ -0,0 +1,3 @@
1
+ export * from "./src/types-external.js";
2
+ export { makeScriptFromMap } from "./src/bundle-lite.js";
3
+ //# sourceMappingURL=script-lite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-lite.d.ts","sourceRoot":"","sources":["script-lite.js"],"names":[],"mappings":""}
package/script-lite.js ADDED
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
4
+ export { makeScriptFromMap } from './src/bundle-lite.js';
package/script.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./src/types-external.js";
2
+ export { makeScript } from "./src/bundle.js";
3
+ //# sourceMappingURL=script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["script.js"],"names":[],"mappings":""}
package/script.js ADDED
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line import/export -- just types
2
+ export * from './src/types-external.js';
3
+
4
+ export { makeScript } from './src/bundle.js';
@@ -1,7 +1,4 @@
1
- export function makeArchiveCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): {
2
- archiveCompartmentMap: CompartmentMapDescriptor;
3
- archiveSources: Sources;
4
- };
1
+ export function makeArchiveCompartmentMap(compartmentMap: CompartmentMapDescriptor, sources: Sources): ArchiveResult;
5
2
  export function makeAndHashArchiveFromMap(powers: ReadFn | ReadPowers, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<{
6
3
  bytes: Uint8Array;
7
4
  sha512?: string;
@@ -12,6 +9,7 @@ export function hashFromMap(powers: HashPowers, compartmentMap: CompartmentMapDe
12
9
  export function writeArchiveFromMap(write: WriteFn, readPowers: ReadFn | ReadPowers, archiveLocation: string, compartmentMap: CompartmentMapDescriptor, options?: ArchiveLiteOptions | undefined): Promise<void>;
13
10
  import type { CompartmentMapDescriptor } from './types.js';
14
11
  import type { Sources } from './types.js';
12
+ import type { ArchiveResult } from './types.js';
15
13
  import type { ReadFn } from './types.js';
16
14
  import type { ReadPowers } from './types.js';
17
15
  import type { ArchiveLiteOptions } from './types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AAiRO,0DAJI,wBAAwB,WACxB,OAAO,GACL;IAAC,qBAAqB,EAAE,wBAAwB,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAC,CAmCtF;AAyGM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAmBzD;AAQM,2CALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,mCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,oCALI,UAAU,kBACV,wBAAwB,6CAEtB,OAAO,CAAC,MAAM,CAAC,CAU3B;AASM,2CANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,wBAAwB,2DAgBlC;8CAncS,YAAY;6BAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;wCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
1
+ {"version":3,"file":"archive-lite.d.ts","sourceRoot":"","sources":["archive-lite.js"],"names":[],"mappings":"AAmHO,0DAJI,wBAAwB,WACxB,OAAO,GACL,aAAa,CAiBzB;AAyGM,kDALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAmBzD;AAQM,2CALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,mCALI,MAAM,GAAG,UAAU,kBACnB,wBAAwB,6CAEtB,OAAO,CAAC,UAAU,CAAC,CAS/B;AAQM,oCALI,UAAU,kBACV,wBAAwB,6CAEtB,OAAO,CAAC,MAAM,CAAC,CAU3B;AASM,2CANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,wBAAwB,2DAgBlC;8CApRS,YAAY;6BAAZ,YAAY;mCAAZ,YAAY;4BAAZ,YAAY;gCAAZ,YAAY;wCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
@@ -33,12 +33,11 @@
33
33
  /**
34
34
  * @import {
35
35
  * ArchiveLiteOptions,
36
+ * ArchiveResult,
36
37
  * ArchiveWriter,
37
38
  * CaptureSourceLocationHook,
38
- * CompartmentDescriptor,
39
39
  * CompartmentMapDescriptor,
40
40
  * HashPowers,
41
- * ModuleDescriptor,
42
41
  * ReadFn,
43
42
  * ReadPowers,
44
43
  * Sources,
@@ -54,12 +53,8 @@ import {
54
53
  makeImportHookMaker,
55
54
  } from './import-hook.js';
56
55
  import { unpackReadPowers } from './powers.js';
57
- import {
58
- assertCompartmentMap,
59
- stringCompare,
60
- pathCompare,
61
- } from './compartment-map.js';
62
56
  import { detectAttenuators } from './policy.js';
57
+ import { digestCompartmentMap } from './digest.js';
63
58
 
64
59
  const textEncoder = new TextEncoder();
65
60
 
@@ -72,160 +67,7 @@ const { assign, create, freeze } = Object;
72
67
  */
73
68
  const resolveLocation = (rel, abs) => new URL(rel, abs).toString();
74
69
 
75
- const { keys, entries, fromEntries } = Object;
76
-
77
- /**
78
- * We attempt to produce compartment maps that are consistent regardless of
79
- * whether the packages were originally laid out on disk for development or
80
- * production, and other trivia like the fully qualified path of a specific
81
- * installation.
82
- *
83
- * Naming compartments for the self-ascribed name and version of each Node.js
84
- * package is insufficient because they are not guaranteed to be unique.
85
- * Dependencies do not necessarilly come from the npm registry and may be
86
- * for example derived from fully qualified URL's or Github org and project
87
- * names.
88
- * Package managers are also not required to fully deduplicate the hard
89
- * copy of each package even when they are identical resources.
90
- * Duplication is undesirable, but we elect to defer that problem to solutions
91
- * in the package managers, as the alternative would be to consistently hash
92
- * the original sources of the packages themselves, which may not even be
93
- * available much less pristine for us.
94
- *
95
- * So, instead, we use the lexically least path of dependency names, delimited
96
- * by hashes.
97
- * The compartment maps generated by the ./node-modules.js tooling pre-compute
98
- * these traces for our use here.
99
- * We sort the compartments lexically on their self-ascribed name and version,
100
- * and use the lexically least dependency name path as a tie-breaker.
101
- * The dependency path is logical and orthogonal to the package manager's
102
- * actual installation location, so should be orthogonal to the vagaries of the
103
- * package manager's deduplication algorithm.
104
- *
105
- * @param {Record<string, CompartmentDescriptor>} compartments
106
- * @returns {Record<string, string>} map from old to new compartment names.
107
- */
108
- const renameCompartments = compartments => {
109
- /** @type {Record<string, string>} */
110
- const compartmentRenames = create(null);
111
- let index = 0;
112
- let prev = '';
113
-
114
- // The sort below combines two comparators to avoid depending on sort
115
- // stability, which became standard as recently as 2019.
116
- // If that date seems quaint, please accept my regards from the distant past.
117
- // We are very proud of you.
118
- const compartmentsByPath = Object.entries(compartments)
119
- .map(([name, compartment]) => ({
120
- name,
121
- path: compartment.path,
122
- label: compartment.label,
123
- }))
124
- .sort((a, b) => {
125
- if (a.label === b.label) {
126
- assert(a.path !== undefined && b.path !== undefined);
127
- return pathCompare(a.path, b.path);
128
- }
129
- return stringCompare(a.label, b.label);
130
- });
131
-
132
- for (const { name, label } of compartmentsByPath) {
133
- if (label === prev) {
134
- compartmentRenames[name] = `${label}-n${index}`;
135
- index += 1;
136
- } else {
137
- compartmentRenames[name] = label;
138
- prev = label;
139
- index = 1;
140
- }
141
- }
142
- return compartmentRenames;
143
- };
144
-
145
- /**
146
- * @param {Record<string, CompartmentDescriptor>} compartments
147
- * @param {Sources} sources
148
- * @param {Record<string, string>} compartmentRenames
149
- */
150
- const translateCompartmentMap = (compartments, sources, compartmentRenames) => {
151
- const result = create(null);
152
- for (const compartmentName of keys(compartmentRenames)) {
153
- const compartment = compartments[compartmentName];
154
- const { name, label, retained: compartmentRetained, policy } = compartment;
155
- if (compartmentRetained) {
156
- // rename module compartments
157
- /** @type {Record<string, ModuleDescriptor>} */
158
- const modules = create(null);
159
- const compartmentModules = compartment.modules;
160
- if (compartment.modules) {
161
- for (const name of keys(compartmentModules).sort()) {
162
- const { retained: moduleRetained, ...retainedModule } =
163
- compartmentModules[name];
164
- if (moduleRetained) {
165
- if (retainedModule.compartment !== undefined) {
166
- modules[name] = {
167
- ...retainedModule,
168
- compartment: compartmentRenames[retainedModule.compartment],
169
- };
170
- } else {
171
- modules[name] = retainedModule;
172
- }
173
- }
174
- }
175
- }
176
-
177
- // integrate sources into modules
178
- const compartmentSources = sources[compartmentName];
179
- if (compartmentSources) {
180
- for (const name of keys(compartmentSources).sort()) {
181
- const source = compartmentSources[name];
182
- const { location, parser, exit, sha512, deferredError } = source;
183
- if (location !== undefined) {
184
- modules[name] = {
185
- location,
186
- parser,
187
- sha512,
188
- };
189
- } else if (exit !== undefined) {
190
- modules[name] = {
191
- exit,
192
- };
193
- } else if (deferredError !== undefined) {
194
- modules[name] = {
195
- deferredError,
196
- };
197
- }
198
- }
199
- }
200
-
201
- result[compartmentRenames[compartmentName]] = {
202
- name,
203
- label,
204
- location: compartmentRenames[compartmentName],
205
- modules,
206
- policy,
207
- // `scopes`, `types`, and `parsers` are not necessary since every
208
- // loadable module is captured in `modules`.
209
- };
210
- }
211
- }
212
-
213
- return result;
214
- };
215
-
216
- /**
217
- * @param {Sources} sources
218
- * @param {Record<string, string>} compartmentRenames
219
- * @returns {Sources}
220
- */
221
- const renameSources = (sources, compartmentRenames) => {
222
- return fromEntries(
223
- entries(sources).map(([name, compartmentSources]) => [
224
- compartmentRenames[name],
225
- compartmentSources,
226
- ]),
227
- );
228
- };
70
+ const { keys } = Object;
229
71
 
230
72
  /**
231
73
  * @param {ArchiveWriter} archive
@@ -269,41 +111,23 @@ const captureSourceLocations = async (sources, captureSourceLocation) => {
269
111
  /**
270
112
  * @param {CompartmentMapDescriptor} compartmentMap
271
113
  * @param {Sources} sources
272
- * @returns {{archiveCompartmentMap: CompartmentMapDescriptor, archiveSources: Sources}}
114
+ * @returns {ArchiveResult}
273
115
  */
274
116
  export const makeArchiveCompartmentMap = (compartmentMap, sources) => {
275
117
  const {
276
- compartments,
277
- entry: { compartment: entryCompartmentName, module: entryModuleSpecifier },
278
- } = compartmentMap;
279
-
280
- const compartmentRenames = renameCompartments(compartments);
281
- const archiveCompartments = translateCompartmentMap(
282
- compartments,
283
- sources,
118
+ compartmentMap: archiveCompartmentMap,
119
+ sources: archiveSources,
120
+ oldToNewCompartmentNames,
121
+ newToOldCompartmentNames,
122
+ compartmentRenames,
123
+ } = digestCompartmentMap(compartmentMap, sources);
124
+ return {
125
+ archiveCompartmentMap,
126
+ archiveSources,
127
+ oldToNewCompartmentNames,
128
+ newToOldCompartmentNames,
284
129
  compartmentRenames,
285
- );
286
- const archiveEntryCompartmentName = compartmentRenames[entryCompartmentName];
287
- const archiveSources = renameSources(sources, compartmentRenames);
288
-
289
- const archiveCompartmentMap = {
290
- // TODO migrate tags to conditions
291
- // https://github.com/endojs/endo/issues/2388
292
- tags: [],
293
- entry: {
294
- compartment: archiveEntryCompartmentName,
295
- module: entryModuleSpecifier,
296
- },
297
- compartments: archiveCompartments,
298
130
  };
299
-
300
- // Cross-check:
301
- // We assert that we have constructed a valid compartment map, not because it
302
- // might not be, but to ensure that the assertCompartmentMap function can
303
- // accept all valid compartment maps.
304
- assertCompartmentMap(archiveCompartmentMap);
305
-
306
- return { archiveCompartmentMap, archiveSources };
307
131
  };
308
132
 
309
133
  /**
@@ -352,7 +176,7 @@ const digestFromMap = async (powers, compartmentMap, options = {}) => {
352
176
  searchSuffixes,
353
177
  entryCompartmentName,
354
178
  entryModuleSpecifier,
355
- exitModuleImportHook: consolidatedExitModuleImportHook,
179
+ importHook: consolidatedExitModuleImportHook,
356
180
  sourceMapHook,
357
181
  });
358
182
  // Induce importHook to record all the necessary modules to import the given module specifier.
@@ -1 +1 @@
1
- {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["archive.js"],"names":[],"mappings":"AA2DO,2CALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAiBzD;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAsC/B;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAuC/B;AAQM,qCALI,UAAU,kBACV,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAuC3B;AASM,oCANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,MAAM,uDA8ChB;4BA5OS,YAAY;gCAAZ,YAAY;oCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
1
+ {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["archive.js"],"names":[],"mappings":"AA2DO,2CALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAiBzD;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAwC/B;AAQM,oCALI,MAAM,GAAG,UAAU,kBACnB,MAAM,yCAEJ,OAAO,CAAC,UAAU,CAAC,CAyC/B;AAQM,qCALI,UAAU,kBACV,MAAM,yCAEJ,OAAO,CAAC,MAAM,CAAC,CAyC3B;AASM,oCANI,OAAO,cACP,MAAM,GAAG,UAAU,mBACnB,MAAM,kBACN,MAAM,uDAgDhB;4BApPS,YAAY;gCAAZ,YAAY;oCAAZ,YAAY;gCAAZ,YAAY;6BAAZ,YAAY"}
package/src/archive.js CHANGED
@@ -85,6 +85,7 @@ export const makeArchive = async (powers, moduleLocation, options = {}) => {
85
85
  dev,
86
86
  tags,
87
87
  conditions = tags,
88
+ strict = false,
88
89
  commonDependencies,
89
90
  policy,
90
91
  languageForExtension,
@@ -99,6 +100,7 @@ export const makeArchive = async (powers, moduleLocation, options = {}) => {
99
100
  } = assignParserForLanguage(options);
100
101
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
101
102
  dev,
103
+ strict,
102
104
  conditions,
103
105
  commonDependencies,
104
106
  policy,
@@ -129,6 +131,7 @@ export const mapLocation = async (powers, moduleLocation, options = {}) => {
129
131
  dev,
130
132
  tags,
131
133
  conditions = tags,
134
+ strict = false,
132
135
  commonDependencies,
133
136
  policy,
134
137
  parserForLanguage,
@@ -144,6 +147,7 @@ export const mapLocation = async (powers, moduleLocation, options = {}) => {
144
147
 
145
148
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
146
149
  dev,
150
+ strict,
147
151
  conditions,
148
152
  commonDependencies,
149
153
  policy,
@@ -174,6 +178,7 @@ export const hashLocation = async (powers, moduleLocation, options = {}) => {
174
178
  dev,
175
179
  tags,
176
180
  conditions = tags,
181
+ strict = false,
177
182
  commonDependencies,
178
183
  policy,
179
184
  parserForLanguage,
@@ -189,6 +194,7 @@ export const hashLocation = async (powers, moduleLocation, options = {}) => {
189
194
 
190
195
  const compartmentMap = await mapNodeModules(powers, moduleLocation, {
191
196
  dev,
197
+ strict,
192
198
  conditions,
193
199
  commonDependencies,
194
200
  policy,
@@ -226,6 +232,7 @@ export const writeArchive = async (
226
232
  dev,
227
233
  tags,
228
234
  conditions = tags,
235
+ strict = false,
229
236
  commonDependencies,
230
237
  policy,
231
238
  parserForLanguage,
@@ -240,6 +247,7 @@ export const writeArchive = async (
240
247
  } = assignParserForLanguage(options);
241
248
  const compartmentMap = await mapNodeModules(readPowers, moduleLocation, {
242
249
  dev,
250
+ strict,
243
251
  conditions,
244
252
  commonDependencies,
245
253
  policy,
@@ -3,6 +3,6 @@ export default _default;
3
3
  export type CjsModuleSource = VirtualModuleSource & {
4
4
  cjsFunctor: string;
5
5
  };
6
- import type { BundlerSupport } from './bundle.js';
6
+ import type { BundlerSupport } from './bundle-lite.js';
7
7
  import type { VirtualModuleSource } from 'ses';
8
8
  //# sourceMappingURL=bundle-cjs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":"wBA4DW,eAAe,eAAe,CAAC;;8BAvD5B,mBAAmB,GAAG;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC;oCAFtB,aAAa;yCADR,KAAK"}
1
+ {"version":3,"file":"bundle-cjs.d.ts","sourceRoot":"","sources":["bundle-cjs.js"],"names":[],"mappings":"wBAyEW,eAAe,eAAe,CAAC;;8BApE5B,mBAAmB,GAAG;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC;oCAFtB,kBAAkB;yCADb,KAAK"}
package/src/bundle-cjs.js CHANGED
@@ -1,10 +1,12 @@
1
1
  /* Provides CommonJS support for `bundle.js`. */
2
2
 
3
3
  /** @import {VirtualModuleSource} from 'ses' */
4
- /** @import {BundlerSupport} from './bundle.js' */
4
+ /** @import {BundlerSupport} from './bundle-lite.js' */
5
5
 
6
6
  /** @typedef {VirtualModuleSource & {cjsFunctor: string}} CjsModuleSource */
7
7
 
8
+ import { join } from './node-module-specifier.js';
9
+
8
10
  /** quotes strings */
9
11
  const q = JSON.stringify;
10
12
 
@@ -21,27 +23,34 @@ const exportsCellRecord = exportsList =>
21
23
 
22
24
  // This function is serialized and references variables from its destination scope.
23
25
  const runtime = `\
24
- function wrapCjsFunctor(num) {
26
+ function wrapCjsFunctor(index, functor) {
25
27
  /* eslint-disable no-undef */
26
28
  return ({ imports = {} }) => {
27
- const moduleCells = cells[num];
28
- const cModule = Object.freeze(
29
- Object.defineProperty({}, 'exports', moduleCells.default),
29
+ const moduleCells = cells[index];
30
+ const cModule = freeze(
31
+ defineProperty({}, 'exports', moduleCells.default),
30
32
  );
31
33
  // TODO: specifier not found handling
32
34
  const requireImpl = specifier => cells[imports[specifier]].default.get();
33
- functors[num](Object.freeze(requireImpl), cModule.exports, cModule);
35
+ functor(freeze(requireImpl), cModule.exports, cModule);
34
36
  // Update all named cells from module.exports.
35
- Object.keys(moduleCells)
36
- .filter(k => k !== 'default' && k !== '*')
37
- .map(k => moduleCells[k].set(cModule.exports[k]));
37
+ const names = keys(moduleCells);
38
+ for (let i = 0; i < names.length; i += 1) {
39
+ const name = names[i];
40
+ if (name !== 'default' && name !== '*') {
41
+ moduleCells[name].set(cModule.exports[name]);
42
+ }
43
+ }
38
44
  // Add new named cells from module.exports.
39
- Object.keys(cModule.exports)
40
- .filter(k => k !== 'default' && k !== '*')
41
- .filter(k => moduleCells[k] === undefined)
42
- .map(k => (moduleCells[k] = cell(k, cModule.exports[k])));
45
+ const exportNames = keys(cModule.exports);
46
+ for (let i = 0; i < exportNames.length; i += 1) {
47
+ const name = exportNames[i];
48
+ if (name !== 'default' && name !== '*' && moduleCells[name] === undefined) {
49
+ moduleCells[name] = cell(name, cModule.exports[name]);
50
+ }
51
+ }
43
52
  // Update the star cell from all cells.
44
- const starExports = Object.create(null, {
53
+ const starExports = create(null, {
45
54
  // Make this appear like an ESM module namespace object.
46
55
  [Symbol.toStringTag]: {
47
56
  value: 'Module',
@@ -50,10 +59,14 @@ function wrapCjsFunctor(num) {
50
59
  configurable: false,
51
60
  },
52
61
  });
53
- Object.keys(moduleCells)
54
- .filter(k => k !== '*')
55
- .map(k => Object.defineProperty(starExports, k, moduleCells[k]));
56
- moduleCells['*'].set(Object.freeze(starExports));
62
+ const allNames = keys(moduleCells);
63
+ for (let i = 0; i < allNames.length; i += 1) {
64
+ const name = allNames[i];
65
+ if (name !== '*') {
66
+ defineProperty(starExports, name, moduleCells[name]);
67
+ }
68
+ }
69
+ moduleCells['*'].set(freeze(starExports));
57
70
  };
58
71
  /* eslint-enable no-undef */
59
72
  }`;
@@ -61,17 +74,27 @@ function wrapCjsFunctor(num) {
61
74
  /** @type {BundlerSupport<CjsModuleSource>} */
62
75
  export default {
63
76
  runtime,
64
- getBundlerKit({
65
- index,
66
- indexedImports,
67
- record: { cjsFunctor, exports: exportsList = {} },
68
- }) {
77
+ getBundlerKit(
78
+ {
79
+ index,
80
+ indexedImports,
81
+ moduleSpecifier,
82
+ sourceDirname,
83
+ record: { cjsFunctor, exports: exportsList = {} },
84
+ },
85
+ { useEvaluate = false },
86
+ ) {
69
87
  const importsMap = JSON.stringify(indexedImports);
70
88
 
89
+ let functor = cjsFunctor;
90
+ if (useEvaluate) {
91
+ const sourceUrl = join(sourceDirname, moduleSpecifier);
92
+ functor = JSON.stringify([functor, sourceUrl]);
93
+ }
94
+
71
95
  return {
72
96
  getFunctor: () => `\
73
- // === functors[${index}] ===
74
- ${cjsFunctor},
97
+ ${functor},
75
98
  `,
76
99
  getCells: () => `\
77
100
  {
@@ -79,9 +102,15 @@ ${exportsCellRecord(exportsList)}\
79
102
  },
80
103
  `,
81
104
  getReexportsWiring: () => '',
82
- getFunctorCall: () => `\
83
- wrapCjsFunctor(${index})({imports: ${importsMap}});
84
- `,
105
+ getFunctorCall: () => {
106
+ let functorExpression = `functors[${index}]`;
107
+ if (useEvaluate) {
108
+ functorExpression = `evaluateSource(...${functorExpression})`;
109
+ }
110
+ return `\
111
+ wrapCjsFunctor(${index}, ${functorExpression})({imports: ${importsMap}});
112
+ `;
113
+ },
85
114
  };
86
115
  },
87
116
  };
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;MAgBC"}
1
+ {"version":3,"file":"bundle-json.d.ts","sourceRoot":"","sources":["bundle-json.js"],"names":[],"mappings":";;IAME;;;;;;;;;MAeC"}
@@ -9,15 +9,14 @@ export default {
9
9
  const json = JSON.stringify(JSON.parse(textDecoder.decode(bytes)));
10
10
  return {
11
11
  getFunctor: () => `\
12
- // === functors[${index}] ===
13
- (set) => set(${json}),
12
+ ${json},
14
13
  `,
15
14
  getCells: () => `\
16
15
  { default: cell('default') },
17
16
  `,
18
17
  getReexportsWiring: () => '',
19
18
  getFunctorCall: () => `\
20
- functors[${index}](cells[${index}].default.set);
19
+ cells[${index}].default.set(functors[${index}]);
21
20
  `,
22
21
  };
23
22
  },