Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 63bb935

Browse files
committed
wip
1 parent f2823d4 commit 63bb935

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/loaders-deprecated.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
tsExtensionsPattern,
1818
getFormatFromFileUrl,
1919
fileProtocol,
20+
isJsonPattern,
2021
type MaybePromise,
2122
type NodeError,
2223
} from './utils.js';
@@ -32,7 +33,7 @@ const _getFormat: getFormat = async function (
3233
context,
3334
defaultGetFormat,
3435
) {
35-
if (url.endsWith('.json')) {
36+
if (isJsonPattern.test(url)) {
3637
return { format: 'module' };
3738
}
3839

@@ -80,7 +81,7 @@ const _transformSource: transformSource = async function (
8081
}
8182

8283
if (
83-
url.endsWith('.json')
84+
isJsonPattern.test(url)
8485
|| tsExtensionsPattern.test(url)
8586
) {
8687
const transformed = await transform(

src/loaders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import {
1616
tsconfigPathsMatcher,
1717
fileMatcher,
1818
tsExtensionsPattern,
19+
isJsonPattern,
1920
getFormatFromFileUrl,
2021
fileProtocol,
2122
type MaybePromise,
2223
type NodeError,
2324
} from './utils.js';
2425

25-
const isJsonPattern = /\.json(?:$|\?)/;
2626
const isDirectoryPattern = /\/(?:$|\?)/;
2727

2828
type NextResolve = (

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const fileProtocol = 'file://';
2727

2828
export const tsExtensionsPattern = /\.([cm]?ts|[tj]sx)($|\?)/;
2929

30+
export const isJsonPattern = /\.json(?:$|\?)/;
31+
3032
const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => {
3133
const extension = path.extname(fileUrl);
3234

0 commit comments

Comments
 (0)