fix(bundle-source): Windows support for tests
MODIFY
packages/bundle-source/README.md
packages/bundle-source/README.md
@@ -7,8 +7,11 @@ To bundle your sources, first do
```js
import bundleSource from '@endo/bundle-source';
+import url from 'url';
-const sourceBundleP = bundleSource(new URL('../path/to/toplevel', import.meta.url).pathname);
+const sourceBundleURL = new URL('../path/to/toplevel', import.meta.url);
+const sourceBundlePath = url.fileURLToPath(sourceBundleURL);
+const sourceBundleP = bundleSource(sourceBundlePath);
```
to get a promise for a source bundle, that resolves after reading the
named sources and bundling them into a form that vats can load, as indicated

MODIFY
packages/bundle-source/src/index.js
packages/bundle-source/src/index.js
-/* global process */
import fs from 'fs';
import { rollup as rollup0 } from 'rollup';
+import url from 'url';
import path from 'path';
+import crypto from 'crypto';
import resolve0 from '@rollup/plugin-node-resolve';
import commonjs0 from '@rollup/plugin-commonjs';
import * as babelParser from '@babel/parser';
import babelGenerate from '@babel/generator';
import babelTraverse from '@babel/traverse';
import { makeArchive } from '@endo/compartment-mapper/archive.js';
-import { makeNodeReadPowers } from '@endo/compartment-mapper/node-powers.js';
+import { makeReadPowers } from '@endo/compartment-mapper/node-powers.js';
import { encodeBase64 } from '@endo/base64';
import SourceMaps from 'source-map';
@@ -29,7 +30,7 @@ const HTML_COMMENT_END_RE = new RegExp(`--${'>'}`, 'g');
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();
-const readPowers = makeNodeReadPowers(fs);
+const readPowers = makeReadPowers({ fs, url, crypto });
function rewriteComment(node, unmapLoc) {
node.type = 'CommentBlock';
@@ -135,8 +136,7 @@ async function transformSource(
}
async function bundleZipBase64(startFilename, dev, powers = {}) {
- const base = new URL(`file://${process.cwd()}`).toString();
- const entry = new URL(startFilename, base).toString();
+ const entry = url.pathToFileURL(path.resolve(startFilename));
const bytes = await makeArchive({ ...readPowers, ...powers }, entry, {
dev,
moduleTransforms: {

MODIFY
packages/bundle-source/test/sanity.js
packages/bundle-source/test/sanity.js
import { lockdown } from '@endo/lockdown';
+import url from 'url';
import { decodeBase64 } from '@endo/base64';
import { parseArchive } from '@endo/compartment-mapper/import-archive.js';
import test from 'ava';
@@ -22,7 +23,7 @@ export function makeSanityTests(stackFiltering) {
test(`endoZipBase64`, async t => {
const { endoZipBase64 } = await bundleSource(
- new URL('../demo/dir1/encourage.js', import.meta.url).pathname,
+ url.fileURLToPath(new URL('../demo/dir1/encourage.js', import.meta.url)),
'endoZipBase64',
);
@@ -43,7 +44,7 @@ export function makeSanityTests(stackFiltering) {
source: src1,
sourceMap: map1,
} = await bundleSource(
- new URL(`../demo/dir1`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/dir1`, import.meta.url)),
'nestedEvaluate',
);
@@ -78,7 +79,7 @@ export function makeSanityTests(stackFiltering) {
source: src2,
sourceMap: map2,
} = await bundleSource(
- new URL(`../demo/dir1/encourage.js`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/dir1/encourage.js`, import.meta.url)),
'nestedEvaluate',
);
t.is(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate');
@@ -100,7 +101,7 @@ export function makeSanityTests(stackFiltering) {
source: src1,
sourceMap: map1,
} = await bundleSource(
- new URL(`../demo/dir1`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/dir1`, import.meta.url)),
'getExport',
);
@@ -125,7 +126,7 @@ export function makeSanityTests(stackFiltering) {
source: src2,
sourceMap: map2,
} = await bundleSource(
- new URL(`../demo/dir1/encourage.js`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/dir1/encourage.js`, import.meta.url)),
'nestedEvaluate',
);
t.is(mf2, 'nestedEvaluate', 'module format 2 is nestedEvaluate');
@@ -161,7 +162,9 @@ export function makeSanityTests(stackFiltering) {
// from @agoric/babel-parser/lib/tokenizer/types.js
const { source: src1 } = await bundleSource(
- new URL(`../demo/babel-parser-mangling.js`, import.meta.url).pathname,
+ url.fileURLToPath(
+ new URL(`../demo/babel-parser-mangling.js`, import.meta.url),
+ ),
'getExport',
);

MODIFY
packages/bundle-source/test/test-bigint-transform.js
packages/bundle-source/test/test-bigint-transform.js
+import url from 'url';
import { test } from './prepare-test-env-ava.js';
import bundleSource from '../src/index.js';
test('bigint transform', async t => {
const bundle = await bundleSource(
- new URL(`../demo/bigint`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/bigint`, import.meta.url)),
'getExport',
);
// console.log(bundle.source);

MODIFY
packages/bundle-source/test/test-circular.js
packages/bundle-source/test/test-circular.js
+import url from 'url';
import { test } from './prepare-test-env-ava.js';
import bundleSource from '../src/index.js';
@@ -8,7 +9,7 @@ function evaluate(src, endowments) {
test('circular export', async t => {
const { source: src1, sourceMap: map1 } = await bundleSource(
- new URL(`../demo/circular/a.js`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/circular/a.js`, import.meta.url)),
'nestedEvaluate',
);

MODIFY
packages/bundle-source/test/test-comment.js
packages/bundle-source/test/test-comment.js
// eslint-disable-next-line import/order
import { test } from './prepare-test-env-ava.js';
+import url from 'url';
import { decodeBase64 } from '@endo/base64';
import { parseArchive } from '@endo/compartment-mapper/import-archive.js';
import bundleSource from '../src/index.js';
@@ -11,7 +12,9 @@ function evaluate(src, endowments) {
test('trailing comment', async t => {
const { source: src1 } = await bundleSource(
- new URL('../demo/comments/trailing-comment.js', import.meta.url).pathname,
+ url.fileURLToPath(
+ new URL('../demo/comments/trailing-comment.js', import.meta.url),
+ ),
'nestedEvaluate',
);
@@ -30,7 +33,9 @@ test('trailing comment', async t => {
test('comment block opener', async t => {
t.plan(1);
const { source: src1 } = await bundleSource(
- new URL('../demo/comments/block-opener.js', import.meta.url).pathname,
+ url.fileURLToPath(
+ new URL('../demo/comments/block-opener.js', import.meta.url),
+ ),
'nestedEvaluate',
);
@@ -48,7 +53,9 @@ test('comment block opener', async t => {
test('comment block closer', async t => {
t.plan(1);
const { source: src1 } = await bundleSource(
- new URL('../demo/comments/block-closer.js', import.meta.url).pathname,
+ url.fileURLToPath(
+ new URL('../demo/comments/block-closer.js', import.meta.url),
+ ),
'nestedEvaluate',
);
@@ -66,7 +73,7 @@ test('comment block closer', async t => {
test('comments not associated with a code AST node', async t => {
t.plan(1);
const { endoZipBase64 } = await bundleSource(
- new URL('../demo/comments/types.js', import.meta.url).pathname,
+ url.fileURLToPath(new URL('../demo/comments/types.js', import.meta.url)),
'endoZipBase64',
);
const endoZipBytes = decodeBase64(endoZipBase64);

MODIFY
packages/bundle-source/test/test-explicit.js
packages/bundle-source/test/test-explicit.js
import { rollup } from 'rollup';
import { resolve as pathResolve } from 'path';
import resolvePlugin from '@rollup/plugin-node-resolve';
+import url from 'url';
import { test } from './prepare-test-env-ava.js';
import bundleSource from '../src/index.js';
test('explicit authority', async t => {
const { moduleFormat } = await bundleSource(
- new URL(`../demo/dir1`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/dir1`, import.meta.url)),
'getExport',
{
rollup,

MODIFY
packages/bundle-source/test/test-external-fs.js
packages/bundle-source/test/test-external-fs.js
+import url from 'url';
import { test } from './prepare-test-env-ava.js';
import bundleSource from '../src/index.js';
@@ -9,7 +10,7 @@ function evaluate(src, endowments) {
test(`external require('fs')`, async t => {
t.plan(1);
const { source: src1 } = await bundleSource(
- new URL(`../demo/external-fs.js`, import.meta.url).pathname,
+ url.fileURLToPath(new URL(`../demo/external-fs.js`, import.meta.url)),
'nestedEvaluate',
);

fix(bundle-source): Windows support for tests