@endo/module-source 1.1.2 → 1.2.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/README.md CHANGED
@@ -74,6 +74,15 @@ the hook returns a promise, it will be dropped and rejections will go uncaught.
74
74
  If the hook must do async work, these should be queued up as a job that the
75
75
  caller can later await.
76
76
 
77
+ ## XS Specific Variant
78
+
79
+ With the `xs` condition, `@endo/module-source` will not entrain Babel and will
80
+ just adapt the native `ModuleSource` to the older interface presented by this
81
+ package.
82
+ That is, the XS native `bindings` will be translated to `imports`, `exports`,
83
+ and `reexports` getters.
84
+ This form of `ModuleSource` ignores all options.
85
+
77
86
  ## Bug Disclosure
78
87
 
79
88
  Please help us practice coordinated security bug disclosure, by using the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@endo/module-source",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Ponyfill for the SES ModuleSource and module-to-program transformer",
5
5
  "keywords": [
6
6
  "ses",
@@ -22,7 +22,10 @@
22
22
  "type": "module",
23
23
  "main": "./index.js",
24
24
  "exports": {
25
- ".": "./index.js",
25
+ ".": {
26
+ "xs": "./src-xs/index.js",
27
+ "default": "./index.js"
28
+ },
26
29
  "./shim.js": "./shim.js",
27
30
  "./package.json": "./package.json"
28
31
  },
@@ -35,14 +38,15 @@
35
38
  "lint:types": "tsc",
36
39
  "lint:eslint": "eslint .",
37
40
  "lint-fix": "eslint --fix .",
38
- "test": "ava"
41
+ "test": "ava",
42
+ "test:xs": "node scripts/generate-test-xs.js && xst tmp/test-xs.js"
39
43
  },
40
44
  "dependencies": {
41
45
  "@agoric/babel-generator": "^7.17.6",
42
46
  "@babel/parser": "^7.23.6",
43
47
  "@babel/traverse": "^7.23.6",
44
48
  "@babel/types": "^7.24.0",
45
- "ses": "^1.10.0"
49
+ "ses": "^1.11.0"
46
50
  },
47
51
  "devDependencies": {
48
52
  "ava": "^6.1.3",
@@ -85,5 +89,5 @@
85
89
  "typeCoverage": {
86
90
  "atLeast": 40.33
87
91
  },
88
- "gitHead": "5486ed1f238104716b6a8321b977fbc508ef80e1"
92
+ "gitHead": "e0683e0bfdbfc84351af332c9e78813d7b67ef89"
89
93
  }
package/shim.js CHANGED
@@ -1,6 +1,10 @@
1
1
  /* global globalThis */
2
2
 
3
- import { ModuleSource } from './index.js';
3
+ // We are using a reflexive import to make sure we pass through the conditional
4
+ // export in package.json.
5
+ // Eslint does not yet seem to have a carve-out for package-reflexive imports.
6
+ // eslint-disable-next-line import/no-extraneous-dependencies
7
+ import { ModuleSource } from '@endo/module-source';
4
8
 
