Fix path errors on Windows systems (#1368)

* Add docs to repl with attr src

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix path errors on Windows systems

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix path errors on Windows systems

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Mike Chen
2023-04-13 23:21:49 +08:00
committed by GitHub
parent 5a92ef3c11
commit 3a9fd3c074
2 changed files with 14 additions and 4 deletions

View File

@@ -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, '/');
}

View File

@@ -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';