From 4325090a856395b1dae4e6124e9f81a5d184754b Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Wed, 20 Mar 2024 14:08:24 +0200 Subject: [PATCH] Addressing review comments. --- src/build/build-example.js | 18 ++++++++++-------- src/build/run.js | 4 ---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/build/build-example.js b/src/build/build-example.js index f555e4cffb..966bf60881 100644 --- a/src/build/build-example.js +++ b/src/build/build-example.js @@ -10,13 +10,9 @@ async function buildAndImport(srcPath, { keepFile = false }) { let absPath = await build(srcPath); let importedModule; try { - let absPathForImport = absPath - if (platform === 'win32') { - absPathForImport = 'file:///' + absPathForImport; - } - importedModule = await import(absPathForImport); + importedModule = await import(absPath); } finally { - if (!keepFile) await fs.unlink(absPath); + if (!keepFile) await fs.unlink(absPath.replace(/^file:\/\/\/*/, '')); } return importedModule; } @@ -49,6 +45,9 @@ async function build(srcPath, isWeb = false) { }); let absPath = path.resolve('.', outfile); + if (platform === 'win32') { + absPath = 'file:///' + absPath; + } return absPath; } @@ -75,6 +74,9 @@ async function buildOne(srcPath) { }); let absPath = path.resolve('.', outfile); + if (platform === 'win32') { + absPath = 'file:///' + absPath; + } return absPath; } @@ -109,13 +111,13 @@ function typescriptPlugin(tsConfig) { } function makeNodeModulesExternal() { - let isNodeModule = /^[^./]|^\.[^./]|^\.\.[^/]/; + let isNodeModule = /^[^./\\]|^\.[^./\\]|^\.\.[^/\\]/; return { name: 'plugin-external', setup(build) { build.onResolve({ filter: isNodeModule }, ({ path }) => ({ path, - external: true, + external: !(platform === 'win32' && path.endsWith('index.js')), })); }, }; diff --git a/src/build/run.js b/src/build/run.js index 40f4600f03..7902f1ccdf 100755 --- a/src/build/run.js +++ b/src/build/run.js @@ -1,6 +1,5 @@ #!/usr/bin/env node import minimist from 'minimist'; -import { platform } from 'node:process'; import { buildAndImport, buildOne } from './build-example.js'; let { @@ -19,9 +18,6 @@ npx snarky-run [file]`); if (!bundle) { let absPath = await buildOne(filePath); console.log(`running ${absPath}`); - if (platform === 'win32') { - absPath = 'file:///' + absPath; - } let module = await import(absPath); if (main) await module.main(); if (runDefault) await module.default();