diff --git a/pyscriptjs/directoryManifest.mjs b/pyscriptjs/directoryManifest.mjs index 4fb5756c..ef8a1000 100644 --- a/pyscriptjs/directoryManifest.mjs +++ b/pyscriptjs/directoryManifest.mjs @@ -2,7 +2,7 @@ // 1. esbuild.mjs // 2. Jest setup.ts -import { join } from 'path'; +import path, { join } from 'path'; import { opendir, readFile } from 'fs/promises'; /** @@ -38,7 +38,16 @@ async function _directoryManifestHelper(root, dir, result) { result.dirs.push(entry); await _directoryManifestHelper(root, entry, result); } else if (d.isFile()) { - result.files.push([entry, await readFile(join(root, entry), { encoding: 'utf-8' })]); + result.files.push([normalizePath(entry), await readFile(join(root, entry), { encoding: 'utf-8' })]); } } } + +/** + * Normalize paths under different operating systems to + * the correct path that will be used for src on browser. + * @param {string} originalPath + */ +function normalizePath(originalPath) { + return path.normalize(originalPath).replace(/\\/g, '/'); +} diff --git a/pyscriptjs/esbuild.mjs b/pyscriptjs/esbuild.mjs index f455f314..5d844265 100644 --- a/pyscriptjs/esbuild.mjs +++ b/pyscriptjs/esbuild.mjs @@ -1,11 +1,12 @@ import { build } from 'esbuild'; import { spawn } from 'child_process'; -import { dirname, join } from 'path'; +import { join } from 'path'; import { watchFile } from 'fs'; import { cp, lstat, readdir } from 'fs/promises'; import { directoryManifest } from './directoryManifest.mjs'; +import { fileURLToPath } from 'url'; -const __dirname = dirname(new URL(import.meta.url).pathname); +const __dirname = fileURLToPath(new URL('.', import.meta.url)); const production = !process.env.NODE_WATCH || process.env.NODE_ENV === 'production';