Skip to content
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
12 changes: 7 additions & 5 deletions src/loaders/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import type { Loader, LoaderResult } from "../loader";
const DECLARATION_RE = /\.d\.[cm]?ts$/;
const CM_LETTER_RE = /(?<=\.)(c|m)(?=[jt]s$)/;

const KNOWN_EXT_RE = /\.(c|m)?[jt]sx?$/;

const TS_EXTS = new Set([".ts", ".mts", ".cts"]);

export const jsLoader: Loader = async (input, { options }) => {
if (
![".ts", ".js", ".cjs", ".mjs", ".tsx", ".jsx"].includes(input.extension) ||
DECLARATION_RE.test(input.path)
) {
if (!KNOWN_EXT_RE.test(input.path) || DECLARATION_RE.test(input.path)) {
console.log("Ignoring file with known extension:", input.path);
return;
}

Expand All @@ -32,7 +34,7 @@ export const jsLoader: Loader = async (input, { options }) => {
}

// typescript => js
if (input.extension === ".ts") {
if (TS_EXTS.has(input.extension)) {
contents = await transform(contents, {
...options.esbuild,
loader: "ts",
Expand Down
1 change: 1 addition & 0 deletions test/fixture/src/ts/test1.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "test1.mts" as string;
1 change: 1 addition & 0 deletions test/fixture/src/ts/test2.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "test2.cts" as string;
8 changes: 8 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe("mkdist", () => {
"dist/components/tsx.mjs",
"dist/bar/index.mjs",
"dist/bar/esm.mjs",
"dist/ts/test1.mjs",
"dist/ts/test2.mjs",
]
.map((f) => resolve(rootDir, f))
.sort()
Expand Down Expand Up @@ -105,6 +107,10 @@ describe("mkdist", () => {
"dist/bar/index.d.ts",
"dist/bar/esm.mjs",
"dist/bar/esm.d.mts",
"dist/ts/test1.mjs",
"dist/ts/test2.mjs",
"dist/ts/test1.d.mts",
"dist/ts/test2.d.cts",
]
.map((f) => resolve(rootDir, f))
.sort()
Expand Down Expand Up @@ -180,6 +186,8 @@ describe("mkdist", () => {
"dist/components/tsx.mjs",
"dist/bar/index.mjs",
"dist/bar/esm.mjs",
"dist/ts/test1.mjs",
"dist/ts/test2.mjs",
]
.map((f) => resolve(rootDir, f))
.sort()
Expand Down