From 4af6d0d1a3266680f43813f03e0d5ce83c8751d3 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Thu, 15 Aug 2024 15:52:52 +0800 Subject: [PATCH] chore: update --- packages/core/src/config.ts | 2 +- packages/core/src/utils/helper.ts | 2 -- packages/core/tests/helper.test.ts | 25 ++----------------------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index af64136d..660613e2 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -401,7 +401,7 @@ const composeBundleConfig = ( // So we add a file extension here when data.request is a relative path return callback( null, - isRelativePath(data.request) + data.request[0] === '.' ? `${data.request}${jsExtension}` : data.request, ); diff --git a/packages/core/src/utils/helper.ts b/packages/core/src/utils/helper.ts index ab01d89f..58585736 100644 --- a/packages/core/src/utils/helper.ts +++ b/packages/core/src/utils/helper.ts @@ -126,6 +126,4 @@ export const readPackageJson = (rootPath: string): undefined | PkgJson => { export const isObject = (obj: unknown): obj is Record => Object.prototype.toString.call(obj) === '[object Object]'; -export const isRelativePath = (p: string): boolean => /^\.\.?($|[\\/])/.test(p); - export { color }; diff --git a/packages/core/tests/helper.test.ts b/packages/core/tests/helper.test.ts index d116b332..15fd5fdc 100644 --- a/packages/core/tests/helper.test.ts +++ b/packages/core/tests/helper.test.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; -import { describe, expect, it, test, vi } from 'vitest'; -import { isRelativePath, readPackageJson } from '../src/utils/helper'; +import { expect, it, vi } from 'vitest'; +import { readPackageJson } from '../src/utils/helper'; vi.mock('rslog'); @@ -11,24 +11,3 @@ it('readPackageJson correctly', async () => { type: 'module', }); }); - -describe('isRelativePath', () => { - test('should return true for relative paths', () => { - expect(isRelativePath('../Documents/file.txt')).toBe(true); - expect(isRelativePath('./file.txt')).toBe(true); - }); - - test('should return false for absolute paths', () => { - expect(isRelativePath('file.txt')).toBe(false); - expect(isRelativePath('/Users/username/Documents/file.txt')).toBe(false); - expect(isRelativePath('C:\\Users\\username\\Documents\\file.txt')).toBe( - false, - ); - }); - - test('should handle edge cases', () => { - expect(isRelativePath('')).toBe(false); // empty path - expect(isRelativePath('.')).toBe(true); // current directory - expect(isRelativePath('./')).toBe(true); // current directory - }); -});