Skip to content

Commit 4b1095b

Browse files
committed
Fix preprocessing not happening for files on Windows
1 parent 6d6aa5b commit 4b1095b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/processScript/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import rollupPluginJSON from "@rollup/plugin-json"
2626
import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
2727
import type { LaxPartial } from "@samual/lib"
2828
import { assert } from "@samual/lib/assert"
29-
import { relative as getRelativePath } from "path"
29+
import { relative as getRelativePath, sep as pathSeparator } from "path"
3030
import prettier from "prettier"
3131
import { rollup } from "rollup"
3232
import { supportedExtensions as extensions } from "../constants"
@@ -47,6 +47,11 @@ export { postprocess } from "./postprocess"
4747
export { preprocess } from "./preprocess"
4848
export { transform } from "./transform"
4949

50+
function isPath(str: string): boolean {
51+
if (pathSeparator == `/`) return str.startsWith(`/`);
52+
return /^[A-Z]:\\/.test(str);
53+
}
54+
5055
export type ProcessOptions = LaxPartial<{
5156
/** whether to minify the given code */ minify: boolean
5257
/** 11 a-z 0-9 characters */ uniqueId: string
@@ -260,7 +265,7 @@ export async function processScript(code: string, {
260265
{
261266
name: `hackmud-script-manager`,
262267
async transform(code, id) {
263-
if (id.startsWith(`/`) && !id.includes(`/node_modules/`))
268+
if (isPath(id) && !id.includes(`${pathSeparator}node_modules${pathSeparator}`))
264269
return (await preprocess(code, { uniqueId })).code
265270

266271
let program!: NodePath<Program>

0 commit comments

Comments
 (0)