fix(compartment-mapper): Work around dynamic import censoring
MODIFY
packages/compartment-mapper/NEWS.md
packages/compartment-mapper/NEWS.md
@@ -2,7 +2,8 @@ User-visible changes to the compartment mapper:
## Next release
-* No changes yet.
+* Embellishes all calls to methods named `import` to work around SES-shim
+ `Compartment` censoring for dynamic import.
## 0.2.1 (2020-11-04)

MODIFY
packages/compartment-mapper/src/import-archive.js
packages/compartment-mapper/src/import-archive.js
-/* eslint no-shadow: 0 */
+/* eslint no-shadow: "off" */
import { readZip } from "./zip.js";
import { assemble } from "./assemble.js";
@@ -75,7 +75,9 @@ export const parseArchive = async (archiveBytes, archiveLocation) => {
__shimTransforms__,
Compartment
});
- return compartment.import(moduleSpecifier);
+ // Wrap import calls to bypass SES censoring for dynamic import.
+ // eslint-disable-next-line prettier/prettier
+ return (compartment.import)(moduleSpecifier);
};
return { import: execute };
@@ -88,5 +90,7 @@ export const loadArchive = async (read, archiveLocation) => {
export const importArchive = async (read, archiveLocation, options) => {
const archive = await loadArchive(read, archiveLocation);
- return archive.import(options);
+ // Wrap import calls to bypass SES censoring for dynamic import.
+ // eslint-disable-next-line prettier/prettier
+ return (archive.import)(options);
};

MODIFY
packages/compartment-mapper/src/import.js
packages/compartment-mapper/src/import.js
-/* eslint no-shadow: 0 */
+/* eslint no-shadow: "off" */
import { compartmentMapForNodeModules } from "./node-modules.js";
import { search } from "./search.js";
@@ -44,7 +44,9 @@ export const loadLocation = async (read, moduleLocation) => {
__shimTransforms__,
Compartment
});
- return compartment.import(moduleSpecifier);
+ // Wrap import calls to bypass SES censoring for dynamic import.
+ // eslint-disable-next-line prettier/prettier
+ return (compartment.import)(moduleSpecifier);
};
return { import: execute };
@@ -52,5 +54,7 @@ export const loadLocation = async (read, moduleLocation) => {
export const importLocation = async (read, moduleLocation, options = {}) => {
const application = await loadLocation(read, moduleLocation);
- return application.import(options);
+ // Wrap import calls to bypass SES censoring for dynamic import.
+ // eslint-disable-next-line prettier/prettier
+ return (application.import)(options);
};

MODIFY
packages/compartment-mapper/src/zip/format-reader.js
packages/compartment-mapper/src/zip/format-reader.js
* comment: string, // presumed UTF-8
* }} CentralDirectoryLocator
*
- * @typedef {import('./buffer-reader.js').BufferReader} BufferReader
+ * @typedef {{
+ * readonly length: number,
+ * offset: number,
+ * read(size: number): Uint8Array,
+ * skip(size: number): void,
+ * seek(index: number): void,
+ * expect(bytes: Uint8Array): boolean,
+ * readUint8(): number,
+ * readUint16LE(): number,
+ * readUint32LE(): number,
+ * }} BufferReader
*/
import "./types.js";

MODIFY
packages/compartment-mapper/src/zip/format-writer.js
packages/compartment-mapper/src/zip/format-writer.js
* comment: Uint8Array,
* } & ArchiveHeaders} FileRecord
*
- * @typedef {import('./buffer-writer.js').BufferWriter} BufferWriter
+ * @typedef {{
+ * index: number,
+ * readonly length: number,
+ * write(bytes: Uint8Array): void,
+ * writeCopy(start: number, end: number): void,
+ * writeUint8(number: number): void,
+ * writeUint16LE(number: number): void,
+ * writeUint32LE(number: number): void,
+ * }} BufferWriter
*/
import "./types.js";

fix(compartment-mapper): Work around dynamic import censoring (#512)