rollup-plugin-typescript2
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -74,2 +74,36 @@ /* eslint-disable */ | ||
var RollupContext = (function () { | ||
function RollupContext(verbosity, bail, context, prefix) { | ||
if (prefix === void 0) { prefix = ""; } | ||
this.verbosity = verbosity; | ||
this.bail = bail; | ||
this.context = context; | ||
this.prefix = prefix; | ||
} | ||
RollupContext.prototype.warn = function (message) { | ||
if (this.verbosity < VerbosityLevel.Warning) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.error = function (message) { | ||
if (this.verbosity < VerbosityLevel.Error) | ||
return; | ||
if (this.bail) | ||
this.context.error("" + this.prefix + message); | ||
else | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.info = function (message) { | ||
if (this.verbosity < VerbosityLevel.Info) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.debug = function (message) { | ||
if (this.verbosity < VerbosityLevel.Debug) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
return RollupContext; | ||
}()); | ||
var LanguageServiceHost = (function () { | ||
@@ -179,2 +213,15 @@ function LanguageServiceHost(parsedConfig) { | ||
function convertDiagnostic(data) { | ||
return _.map(data, function (diagnostic) { | ||
var entry = { | ||
flatMessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
category: diagnostic.category, | ||
}; | ||
if (diagnostic.file) { | ||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; | ||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")"; | ||
} | ||
return entry; | ||
}); | ||
} | ||
var Cache = (function () { | ||
@@ -186,5 +233,10 @@ function Cache(host, cache, options, rootFilenames, context) { | ||
this.context = context; | ||
this.cacheVersion = "1"; | ||
this.cacheVersion = "2"; | ||
this.ambientTypesDirty = false; | ||
this.cacheDir = cache + "/" + hash.sha1({ version: this.cacheVersion, rootFilenames: rootFilenames, options: this.options }); | ||
this.cacheDir = cache + "/" + hash.sha1({ | ||
version: this.cacheVersion, | ||
rootFilenames: rootFilenames, | ||
options: this.options, | ||
tsVersion: ts.version, | ||
}); | ||
this.dependencyTree = new graph.Graph({ directed: true }); | ||
@@ -227,3 +279,4 @@ this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; }); | ||
this.codeCache.roll(); | ||
this.diagnosticsCache.roll(); | ||
this.semanticDiagnosticsCache.roll(); | ||
this.syntacticDiagnosticsCache.roll(); | ||
this.typesCache.roll(); | ||
@@ -245,8 +298,14 @@ }; | ||
}; | ||
Cache.prototype.getDiagnostics = function (id, snapshot, check) { | ||
Cache.prototype.getSyntacticDiagnostics = function (id, snapshot, check) { | ||
return this.getDiagnostics(this.syntacticDiagnosticsCache, id, snapshot, check); | ||
}; | ||
Cache.prototype.getSemanticDiagnostics = function (id, snapshot, check) { | ||
return this.getDiagnostics(this.semanticDiagnosticsCache, id, snapshot, check); | ||
}; | ||
Cache.prototype.getDiagnostics = function (cache, id, snapshot, check) { | ||
var name = this.makeName(id, snapshot); | ||
if (!this.diagnosticsCache.exists(name) || this.isDirty(id, snapshot, true)) { | ||
if (!cache.exists(name) || this.isDirty(id, snapshot, true)) { | ||
this.context.debug("fresh diagnostics for: " + id); | ||
var data_2 = this.convert(check()); | ||
this.diagnosticsCache.write(name, data_2); | ||
var data_2 = convertDiagnostic(check()); | ||
cache.write(name, data_2); | ||
this.markAsDirty(id, snapshot); | ||
@@ -256,4 +315,4 @@ return data_2; | ||
this.context.debug("old diagnostics for: " + id); | ||
var data = this.diagnosticsCache.read(name); | ||
this.diagnosticsCache.write(name, data); | ||
var data = cache.read(name); | ||
cache.write(name, data); | ||
return data; | ||
@@ -264,3 +323,4 @@ }; | ||
this.typesCache = new RollingCache(this.cacheDir + "/types", false); | ||
this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); | ||
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", false); | ||
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", false); | ||
}; | ||
@@ -296,14 +356,2 @@ Cache.prototype.markAsDirty = function (id, _snapshot) { | ||
}; | ||
Cache.prototype.convert = function (data) { | ||
return _.map(data, function (diagnostic) { | ||
var entry = { | ||
flatMessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
}; | ||
if (diagnostic.file) { | ||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; | ||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")"; | ||
} | ||
return entry; | ||
}); | ||
}; | ||
return Cache; | ||
@@ -363,6 +411,23 @@ }()); | ||
_.each(diagnostics, function (diagnostic) { | ||
var print; | ||
var color; | ||
switch (diagnostic.category) { | ||
case ts.DiagnosticCategory.Message: | ||
print = context.info; | ||
color = colors.white; | ||
break; | ||
case ts.DiagnosticCategory.Error: | ||
print = context.error; | ||
color = colors.red; | ||
break; | ||
case ts.DiagnosticCategory.Warning: | ||
default: | ||
print = context.warn; | ||
color = colors.yellow; | ||
break; | ||
} | ||
if (diagnostic.fileLine) | ||
context.warn(diagnostic.fileLine + ": " + colors.yellow(diagnostic.flatMessage)); | ||
print.call(context, [diagnostic.fileLine + ": " + color(diagnostic.flatMessage)]); | ||
else | ||
context.warn(colors.yellow(diagnostic.flatMessage)); | ||
print.call(context, [color(diagnostic.flatMessage)]); | ||
}); | ||
@@ -380,2 +445,3 @@ } | ||
exclude: ["*.d.ts", "**/*.d.ts"], | ||
abortOnError: true, | ||
}); | ||
@@ -416,13 +482,17 @@ var filter$$1 = createFilter(options.include, options.exclude); | ||
return undefined; | ||
var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); | ||
contextWrapper.debug(id); | ||
var snapshot = servicesHost.setSnapshot(id, code); | ||
// getting compiled file from cache of from ts | ||
var result = cache.getCompiled(id, snapshot, function () { | ||
var output = services.getEmitOutput(id); | ||
if (output.emitSkipped) { | ||
var diagnostics = cache.getDiagnostics(id, snapshot, function () { | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
}); | ||
printDiagnostics(_this, diagnostics); | ||
if (options.check) { | ||
var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
// if no output was generated, aborting compilation | ||
_this.error(colors.red("failed to transpile " + id)); | ||
@@ -437,7 +507,22 @@ } | ||
}); | ||
// printing syntactic errors | ||
if (options.check) { | ||
var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
return result; | ||
}, | ||
intro: function () { | ||
context.debug("intro"); | ||
// printing compiler option errors | ||
if (options.check) | ||
printDiagnostics(context, convertDiagnostic(services.getCompilerOptionsDiagnostics())); | ||
}, | ||
outro: function () { | ||
context.debug("outro"); | ||
cache.compileDone(); | ||
// printing semantic errors | ||
if (options.check) { | ||
@@ -450,7 +535,4 @@ cache.walkTree(function (id) { | ||
} | ||
var diagnostics = cache.getDiagnostics(id, snapshot, function () { | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
var diagnostics = cache.getSemanticDiagnostics(id, snapshot, function () { | ||
return services.getSemanticDiagnostics(id); | ||
}); | ||
@@ -457,0 +539,0 @@ printDiagnostics(context, diagnostics); |
/* eslint-disable */ | ||
import { emptyDirSync, ensureFile, ensureFileSync, existsSync, move, readFileSync, readJsonSync, readdirSync, remove, writeJson, writeJsonSync } from 'fs-extra'; | ||
import * as fs from 'fs-extra'; | ||
import { ModuleKind, ScriptSnapshot, createDocumentRegistry, createLanguageService, flattenDiagnosticMessageText, getDefaultLibFilePath, nodeModuleNameResolver, parseConfigFileTextToJson, parseJsonConfigFileContent, sys } from 'typescript'; | ||
import { DiagnosticCategory, ModuleKind, ScriptSnapshot, createDocumentRegistry, createLanguageService, flattenDiagnosticMessageText, getDefaultLibFilePath, nodeModuleNameResolver, parseConfigFileTextToJson, parseJsonConfigFileContent, sys, version } from 'typescript'; | ||
import * as ts from 'typescript'; | ||
@@ -14,3 +14,3 @@ import { defaults, each, endsWith, filter, find, has, isEqual, map, some } from 'lodash'; | ||
import * as path from 'path'; | ||
import { red, yellow } from 'colors/safe'; | ||
import { red, white, yellow } from 'colors/safe'; | ||
import * as colors from 'colors/safe'; | ||
@@ -80,2 +80,36 @@ | ||
var RollupContext = (function () { | ||
function RollupContext(verbosity, bail, context, prefix) { | ||
if (prefix === void 0) { prefix = ""; } | ||
this.verbosity = verbosity; | ||
this.bail = bail; | ||
this.context = context; | ||
this.prefix = prefix; | ||
} | ||
RollupContext.prototype.warn = function (message) { | ||
if (this.verbosity < VerbosityLevel.Warning) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.error = function (message) { | ||
if (this.verbosity < VerbosityLevel.Error) | ||
return; | ||
if (this.bail) | ||
this.context.error("" + this.prefix + message); | ||
else | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.info = function (message) { | ||
if (this.verbosity < VerbosityLevel.Info) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
RollupContext.prototype.debug = function (message) { | ||
if (this.verbosity < VerbosityLevel.Debug) | ||
return; | ||
this.context.warn("" + this.prefix + message); | ||
}; | ||
return RollupContext; | ||
}()); | ||
var LanguageServiceHost = (function () { | ||
@@ -185,2 +219,15 @@ function LanguageServiceHost(parsedConfig) { | ||
function convertDiagnostic(data) { | ||
return map(data, function (diagnostic) { | ||
var entry = { | ||
flatMessage: flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
category: diagnostic.category, | ||
}; | ||
if (diagnostic.file) { | ||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; | ||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")"; | ||
} | ||
return entry; | ||
}); | ||
} | ||
var Cache = (function () { | ||
@@ -192,5 +239,10 @@ function Cache(host, cache, options, rootFilenames, context) { | ||
this.context = context; | ||
this.cacheVersion = "1"; | ||
this.cacheVersion = "2"; | ||
this.ambientTypesDirty = false; | ||
this.cacheDir = cache + "/" + sha1({ version: this.cacheVersion, rootFilenames: rootFilenames, options: this.options }); | ||
this.cacheDir = cache + "/" + sha1({ | ||
version: this.cacheVersion, | ||
rootFilenames: rootFilenames, | ||
options: this.options, | ||
tsVersion: version, | ||
}); | ||
this.dependencyTree = new Graph({ directed: true }); | ||
@@ -233,3 +285,4 @@ this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; }); | ||
this.codeCache.roll(); | ||
this.diagnosticsCache.roll(); | ||
this.semanticDiagnosticsCache.roll(); | ||
this.syntacticDiagnosticsCache.roll(); | ||
this.typesCache.roll(); | ||
@@ -251,8 +304,14 @@ }; | ||
}; | ||
Cache.prototype.getDiagnostics = function (id, snapshot, check) { | ||
Cache.prototype.getSyntacticDiagnostics = function (id, snapshot, check) { | ||
return this.getDiagnostics(this.syntacticDiagnosticsCache, id, snapshot, check); | ||
}; | ||
Cache.prototype.getSemanticDiagnostics = function (id, snapshot, check) { | ||
return this.getDiagnostics(this.semanticDiagnosticsCache, id, snapshot, check); | ||
}; | ||
Cache.prototype.getDiagnostics = function (cache, id, snapshot, check) { | ||
var name = this.makeName(id, snapshot); | ||
if (!this.diagnosticsCache.exists(name) || this.isDirty(id, snapshot, true)) { | ||
if (!cache.exists(name) || this.isDirty(id, snapshot, true)) { | ||
this.context.debug("fresh diagnostics for: " + id); | ||
var data_2 = this.convert(check()); | ||
this.diagnosticsCache.write(name, data_2); | ||
var data_2 = convertDiagnostic(check()); | ||
cache.write(name, data_2); | ||
this.markAsDirty(id, snapshot); | ||
@@ -262,4 +321,4 @@ return data_2; | ||
this.context.debug("old diagnostics for: " + id); | ||
var data = this.diagnosticsCache.read(name); | ||
this.diagnosticsCache.write(name, data); | ||
var data = cache.read(name); | ||
cache.write(name, data); | ||
return data; | ||
@@ -270,3 +329,4 @@ }; | ||
this.typesCache = new RollingCache(this.cacheDir + "/types", false); | ||
this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); | ||
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", false); | ||
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", false); | ||
}; | ||
@@ -302,14 +362,2 @@ Cache.prototype.markAsDirty = function (id, _snapshot) { | ||
}; | ||
Cache.prototype.convert = function (data) { | ||
return map(data, function (diagnostic) { | ||
var entry = { | ||
flatMessage: flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
}; | ||
if (diagnostic.file) { | ||
var _a = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start), line = _a.line, character = _a.character; | ||
entry.fileLine = diagnostic.file.fileName + " (" + (line + 1) + "," + (character + 1) + ")"; | ||
} | ||
return entry; | ||
}); | ||
}; | ||
return Cache; | ||
@@ -369,6 +417,23 @@ }()); | ||
each(diagnostics, function (diagnostic) { | ||
var print; | ||
var color; | ||
switch (diagnostic.category) { | ||
case DiagnosticCategory.Message: | ||
print = context.info; | ||
color = white; | ||
break; | ||
case DiagnosticCategory.Error: | ||
print = context.error; | ||
color = red; | ||
break; | ||
case DiagnosticCategory.Warning: | ||
default: | ||
print = context.warn; | ||
color = yellow; | ||
break; | ||
} | ||
if (diagnostic.fileLine) | ||
context.warn(diagnostic.fileLine + ": " + yellow(diagnostic.flatMessage)); | ||
print.call(context, [diagnostic.fileLine + ": " + color(diagnostic.flatMessage)]); | ||
else | ||
context.warn(yellow(diagnostic.flatMessage)); | ||
print.call(context, [color(diagnostic.flatMessage)]); | ||
}); | ||
@@ -386,2 +451,3 @@ } | ||
exclude: ["*.d.ts", "**/*.d.ts"], | ||
abortOnError: true, | ||
}); | ||
@@ -422,13 +488,17 @@ var filter$$1 = createFilter(options.include, options.exclude); | ||
return undefined; | ||
var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); | ||
contextWrapper.debug(id); | ||
var snapshot = servicesHost.setSnapshot(id, code); | ||
// getting compiled file from cache of from ts | ||
var result = cache.getCompiled(id, snapshot, function () { | ||
var output = services.getEmitOutput(id); | ||
if (output.emitSkipped) { | ||
var diagnostics = cache.getDiagnostics(id, snapshot, function () { | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
}); | ||
printDiagnostics(_this, diagnostics); | ||
if (options.check) { | ||
var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
// if no output was generated, aborting compilation | ||
_this.error(red("failed to transpile " + id)); | ||
@@ -443,7 +513,22 @@ } | ||
}); | ||
// printing syntactic errors | ||
if (options.check) { | ||
var diagnostics = cache.getSyntacticDiagnostics(id, snapshot, function () { | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
return result; | ||
}, | ||
intro: function () { | ||
context.debug("intro"); | ||
// printing compiler option errors | ||
if (options.check) | ||
printDiagnostics(context, convertDiagnostic(services.getCompilerOptionsDiagnostics())); | ||
}, | ||
outro: function () { | ||
context.debug("outro"); | ||
cache.compileDone(); | ||
// printing semantic errors | ||
if (options.check) { | ||
@@ -456,7 +541,4 @@ cache.walkTree(function (id) { | ||
} | ||
var diagnostics = cache.getDiagnostics(id, snapshot, function () { | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
var diagnostics = cache.getSemanticDiagnostics(id, snapshot, function () { | ||
return services.getSemanticDiagnostics(id); | ||
}); | ||
@@ -463,0 +545,0 @@ printDiagnostics(context, diagnostics); |
{ | ||
"name": "rollup-plugin-typescript2", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "Seamless integration between Rollup and TypeScript. Now with errors.", | ||
@@ -32,3 +32,3 @@ "main": "dist/rollup-plugin-typescript2.cjs.js", | ||
"rollup-pluginutils": "^2.0.1", | ||
"tslib": "^1.5.0" | ||
"tslib": "^1.6.0" | ||
}, | ||
@@ -40,3 +40,3 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"rollup-plugin-typescript2": "^0.1.0", | ||
"rollup-plugin-typescript2": "^0.1.2", | ||
"@types/colors": "^1.1.1", | ||
@@ -50,4 +50,4 @@ "@types/fs-extra": "0.0.37", | ||
"rollup": "^0.41.4", | ||
"tslint": "^4.4.2", | ||
"typescript": "^2.1.5" | ||
"tslint": "^4.5.1", | ||
"typescript": "^2.2.1" | ||
}, | ||
@@ -54,0 +54,0 @@ "repository": { |
@@ -36,16 +36,33 @@ # rollup-plugin-typescript2 | ||
Plugin takes following options: | ||
* `check`: true | ||
- set to false to avoid doing any diagnostic checks on the code | ||
Set to false to avoid doing any diagnostic checks on the code. | ||
* `verbosity`: 2 | ||
- goes up to 3 | ||
Goes up to 3. | ||
* `clean`: false | ||
- set to true for clean build (wipes out cache) | ||
Set to true for clean build (wipes out cache on every build). | ||
* `cacheRoot`: ".rts2_cache" | ||
- path to cache | ||
Path to cache. | ||
* `include`: `[ "*.ts+(|x)", "**/*.ts+(|x)" ]` | ||
- passes all .ts files through typescript compiler. | ||
Passes all .ts files through typescript compiler. | ||
* `exclude`: `[ "*.d.ts", "**/*.d.ts" ]` | ||
- but not types | ||
But excludes types. | ||
* `abortOnError`: true | ||
Bail out on first syntactic error. Im most cases setting this to false will result in exception in rollup itself. | ||
### TypeScript version | ||
This plugin currently requires TypeScript 2.0+. |
@@ -24,2 +24,3 @@ import { IContext } from "./context"; | ||
fileLine?: string; | ||
category: ts.DiagnosticCategory; | ||
} | ||
@@ -33,5 +34,25 @@ | ||
export function convertDiagnostic(data: ts.Diagnostic[]): IDiagnostics[] | ||
{ | ||
return _.map(data, (diagnostic) => | ||
{ | ||
let entry: IDiagnostics = | ||
{ | ||
flatMessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
category: diagnostic.category, | ||
}; | ||
if (diagnostic.file) | ||
{ | ||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); | ||
entry.fileLine = `${diagnostic.file.fileName} (${line + 1},${character + 1})`; | ||
} | ||
return entry; | ||
}); | ||
} | ||
export class Cache | ||
{ | ||
private cacheVersion = "1"; | ||
private cacheVersion = "2"; | ||
private dependencyTree: graph.Graph; | ||
@@ -43,7 +64,13 @@ private ambientTypes: ITypeSnapshot[]; | ||
private typesCache: RollingCache<string>; | ||
private diagnosticsCache: RollingCache<IDiagnostics[]>; | ||
private semanticDiagnosticsCache: RollingCache<IDiagnostics[]>; | ||
private syntacticDiagnosticsCache: RollingCache<IDiagnostics[]>; | ||
constructor(private host: ts.LanguageServiceHost, cache: string, private options: ts.CompilerOptions, rootFilenames: string[], private context: IContext) | ||
{ | ||
this.cacheDir = `${cache}/${hash.sha1({ version: this.cacheVersion, rootFilenames, options: this.options })}`; | ||
this.cacheDir = `${cache}/${hash.sha1({ | ||
version: this.cacheVersion, | ||
rootFilenames, | ||
options: this.options, | ||
tsVersion : ts.version, | ||
})}`; | ||
@@ -108,3 +135,4 @@ this.dependencyTree = new graph.Graph({ directed: true }); | ||
this.codeCache.roll(); | ||
this.diagnosticsCache.roll(); | ||
this.semanticDiagnosticsCache.roll(); | ||
this.syntacticDiagnosticsCache.roll(); | ||
this.typesCache.roll(); | ||
@@ -134,12 +162,22 @@ } | ||
public getDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[] | ||
public getSyntacticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[] | ||
{ | ||
return this.getDiagnostics(this.syntacticDiagnosticsCache, id, snapshot, check); | ||
} | ||
public getSemanticDiagnostics(id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[] | ||
{ | ||
return this.getDiagnostics(this.semanticDiagnosticsCache, id, snapshot, check); | ||
} | ||
private getDiagnostics(cache: RollingCache<IDiagnostics[]>, id: string, snapshot: ts.IScriptSnapshot, check: () => ts.Diagnostic[]): IDiagnostics[] | ||
{ | ||
let name = this.makeName(id, snapshot); | ||
if (!this.diagnosticsCache.exists(name) || this.isDirty(id, snapshot, true)) | ||
if (!cache.exists(name) || this.isDirty(id, snapshot, true)) | ||
{ | ||
this.context.debug(`fresh diagnostics for: ${id}`); | ||
let data = this.convert(check()); | ||
this.diagnosticsCache.write(name, data); | ||
let data = convertDiagnostic(check()); | ||
cache.write(name, data); | ||
this.markAsDirty(id, snapshot); | ||
@@ -151,4 +189,4 @@ return data; | ||
let data = this.diagnosticsCache.read(name); | ||
this.diagnosticsCache.write(name, data); | ||
let data = cache.read(name); | ||
cache.write(name, data); | ||
return data; | ||
@@ -161,3 +199,4 @@ } | ||
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, false); | ||
this.diagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/diagnostics`, false); | ||
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, false); | ||
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, false); | ||
} | ||
@@ -207,21 +246,2 @@ | ||
} | ||
private convert(data: ts.Diagnostic[]): IDiagnostics[] | ||
{ | ||
return _.map(data, (diagnostic) => | ||
{ | ||
let entry: IDiagnostics = | ||
{ | ||
flatMessage: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), | ||
}; | ||
if (diagnostic.file) | ||
{ | ||
let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); | ||
entry.fileLine = `${diagnostic.file.fileName} (${line + 1},${character + 1})`; | ||
} | ||
return entry; | ||
}); | ||
} | ||
} |
@@ -0,4 +1,5 @@ | ||
import { RollupContext } from "./rollupcontext"; | ||
import { IContext, ConsoleContext, IRollupContext, VerbosityLevel } from "./context"; | ||
import { LanguageServiceHost } from "./host"; | ||
import { Cache, ICode, IDiagnostics } from "./cache"; | ||
import { Cache, convertDiagnostic, ICode, IDiagnostics } from "./cache"; | ||
import * as ts from "typescript"; | ||
@@ -75,10 +76,29 @@ import * as fs from "fs-extra"; | ||
function printDiagnostics(context: IContext | IRollupContext, diagnostics: IDiagnostics[]) | ||
function printDiagnostics(context: IContext, diagnostics: IDiagnostics[]) | ||
{ | ||
_.each(diagnostics, (diagnostic) => | ||
{ | ||
let print; | ||
let color; | ||
switch (diagnostic.category) | ||
{ | ||
case ts.DiagnosticCategory.Message: | ||
print = context.info; | ||
color = colors.white; | ||
break; | ||
case ts.DiagnosticCategory.Error: | ||
print = context.error; | ||
color = colors.red; | ||
break; | ||
case ts.DiagnosticCategory.Warning: | ||
default: | ||
print = context.warn; | ||
color = colors.yellow; | ||
break; | ||
} | ||
if (diagnostic.fileLine) | ||
context.warn(`${diagnostic.fileLine}: ${colors.yellow(diagnostic.flatMessage)}`); | ||
print.call(context, [`${diagnostic.fileLine}: ${color(diagnostic.flatMessage)}`]); | ||
else | ||
context.warn(colors.yellow(diagnostic.flatMessage)); | ||
print.call(context, [color(diagnostic.flatMessage)]); | ||
}); | ||
@@ -95,2 +115,3 @@ }; | ||
cacheRoot: string; | ||
abortOnError: boolean; | ||
} | ||
@@ -110,2 +131,3 @@ | ||
exclude: [ "*.d.ts", "**/*.d.ts" ], | ||
abortOnError: true, | ||
}); | ||
@@ -115,3 +137,3 @@ | ||
let parsedConfig = parseTsConfig(); | ||
const parsedConfig = parseTsConfig(); | ||
@@ -170,4 +192,10 @@ const servicesHost = new LanguageServiceHost(parsedConfig); | ||
const contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rollup-plugin-typescript2: "); | ||
contextWrapper.debug(id); | ||
const snapshot = servicesHost.setSnapshot(id, code); | ||
let result = cache.getCompiled(id, snapshot, () => | ||
// getting compiled file from cache of from ts | ||
const result = cache.getCompiled(id, snapshot, () => | ||
{ | ||
@@ -178,15 +206,18 @@ const output = services.getEmitOutput(id); | ||
{ | ||
const diagnostics = cache.getDiagnostics(id, snapshot, () => | ||
if (options.check) | ||
{ | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
}); | ||
printDiagnostics(this, diagnostics); | ||
const diagnostics = cache.getSyntacticDiagnostics(id, snapshot, () => | ||
{ | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
// if no output was generated, aborting compilation | ||
this.error(colors.red(`failed to transpile ${id}`)); | ||
} | ||
const transpiled = _.find(output.outputFiles, (entry: ts.OutputFile) => _.endsWith(entry.name, ".js") ); | ||
const map = _.find(output.outputFiles, (entry: ts.OutputFile) => _.endsWith(entry.name, ".map") ); | ||
const transpiled = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".js") ); | ||
const map = _.find(output.outputFiles, (entry) => _.endsWith(entry.name, ".map") ); | ||
@@ -199,10 +230,32 @@ return { | ||
// printing syntactic errors | ||
if (options.check) | ||
{ | ||
const diagnostics = cache.getSyntacticDiagnostics(id, snapshot, () => | ||
{ | ||
return services.getSyntacticDiagnostics(id); | ||
}); | ||
contextWrapper.debug("printDiagnostics"); | ||
printDiagnostics(contextWrapper, diagnostics); | ||
} | ||
return result; | ||
}, | ||
intro(): void | ||
{ | ||
context.debug("intro"); | ||
// printing compiler option errors | ||
if (options.check) | ||
printDiagnostics(context, convertDiagnostic(services.getCompilerOptionsDiagnostics())); | ||
}, | ||
outro(): void | ||
{ | ||
context.debug("outro"); | ||
cache.compileDone(); | ||
// printing semantic errors | ||
if (options.check) | ||
@@ -220,8 +273,5 @@ { | ||
const diagnostics = cache.getDiagnostics(id, snapshot, () => | ||
const diagnostics = cache.getSemanticDiagnostics(id, snapshot, () => | ||
{ | ||
return services | ||
.getCompilerOptionsDiagnostics() | ||
.concat(services.getSyntacticDiagnostics(id)) | ||
.concat(services.getSemanticDiagnostics(id)); | ||
return services.getSemanticDiagnostics(id); | ||
}); | ||
@@ -228,0 +278,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67258
11
1664
68
Updatedtslib@^1.6.0