diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js index 3d60fca..727c8f0 100644 --- a/dist/rollup-plugin-typescript2.cjs.js +++ b/dist/rollup-plugin-typescript2.cjs.js @@ -167,6 +167,9 @@ var RollingCache = (function () { return true; return fs.existsSync(this.oldCacheRoot + "/" + name); }; + RollingCache.prototype.path = function (name) { + return this.oldCacheRoot + "/" + name; + }; /** * @returns true if old cache contains all names and nothing more */ @@ -258,13 +261,18 @@ var Cache = (function () { }; Cache.prototype.setDependency = function (importee, importer) { // importee -> importer - this.context.debug(importee + " -> " + importer); + this.context.debug("" + importee); + this.context.debug(" imported by " + importer); this.dependencyTree.setEdge(importer, importee); }; Cache.prototype.compileDone = function () { var _this = this; - var typeNames = _.filter(this.ambientTypes, function (snaphot) { return snaphot.snapshot !== undefined; }) - .map(function (snaphot) { return _this.makeName(snaphot.id, snaphot.snapshot); }); + this.context.debug("Ambient types:"); + var typeNames = _.filter(this.ambientTypes, function (snapshot) { return snapshot.snapshot !== undefined; }) + .map(function (snapshot) { + _this.context.debug(" " + snapshot.id); + return _this.makeName(snapshot.id, snapshot.snapshot); + }); // types dirty if any d.ts changed, added or removed this.ambientTypesDirty = !this.typesCache.match(typeNames); if (this.ambientTypesDirty) @@ -279,14 +287,16 @@ var Cache = (function () { }; Cache.prototype.getCompiled = function (id, snapshot, transform) { var name = this.makeName(id, snapshot); + this.context.debug("transpiling '" + id + "'"); + this.context.debug(" cache: '" + this.codeCache.path(name) + "'"); if (!this.codeCache.exists(name) || this.isDirty(id, snapshot, false)) { - this.context.debug("fresh transpile for: " + id); + this.context.debug(" cache miss"); var data_1 = transform(); this.codeCache.write(name, data_1); this.markAsDirty(id, snapshot); return data_1; } - this.context.debug("old transpile for: " + id); + this.context.debug(" cache hit"); var data = this.codeCache.read(name); this.codeCache.write(name, data); return data; @@ -299,14 +309,16 @@ var Cache = (function () { }; Cache.prototype.getDiagnostics = function (cache, id, snapshot, check) { var name = this.makeName(id, snapshot); + this.context.debug("diagnostics for '" + id + "'"); + this.context.debug(" cache: '" + cache.path(name) + "'"); if (!cache.exists(name) || this.isDirty(id, snapshot, true)) { - this.context.debug("fresh diagnostics for: " + id); + this.context.debug(" cache miss"); var data_2 = convertDiagnostic(check()); cache.write(name, data_2); this.markAsDirty(id, snapshot); return data_2; } - this.context.debug("old diagnostics for: " + id); + this.context.debug(" cache hit"); var data = cache.read(name); cache.write(name, data); return data; @@ -318,7 +330,6 @@ var Cache = (function () { this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", false); }; Cache.prototype.markAsDirty = function (id, _snapshot) { - this.context.debug("changed: " + id); this.dependencyTree.setNode(id, { dirty: true }); }; // returns true if node or any of its imports or any of global types changed @@ -439,7 +450,7 @@ function typescript(options) { exclude: ["*.d.ts", "**/*.d.ts"], abortOnError: true, }); - var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); + var context = new ConsoleContext(options.verbosity, "rpt2: "); var filter$$1 = createFilter(options.include, options.exclude); var parsedConfig = parseTsConfig(context); var servicesHost = new LanguageServiceHost(parsedConfig); @@ -473,8 +484,7 @@ function typescript(options) { var _this = this; if (!filter$$1(id)) return undefined; - var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); - contextWrapper.debug(id); + var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rpt2: "); var snapshot = servicesHost.setSnapshot(id, code); // getting compiled file from cache of from ts var result = cache.getCompiled(id, snapshot, function () { @@ -484,7 +494,6 @@ function typescript(options) { var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { return services.getSyntacticDiagnostics(id); }); - contextWrapper.debug("printDiagnostics"); printDiagnostics(contextWrapper, diagnostics); } // if no output was generated, aborting compilation @@ -502,7 +511,6 @@ function typescript(options) { var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { return services.getSyntacticDiagnostics(id); }); - contextWrapper.debug("printDiagnostics"); printDiagnostics(contextWrapper, diagnostics); } return result; diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js index 7d5edc6..83ec141 100644 --- a/dist/rollup-plugin-typescript2.es.js +++ b/dist/rollup-plugin-typescript2.es.js @@ -172,6 +172,9 @@ var RollingCache = (function () { return true; return existsSync(this.oldCacheRoot + "/" + name); }; + RollingCache.prototype.path = function (name) { + return this.oldCacheRoot + "/" + name; + }; /** * @returns true if old cache contains all names and nothing more */ @@ -263,13 +266,18 @@ var Cache = (function () { }; Cache.prototype.setDependency = function (importee, importer) { // importee -> importer - this.context.debug(importee + " -> " + importer); + this.context.debug("" + importee); + this.context.debug(" imported by " + importer); this.dependencyTree.setEdge(importer, importee); }; Cache.prototype.compileDone = function () { var _this = this; - var typeNames = filter(this.ambientTypes, function (snaphot) { return snaphot.snapshot !== undefined; }) - .map(function (snaphot) { return _this.makeName(snaphot.id, snaphot.snapshot); }); + this.context.debug("Ambient types:"); + var typeNames = filter(this.ambientTypes, function (snapshot) { return snapshot.snapshot !== undefined; }) + .map(function (snapshot) { + _this.context.debug(" " + snapshot.id); + return _this.makeName(snapshot.id, snapshot.snapshot); + }); // types dirty if any d.ts changed, added or removed this.ambientTypesDirty = !this.typesCache.match(typeNames); if (this.ambientTypesDirty) @@ -284,14 +292,16 @@ var Cache = (function () { }; Cache.prototype.getCompiled = function (id, snapshot, transform) { var name = this.makeName(id, snapshot); + this.context.debug("transpiling '" + id + "'"); + this.context.debug(" cache: '" + this.codeCache.path(name) + "'"); if (!this.codeCache.exists(name) || this.isDirty(id, snapshot, false)) { - this.context.debug("fresh transpile for: " + id); + this.context.debug(" cache miss"); var data_1 = transform(); this.codeCache.write(name, data_1); this.markAsDirty(id, snapshot); return data_1; } - this.context.debug("old transpile for: " + id); + this.context.debug(" cache hit"); var data = this.codeCache.read(name); this.codeCache.write(name, data); return data; @@ -304,14 +314,16 @@ var Cache = (function () { }; Cache.prototype.getDiagnostics = function (cache, id, snapshot, check) { var name = this.makeName(id, snapshot); + this.context.debug("diagnostics for '" + id + "'"); + this.context.debug(" cache: '" + cache.path(name) + "'"); if (!cache.exists(name) || this.isDirty(id, snapshot, true)) { - this.context.debug("fresh diagnostics for: " + id); + this.context.debug(" cache miss"); var data_2 = convertDiagnostic(check()); cache.write(name, data_2); this.markAsDirty(id, snapshot); return data_2; } - this.context.debug("old diagnostics for: " + id); + this.context.debug(" cache hit"); var data = cache.read(name); cache.write(name, data); return data; @@ -323,7 +335,6 @@ var Cache = (function () { this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", false); }; Cache.prototype.markAsDirty = function (id, _snapshot) { - this.context.debug("changed: " + id); this.dependencyTree.setNode(id, { dirty: true }); }; // returns true if node or any of its imports or any of global types changed @@ -444,7 +455,7 @@ function typescript(options) { exclude: ["*.d.ts", "**/*.d.ts"], abortOnError: true, }); - var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); + var context = new ConsoleContext(options.verbosity, "rpt2: "); var filter$$1 = createFilter(options.include, options.exclude); var parsedConfig = parseTsConfig(context); var servicesHost = new LanguageServiceHost(parsedConfig); @@ -478,8 +489,7 @@ function typescript(options) { var _this = this; if (!filter$$1(id)) return undefined; - var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); - contextWrapper.debug(id); + var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rpt2: "); var snapshot = servicesHost.setSnapshot(id, code); // getting compiled file from cache of from ts var result = cache.getCompiled(id, snapshot, function () { @@ -489,7 +499,6 @@ function typescript(options) { var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { return services.getSyntacticDiagnostics(id); }); - contextWrapper.debug("printDiagnostics"); printDiagnostics(contextWrapper, diagnostics); } // if no output was generated, aborting compilation @@ -507,7 +516,6 @@ function typescript(options) { var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { return services.getSyntacticDiagnostics(id); }); - contextWrapper.debug("printDiagnostics"); printDiagnostics(contextWrapper, diagnostics); } return result; diff --git a/src/cache.ts b/src/cache.ts index d852969..9a2a805 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -34,7 +34,7 @@ export function convertDiagnostic(data: ts.Diagnostic[]): IDiagnostics[] { return _.map(data, (diagnostic) => { - let entry: IDiagnostics = + const entry: IDiagnostics = { flatMessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), category: diagnostic.category, @@ -42,7 +42,7 @@ export function convertDiagnostic(data: ts.Diagnostic[]): IDiagnostics[] if (diagnostic.file) { - let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); entry.fileLine = `${diagnostic.file.fileName} (${line + 1},${character + 1})`; } @@ -107,15 +107,21 @@ export class Cache public setDependency(importee: string, importer: string): void { // importee -> importer - this.context.debug(`${importee} -> ${importer}`); + this.context.debug(`${importee}`); + this.context.debug(` imported by ${importer}`); this.dependencyTree.setEdge(importer, importee); } public compileDone(): void { - let typeNames = _ - .filter(this.ambientTypes, (snaphot) => snaphot.snapshot !== undefined) - .map((snaphot) => this.makeName(snaphot.id, snaphot.snapshot!)); + this.context.debug("Ambient types:"); + const typeNames = _ + .filter(this.ambientTypes, (snapshot) => snapshot.snapshot !== undefined) + .map((snapshot) => + { + this.context.debug(` ${snapshot.id}`); + return this.makeName(snapshot.id, snapshot.snapshot!); + }); // types dirty if any d.ts changed, added or removed this.ambientTypesDirty = !this.typesCache.match(typeNames); @@ -136,21 +142,24 @@ export class Cache public getCompiled(id: string, snapshot: ts.IScriptSnapshot, transform: () => ICode | undefined): ICode | undefined { - let name = this.makeName(id, snapshot); + const name = this.makeName(id, snapshot); + + this.context.debug(`transpiling '${id}'`); + this.context.debug(` cache: '${this.codeCache.path(name)}'`); if (!this.codeCache.exists(name) || this.isDirty(id, snapshot, false)) { - this.context.debug(`fresh transpile for: ${id}`); + this.context.debug(` cache miss`); - let data = transform(); + const data = transform(); this.codeCache.write(name, data); this.markAsDirty(id, snapshot); return data; } - this.context.debug(`old transpile for: ${id}`); + this.context.debug(` cache hit`); - let data = this.codeCache.read(name); + const data = this.codeCache.read(name); this.codeCache.write(name, data); return data; } @@ -167,21 +176,24 @@ export class Cache private getDiagnostics(cache: RollingCache, id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[] { - let name = this.makeName(id, snapshot); + const name = this.makeName(id, snapshot); + + this.context.debug(`diagnostics for '${id}'`); + this.context.debug(` cache: '${cache.path(name)}'`); if (!cache.exists(name) || this.isDirty(id, snapshot, true)) { - this.context.debug(`fresh diagnostics for: ${id}`); + this.context.debug(` cache miss`); - let data = convertDiagnostic(check()); + const data = convertDiagnostic(check()); cache.write(name, data); this.markAsDirty(id, snapshot); return data; } - this.context.debug(`old diagnostics for: ${id}`); + this.context.debug(` cache hit`); - let data = cache.read(name); + const data = cache.read(name); cache.write(name, data); return data; } @@ -196,14 +208,13 @@ export class Cache private markAsDirty(id: string, _snapshot: ts.IScriptSnapshot): void { - this.context.debug(`changed: ${id}`); this.dependencyTree.setNode(id, { dirty: true }); } // returns true if node or any of its imports or any of global types changed private isDirty(id: string, _snapshot: ts.IScriptSnapshot, checkImports: boolean): boolean { - let label = this.dependencyTree.node(id) as INodeLabel; + const label = this.dependencyTree.node(id) as INodeLabel; if (!label) return false; @@ -214,15 +225,15 @@ export class Cache if (this.ambientTypesDirty) return true; - let dependencies = graph.alg.dijkstra(this.dependencyTree, id); + const dependencies = graph.alg.dijkstra(this.dependencyTree, id); return _.some(dependencies, (dependency, node) => { if (!node || dependency.distance === Infinity) return false; - let l = this.dependencyTree.node(node) as INodeLabel | undefined; - let dirty = l === undefined ? true : l.dirty; + const l = this.dependencyTree.node(node) as INodeLabel | undefined; + const dirty = l === undefined ? true : l.dirty; if (dirty) this.context.debug(`import changed: ${id} -> ${node}`); @@ -233,7 +244,7 @@ export class Cache private makeName(id: string, snapshot: ts.IScriptSnapshot) { - let data = snapshot.getText(0, snapshot.getLength()); + const data = snapshot.getText(0, snapshot.getLength()); return hash.sha1({ data, id }); } } diff --git a/src/index.ts b/src/index.ts index 9d6d5aa..91e69a1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -136,7 +136,7 @@ export default function typescript (options: IOptions) abortOnError: true, }); - const context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); + const context = new ConsoleContext(options.verbosity, "rpt2: "); const filter = createFilter(options.include, options.exclude); @@ -163,7 +163,7 @@ export default function typescript (options: IOptions) importer = importer.split("\\").join("/"); - let result = ts.nodeModuleNameResolver(importee, importer, parsedConfig.options, ts.sys); + const result = ts.nodeModuleNameResolver(importee, importer, parsedConfig.options, ts.sys); if (result.resolvedModule && result.resolvedModule.resolvedFileName) { @@ -192,9 +192,7 @@ export default function typescript (options: IOptions) if (!filter(id)) return undefined; - const contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); - - contextWrapper.debug(id); + const contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rpt2: "); const snapshot = servicesHost.setSnapshot(id, code); diff --git a/src/rollingcache.ts b/src/rollingcache.ts index aab4340..43214b9 100644 --- a/src/rollingcache.ts +++ b/src/rollingcache.ts @@ -33,6 +33,11 @@ export class RollingCache return fs.existsSync(`${this.oldCacheRoot}/${name}`); } + public path(name: string): string + { + return `${this.oldCacheRoot}/${name}`; + } + /** * @returns true if old cache contains all names and nothing more */ diff --git a/tsconfig.json b/tsconfig.json index 0d1de9d..31583e0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,9 @@ "pretty": true, "moduleResolution": "node", "noEmitOnError": true, - "strictNullChecks": true + "strictNullChecks": true, + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true }, "include": [ "src/**/*.ts"