- "clean: true" will not create cache in the first place #68

This commit is contained in:
Eugene Zolenko 2018-03-29 18:24:49 -06:00
parent a3b71f0a18
commit f15cb84dcc
10 changed files with 170 additions and 30 deletions

10
dist/nocache.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
import { ICache } from "./icache";
export declare class NoCache<DataType> implements ICache<DataType> {
exists(_name: string): boolean;
path(name: string): string;
match(_names: string[]): boolean;
read(_name: string): DataType | null | undefined;
write(_name: string, _data: DataType): void;
touch(_name: string): void;
roll(): void;
}

View File

@ -19527,6 +19527,33 @@ var FormatHost = /** @class */ (function () {
}());
var formatHost = new FormatHost();
var NoCache = /** @class */ (function () {
function NoCache() {
}
NoCache.prototype.exists = function (_name) {
return false;
};
NoCache.prototype.path = function (name) {
return name;
};
NoCache.prototype.match = function (_names) {
return false;
};
NoCache.prototype.read = function (_name) {
return undefined;
};
NoCache.prototype.write = function (_name, _data) {
return;
};
NoCache.prototype.touch = function (_name) {
return;
};
NoCache.prototype.roll = function () {
return;
};
return NoCache;
}());
function convertDiagnostic(type, data) {
return lodash_7(data, function (diagnostic) {
var entry = {
@ -19544,8 +19571,9 @@ function convertDiagnostic(type, data) {
});
}
var TsCache = /** @class */ (function () {
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
function TsCache(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
var _this = this;
this.noCache = noCache;
this.host = host;
this.options = options;
this.rollupConfig = rollupConfig;
@ -19571,8 +19599,10 @@ var TsCache = /** @class */ (function () {
this.checkAmbientTypes();
}
TsCache.prototype.clean = function () {
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
fsExtra.emptyDirSync(this.cacheDir);
if (fsExtra.pathExistsSync(this.cacheDir)) {
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
fsExtra.emptyDirSync(this.cacheDir);
}
this.init();
};
TsCache.prototype.setDependency = function (importee, importer) {
@ -19657,10 +19687,18 @@ var TsCache = /** @class */ (function () {
return convertedData;
};
TsCache.prototype.init = function () {
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
if (this.noCache) {
this.codeCache = new NoCache();
this.typesCache = new NoCache();
this.syntacticDiagnosticsCache = new NoCache();
this.semanticDiagnosticsCache = new NoCache();
}
else {
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
}
};
TsCache.prototype.markAsDirty = function (id) {
this.dependencyTree.setNode(id, { dirty: true });
@ -19828,7 +19866,7 @@ function typescript(options) {
var _cache;
var cache = function () {
if (!_cache)
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};
var pluginOptions = __assign({}, options);

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
/* eslint-disable */
import { existsSync, readdirSync, renameSync, readFileSync } from 'fs';
import crypto from 'crypto';
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync } from 'fs-extra';
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync, pathExistsSync } from 'fs-extra';
import { dirname, isAbsolute, join, relative, normalize } from 'path';
import { sync } from 'resolve';
@ -19523,6 +19523,33 @@ var FormatHost = /** @class */ (function () {
}());
var formatHost = new FormatHost();
var NoCache = /** @class */ (function () {
function NoCache() {
}
NoCache.prototype.exists = function (_name) {
return false;
};
NoCache.prototype.path = function (name) {
return name;
};
NoCache.prototype.match = function (_names) {
return false;
};
NoCache.prototype.read = function (_name) {
return undefined;
};
NoCache.prototype.write = function (_name, _data) {
return;
};
NoCache.prototype.touch = function (_name) {
return;
};
NoCache.prototype.roll = function () {
return;
};
return NoCache;
}());
function convertDiagnostic(type, data) {
return lodash_7(data, function (diagnostic) {
var entry = {
@ -19540,8 +19567,9 @@ function convertDiagnostic(type, data) {
});
}
var TsCache = /** @class */ (function () {
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
function TsCache(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
var _this = this;
this.noCache = noCache;
this.host = host;
this.options = options;
this.rollupConfig = rollupConfig;
@ -19567,8 +19595,10 @@ var TsCache = /** @class */ (function () {
this.checkAmbientTypes();
}
TsCache.prototype.clean = function () {
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
emptyDirSync(this.cacheDir);
if (pathExistsSync(this.cacheDir)) {
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
emptyDirSync(this.cacheDir);
}
this.init();
};
TsCache.prototype.setDependency = function (importee, importer) {
@ -19653,10 +19683,18 @@ var TsCache = /** @class */ (function () {
return convertedData;
};
TsCache.prototype.init = function () {
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
if (this.noCache) {
this.codeCache = new NoCache();
this.typesCache = new NoCache();
this.syntacticDiagnosticsCache = new NoCache();
this.semanticDiagnosticsCache = new NoCache();
}
else {
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
}
};
TsCache.prototype.markAsDirty = function (id) {
this.dependencyTree.setNode(id, { dirty: true });
@ -19824,7 +19862,7 @@ function typescript(options) {
var _cache;
var cache = function () {
if (!_cache)
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};
var pluginOptions = __assign({}, options);

File diff suppressed because one or more lines are too long

3
dist/tscache.d.ts vendored
View File

@ -21,6 +21,7 @@ export interface IDiagnostics {
}
export declare function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDiagnostics[];
export declare class TsCache {
private noCache;
private host;
private options;
private rollupConfig;
@ -34,7 +35,7 @@ export declare class TsCache {
private typesCache;
private semanticDiagnosticsCache;
private syntacticDiagnosticsCache;
constructor(host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
constructor(noCache: boolean, host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
clean(): void;
setDependency(importee: string, importer: string): void;
walkTree(cb: (id: string) => void | false): void;

View File

@ -2,6 +2,6 @@ import ts from "./build-self/dist/rollup-plugin-typescript2.es";
import config from "./rollup.config.base";
config.plugins.push(ts({ verbosity: 2, abortOnError: false }));
config.plugins.push(ts({ verbosity: 2, abortOnError: false, clean: false }));
export default config;

View File

@ -36,7 +36,7 @@ export default function typescript(options?: Partial<IOptions>)
const cache = (): TsCache =>
{
if (!_cache)
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
return _cache;
};

39
src/nocache.ts Normal file
View File

@ -0,0 +1,39 @@
import { ICache } from "./icache";
export class NoCache<DataType> implements ICache<DataType>
{
public exists(_name: string): boolean
{
return false;
}
public path(name: string): string
{
return name;
}
public match(_names: string[]): boolean
{
return false;
}
public read(_name: string): DataType | null | undefined
{
return undefined;
}
public write(_name: string, _data: DataType): void
{
return;
}
public touch(_name: string)
{
return;
}
public roll()
{
return;
}
}

View File

@ -7,8 +7,9 @@ import * as _ from "lodash";
import { tsModule } from "./tsproxy";
import * as tsTypes from "typescript";
import { blue, yellow, green } from "colors/safe";
import { emptyDirSync } from "fs-extra";
import { emptyDirSync, pathExistsSync } from "fs-extra";
import { formatHost } from "./diagnostics-format-host";
import { NoCache } from "./nocache";
export interface ICode
{
@ -79,7 +80,7 @@ export class TsCache
private semanticDiagnosticsCache!: ICache<IDiagnostics[]>;
private syntacticDiagnosticsCache!: ICache<IDiagnostics[]>;
constructor(private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
constructor(private noCache: boolean, private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
{
this.cacheDir = `${cache}/${sha1({
version: this.cacheVersion,
@ -107,8 +108,11 @@ export class TsCache
public clean()
{
this.context.info(blue(`cleaning cache: ${this.cacheDir}`));
emptyDirSync(this.cacheDir);
if (pathExistsSync(this.cacheDir))
{
this.context.info(blue(`cleaning cache: ${this.cacheDir}`));
emptyDirSync(this.cacheDir);
}
this.init();
}
@ -231,10 +235,20 @@ export class TsCache
private init()
{
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`, true);
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, true);
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, true);
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, true);
if (this.noCache)
{
this.codeCache = new NoCache<ICode>();
this.typesCache = new NoCache<string>();
this.syntacticDiagnosticsCache = new NoCache<IDiagnostics[]>();
this.semanticDiagnosticsCache = new NoCache<IDiagnostics[]>();
}
else
{
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`, true);
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, true);
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, true);
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, true);
}
}
private markAsDirty(id: string): void