From 17f409fe40b64b33f0c8a85123dee394ee7fb4e1 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 26 Nov 2019 21:14:07 -0600 Subject: [PATCH] xs pathlib: bundleSource --- xs-platform/pathlib.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/xs-platform/pathlib.js b/xs-platform/pathlib.js index 7b85784449f..ecdbabcacc6 100644 --- a/xs-platform/pathlib.js +++ b/xs-platform/pathlib.js @@ -32,14 +32,32 @@ export function makePath(filename, { File, Iterator }) { return items; } + function butLast(p) { + const pos = p.lastIndexOf('/'); + return pos >= 0 ? p.slice(0, pos + 1) : p; + } + + function bundleSource() { + const parts = filename.match(/vat(-)([^\.]+).js$/); + if (!parts) { + throw new Error(`expected vat-NAME.js; got: ${filename}`); + } + const bundlePath = `${butLast(filename)}vat_${parts[2]}-src.js`; + console.log(`@@bundleSource ${filename} -> ${bundlePath}`); + const src = mk(bundlePath).readFileSync(); + return { + source: src.replace(/^export default /, ''), + sourceMap: `//# sourceURL=${filename}\n`, + }; + } + return harden({ toString() { return filename; }, resolve(...others) { // ISSUE: support ../? - // TODO: chop off filename at last / - return mk([filename, ...others].join('/')); + return mk([butLast(filename), ...others].join('/')); }, join(...others) { // ISSUE: support ../? @@ -54,5 +72,6 @@ export function makePath(filename, { File, Iterator }) { return readFileSync().replace(/\n$/, '').split('\n'); }, readdirSync, + bundleSource, }); }