fix: code workspace path error
parent
30f7472d26
commit
6d4991d852
|
@ -36,7 +36,7 @@ function resetRoutes() {
|
|||
// 这些路由需要指定 name,防止在路由重置时,不能删除没有指定 name 的路由
|
||||
if (import.meta.env.DEV && !route.name) {
|
||||
console.warn(
|
||||
`The route with the path ${route.path} needs to specify the field name.`,
|
||||
`The route with the path ${route.path} needs to have the field name specified.`,
|
||||
);
|
||||
}
|
||||
return route.name;
|
||||
|
|
|
@ -9,6 +9,7 @@ export {
|
|||
getPackages,
|
||||
getPackagesSync,
|
||||
} from './monorepo';
|
||||
export { toPosixPath } from './path';
|
||||
export { prettierFormat } from './prettier';
|
||||
export type { Package } from '@manypkg/get-packages';
|
||||
export { consola } from 'consola';
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
// pathUtils.test.ts
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { toPosixPath } from './path';
|
||||
|
||||
describe('toPosixPath', () => {
|
||||
// 测试 Windows 风格路径到 POSIX 风格路径的转换
|
||||
it('converts Windows-style paths to POSIX paths', () => {
|
||||
const windowsPath = String.raw`C:\Users\Example\file.txt`;
|
||||
const expectedPosixPath = 'C:/Users/Example/file.txt';
|
||||
expect(toPosixPath(windowsPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
|
||||
// 确认 POSIX 风格路径不会被改变
|
||||
it('leaves POSIX-style paths unchanged', () => {
|
||||
const posixPath = '/home/user/file.txt';
|
||||
expect(toPosixPath(posixPath)).toBe(posixPath);
|
||||
});
|
||||
|
||||
// 测试带有多个分隔符的路径
|
||||
it('converts paths with mixed separators', () => {
|
||||
const mixedPath = String.raw`C:/Users\Example\file.txt`;
|
||||
const expectedPosixPath = 'C:/Users/Example/file.txt';
|
||||
expect(toPosixPath(mixedPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
|
||||
// 测试空字符串
|
||||
it('handles empty strings', () => {
|
||||
const emptyPath = '';
|
||||
expect(toPosixPath(emptyPath)).toBe('');
|
||||
});
|
||||
|
||||
// 测试仅包含分隔符的路径
|
||||
it('handles path with only separators', () => {
|
||||
const separatorsPath = '\\\\\\';
|
||||
const expectedPosixPath = '///';
|
||||
expect(toPosixPath(separatorsPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
|
||||
// 测试不包含任何分隔符的路径
|
||||
it('handles path without separators', () => {
|
||||
const noSeparatorPath = 'file.txt';
|
||||
expect(toPosixPath(noSeparatorPath)).toBe('file.txt');
|
||||
});
|
||||
|
||||
// 测试以分隔符结尾的路径
|
||||
it('handles path ending with a separator', () => {
|
||||
const endingSeparatorPath = 'C:\\Users\\Example\\';
|
||||
const expectedPosixPath = 'C:/Users/Example/';
|
||||
expect(toPosixPath(endingSeparatorPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
|
||||
// 测试以分隔符开头的路径
|
||||
it('handles path starting with a separator', () => {
|
||||
const startingSeparatorPath = String.raw`\Users\Example`;
|
||||
const expectedPosixPath = '/Users/Example';
|
||||
expect(toPosixPath(startingSeparatorPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
|
||||
// 测试包含非法字符的路径
|
||||
it('handles path with invalid characters', () => {
|
||||
const invalidCharsPath = String.raw`C:\Us*?ers\Ex<ample>|file.txt`;
|
||||
const expectedPosixPath = 'C:/Us*?ers/Ex<ample>|file.txt';
|
||||
expect(toPosixPath(invalidCharsPath)).toBe(expectedPosixPath);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
import { posix } from 'node:path';
|
||||
|
||||
/**
|
||||
* 将给定的文件路径转换为 POSIX 风格。
|
||||
* @param {string} pathname - 原始文件路径。
|
||||
*/
|
||||
function toPosixPath(pathname: string) {
|
||||
return pathname.split(`\\`).join(posix.sep);
|
||||
}
|
||||
|
||||
export { toPosixPath };
|
|
@ -140,7 +140,7 @@ async function viteImportMapPlugin(
|
|||
// 未生成importmap时,抛出错误,防止被turbo缓存
|
||||
if (!installed && !isSSR) {
|
||||
installError && console.error(installError);
|
||||
throw new Error('importmap install failed.');
|
||||
throw new Error('Importmap installation failed.');
|
||||
}
|
||||
},
|
||||
enforce: 'post',
|
||||
|
|
|
@ -36,7 +36,7 @@ export async function getEnvConfig(
|
|||
const env = dotenv.parse(envPath);
|
||||
envConfig = { ...envConfig, ...env };
|
||||
} catch (error) {
|
||||
console.error(`Error in parsing ${confFile}`, error);
|
||||
console.error(`Error while parsing ${confFile}`, error);
|
||||
}
|
||||
}
|
||||
const reg = new RegExp(`^(${match})`);
|
||||
|
|
|
@ -251,7 +251,7 @@ const useTabsStore = defineStore('tabs', {
|
|||
this._close(currentRoute.value);
|
||||
await this._goToTab(before, router);
|
||||
} else {
|
||||
console.error('关闭标签页失败,当前只剩一个标签页。');
|
||||
console.error('Failed to close the tab; only one tab remains open.');
|
||||
}
|
||||
},
|
||||
/**
|
||||
|
|
|
@ -47,7 +47,7 @@ authentication:
|
|||
username: 账号
|
||||
password: 密码
|
||||
username-tip: 请输入用户名
|
||||
password-tip: 请输入用户名
|
||||
password-tip: 请输入密码
|
||||
remember-me: 记住账号
|
||||
create-an-account: 创建一个账号
|
||||
create-account: 创建账号
|
||||
|
|
|
@ -10,6 +10,7 @@ import {
|
|||
getPackages,
|
||||
gitAdd,
|
||||
prettierFormat,
|
||||
toPosixPath,
|
||||
} from '@vben/node-utils';
|
||||
|
||||
const CODE_WORKSPACE_FILE = join('vben-admin.code-workspace');
|
||||
|
@ -29,7 +30,7 @@ async function createCodeWorkspace({
|
|||
const { dir, packageJson } = pkg;
|
||||
return {
|
||||
name: packageJson.name,
|
||||
path: relative(rootDir, dir),
|
||||
path: toPosixPath(relative(rootDir, dir)),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue