Skip to content

Commit a823737

Browse files
authored
fix: do not treat .d.ts as entry (#636)
1 parent d637e02 commit a823737

File tree

3 files changed

+51
-11
lines changed

3 files changed

+51
-11
lines changed

packages/core/src/constant.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,24 @@ export const SHEBANG_REGEX: RegExp = /#!.*[\s\n\r]*$/;
1616
export const REACT_DIRECTIVE_REGEX: RegExp =
1717
/^['"]use (client|server)['"](;?)[\s\n\r]*$/;
1818

19-
export const JS_EXTENSIONS: string[] = [
19+
const JS_EXTENSIONS: string[] = [
2020
'js',
2121
'mjs',
2222
'jsx',
23-
'ts',
24-
'mts',
23+
'(?<!d.)ts', // ignore d.ts,
24+
'(?<!d.)mts', // ditto
25+
'(?<!d.)cts', // ditto
2526
'tsx',
2627
'cjs',
2728
'cjsx',
2829
'mjsx',
2930
'mtsx',
30-
'cts',
3131
'ctsx',
3232
] as const;
3333

34-
export const CSS_EXTENSIONS: string[] = [
35-
'css',
36-
'sass',
37-
'scss',
38-
'less',
39-
] as const;
34+
const CSS_EXTENSIONS: string[] = ['css', 'sass', 'scss', 'less'] as const;
4035

41-
export const ENTRY_EXTENSIONS: string[] = [
36+
const ENTRY_EXTENSIONS: string[] = [
4237
...JS_EXTENSIONS,
4338
...CSS_EXTENSIONS,
4439
] as const;

packages/core/tests/constant.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect, test } from 'vitest';
2+
import {
3+
CSS_EXTENSIONS_PATTERN,
4+
ENTRY_EXTENSIONS_PATTERN,
5+
JS_EXTENSIONS_PATTERN,
6+
} from '../src/constant';
7+
8+
const jsTestStrings = [
9+
{ str: 'index.js', expected: true },
10+
{ str: './index.ts', expected: true },
11+
{ str: './index.d.ts', expected: false },
12+
{ str: '/Users/path/index.ts', expected: true },
13+
{ str: '/Users/path/index.d.ts', expected: false },
14+
{ str: '/Users/path/index.d.mts', expected: false },
15+
{ str: '/Users/path/index.d.cts', expected: false },
16+
{ str: '/Users/path/index.tsx', expected: true },
17+
];
18+
19+
const cssTestStrings = [
20+
{ str: 'index.css', expected: true },
21+
{ str: './index.scss', expected: true },
22+
{ str: './index.less', expected: true },
23+
{ str: '/Users/path/index.scss', expected: true },
24+
{ str: '/Users/path/index.less', expected: true },
25+
{ str: '/Users/path/index.sass', expected: true },
26+
];
27+
28+
test('JS_EXTENSIONS_PATTERN', () => {
29+
for (const { str, expected } of jsTestStrings) {
30+
expect(JS_EXTENSIONS_PATTERN.test(str)).toBe(expected);
31+
}
32+
});
33+
34+
test('CSS_EXTENSIONS_PATTERN', () => {
35+
for (const { str, expected } of cssTestStrings) {
36+
expect(CSS_EXTENSIONS_PATTERN.test(str)).toBe(expected);
37+
}
38+
});
39+
40+
test('ENTRY_EXTENSIONS_PATTERN', () => {
41+
for (const { str, expected } of [...jsTestStrings, ...cssTestStrings]) {
42+
expect(ENTRY_EXTENSIONS_PATTERN.test(str)).toBe(expected);
43+
}
44+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module '*.mdx' {}

0 commit comments

Comments
 (0)