- fix for type definitions eating memory in watch mode

- publishing type definitions
This commit is contained in:
ezolenko 2017-05-29 22:41:44 -06:00
parent b948b49d75
commit 80a42b63fa
11 changed files with 179 additions and 17 deletions

View File

@ -75,8 +75,7 @@ Plugin takes following options:
### Declarations
This plugin respects `declaration: true` in your `tsconfig.json` file. When set, it will emit `*.d.ts` files for your bundle. The resulting file(s) can then be used with the `types`
property in your `package.json` file as described [here](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).
This plugin respects `declaration: true` in your `tsconfig.json` file. When set, it will emit `*.d.ts` files for your bundle. The resulting file(s) can then be used with the `types` property in your `package.json` file as described [here](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html).
### Watch mode

25
dist/context.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
export interface IRollupContext {
warn(message: string): void;
error(message: string): void;
}
export interface IContext {
warn(message: string): void;
error(message: string): void;
info(message: string): void;
debug(message: string): void;
}
export declare enum VerbosityLevel {
Error = 0,
Warning = 1,
Info = 2,
Debug = 3,
}
export declare class ConsoleContext implements IContext {
private verbosity;
private prefix;
constructor(verbosity: VerbosityLevel, prefix?: string);
warn(message: string): void;
error(message: string): void;
info(message: string): void;
debug(message: string): void;
}

17
dist/host.d.ts vendored Normal file
View File

@ -0,0 +1,17 @@
import * as ts from "typescript";
export declare class LanguageServiceHost implements ts.LanguageServiceHost {
private parsedConfig;
private cwd;
private snapshots;
private versions;
constructor(parsedConfig: ts.ParsedCommandLine);
reset(): void;
setSnapshot(fileName: string, data: string): ts.IScriptSnapshot;
getScriptSnapshot(fileName: string): ts.IScriptSnapshot | undefined;
getCurrentDirectory(): string;
getScriptVersion(fileName: string): string;
getScriptFileNames(): string[];
getCompilationSettings(): ts.CompilerOptions;
getDefaultLibFileName(opts: ts.CompilerOptions): string;
private normalize(fileName);
}

20
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
import { IRollupContext } from "./context";
import { ICode } from "./tscache";
export interface IOptions {
include: string;
exclude: string;
check: boolean;
verbosity: number;
clean: boolean;
cacheRoot: string;
abortOnError: boolean;
rollupCommonJSResolveHack: boolean;
}
export default function typescript(options: IOptions): {
options(config: any): void;
resolveId(importee: string, importer: string): string | null;
load(id: string): string | undefined;
transform(this: IRollupContext, code: string, id: string): ICode | undefined;
ongenerate(bundleOptions: any): void;
onwrite(): void;
};

36
dist/rollingcache.d.ts vendored Normal file
View File

@ -0,0 +1,36 @@
import { ICache } from "./icache";
/**
* Saves data in new cache folder or reads it from old one.
* Avoids perpetually growing cache and situations when things need to consider changed and then reverted data to be changed.
*/
export declare class RollingCache<DataType> implements ICache<DataType> {
private cacheRoot;
private checkNewCache;
private oldCacheRoot;
private newCacheRoot;
private rolled;
/**
* @param cacheRoot: root folder for the cache
* @param checkNewCache: whether to also look in new cache when reading from cache
*/
constructor(cacheRoot: string, checkNewCache: boolean);
/**
* @returns true if name exist in old cache (or either old of new cache if checkNewCache is true)
*/
exists(name: string): boolean;
path(name: string): string;
/**
* @returns true if old cache contains all names and nothing more
*/
match(names: string[]): boolean;
/**
* @returns data for name, must exist in old cache (or either old of new cache if checkNewCache is true)
*/
read(name: string): DataType;
write(name: string, data: DataType): void;
touch(name: string): void;
/**
* clears old cache and moves new in its place
*/
roll(): void;
}

View File

