- fix for TS5052

- cleanup
This commit is contained in:
ezolenko 2017-07-31 23:27:05 -06:00
parent c72a610400
commit c501e1a34f
10 changed files with 56 additions and 37 deletions

View File

@ -1,3 +1,3 @@
import { CompilerOptions } from "typescript";
import { IOptions } from "./ioptions";
export declare function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions): CompilerOptions;
export declare function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions, tsConfigJson?: any): CompilerOptions;

View File

@ -449,9 +449,10 @@ function printDiagnostics(context, diagnostics) {
});
}
function getOptionsOverrides(_a) {
function getOptionsOverrides(_a, tsConfigJson) {
var useTsconfigDeclarationDir = _a.useTsconfigDeclarationDir;
return __assign({ module: typescript.ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
var declaration = lodash.get(tsConfigJson, "compilerOptions.declaration", false);
return __assign({ module: typescript.ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (!declaration || useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
}
function parseTsConfig(tsconfig, context, pluginOptions) {
@ -464,7 +465,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
printDiagnostics(context, convertDiagnostic("config", [result.error]));
throw new Error("failed to parse " + fileName);
}
return typescript.parseJsonConfigFileContent(result.config, typescript.sys, path.dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
return typescript.parseJsonConfigFileContent(result.config, typescript.sys, path.dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
}
// The injected id for helpers.
@ -512,6 +513,7 @@ function typescript$1(options) {
abortOnError: true,
rollupCommonJSResolveHack: false,
tsconfig: "tsconfig.json",
useTsconfigDeclarationDir: false,
});
return {
options: function (config) {
@ -629,14 +631,17 @@ function typescript$1(options) {
var baseDeclarationDir = parsedConfig.options.outDir;
lodash.each(declarations, function (_a) {
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
var writeToPath;
// 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 (dest == null || pluginOptions.useTsconfigDeclarationDir)
return typescript.sys.writeFile(name, text, writeByteOrderMark);
// Otherwise, take the directory name from the path and make sure it is absolute.
var destDirname = path.dirname(dest);
var destDirectory = path.isAbsolute(dest) ? destDirname : path.join(process.cwd(), destDirname);
var writeToPath = path.join(destDirectory, path.relative(baseDeclarationDir, name));
if (!dest || pluginOptions.useTsconfigDeclarationDir)
writeToPath = name;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
var destDirname = path.dirname(dest);
var destDirectory = path.isAbsolute(dest) ? destDirname : path.join(process.cwd(), destDirname);
writeToPath = path.join(destDirectory, path.relative(baseDeclarationDir, name));
}
// Write the declaration file to disk.
typescript.sys.writeFile(writeToPath, text, writeByteOrderMark);
});

View File

@ -448,9 +448,10 @@ function printDiagnostics(context, diagnostics) {
});
}
function getOptionsOverrides(_a) {
function getOptionsOverrides(_a, tsConfigJson) {
var useTsconfigDeclarationDir = _a.useTsconfigDeclarationDir;
return __assign({ module: ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
var declaration = get(tsConfigJson, "compilerOptions.declaration", false);
return __assign({ module: ModuleKind.ES2015, noEmitHelpers: true, importHelpers: true, noResolve: false, outDir: process.cwd() }, (!declaration || useTsconfigDeclarationDir ? {} : { declarationDir: process.cwd() }));
}
function parseTsConfig(tsconfig, context, pluginOptions) {
@ -463,7 +464,7 @@ function parseTsConfig(tsconfig, context, pluginOptions) {
printDiagnostics(context, convertDiagnostic("config", [result.error]));
throw new Error("failed to parse " + fileName);
}
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
}
// The injected id for helpers.
@ -511,6 +512,7 @@ function typescript$1(options) {
abortOnError: true,
rollupCommonJSResolveHack: false,
tsconfig: "tsconfig.json",
useTsconfigDeclarationDir: false,
});
return {
options: function (config) {
@ -628,14 +630,17 @@ function typescript$1(options) {
var baseDeclarationDir = parsedConfig.options.outDir;
each(declarations, function (_a) {
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
var writeToPath;
// 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 (dest == null || pluginOptions.useTsconfigDeclarationDir)
return sys.writeFile(name, text, writeByteOrderMark);
// Otherwise, take the directory name from the path and make sure it is absolute.
var destDirname = dirname(dest);
var destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
var writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
if (!dest || pluginOptions.useTsconfigDeclarationDir)
writeToPath = name;
else {
// Otherwise, take the directory name from the path and make sure it is absolute.
var destDirname = dirname(dest);
var destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
}
// Write the declaration file to disk.
sys.writeFile(writeToPath, text, writeByteOrderMark);
});

View File

@ -7,6 +7,7 @@ export default {
external: [
'path',
'fs',
'fs-extra',
'object-assign',
'rollup-pluginutils',

View File

@ -1,13 +1,16 @@
import {CompilerOptions, ModuleKind} from "typescript";
import {IOptions} from "./ioptions";
import { CompilerOptions, ModuleKind } from "typescript";
import { IOptions } from "./ioptions";
import { get } from "lodash";
export function getOptionsOverrides({useTsconfigDeclarationDir}: IOptions): CompilerOptions {
export function getOptionsOverrides({ useTsconfigDeclarationDir }: IOptions, tsConfigJson?: any): CompilerOptions
{
const declaration = get(tsConfigJson, "compilerOptions.declaration", false);
return {
module: ModuleKind.ES2015,
noEmitHelpers: true,
importHelpers: true,
noResolve: false,
outDir: process.cwd(),
...(useTsconfigDeclarationDir ? {} : {declarationDir: process.cwd()}),
...(!declaration || useTsconfigDeclarationDir ? {} : {declarationDir: process.cwd()}),
};
}

View File

@ -51,6 +51,7 @@ export default function typescript(options?: Partial<IOptions>)
abortOnError: true,
rollupCommonJSResolveHack: false,
tsconfig: "tsconfig.json",
useTsconfigDeclarationDir: false,
});
return {
@ -235,17 +236,22 @@ export default function typescript(options?: Partial<IOptions>)
onwrite({dest}: IRollupOptions)
{
const baseDeclarationDir = parsedConfig.options.outDir as string;
const baseDeclarationDir = parsedConfig.options.outDir;
each(declarations, ({ name, text, writeByteOrderMark }) =>
{
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 (dest == null || pluginOptions.useTsconfigDeclarationDir) return sys.writeFile(name, text, writeByteOrderMark);
if (!dest || pluginOptions.useTsconfigDeclarationDir)
writeToPath = name;
else
{
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(dest);
const destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
writeToPath = join(destDirectory, relative(baseDeclarationDir!, name));
}
// Otherwise, take the directory name from the path and make sure it is absolute.
const destDirname = dirname(dest);
const destDirectory = isAbsolute(dest) ? destDirname : join(process.cwd(), destDirname);
const writeToPath = join(destDirectory, relative(baseDeclarationDir, name));
// Write the declaration file to disk.
sys.writeFile(writeToPath, text, writeByteOrderMark);
});

View File

@ -1,3 +1,4 @@
export interface IRollupOptions {
export interface IRollupOptions
{
dest?: string;
}

View File

@ -6,7 +6,8 @@ import {convertDiagnostic} from "./tscache";
import {getOptionsOverrides} from "./get-options-overrides";
import {IOptions} from "./ioptions";
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): ParsedCommandLine {
export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions: IOptions): ParsedCommandLine
{
const fileName = findConfigFile(process.cwd(), sys.fileExists, tsconfig);
if (!fileName)
@ -20,5 +21,5 @@ export function parseTsConfig(tsconfig: string, context: IContext, pluginOptions
throw new Error(`failed to parse ${fileName}`);
}
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions), fileName);
return parseJsonConfigFileContent(result.config, sys, dirname(fileName), getOptionsOverrides(pluginOptions, result.config), fileName);
}

View File

@ -1,3 +1 @@
export declare type Partial<T> = {
[P in keyof T]?: T[P];
};
export declare type Partial<T> = { [P in keyof T]?: T[P]; };

View File

@ -15,8 +15,7 @@
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"declaration": true,
"declarationDir": "./dist"
"declaration": true
},
"include": [
"src/**/*.ts"