Skip to content

Commit

Permalink
Addressing review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
shimkiv committed Mar 20, 2024
1 parent 6c7744d commit 4325090
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 10 additions & 8 deletions src/build/build-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -49,6 +45,9 @@ async function build(srcPath, isWeb = false) {
});

let absPath = path.resolve('.', outfile);
if (platform === 'win32') {
absPath = 'file:///' + absPath;
}
return absPath;
}

Expand All @@ -75,6 +74,9 @@ async function buildOne(srcPath) {
});

let absPath = path.resolve('.', outfile);
if (platform === 'win32') {
absPath = 'file:///' + absPath;
}
return absPath;
}

Expand Down Expand Up @@ -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')),
}));
},
};
Expand Down
4 changes: 0 additions & 4 deletions src/build/run.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit 4325090

Please sign in to comment.