@ -492,7 +492,7 @@ function typescript(options) {
return _cache;
};
var noErrors = true;
var declarations = [];
var declarations = {};
// printing compiler option errors
if (options.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
@ -573,7 +573,8 @@ function typescript(options) {
printDiagnostics(contextWrapper, diagnostics);
}
if (result && result.dts) {
declarations.push(result.dts);
declarations[result.dts.name] = result.dts;
result.dts = undefined;
}
return result;
},
@ -597,7 +598,7 @@ function typescript(options) {
round++;
},
onwrite: function () {
declarations.forEach(function (_a) {
_.each(declarations, function (_a) {
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
ts.sys.writeFile(name, text, writeByteOrderMark);
});

View File

@ -498,7 +498,7 @@ function typescript(options) {
return _cache;
};
var noErrors = true;
var declarations = [];
var declarations = {};
// printing compiler option errors
if (options.check)
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
@ -579,7 +579,8 @@ function typescript(options) {
printDiagnostics(contextWrapper, diagnostics);
}
if (result && result.dts) {
declarations.push(result.dts);
declarations[result.dts.name] = result.dts;
result.dts = undefined;
}
return result;
},
@ -603,7 +604,7 @@ function typescript(options) {
round++;
},
onwrite: function () {
declarations.forEach(function (_a) {
each(declarations, function (_a) {
var name = _a.name, text = _a.text, writeByteOrderMark = _a.writeByteOrderMark;
sys.writeFile(name, text, writeByteOrderMark);
});

13
dist/rollupcontext.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
import { IContext, IRollupContext, VerbosityLevel } from "./context";
export declare class RollupContext implements IContext {
private verbosity;
private bail;
private context;
private prefix;
private hasContext;
constructor(verbosity: VerbosityLevel, bail: boolean, context: IRollupContext, prefix?: string);
warn(message: string): void;
error(message: string): void;
info(message: string): void;
debug(message: string): void;
}

44
dist/tscache.d.ts vendored Normal file
View File

@ -0,0 +1,44 @@
import { IContext } from "./context";
import * as ts from "typescript";
export interface ICode {
code: string | undefined;
map: string | undefined;
dts?: ts.OutputFile | undefined;
}
export interface IDiagnostics {
flatMessage: string;
fileLine?: string;
category: ts.DiagnosticCategory;
code: number;
type: string;
}
export declare function convertDiagnostic(type: string, data: ts.Diagnostic[]): IDiagnostics[];
export declare class TsCache {
private host;
private options;
private rollupConfig;
private context;
private cacheVersion;
private dependencyTree;
private ambientTypes;
private ambientTypesDirty;
private cacheDir;
private codeCache;
private typesCache;
private semanticDiagnosticsCache;
private syntacticDiagnosticsCache;
constructor(host: ts.LanguageServiceHost, cache: string, options: ts.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
clean(): void;
setDependency(importee: string, importer: string): void;
walkTree(cb: (id: string) => void | false): void;
done(): void;
getCompiled(id: string, snapshot: ts.IScriptSnapshot, transform: () => ICode | undefined): ICode | undefined;
getSyntacticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
getSemanticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[];
private checkAmbientTypes();
private getDiagnostics(type, cache, id, snapshot, check);
private init();
private markAsDirty(id, _snapshot);
private isDirty(id, _snapshot, checkImports);
private makeName(id, snapshot);
}

View File

@ -94,7 +94,7 @@ function printDiagnostics(context: IContext, diagnostics: IDiagnostics[])
});
}
interface IOptions
export interface IOptions
{
include: string;
exclude: string;
@ -152,7 +152,7 @@ export default function typescript(options: IOptions)
let noErrors = true;
const declarations: ts.OutputFile[] = [];
const declarations: { [name: string]: ts.OutputFile } = {};
// printing compiler option errors
if (options.check)
@ -249,8 +249,8 @@ export default function typescript(options: IOptions)
this.error(colors.red(`failed to transpile '${id}'`));
}
const transpiled = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".js") );
const map = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".map") );
const transpiled = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".js"));
const map = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".map"));
const dts = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".d.ts"));
return {
@ -279,8 +279,10 @@ export default function typescript(options: IOptions)
printDiagnostics(contextWrapper, diagnostics);
}
if (result && result.dts) {
declarations.push(result.dts);
if (result && result.dts)
{
declarations[result.dts.name] = result.dts;
result.dts = undefined;
}
return result;
@ -320,8 +322,10 @@ export default function typescript(options: IOptions)
round++;
},
onwrite() {
declarations.forEach(({ name, text, writeByteOrderMark }) => {
onwrite()
{
_.each(declarations, ({ name, text, writeByteOrderMark }) =>
{
ts.sys.writeFile(name, text, writeByteOrderMark);
});
},

View File

@ -14,7 +14,9 @@
"noEmitOnError": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true
"noImplicitReturns": true,
"declaration": true,
"declarationDir": "./dist"
},
"include": [
"src/**/*.ts"