mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- readme, options
This commit is contained in:
parent
37fe6093b7
commit
e039c74695
26
README.md
26
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+.
|
||||
|
||||
14
dist/rollup-plugin-typescript2.cjs.js
vendored
14
dist/rollup-plugin-typescript2.cjs.js
vendored
@ -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();
|
||||
|
||||
14
dist/rollup-plugin-typescript2.es.js
vendored
14
dist/rollup-plugin-typescript2.es.js
vendored
@ -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();
|
||||
|
||||
15
src/cache.ts
15
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<ICode>(`${this.cacheDir}/code`, true);
|
||||
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, false);
|
||||
this.diagnosticsCache = new RollingCache<IDiagnostics[]>(`${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<ICode>(`${this.cacheDir}/code`, true);
|
||||
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, false);
|
||||
this.diagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/diagnostics`, false);
|
||||
}
|
||||
|
||||
private markAsDirty(id: string, _snapshot: ts.IScriptSnapshot): void
|
||||
{
|
||||
this.context.debug(`changed: ${id}`);
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user