Skip to content

Commit

Permalink
fix: respect directory separator when matching entries (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernankez authored Apr 15, 2023
1 parent 968612b commit 5df5058
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export function inferEntries(
if (source) {
return source;
}
const SOURCE_RE = new RegExp(`${d}${isDir ? "" : "\\.\\w+"}$`);
const SOURCE_RE = new RegExp(`(?<=/|$)${d}${isDir ? "" : "\\.\\w+"}$`);
return sourceFiles
.find((i) => i.match(SOURCE_RE))
.find((i) => SOURCE_RE.test(i))
?.replace(/(\.d\.ts|\.\w+)$/, "");
}, undefined as any);

Expand Down
16 changes: 13 additions & 3 deletions test/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,23 @@ describe("inferEntries", () => {
it("handles multiple entries", () => {
expect(
inferEntries(
{ exports: { ".": "./dist/index.cjs", "./test": "./dist/test.cjs" } },
["src/", "src/", "src/index.ts", "src/test.mjs"]
{
exports: {
".": "./dist/index.cjs",
"first-test": "./dist/first-test.cjs",
"./test": "./dist/test.cjs",
},
},
["src/", "src/", "src/index.ts", "src/first-test.ts", "src/test.mjs"]
)
).to.deep.equal({
cjs: true,
dts: false,
entries: [{ input: "src/index" }, { input: "src/test" }],
entries: [
{ input: "src/index" },
{ input: "src/first-test" },
{ input: "src/test" },
],
warnings: [],
});
});
Expand Down

0 comments on commit 5df5058

Please sign in to comment.