5
9
  Object.defineProperty(globalThis, 'ModuleSource', {
6
10
  value: ModuleSource,
@@ -1 +1 @@
1
- {"version":3,"file":"babelPlugin.d.ts","sourceRoot":"","sources":["babelPlugin.js"],"names":[],"mappings":";AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6kBC"}
1
+ {"version":3,"file":"babelPlugin.d.ts","sourceRoot":"","sources":["babelPlugin.js"],"names":[],"mappings":";AAwCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+kBC"}
@@ -49,6 +49,7 @@ function makeModulePlugins(options) {
49
49
  reexportMap,
50
50
  liveExportMap,
51
51
  importMeta,
52
+ dynamicImport,
52
53
  } = options;
53
54
 
54
55
  if (sourceType !== 'module') {
@@ -286,6 +287,7 @@ function makeModulePlugins(options) {
286
287
  CallExpression(path) {
287
288
  // import(FOO) -> $h_import(FOO)
288
289
  if (path.node.callee.type === 'Import') {
290
+ dynamicImport.present = true;
289
291
  path.node.callee = hiddenIdentifier(h.HIDDEN_IMPORT);
290
292
  }
291
293
  },
@@ -62,6 +62,7 @@ export class ModuleSource {
62
62
  __liveExportMap__: any;
63
63
  __reexportMap__: any;
64
64
  __fixedExportMap__: any;
65
+ __needsImport__: boolean;
65
66
  __needsImportMeta__: boolean;
66
67
  }
67
68
  export type SourceMapHookDetails = {
@@ -1 +1 @@
1
- {"version":3,"file":"module-source.d.ts","sourceRoot":"","sources":["module-source.js"],"names":[],"mappings":"AAmCA;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAKH;;;;;;;GAOG;AACH,qCAHW,MAAM,6CAoChB;;IAlED;;;;;;OAMG;IAEH;;;;OAIG;IAEH;;;;;;OAMG;IAKH;;;;;;;OAOG;IACH,oBAHW,MAAM,uCAoChB;IAfC,kBAAyC;IACzC,eAMC;IACD,mBAA+C;IAC/C,8BAA0C;IAC1C,uBAAsC;IACtC,qBAAkC;IAClC,wBAAwC;IACxC,6BAA0C;;;iBA9D9B,MAAM;YACN,MAAM;cACN,MAAM;YACN,MAAM;;wCAKT,MAAM,WACN,oBAAoB"}
1
+ {"version":3,"file":"module-source.d.ts","sourceRoot":"","sources":["module-source.js"],"names":[],"mappings":"AAmCA;;;;;;GAMG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AAKH;;;;;;;GAOG;AACH,qCAHW,MAAM,6CAsChB;;IApED;;;;;;OAMG;IAEH;;;;OAIG;IAEH;;;;;;OAMG;IAKH;;;;;;;OAOG;IACH,oBAHW,MAAM,uCAsChB;IAhBC,kBAAyC;IACzC,eAMC;IACD,mBAA+C;IAC/C,8BAA0C;IAC1C,uBAAsC;IACtC,qBAAkC;IAClC,wBAAwC;IACxC,yBAAkC;IAClC,6BAA0C;;;iBAhE9B,MAAM;YACN,MAAM;cACN,MAAM;YACN,MAAM;;wCAKT,MAAM,WACN,oBAAoB"}
@@ -82,6 +82,7 @@ export function ModuleSource(source, opts = {}) {
82
82
  reexportMap,
83
83
  fixedExportMap,
84
84
  exportAlls,
85
+ needsImport,
85
86
  needsImportMeta,
86
87
  } = analyzeModule(source, opts);
87
88
  this.imports = freeze([...keys(imports)]);
@@ -97,6 +98,7 @@ export function ModuleSource(source, opts = {}) {
97
98
  this.__liveExportMap__ = liveExportMap;
98
99
  this.__reexportMap__ = reexportMap;
99
100
  this.__fixedExportMap__ = fixedExportMap;
101
+ this.__needsImport__ = needsImport;
100
102
  this.__needsImportMeta__ = needsImportMeta;
101
103
  freeze(this);
102
104
  }
@@ -4,6 +4,7 @@ export function makeModuleAnalyzer(babel: any): (moduleSource: string, { sourceU
4
4
  liveExportMap: any;
5
5
  fixedExportMap: any;
6
6
  reexportMap: any;
7
+ needsImport: boolean;
7
8
  needsImportMeta: boolean;
8
9
  functorSource: string;
9
10
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"transform-analyze.d.ts","sourceRoot":"","sources":["transform-analyze.js"],"names":[],"mappings":"AA+HO,+DAlHM,MAAM,0DACN,OAAO;;;;;;;;GAoHnB;AAEM;;EA6DN;6BAzL0B,oBAAoB"}
1
+ {"version":3,"file":"transform-analyze.d.ts","sourceRoot":"","sources":["transform-analyze.js"],"names":[],"mappings":"AAkIO,+DArHM,MAAM,0DACN,OAAO;;;;;;;;;GAuHnB;AAEM;;EA6DN;6BA5L0B,oBAAoB"}
@@ -41,6 +41,7 @@ const makeCreateStaticRecord = transformSource =>
41
41
  hoistedDecls: [],
42
42
  importSources: Object.create(null),
43
43
  importDecls: [],
44
+ dynamicImport: { present: false },
44
45
  // enables passing import.meta usage hints up.
45
46
  importMeta: { present: false },
46
47
  };
@@ -103,6 +104,7 @@ const makeCreateStaticRecord = transformSource =>
103
104
  imports: ${h.HIDDEN_IMPORTS}, \
104
105
  liveVar: ${h.HIDDEN_LIVE}, \
105
106
  onceVar: ${h.HIDDEN_ONCE}, \
107
+ import: ${h.HIDDEN_IMPORT}, \
106
108
  importMeta: ${h.HIDDEN_META}, \
107
109
  }) => (function () { 'use strict'; \
108
110
  ${preamble} \
@@ -119,6 +121,7 @@ const makeCreateStaticRecord = transformSource =>
119
121
  liveExportMap: freeze(sourceOptions.liveExportMap),
120
122
  fixedExportMap: freeze(sourceOptions.fixedExportMap),
121
123
  reexportMap: freeze(sourceOptions.reexportMap),
124
+ needsImport: sourceOptions.dynamicImport.present,
122
125
  needsImportMeta: sourceOptions.importMeta.present,
123
126
  functorSource,
124
127
  });