Skip to content

Commit

Permalink
fix: declaration extensions should correspond to their js extension (u…
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearson committed Dec 13, 2024
1 parent 9390803 commit 8c69d0c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 76 deletions.
17 changes: 8 additions & 9 deletions src/loaders/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ export const jsLoader: Loader = async (input, { options }) => {

let contents = await input.getContents();

const isCjs = options.format === "cjs";
let extension = isCjs ? ".js" : ".mjs"; // TODO: Default to .cjs in next major version
if (options.ext) {
extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
}

// declaration
if (options.declaration && !input.srcPath?.match(DECLARATION_RE)) {
const cm = input.srcPath?.match(CM_LETTER_RE)?.[0] || "";
const extension = `.d.${cm}ts`;
const cm = extension.match(CM_LETTER_RE)?.[0] || "";
output.push({
contents,
srcPath: input.srcPath,
path: input.path,
extension,
extension: `.d.${cm}ts`,
declaration: true,
});
}
Expand All @@ -46,7 +51,6 @@ export const jsLoader: Loader = async (input, { options }) => {
}

// esm => cjs
const isCjs = options.format === "cjs";
if (isCjs) {
contents = jiti("")
.transform({ source: contents, retainLines: false })
Expand All @@ -55,11 +59,6 @@ export const jsLoader: Loader = async (input, { options }) => {
.replace("module.exports = void 0;", "");
}

let extension = isCjs ? ".js" : ".mjs"; // TODO: Default to .cjs in next major version
if (options.ext) {
extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
}

output.push({
contents,
path: input.path,
Expand Down
Loading

0 comments on commit 8c69d0c

Please sign in to comment.