From 5979907d960cf682b083007cb994b88a59f7f489 Mon Sep 17 00:00:00 2001 From: forehalo Date: Mon, 13 Jan 2025 02:40:13 +0000 Subject: [PATCH] fix(tools): always use posix for path resolving (#9627) --- tools/cli/src/webpack/html-plugin.ts | 2 +- tools/cli/src/webpack/index.ts | 2 +- tools/utils/src/path.ts | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/cli/src/webpack/html-plugin.ts b/tools/cli/src/webpack/html-plugin.ts index 3eee8b425f..76cf91398c 100644 --- a/tools/cli/src/webpack/html-plugin.ts +++ b/tools/cli/src/webpack/html-plugin.ts @@ -45,7 +45,7 @@ const gitShortHash = once(() => { if (GITHUB_SHA) { return GITHUB_SHA.substring(0, 9); } - const repo = new Repository(ProjectRoot.path); + const repo = new Repository(ProjectRoot.value); const shortSha = repo.head().target()?.substring(0, 9); if (shortSha) { return shortSha; diff --git a/tools/cli/src/webpack/index.ts b/tools/cli/src/webpack/index.ts index 5d3c05d688..2e88082813 100644 --- a/tools/cli/src/webpack/index.ts +++ b/tools/cli/src/webpack/index.ts @@ -265,7 +265,7 @@ export function createWebpackConfig( pkg.join('tailwind.config.js').exists() ? [ require('tailwindcss')( - require(pkg.join('tailwind.config.js').path) + require(pkg.join('tailwind.config.js').value) ), 'autoprefixer', ] diff --git a/tools/utils/src/path.ts b/tools/utils/src/path.ts index 644ae744ef..953f97a21c 100644 --- a/tools/utils/src/path.ts +++ b/tools/utils/src/path.ts @@ -1,10 +1,12 @@ import { existsSync, statSync } from 'node:fs'; -import { join, relative } from 'node:path'; +import { join, relative } from 'node:path/posix'; import { fileURLToPath, pathToFileURL } from 'node:url'; export class Path { + private readonly path: string; + static dir(url: string) { - return new Path(join(fileURLToPath(url), '..')); + return new Path(fileURLToPath(url)).join('..'); } get value() { @@ -15,7 +17,9 @@ export class Path { return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/'); } - constructor(public readonly path: string) {} + constructor(path: string) { + this.path = path.replaceAll('\\', '/'); + } join(...paths: string[]) { return new Path(join(this.path, ...paths));