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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Sep 17, 2023
1 parent f2823d4 commit 63bb935
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/loaders-deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
tsExtensionsPattern,
getFormatFromFileUrl,
fileProtocol,
isJsonPattern,
type MaybePromise,
type NodeError,
} from './utils.js';
Expand All @@ -32,7 +33,7 @@ const _getFormat: getFormat = async function (
context,
defaultGetFormat,
) {
if (url.endsWith('.json')) {
if (isJsonPattern.test(url)) {
return { format: 'module' };
}

Expand Down Expand Up @@ -80,7 +81,7 @@ const _transformSource: transformSource = async function (
}

if (
url.endsWith('.json')
isJsonPattern.test(url)
|| tsExtensionsPattern.test(url)
) {
const transformed = await transform(
Expand Down
2 changes: 1 addition & 1 deletion src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
tsconfigPathsMatcher,
fileMatcher,
tsExtensionsPattern,
isJsonPattern,
getFormatFromFileUrl,
fileProtocol,
type MaybePromise,
type NodeError,
} from './utils.js';

const isJsonPattern = /\.json(?:$|\?)/;
const isDirectoryPattern = /\/(?:$|\?)/;

type NextResolve = (
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export const fileProtocol = 'file://';

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

export const isJsonPattern = /\.json(?:$|\?)/;

const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => {
const extension = path.extname(fileUrl);

Expand Down

0 comments on commit 63bb935

Please sign in to comment.