From fe272e0d27c88e96426f1a71e292a2584d72915f Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Mon, 1 Dec 2025 16:09:54 +0800 Subject: [PATCH] update --- src/command/sync/modules/base.ts | 9 +++++---- src/uitls/file.ts | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/command/sync/modules/base.ts b/src/command/sync/modules/base.ts index 564a370..91aa44e 100644 --- a/src/command/sync/modules/base.ts +++ b/src/command/sync/modules/base.ts @@ -6,7 +6,7 @@ import { getHash } from '@/uitls/hash.ts'; import glob from 'fast-glob'; import { isMatch } from 'micromatch'; import { logger } from '@/module/logger.ts'; - +import { normalizeScriptPath } from "@/uitls/file.ts"; export type SyncOptions = { dir?: string; configFilename?: string; @@ -70,7 +70,7 @@ export class SyncBase { const set = new Set(defaultIgnore); return new Array(...set); } - getMatchList(opts?: { matchList?: string[]; ignore: string[]; matchObjectList?: { path: string; [key: string]: any }[] }) { + getMatchList(opts?: { matchList?: string[]; ignore: string[]; matchObjectList?: { path: string;[key: string]: any }[] }) { const { matchList = [], ignore = [], matchObjectList = [] } = opts || {}; const _ignore = this.getIngore(ignore); const _matchList = matchList.filter((file) => !isMatch(file, _ignore)); @@ -175,8 +175,9 @@ export class SyncBase { const replaceKeys = Object.keys(replace); let newKey = key; for (let replaceKey of replaceKeys) { - if (newKey.startsWith(replaceKey)) { - newKey = key.replace(replaceKey, replace[replaceKey]); + const _replaceKey = normalizeScriptPath(replaceKey); + if (newKey.startsWith(_replaceKey)) { + newKey = key.replace(_replaceKey, replace[replaceKey]); } } const pathname = path.join(_registryURL.pathname, newKey); diff --git a/src/uitls/file.ts b/src/uitls/file.ts index ac3c8f5..520aeab 100644 --- a/src/uitls/file.ts +++ b/src/uitls/file.ts @@ -26,3 +26,10 @@ export const pathExists = (path: string, type?: 'file' | 'directory') => { return false; } }; +export const normalizeScriptPath = (scriptPath: string): string => { + if (process.platform === 'win32') { + // 在 Windows 上,将反斜杠转换为正斜杠,PM2 更好地支持正斜杠 + return scriptPath.replace(/\\/g, '/'); + } + return scriptPath; +}; \ No newline at end of file