Skip to content

Commit

Permalink
fix(xsnap): Accommodate spaces in installation path
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed Sep 12, 2024
1 parent 66e4cc0 commit 1768df2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/xsnap/src/avaXS.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Usage:
import '@endo/init';

import fs from 'fs';
import { fileURLToPath } from 'url';
import { tmpName } from 'tmp';

import { assert, q, Fail } from '@endo/errors';
Expand All @@ -21,7 +22,7 @@ const avaHandler = `./avaHandler.cjs`;

/** @type { (ref: string, readFile: typeof import('fs').promises.readFile ) => Promise<string> } */
const asset = (ref, readFile) =>
readFile(new URL(ref, import.meta.url).pathname, 'utf8');
readFile(fileURLToPath(new URL(ref, import.meta.url)), 'utf8');

/**
* When we bundle test scripts, we leave these externals
Expand Down
3 changes: 2 additions & 1 deletion packages/xsnap/src/build.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env node
/* global process */
import * as childProcessTop from 'child_process';
import { fileURLToPath } from 'url';
import fsTop from 'fs';
import osTop from 'os';

const { freeze } = Object;

/** @param {string} path */
const asset = path => new URL(path, import.meta.url).pathname;
const asset = path => fileURLToPath(new URL(path, import.meta.url));

const ModdableSDK = {
MODDABLE: asset('../moddable'),
Expand Down
15 changes: 11 additions & 4 deletions packages/xsnap/src/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import osPowers from 'os';
import fsPowers from 'fs';
import { Readable } from 'stream';
import { tmpName as tmpNamePower } from 'tmp';
import { fileURLToPath } from 'url';
import { makeQueue } from '@endo/stream';
import { xsnap, DEFAULT_CRANK_METERING_LIMIT } from './xsnap.js';

Expand All @@ -38,7 +39,9 @@ function makeSyncStorage(path, { writeFileSync }) {
file: fn => {
/** @param {Uint8Array} data */
const put = data =>
writeFileSync(new URL(fn, base).pathname, data, { flag: 'wx' });
writeFileSync(fileURLToPath(new URL(fn, base)), data, {
flag: 'wx',
});

return freeze({
put,
Expand All @@ -60,14 +63,18 @@ function makeSyncAccess(path, { readdirSync, readFileSync }) {
const base = new URL(path, 'file://');
/** @param {string} fn */
const file = fn => {
const fullname = new URL(fn, base).pathname;
const fullname = fileURLToPath(new URL(fn, base));

return freeze({
getData: () => readFileSync(fullname),
getText: () => readFileSync(fullname, 'utf-8'),
});
};
return freeze({ path, file, readdir: () => readdirSync(base.pathname) });
return freeze({
path,
file,
readdir: () => readdirSync(fileURLToPath(base)),
});
}

/**
Expand Down Expand Up @@ -320,7 +327,7 @@ export async function main(
}

/* global process */
if (process.argv[1] === new URL(import.meta.url).pathname) {
if (process.argv[1] === fileURLToPath(new URL(import.meta.url))) {
main([...process.argv.slice(2)], {
spawn: childProcessPowers.spawn,
fs: { ...fsPowers, ...fsPowers.promises },
Expand Down
15 changes: 9 additions & 6 deletions packages/xsnap/src/xsnap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { finished } from 'stream/promises';
import { PassThrough, Readable } from 'stream';
import { promisify } from 'util';
import { fileURLToPath } from 'url';
import { Fail, q } from '@endo/errors';
import { makeNetstringReader, makeNetstringWriter } from '@endo/netstring';
import { makeNodeReader, makeNodeWriter } from '@endo/stream-node';
Expand Down Expand Up @@ -174,12 +175,14 @@ export async function xsnap(options) {
throw Error(`xsnap does not support platform ${os}`);
}

let bin = new URL(
`../xsnap-native/xsnap/build/bin/${platform}/${
debug ? 'debug' : 'release'
}/xsnap-worker`,
import.meta.url,
).pathname;
let bin = fileURLToPath(
new URL(
`../xsnap-native/xsnap/build/bin/${platform}/${
debug ? 'debug' : 'release'
}/xsnap-worker`,
import.meta.url,
),
);

/** @type {PromiseKit<void>} */
const vatExit = makePromiseKit();
Expand Down

0 comments on commit 1768df2

Please sign in to comment.