File tree Expand file tree Collapse file tree 1 file changed +6
-20
lines changed Expand file tree Collapse file tree 1 file changed +6
-20
lines changed Original file line number Diff line number Diff line change @@ -3,31 +3,17 @@ import type { ModuleFormat } from 'node:module';
3
3
import { tsExtensions } from '../../utils/path-utils.js' ;
4
4
import { getPackageType } from './package-json.js' ;
5
5
6
- const getFormatFromExtension = ( fileUrl : string ) : ModuleFormat | undefined => {
7
- [ fileUrl ] = fileUrl . split ( '?' ) ;
8
-
9
- const extension = path . extname ( fileUrl ) ;
10
-
11
- if ( extension === '.mts' ) {
6
+ export const getFormatFromFileUrl = ( fileUrl : string ) => {
7
+ const { pathname } = new URL ( fileUrl ) ;
8
+ const extension = path . extname ( pathname ) ;
9
+ if ( extension === '.mts' || extension === '.mjs' ) {
12
10
return 'module' ;
13
11
}
14
-
15
- if ( extension === '.cts' ) {
12
+ if ( extension === '.cts' || extension === '.cjs' ) {
16
13
return 'commonjs' ;
17
14
}
18
- } ;
19
15
20
- export const getFormatFromFileUrl = ( fileUrl : string ) => {
21
- const format = getFormatFromExtension ( fileUrl ) ;
22
-
23
- if ( format ) {
24
- return format ;
25
- }
26
-
27
- // ts, tsx, jsx
28
- const { pathname } = new URL ( fileUrl ) ;
29
- const extension = path . extname ( pathname ) ;
30
- if ( tsExtensions . includes ( extension ) || extension === '.js' ) {
16
+ if ( extension === '.js' || tsExtensions . includes ( extension ) ) {
31
17
return getPackageType ( fileUrl ) ;
32
18
}
33
19
} ;
You can’t perform that action at this time.
0 commit comments