fix(endo): Windows support fixes
MODIFY
packages/endo/mitm/.gitignore
packages/endo/mitm/.gitignore
node
+node.cmd

MODIFY
packages/endo/src/cli.js
packages/endo/src/cli.js
@@ -12,8 +12,10 @@ import {
makeNodeReadPowers,
makeNodeWritePowers,
} from '@endo/compartment-mapper/node-powers.js';
+import { platform } from 'os';
+import { fileURLToPath } from 'url';
-const mitmPath = new URL('../mitm', import.meta.url).pathname;
+const mitmPath = fileURLToPath(new URL('../mitm', import.meta.url));
function usage(message) {
console.error(message);
@@ -122,8 +124,9 @@ async function run(
}
async function exec([arg, ...args]) {
+ const splitSymbol = platform() === 'win32' ? ';' : ':';
const child = subprocess.spawn(arg, args, {
- env: { ...env, PATH: `${mitmPath}:${env.PATH}` },
+ env: { ...env, PATH: `${mitmPath}${splitSymbol}${env.PATH}` },
stdio: 'inherit',
});
return new Promise(resolve => child.on('exit', resolve));

MODIFY
packages/endo/src/postinstall.js
packages/endo/src/postinstall.js
/* global process */
import fs from 'fs';
+import { platform } from 'os';
+import { fileURLToPath } from 'url';
const node = process.argv[0];
-const lockdown = new URL('./lockdown.cjs', import.meta.url).pathname;
-const mitm = new URL('../mitm/node', import.meta.url).pathname;
+const lockdown = fileURLToPath(new URL('./lockdown.cjs', import.meta.url));
+const mitm = fileURLToPath(
+ new URL(
+ `../mitm/node${platform() === 'win32' ? '.cmd' : ''}`,
+ import.meta.url,
+ ),
+);
-const script = `#!/bin/bash
+const nixScript = `#!/bin/bash
set -ueo pipefail
${node} -r ${lockdown} "$@"`;
-fs.writeFileSync(mitm, script, 'utf-8');
+const win32Script = `
+@IF EXIST "%~dp0\\node.exe" (
+ "%~dp0\\node.exe" -r ${lockdown} -r %*
+) ELSE (
+ @SETLOCAL
+ @SET PATHEXT=%PATHEXT:;.JS;=;%
+ node -r ${lockdown} %*
+)
+`;
+
+fs.writeFileSync(
+ mitm,
+ platform() === 'win32' ? win32Script : nixScript,
+ 'utf-8',
+);
fs.chmodSync(mitm, 0o755);

fix(endo): Windows support fixes