fix(compartment-mapper): handle passing and reading exports reference
MODIFY
packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js
packages/compartment-mapper/src/parse-cjs-shared-export-wrapper.js
@@ -42,10 +42,7 @@ export const wrap = (moduleEnvironmentRecord, compartment, resolvedImports) => {
moduleEnvironmentRecord.default[prop] = value;
};
- const originalExports = new Proxy(Object.create(null), {
- get(target, prop) {
- return moduleEnvironmentRecord.default[prop];
- },
+ const originalExports = new Proxy(moduleEnvironmentRecord.default, {
set(_target, prop, value) {
assignProp(prop, value);
return true;

MODIFY
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/index.js
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/index.js
-const callself = require('callself');
+const exportsShenanigans = require('exports-shenanigans');
+const fromDebug = require('exports-shenanigans/from-debug');
const interops = require('interops');
const moduleinterops = require('./moduleinterops');
const stableOrderJson = require('./assertion-generators/json.cjs');
@@ -76,13 +77,16 @@ module.exports.assertions = {
expect: whatWouldNodejsRequireDo,
});
},
- packageReferencingItself() {
+ packageExportsShenanigans() {
try {
- callself.makeTheCall();
+ exportsShenanigans.makeTheCall();
} catch (e) {
throw Error(
'Referencing exported functions should be possible. ' + e.message,
);
}
+ if(!fromDebug.isOk) {
+ throw Error(`Overwriting exports with derivation of exports should work. exports-shenanigans/from-debug fixture did not load.`)
+ }
},
};

MODIFY
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/package.json
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/app/package.json
"version": "1.0.0",
"main": "./index.js",
"dependencies": {
- "callself": "^1.0.0",
+ "exports-shenanigans": "^1.0.0",
"defineprop": "^1.0.0",
"interops": "^1.0.0",
"parser-struggles": "^1.0.0",

DELETE
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/callself/package.json
-{
- "name": "callself",
- "exports": "./main.js"
-}

RENAME
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/callself/README.md
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/exports-shenanigans/README.md
ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/exports-shenanigans/debug-common.js
+
+function setup(env) {
+ createDebug.enable = enable;
+ Object.keys(env).forEach(key => {
+ createDebug[key] = env[key];
+ });
+
+ function enable(lo) {
+ createDebug.isOk = lo;
+ }
+ function createDebug(){}
+
+ createDebug.enable(createDebug.load());
+
+ return createDebug;
+}
+
+module.exports = setup;
\ No newline at end of file

ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/exports-shenanigans/from-debug.js
+
+exports.load = load;
+
+function load() {
+ return 1;
+}
+
+module.exports = require('./debug-common')(exports);
\ No newline at end of file

RENAME
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/callself/main.js
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/exports-shenanigans/main.js
ADD
packages/compartment-mapper/test/fixtures-cjs-compat/node_modules/exports-shenanigans/package.json
+{
+ "name": "exports-shenanigans",
+ "main": "./main.js"
+}

MODIFY
packages/compartment-mapper/test/scaffold.js
packages/compartment-mapper/test/scaffold.js
@@ -18,6 +18,7 @@ import { makeReadPowers } from '../src/node-powers.js';
export const readPowers = makeReadPowers({ fs, crypto, url });
const globals = {
+ // process: { _rawDebug: process._rawDebug }, // useful for debugging
globalProperty: 42,
globalLexical: 'global', // should be overshadowed
};

MODIFY
packages/compartment-mapper/test/test-cjs-compat.js
packages/compartment-mapper/test/test-cjs-compat.js
@@ -12,7 +12,7 @@ const fixture = new URL(
const assertFixture = (t, { namespace }) => {
const { assertions } = namespace;
- assertions.packageReferencingItself();
+ assertions.packageExportsShenanigans();
assertions.packageWithDefaultField();
assertions.moduleWithDefaultField();
assertions.parserStruggles();

fix(compartment-mapper): handle passing and reading exports reference (#1142)