Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Aug 15, 2024
1 parent bf91e64 commit 4af6d0d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,4 @@ export const readPackageJson = (rootPath: string): undefined | PkgJson => {
export const isObject = (obj: unknown): obj is Record<string, any> =>
Object.prototype.toString.call(obj) === '[object Object]';

export const isRelativePath = (p: string): boolean => /^\.\.?($|[\\/])/.test(p);

export { color };
25 changes: 2 additions & 23 deletions packages/core/tests/helper.test.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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
});
});

0 comments on commit 4af6d0d

Please sign in to comment.