Skip to content

Commit

Permalink
fix: do not treat .d.ts as entry (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored Jan 2, 2025
1 parent d637e02 commit a823737
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/core/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@ export const SHEBANG_REGEX: RegExp = /#!.*[\s\n\r]*$/;
export const REACT_DIRECTIVE_REGEX: RegExp =
/^['"]use (client|server)['"](;?)[\s\n\r]*$/;

export const JS_EXTENSIONS: string[] = [
const JS_EXTENSIONS: string[] = [
'js',
'mjs',
'jsx',
'ts',
'mts',
'(?<!d.)ts', // ignore d.ts,
'(?<!d.)mts', // ditto
'(?<!d.)cts', // ditto
'tsx',
'cjs',
'cjsx',
'mjsx',
'mtsx',
'cts',
'ctsx',
] as const;

export const CSS_EXTENSIONS: string[] = [
'css',
'sass',
'scss',
'less',
] as const;
const CSS_EXTENSIONS: string[] = ['css', 'sass', 'scss', 'less'] as const;

export const ENTRY_EXTENSIONS: string[] = [
const ENTRY_EXTENSIONS: string[] = [
...JS_EXTENSIONS,
...CSS_EXTENSIONS,
] as const;
Expand Down
44 changes: 44 additions & 0 deletions packages/core/tests/constant.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect, test } from 'vitest';
import {
CSS_EXTENSIONS_PATTERN,
ENTRY_EXTENSIONS_PATTERN,
JS_EXTENSIONS_PATTERN,
} from '../src/constant';

const jsTestStrings = [
{ str: 'index.js', expected: true },
{ str: './index.ts', expected: true },
{ str: './index.d.ts', expected: false },
{ str: '/Users/path/index.ts', expected: true },
{ str: '/Users/path/index.d.ts', expected: false },
{ str: '/Users/path/index.d.mts', expected: false },
{ str: '/Users/path/index.d.cts', expected: false },
{ str: '/Users/path/index.tsx', expected: true },
];

const cssTestStrings = [
{ str: 'index.css', expected: true },
{ str: './index.scss', expected: true },
{ str: './index.less', expected: true },
{ str: '/Users/path/index.scss', expected: true },
{ str: '/Users/path/index.less', expected: true },
{ str: '/Users/path/index.sass', expected: true },
];

test('JS_EXTENSIONS_PATTERN', () => {
for (const { str, expected } of jsTestStrings) {
expect(JS_EXTENSIONS_PATTERN.test(str)).toBe(expected);
}
});

test('CSS_EXTENSIONS_PATTERN', () => {
for (const { str, expected } of cssTestStrings) {
expect(CSS_EXTENSIONS_PATTERN.test(str)).toBe(expected);
}
});

test('ENTRY_EXTENSIONS_PATTERN', () => {
for (const { str, expected } of [...jsTestStrings, ...cssTestStrings]) {
expect(ENTRY_EXTENSIONS_PATTERN.test(str)).toBe(expected);
}
});
1 change: 1 addition & 0 deletions tests/integration/entry/glob/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.mdx' {}

0 comments on commit a823737

Please sign in to comment.