From 4b1095bb77e4cc20a806c5555bff67ad99c29b8f Mon Sep 17 00:00:00 2001 From: SarahIsWeird Date: Tue, 21 Jan 2025 19:53:51 +0100 Subject: [PATCH 1/3] Fix preprocessing not happening for files on Windows --- src/processScript/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/processScript/index.ts b/src/processScript/index.ts index 4038ea0..d213ce5 100644 --- a/src/processScript/index.ts +++ b/src/processScript/index.ts @@ -26,7 +26,7 @@ import rollupPluginJSON from "@rollup/plugin-json" import rollupPluginNodeResolve from "@rollup/plugin-node-resolve" import type { LaxPartial } from "@samual/lib" import { assert } from "@samual/lib/assert" -import { relative as getRelativePath } from "path" +import { relative as getRelativePath, sep as pathSeparator } from "path" import prettier from "prettier" import { rollup } from "rollup" import { supportedExtensions as extensions } from "../constants" @@ -47,6 +47,11 @@ export { postprocess } from "./postprocess" export { preprocess } from "./preprocess" export { transform } from "./transform" +function isPath(str: string): boolean { + if (pathSeparator == `/`) return str.startsWith(`/`); + return /^[A-Z]:\\/.test(str); +} + export type ProcessOptions = LaxPartial<{ /** whether to minify the given code */ minify: boolean /** 11 a-z 0-9 characters */ uniqueId: string @@ -260,7 +265,7 @@ export async function processScript(code: string, { { name: `hackmud-script-manager`, async transform(code, id) { - if (id.startsWith(`/`) && !id.includes(`/node_modules/`)) + if (isPath(id) && !id.includes(`${pathSeparator}node_modules${pathSeparator}`)) return (await preprocess(code, { uniqueId })).code let program!: NodePath From ba9c5a77da6a75d05007f21aac3a1c55fba2439b Mon Sep 17 00:00:00 2001 From: SarahIsWeird Date: Tue, 21 Jan 2025 19:58:35 +0100 Subject: [PATCH 2/3] Add Sarah as contributor --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cd19ea0..beeceff 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "contributors": [ "Daniel Swann (https://github.com/danswann)", "Longboyy", - "Helloman892" + "Helloman892", + "Sarah Klocke (https://sarahisweird.dev/)" ], "main": "index.js", "repository": { From a8a820dae816cd6f12746a928a3b1850c14f4cbc Mon Sep 17 00:00:00 2001 From: SarahIsWeird Date: Tue, 21 Jan 2025 20:21:45 +0100 Subject: [PATCH 3/3] Use path.isAbsolute instead of custom function --- src/processScript/index.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/processScript/index.ts b/src/processScript/index.ts index d213ce5..05abeea 100644 --- a/src/processScript/index.ts +++ b/src/processScript/index.ts @@ -26,7 +26,7 @@ import rollupPluginJSON from "@rollup/plugin-json" import rollupPluginNodeResolve from "@rollup/plugin-node-resolve" import type { LaxPartial } from "@samual/lib" import { assert } from "@samual/lib/assert" -import { relative as getRelativePath, sep as pathSeparator } from "path" +import { relative as getRelativePath, sep as pathSeparator, isAbsolute as isAbsolutePath } from "path" import prettier from "prettier" import { rollup } from "rollup" import { supportedExtensions as extensions } from "../constants" @@ -47,11 +47,6 @@ export { postprocess } from "./postprocess" export { preprocess } from "./preprocess" export { transform } from "./transform" -function isPath(str: string): boolean { - if (pathSeparator == `/`) return str.startsWith(`/`); - return /^[A-Z]:\\/.test(str); -} - export type ProcessOptions = LaxPartial<{ /** whether to minify the given code */ minify: boolean /** 11 a-z 0-9 characters */ uniqueId: string @@ -265,7 +260,7 @@ export async function processScript(code: string, { { name: `hackmud-script-manager`, async transform(code, id) { - if (isPath(id) && !id.includes(`${pathSeparator}node_modules${pathSeparator}`)) + if (isAbsolutePath(id) && !id.includes(`${pathSeparator}node_modules${pathSeparator}`)) return (await preprocess(code, { uniqueId })).code let program!: NodePath