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

Commit

Permalink
feat: support declarationDir
Browse files Browse the repository at this point in the history
  • Loading branch information
s-panferov committed Mar 7, 2017
1 parent 905e14b commit 4b6459c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/__test__/declaration.ts
Expand Up @@ -15,6 +15,7 @@ spec(__filename, async function() {
`);

tsconfig({
declarationDir: 'decl',
declaration: true
});

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

expectErrors(stats, 0);

checkOutput('src/index.d.ts', `
checkOutput('../decl/index.d.ts', `
export { default as sum } from './utils/sum'
`);

checkOutput('src/utils/sum.d.ts', `
checkOutput('../decl/utils/sum.d.ts', `
export default function sum(a: number, b: number): number
`);

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

await watcher.wait();

checkOutput('src/utils/mul.d.ts', `
checkOutput('../decl/utils/mul.d.ts', `
export default function mul(a: number, b: number): number
`);

checkOutput('src/index.d.ts', `
checkOutput('../decl/index.d.ts', `
export { default as sum } from './utils/sum';
export { default as mul } from './utils/mul';
`);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.ts
Expand Up @@ -14,7 +14,7 @@ export function toUnix(fileName: string): string {
}

function withoutExt(fileName: string): string {
return path.join(path.dirname(fileName), path.basename(fileName).split('.')[0]);
return path.basename(fileName).split('.')[0];
}

function isFileEmit(fileName, outputFileName, sourceFileName) {
Expand Down
12 changes: 5 additions & 7 deletions src/index.ts
@@ -1,5 +1,6 @@
import * as _ from 'lodash';
import * as path from 'path';
import * as fs from 'fs';

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

const loaderUtils = require('loader-utils');
const mkdirp = require('mkdirp');

function loader(text) {
try {
Expand Down Expand Up @@ -163,13 +165,9 @@ function transform(
}

if (emitResult.declaration) {
const declPath = path.relative(
instance.context,
emitResult.declaration.name
);

webpack.emitFile(
declPath,
mkdirp.sync(path.dirname(emitResult.declaration.name));
fs.writeFileSync(
emitResult.declaration.name,
emitResult.declaration.text
);
}
Expand Down
1 change: 1 addition & 0 deletions src/instance.ts
Expand Up @@ -235,6 +235,7 @@ function applyDefaults(
_.defaults(compilerConfig.options, {
sourceMap: true,
verbose: false,
declarationDir: compilerConfig.options.outDir,
skipDefaultLibCheck: true,
suppressOutputPathCheck: true
});
Expand Down

0 comments on commit 4b6459c

Please sign in to comment.