From 3fa40ecb69d89e4e5efc532e2bdc3a260c1fec4e Mon Sep 17 00:00:00 2001 From: Yu Chao Liang Date: Sat, 9 Mar 2019 01:57:06 +0800 Subject: [PATCH] - if output.file not exist use output.dir --- src/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3133836d..abcc4eb6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -283,7 +283,7 @@ const typescript: PluginImpl> = (options) => generateRound++; }, - _onwrite({ file }: OutputOptions): void + _onwrite({ file, dir }: OutputOptions): void { if (parsedConfig.options.declaration) { @@ -300,6 +300,7 @@ const typescript: PluginImpl> = (options) => }); const bundleFile = file; + const outputDir = dir; const writeDeclaration = (key: string, extension: string, entry?: tsTypes.OutputFile) => { @@ -313,12 +314,12 @@ const typescript: PluginImpl> = (options) => let writeToPath: string; // If for some reason no 'dest' property exists or if 'useTsconfigDeclarationDir' is given in the plugin options, // use the path provided by Typescript's LanguageService. - if (!bundleFile || pluginOptions.useTsconfigDeclarationDir) + if ((!bundleFile && !outputDir) || pluginOptions.useTsconfigDeclarationDir) writeToPath = fileName; else { // Otherwise, take the directory name from the path and make sure it is absolute. - const destDirname = dirname(bundleFile); + const destDirname = bundleFile ? dirname(bundleFile) : outputDir; const destDirectory = isAbsolute(destDirname) ? destDirname : join(process.cwd(), destDirname); writeToPath = join(destDirectory, relative(process.cwd(), fileName)); }