From e039c7469518a9b05f692fa63b8be7b6906aad51 Mon Sep 17 00:00:00 2001 From: ezolenko Date: Fri, 10 Feb 2017 22:35:00 -0700 Subject: [PATCH] - readme, options --- README.md | 26 +++++++++++++++++++------- dist/rollup-plugin-typescript2.cjs.js | 14 +++++++++----- dist/rollup-plugin-typescript2.es.js | 14 +++++++++----- src/cache.ts | 15 +++++++++++---- src/index.ts | 6 +++--- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f6068db..94e607b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Rollup plugin for typescript with compiler errors. This is a rewrite of original rollup-plugin-typescript, starting and borrowing from [this fork](https://github.com/alexlur/rollup-plugin-typescript). -This version is significantly slower than original, but it will print out typescript errors and warnings. +This version is somewhat slower than original, but it will print out typescript syntactic and semantic diagnostic messages (the main reason for using typescript after all). ## Usage @@ -15,11 +15,11 @@ This version is significantly slower than original, but it will print out typesc import typescript from 'rollup-plugin-typescript'; export default { - entry: './main.ts', + entry: './main.ts', - plugins: [ - typescript() - ] + plugins: [ + typescript() + ] } ``` @@ -32,7 +32,19 @@ Following compiler options are forced though: * `importHelpers`: true * `noResolve`: false -Plugin itself takes standard include/exclude options (each a minimatch pattern, or array of minimatch patterns), which determine which files are transpiled by Typescript (all `.ts` and `.tsx` files by default) +Plugin takes following options: +* `check`: true + - set to false to avoid doing any diagnostic checks on the code +* `verbosity`: 2 + - goes up to 3 +* `clean`: false + - set to true for clean build (wipes out cache) +* `cacheRoot`: ".rts2_cache" + - path to cache +* `include`: `[ "*.ts+(|x)", "**/*.ts+(|x)" ]` + - passes all .ts files through typescript compiler. +* `exclude`: `[ "*.d.ts", "**/*.d.ts" ]` + - but not types ### TypeScript version -This plugin currently requires TypeScript > 2.0. +This plugin currently requires TypeScript 2.0+. diff --git a/dist/rollup-plugin-typescript2.cjs.js b/dist/rollup-plugin-typescript2.cjs.js index ba45c7d..b7e697c 100644 --- a/dist/rollup-plugin-typescript2.cjs.js +++ b/dist/rollup-plugin-typescript2.cjs.js @@ -171,17 +171,16 @@ var Cache = (function () { this.cacheVersion = "1"; this.ambientTypesDirty = false; this.cacheDir = cache + "/" + hash.sha1({ version: this.cacheVersion, rootFilenames: rootFilenames, options: this.options }); - this.codeCache = new RollingCache(this.cacheDir + "/code", true); - this.typesCache = new RollingCache(this.cacheDir + "/types", false); - this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); this.dependencyTree = new graph.Graph({ directed: true }); this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; }); this.ambientTypes = _.filter(rootFilenames, function (file) { return _.endsWith(file, ".d.ts"); }) .map(function (id) { return { id: id, snapshot: _this.host.getScriptSnapshot(id) }; }); + this.init(); } Cache.prototype.clean = function () { this.context.info("cleaning cache: " + this.cacheDir); fs.emptyDirSync(this.cacheDir); + this.init(); }; Cache.prototype.walkTree = function (cb) { var acyclic = graph.alg.isAcyclic(this.dependencyTree); @@ -240,6 +239,11 @@ var Cache = (function () { this.diagnosticsCache.write(name, data); return data; }; + Cache.prototype.init = function () { + this.codeCache = new RollingCache(this.cacheDir + "/code", true); + this.typesCache = new RollingCache(this.cacheDir + "/types", false); + this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); + }; Cache.prototype.markAsDirty = function (id, _snapshot) { this.context.debug("changed: " + id); this.dependencyTree.setNode(id, { dirty: true }); @@ -344,7 +348,7 @@ function typescript(options) { options = __assign({}, options); _.defaults(options, { check: true, - verbose: VerbosityLevel.Info, + verbosity: VerbosityLevel.Info, clean: false, cacheRoot: process.cwd() + "/.rts2_cache", include: ["*.ts+(|x)", "**/*.ts+(|x)"], @@ -354,7 +358,7 @@ function typescript(options) { var parsedConfig = parseTsConfig(); var servicesHost = new LanguageServiceHost(parsedConfig); var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); - var context = new ConsoleContext(options.verbose, ""); + var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); var cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context); if (options.clean) cache.clean(); diff --git a/dist/rollup-plugin-typescript2.es.js b/dist/rollup-plugin-typescript2.es.js index c482424..9d73f06 100644 --- a/dist/rollup-plugin-typescript2.es.js +++ b/dist/rollup-plugin-typescript2.es.js @@ -176,17 +176,16 @@ var Cache = (function () { this.cacheVersion = "1"; this.ambientTypesDirty = false; this.cacheDir = cache + "/" + sha1({ version: this.cacheVersion, rootFilenames: rootFilenames, options: this.options }); - this.codeCache = new RollingCache(this.cacheDir + "/code", true); - this.typesCache = new RollingCache(this.cacheDir + "/types", false); - this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); this.dependencyTree = new Graph({ directed: true }); this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; }); this.ambientTypes = filter(rootFilenames, function (file) { return endsWith(file, ".d.ts"); }) .map(function (id) { return { id: id, snapshot: _this.host.getScriptSnapshot(id) }; }); + this.init(); } Cache.prototype.clean = function () { this.context.info("cleaning cache: " + this.cacheDir); emptyDirSync(this.cacheDir); + this.init(); }; Cache.prototype.walkTree = function (cb) { var acyclic = alg.isAcyclic(this.dependencyTree); @@ -245,6 +244,11 @@ var Cache = (function () { this.diagnosticsCache.write(name, data); return data; }; + Cache.prototype.init = function () { + this.codeCache = new RollingCache(this.cacheDir + "/code", true); + this.typesCache = new RollingCache(this.cacheDir + "/types", false); + this.diagnosticsCache = new RollingCache(this.cacheDir + "/diagnostics", false); + }; Cache.prototype.markAsDirty = function (id, _snapshot) { this.context.debug("changed: " + id); this.dependencyTree.setNode(id, { dirty: true }); @@ -349,7 +353,7 @@ function typescript(options) { options = __assign({}, options); defaults(options, { check: true, - verbose: VerbosityLevel.Info, + verbosity: VerbosityLevel.Info, clean: false, cacheRoot: process.cwd() + "/.rts2_cache", include: ["*.ts+(|x)", "**/*.ts+(|x)"], @@ -359,7 +363,7 @@ function typescript(options) { var parsedConfig = parseTsConfig(); var servicesHost = new LanguageServiceHost(parsedConfig); var services = createLanguageService(servicesHost, createDocumentRegistry()); - var context = new ConsoleContext(options.verbose, ""); + var context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); var cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context); if (options.clean) cache.clean(); diff --git a/src/cache.ts b/src/cache.ts index 8da7928..5e00ba2 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -44,22 +44,22 @@ export class Cache { this.cacheDir = `${cache}/${hash.sha1({ version: this.cacheVersion, rootFilenames, options: this.options })}`; - this.codeCache = new RollingCache(`${this.cacheDir}/code`, true); - this.typesCache = new RollingCache(`${this.cacheDir}/types`, false); - this.diagnosticsCache = new RollingCache(`${this.cacheDir}/diagnostics`, false); - this.dependencyTree = new graph.Graph({ directed: true }); this.dependencyTree.setDefaultNodeLabel((_node: string) => { return { dirty: false }; }); this.ambientTypes = _ .filter(rootFilenames, (file) => _.endsWith(file, ".d.ts")) .map((id) => { return { id, snapshot: this.host.getScriptSnapshot(id) }; }); + + this.init(); } public clean() { this.context.info(`cleaning cache: ${this.cacheDir}`); fs.emptyDirSync(this.cacheDir); + + this.init(); } public walkTree(cb: (id: string) => void | false): void @@ -148,6 +148,13 @@ export class Cache return data; } + private init() + { + this.codeCache = new RollingCache(`${this.cacheDir}/code`, true); + this.typesCache = new RollingCache(`${this.cacheDir}/types`, false); + this.diagnosticsCache = new RollingCache(`${this.cacheDir}/diagnostics`, false); + } + private markAsDirty(id: string, _snapshot: ts.IScriptSnapshot): void { this.context.debug(`changed: ${id}`); diff --git a/src/index.ts b/src/index.ts index 1e824d5..e9bfa9c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -86,7 +86,7 @@ interface IOptions include: string; exclude: string; check: boolean; - verbose: number; + verbosity: number; clean: boolean; cacheRoot: string; } @@ -98,7 +98,7 @@ export default function typescript (options: IOptions) _.defaults(options, { check: true, - verbose: VerbosityLevel.Info, + verbosity: VerbosityLevel.Info, clean: false, cacheRoot: `${process.cwd()}/.rts2_cache`, include: [ "*.ts+(|x)", "**/*.ts+(|x)" ], @@ -113,7 +113,7 @@ export default function typescript (options: IOptions) const services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); - const context = new ConsoleContext(options.verbose, ""); + const context = new ConsoleContext(options.verbosity, "rollup-plugin-typescript2: "); const cache = new Cache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);