Skip to content

Commit dd6c7c6

Browse files
authored
feat: exports with dir index (#393)
1 parent 030ef64 commit dd6c7c6

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"editor.formatOnSave": true,
3-
"cSpell.words": ["tsdown"],
3+
"cSpell.words": ["rolldown", "tsdown"],
44
"files.readonlyInclude": {
55
"docs/**/reference/api/**": true
66
},

src/features/exports.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,30 @@ describe.concurrent('generateExports', () => {
7272
`)
7373
})
7474

75+
test('index entry in dir', async ({ expect }) => {
76+
const results = generateExports(
77+
FAKE_PACKAGE_JSON,
78+
cwd,
79+
{
80+
es: [genChunk('index.js'), genChunk('foo/index.js')],
81+
},
82+
{},
83+
)
84+
await expect(results).resolves.toMatchInlineSnapshot(`
85+
{
86+
"exports": {
87+
".": "./index.js",
88+
"./foo": "./foo/index.js",
89+
"./package.json": "./package.json",
90+
},
91+
"main": "./index.js",
92+
"module": "./index.js",
93+
"publishExports": undefined,
94+
"types": undefined,
95+
}
96+
`)
97+
})
98+
7599
test('multiple entries', async ({ expect }) => {
76100
const results = generateExports(
77101
FAKE_PACKAGE_JSON,

src/features/exports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export async function generateExports(
142142
}
143143
}
144144
} else {
145-
name = `./${name}`
145+
const isDirIndex = name.endsWith('/index')
146+
name = isDirIndex ? `./${name.slice(0, -6)}` : `./${name}`
146147
}
147148

148149
let subExport = exportsMap.get(name)

0 commit comments

Comments
 (0)