Skip to content

fix: do not treat .d.ts as entry #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' {}
Loading