Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit 4b6459c

Browse files
committed
feat: support declarationDir
1 parent 905e14b commit 4b6459c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/__test__/declaration.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec(__filename, async function() {
1515
`);
1616

1717
tsconfig({
18+
declarationDir: 'decl',
1819
declaration: true
1920
});
2021

@@ -24,11 +25,11 @@ spec(__filename, async function() {
2425

2526
expectErrors(stats, 0);
2627

27-
checkOutput('src/index.d.ts', `
28+
checkOutput('../decl/index.d.ts', `
2829
export { default as sum } from './utils/sum'
2930
`);
3031

31-
checkOutput('src/utils/sum.d.ts', `
32+
checkOutput('../decl/utils/sum.d.ts', `
3233
export default function sum(a: number, b: number): number
3334
`);
3435

@@ -45,11 +46,11 @@ spec(__filename, async function() {
4546

4647
await watcher.wait();
4748

48-
checkOutput('src/utils/mul.d.ts', `
49+
checkOutput('../decl/utils/mul.d.ts', `
4950
export default function mul(a: number, b: number): number
5051
`);
5152

52-
checkOutput('src/index.d.ts', `
53+
checkOutput('../decl/index.d.ts', `
5354
export { default as sum } from './utils/sum';
5455
export { default as mul } from './utils/mul';
5556
`);

src/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function toUnix(fileName: string): string {
1414
}
1515

1616
function withoutExt(fileName: string): string {
17-
return path.join(path.dirname(fileName), path.basename(fileName).split('.')[0]);
17+
return path.basename(fileName).split('.')[0];
1818
}
1919

2020
function isFileEmit(fileName, outputFileName, sourceFileName) {

src/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as _ from 'lodash';
22
import * as path from 'path';
3+
import * as fs from 'fs';
34

45
import { findCompiledModule, cache } from './cache';
56
import * as helpers from './helpers';
@@ -8,6 +9,7 @@ import { PathPlugin } from './paths-plugin';
89
import { CheckerPlugin as _CheckerPlugin } from './watch-mode';
910

1011
const loaderUtils = require('loader-utils');
12+
const mkdirp = require('mkdirp');
1113

1214
function loader(text) {
1315
try {
@@ -163,13 +165,9 @@ function transform(
163165
}
164166

165167
if (emitResult.declaration) {
166-
const declPath = path.relative(
167-
instance.context,
168-
emitResult.declaration.name
169-
);
170-
171-
webpack.emitFile(
172-
declPath,
168+
mkdirp.sync(path.dirname(emitResult.declaration.name));
169+
fs.writeFileSync(
170+
emitResult.declaration.name,
173171
emitResult.declaration.text
174172
);
175173
}

src/instance.ts

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function applyDefaults(
235235
_.defaults(compilerConfig.options, {
236236
sourceMap: true,
237237
verbose: false,
238+
declarationDir: compilerConfig.options.outDir,
238239
skipDefaultLibCheck: true,
239240
suppressOutputPathCheck: true
240241
});

0 commit comments

Comments
 (0)