Skip to content

Commit 5995c5e

Browse files
committed
fix: resolve extraOutdir path
1 parent 1983773 commit 5995c5e

File tree

8 files changed

+44
-49
lines changed

8 files changed

+44
-49
lines changed

src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,15 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
213213
const { inputBase, entryMap } = resolveEntry(input, options.inputBase)
214214
debug('[rollup] input base:', inputBase)
215215

216-
let { entryFileNames = '[name].js', dir: outDir } = outputOptions
216+
const { entryFileNames = '[name].js', dir: outDir } = outputOptions
217217
if (typeof entryFileNames !== 'string') {
218218
return this.error('entryFileNames must be a string')
219219
}
220220

221-
if (options.extraOutdir) {
222-
entryFileNames = path.join(options.extraOutdir, entryFileNames)
223-
}
224-
225221
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(
226222
outputFiles,
227223
)) {
228-
const emitName = rewriteImports(
224+
let emitName = rewriteImports(
229225
s,
230226
options,
231227
imports,
@@ -240,6 +236,9 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
240236
source = patchCjsDefaultExport(source)
241237
}
242238

239+
if (options.extraOutdir) {
240+
emitName = path.join(options.extraOutdir || '', emitName)
241+
}
243242
debug('[rollup] emit dts file:', emitName)
244243
if (options.sourceMap && map && outDir) {
245244
source = appendMapUrl(source, emitName)
@@ -288,14 +287,11 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
288287
extFormatMap.get(output.format || 'esm') || 'js',
289288
)
290289

291-
let entryFileNames = output.entryFilename
292-
if (options.extraOutdir) {
293-
entryFileNames = path.join(options.extraOutdir, entryFileNames)
294-
}
290+
const entryFileNames = output.entryFilename
295291
for (const [srcFilename, { s, imports, map, ext }] of Object.entries(
296292
outputFiles,
297293
)) {
298-
const emitName = rewriteImports(
294+
let emitName = rewriteImports(
299295
s,
300296
options,
301297
imports,
@@ -310,6 +306,10 @@ export const IsolatedDecl: UnpluginInstance<Options | undefined, false> =
310306
source = patchCjsDefaultExport(source)
311307
}
312308

309+
if (options.extraOutdir) {
310+
emitName = path.join(options.extraOutdir || '', emitName)
311+
}
312+
313313
debug('[farm] emit dts file:', emitName)
314314
const outDir = output.path
315315
if (options.sourceMap && map && outDir) {

tests/__snapshots__/rolldown.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export { c, hello, num };
2323
export declare function Component(): React.JSX.Element;
2424
2525
// temp/main.d.ts
26-
import { type Num } from "../temp/types.js";
26+
import { type Num } from "./types.js";
2727
export type Str = string;
2828
export declare function hello(s: Str): Str;
2929
export declare let c: React.JSX.Element;
3030
export declare let num: Num;
3131
3232
// temp/types.d.ts
33-
import type { Num2 } from "../temp/types2.js";
33+
import type { Num2 } from "./types2.js";
3434
export type Num = Num2;
3535
3636
// temp/types2.d.ts

tests/__snapshots__/rollup.test.ts.snap

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,6 @@ export type Str = string;
1212
"
1313
`;
1414

15-
exports[`rollup > extraOutdir 1`] = `
16-
"// main.js
17-
function Component() {
18-
return /* @__PURE__ */ React.createElement("div", null, "I'm a div in a tsx component!");
19-
}
20-
21-
function hello(s) {
22-
return "hello" + s;
23-
}
24-
let c = Component;
25-
let num = 1;
26-
27-
export { c, hello, num };
28-
29-
// types/component.d.ts
30-
export declare function Component(): React.JSX.Element;
31-
32-
// types/main.d.ts
33-
import { type Num } from '../types/types.js';
34-
export type Str = string;
35-
export declare function hello(s: Str): Str;
36-
export declare let c: React.JSX.Element;
37-
export declare let num: Num;
38-
39-
// types/types.d.ts
40-
import type { Num2 } from '../types/types2.js';
41-
export type Num = Num2;
42-
43-
// types/types2.d.ts
44-
export type Num2 = number;
45-
"
46-
`;
47-
4815
exports[`rollup > generate basic 1`] = `
4916
"// component.d.ts
5017
export declare function Component(): React.JSX.Element;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## main.js
2+
3+
```js
4+
5+
6+
```
7+
## types/main.d.ts
8+
9+
```ts
10+
export * from './utils/types.js';
11+
12+
```
13+
## types/test.d.ts
14+
15+
```ts
16+
export type Str = string;
17+
18+
```
19+
## types/utils/types.d.ts
20+
21+
```ts
22+
export * from '../test.js';
23+
24+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './utils/types'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type Str = string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '../test'

tests/rollup.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,18 @@ describe('rollup', () => {
4040
})
4141

4242
test(`extraOutdir`, async () => {
43-
const dir = 'basic'
43+
const dir = 'extra-outdir'
4444
const input = path.resolve(fixtures, dir, 'main.ts')
45+
const dist = path.resolve(TEST_SANDBOX_FOLDER, dir)
4546

4647
const bundle = await rollup({
4748
input,
4849
plugins: [UnpluginIsolatedDecl({ extraOutdir: 'types' }), esbuild()],
4950
logLevel: 'silent',
5051
})
51-
const result = await bundle.generate({})
52+
await bundle.write({ dir: dist })
5253

53-
expect(outputToSnapshot(result.output)).toMatchSnapshot()
54+
await expectSnapshot(dist, `rollup/${dir}`)
5455
})
5556

5657
test('write entry-points (#22)', async () => {

0 commit comments

Comments
 (0)