Skip to content

Commit f15cb84

Browse files
committed
- "clean: true" will not create cache in the first place ezolenko#68
1 parent a3b71f0 commit f15cb84

10 files changed

+170
-30
lines changed

dist/nocache.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ICache } from "./icache";
2+
export declare class NoCache<DataType> implements ICache<DataType> {
3+
exists(_name: string): boolean;
4+
path(name: string): string;
5+
match(_names: string[]): boolean;
6+
read(_name: string): DataType | null | undefined;
7+
write(_name: string, _data: DataType): void;
8+
touch(_name: string): void;
9+
roll(): void;
10+
}

dist/rollup-plugin-typescript2.cjs.js

+46-8
Original file line numberDiff line numberDiff line change
@@ -19527,6 +19527,33 @@ var FormatHost = /** @class */ (function () {
1952719527
}());
1952819528
var formatHost = new FormatHost();
1952919529

19530+
var NoCache = /** @class */ (function () {
19531+
function NoCache() {
19532+
}
19533+
NoCache.prototype.exists = function (_name) {
19534+
return false;
19535+
};
19536+
NoCache.prototype.path = function (name) {
19537+
return name;
19538+
};
19539+
NoCache.prototype.match = function (_names) {
19540+
return false;
19541+
};
19542+
NoCache.prototype.read = function (_name) {
19543+
return undefined;
19544+
};
19545+
NoCache.prototype.write = function (_name, _data) {
19546+
return;
19547+
};
19548+
NoCache.prototype.touch = function (_name) {
19549+
return;
19550+
};
19551+
NoCache.prototype.roll = function () {
19552+
return;
19553+
};
19554+
return NoCache;
19555+
}());
19556+
1953019557
function convertDiagnostic(type, data) {
1953119558
return lodash_7(data, function (diagnostic) {
1953219559
var entry = {
@@ -19544,8 +19571,9 @@ function convertDiagnostic(type, data) {
1954419571
});
1954519572
}
1954619573
var TsCache = /** @class */ (function () {
19547-
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
19574+
function TsCache(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
1954819575
var _this = this;
19576+
this.noCache = noCache;
1954919577
this.host = host;
1955019578
this.options = options;
1955119579
this.rollupConfig = rollupConfig;
@@ -19571,8 +19599,10 @@ var TsCache = /** @class */ (function () {
1957119599
this.checkAmbientTypes();
1957219600
}
1957319601
TsCache.prototype.clean = function () {
19574-
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
19575-
fsExtra.emptyDirSync(this.cacheDir);
19602+
if (fsExtra.pathExistsSync(this.cacheDir)) {
19603+
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
19604+
fsExtra.emptyDirSync(this.cacheDir);
19605+
}
1957619606
this.init();
1957719607
};
1957819608
TsCache.prototype.setDependency = function (importee, importer) {
@@ -19657,10 +19687,18 @@ var TsCache = /** @class */ (function () {
1965719687
return convertedData;
1965819688
};
1965919689
TsCache.prototype.init = function () {
19660-
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
19661-
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
19662-
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
19663-
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
19690+
if (this.noCache) {
19691+
this.codeCache = new NoCache();
19692+
this.typesCache = new NoCache();
19693+
this.syntacticDiagnosticsCache = new NoCache();
19694+
this.semanticDiagnosticsCache = new NoCache();
19695+
}
19696+
else {
19697+
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
19698+
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
19699+
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
19700+
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
19701+
}
1966419702
};
1966519703
TsCache.prototype.markAsDirty = function (id) {
1966619704
this.dependencyTree.setNode(id, { dirty: true });
@@ -19828,7 +19866,7 @@ function typescript(options) {
1982819866
var _cache;
1982919867
var cache = function () {
1983019868
if (!_cache)
19831-
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
19869+
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
1983219870
return _cache;
1983319871
};
1983419872
var pluginOptions = __assign({}, options);

dist/rollup-plugin-typescript2.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rollup-plugin-typescript2.es.js

+47-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
import { existsSync, readdirSync, renameSync, readFileSync } from 'fs';
33
import crypto from 'crypto';
4-
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync } from 'fs-extra';
4+
import { emptyDirSync, ensureFileSync, readJsonSync, removeSync, writeJsonSync, pathExistsSync } from 'fs-extra';
55
import { dirname, isAbsolute, join, relative, normalize } from 'path';
66
import { sync } from 'resolve';
77

@@ -19523,6 +19523,33 @@ var FormatHost = /** @class */ (function () {
1952319523
}());
1952419524
var formatHost = new FormatHost();
1952519525

19526+
var NoCache = /** @class */ (function () {
19527+
function NoCache() {
19528+
}
19529+
NoCache.prototype.exists = function (_name) {
19530+
return false;
19531+
};
19532+
NoCache.prototype.path = function (name) {
19533+
return name;
19534+
};
19535+
NoCache.prototype.match = function (_names) {
19536+
return false;
19537+
};
19538+
NoCache.prototype.read = function (_name) {
19539+
return undefined;
19540+
};
19541+
NoCache.prototype.write = function (_name, _data) {
19542+
return;
19543+
};
19544+
NoCache.prototype.touch = function (_name) {
19545+
return;
19546+
};
19547+
NoCache.prototype.roll = function () {
19548+
return;
19549+
};
19550+
return NoCache;
19551+
}());
19552+
1952619553
function convertDiagnostic(type, data) {
1952719554
return lodash_7(data, function (diagnostic) {
1952819555
var entry = {
@@ -19540,8 +19567,9 @@ function convertDiagnostic(type, data) {
1954019567
});
1954119568
}
1954219569
var TsCache = /** @class */ (function () {
19543-
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
19570+
function TsCache(noCache, host, cache, options, rollupConfig, rootFilenames, context) {
1954419571
var _this = this;
19572+
this.noCache = noCache;
1954519573
this.host = host;
1954619574
this.options = options;
1954719575
this.rollupConfig = rollupConfig;
@@ -19567,8 +19595,10 @@ var TsCache = /** @class */ (function () {
1956719595
this.checkAmbientTypes();
1956819596
}
1956919597
TsCache.prototype.clean = function () {
19570-
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
19571-
emptyDirSync(this.cacheDir);
19598+
if (pathExistsSync(this.cacheDir)) {
19599+
this.context.info(safe_5("cleaning cache: " + this.cacheDir));
19600+
emptyDirSync(this.cacheDir);
19601+
}
1957219602
this.init();
1957319603
};
1957419604
TsCache.prototype.setDependency = function (importee, importer) {
@@ -19653,10 +19683,18 @@ var TsCache = /** @class */ (function () {
1965319683
return convertedData;
1965419684
};
1965519685
TsCache.prototype.init = function () {
19656-
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
19657-
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
19658-
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
19659-
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
19686+
if (this.noCache) {
19687+
this.codeCache = new NoCache();
19688+
this.typesCache = new NoCache();
19689+
this.syntacticDiagnosticsCache = new NoCache();
19690+
this.semanticDiagnosticsCache = new NoCache();
19691+
}
19692+
else {
19693+
this.codeCache = new RollingCache(this.cacheDir + "/code", true);
19694+
this.typesCache = new RollingCache(this.cacheDir + "/types", true);
19695+
this.syntacticDiagnosticsCache = new RollingCache(this.cacheDir + "/syntacticDiagnostics", true);
19696+
this.semanticDiagnosticsCache = new RollingCache(this.cacheDir + "/semanticDiagnostics", true);
19697+
}
1966019698
};
1966119699
TsCache.prototype.markAsDirty = function (id) {
1966219700
this.dependencyTree.setNode(id, { dirty: true });
@@ -19824,7 +19862,7 @@ function typescript(options) {
1982419862
var _cache;
1982519863
var cache = function () {
1982619864
if (!_cache)
19827-
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
19865+
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
1982819866
return _cache;
1982919867
};
1983019868
var pluginOptions = __assign({}, options);

dist/rollup-plugin-typescript2.es.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tscache.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface IDiagnostics {
2121
}
2222
export declare function convertDiagnostic(type: string, data: tsTypes.Diagnostic[]): IDiagnostics[];
2323
export declare class TsCache {
24+
private noCache;
2425
private host;
2526
private options;
2627
private rollupConfig;
@@ -34,7 +35,7 @@ export declare class TsCache {
3435
private typesCache;
3536
private semanticDiagnosticsCache;
3637
private syntacticDiagnosticsCache;
37-
constructor(host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
38+
constructor(noCache: boolean, host: tsTypes.LanguageServiceHost, cache: string, options: tsTypes.CompilerOptions, rollupConfig: any, rootFilenames: string[], context: IContext);
3839
clean(): void;
3940
setDependency(importee: string, importer: string): void;
4041
walkTree(cb: (id: string) => void | false): void;

rollup.config.self.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import ts from "./build-self/dist/rollup-plugin-typescript2.es";
22

33
import config from "./rollup.config.base";
44

5-
config.plugins.push(ts({ verbosity: 2, abortOnError: false }));
5+
config.plugins.push(ts({ verbosity: 2, abortOnError: false, clean: false }));
66

77
export default config;

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function typescript(options?: Partial<IOptions>)
3636
const cache = (): TsCache =>
3737
{
3838
if (!_cache)
39-
_cache = new TsCache(servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
39+
_cache = new TsCache(pluginOptions.clean, servicesHost, pluginOptions.cacheRoot, parsedConfig.options, rollupOptions, parsedConfig.fileNames, context);
4040
return _cache;
4141
};
4242

src/nocache.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ICache } from "./icache";
2+
3+
export class NoCache<DataType> implements ICache<DataType>
4+
{
5+
public exists(_name: string): boolean
6+
{
7+
return false;
8+
}
9+
10+
public path(name: string): string
11+
{
12+
return name;
13+
}
14+
15+
public match(_names: string[]): boolean
16+
{
17+
return false;
18+
}
19+
20+
public read(_name: string): DataType | null | undefined
21+
{
22+
return undefined;
23+
}
24+
25+
public write(_name: string, _data: DataType): void
26+
{
27+
return;
28+
}
29+
30+
public touch(_name: string)
31+
{
32+
return;
33+
}
34+
35+
public roll()
36+
{
37+
return;
38+
}
39+
}

src/tscache.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import * as _ from "lodash";
77
import { tsModule } from "./tsproxy";
88
import * as tsTypes from "typescript";
99
import { blue, yellow, green } from "colors/safe";
10-
import { emptyDirSync } from "fs-extra";
10+
import { emptyDirSync, pathExistsSync } from "fs-extra";
1111
import { formatHost } from "./diagnostics-format-host";
12+
import { NoCache } from "./nocache";
1213

1314
export interface ICode
1415
{
@@ -79,7 +80,7 @@ export class TsCache
7980
private semanticDiagnosticsCache!: ICache<IDiagnostics[]>;
8081
private syntacticDiagnosticsCache!: ICache<IDiagnostics[]>;
8182

82-
constructor(private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
83+
constructor(private noCache: boolean, private host: tsTypes.LanguageServiceHost, cache: string, private options: tsTypes.CompilerOptions, private rollupConfig: any, rootFilenames: string[], private context: IContext)
8384
{
8485
this.cacheDir = `${cache}/${sha1({
8586
version: this.cacheVersion,
@@ -107,8 +108,11 @@ export class TsCache
107108

108109
public clean()
109110
{
110-
this.context.info(blue(`cleaning cache: ${this.cacheDir}`));
111-
emptyDirSync(this.cacheDir);
111+
if (pathExistsSync(this.cacheDir))
112+
{
113+
this.context.info(blue(`cleaning cache: ${this.cacheDir}`));
114+
emptyDirSync(this.cacheDir);
115+
}
112116

113117
this.init();
114118
}
@@ -231,10 +235,20 @@ export class TsCache
231235

232236
private init()
233237
{
234-
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`, true);
235-
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, true);
236-
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, true);
237-
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, true);
238+
if (this.noCache)
239+
{
240+
this.codeCache = new NoCache<ICode>();
241+
this.typesCache = new NoCache<string>();
242+
this.syntacticDiagnosticsCache = new NoCache<IDiagnostics[]>();
243+
this.semanticDiagnosticsCache = new NoCache<IDiagnostics[]>();
244+
}
245+
else
246+
{
247+
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`, true);
248+
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, true);
249+
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, true);
250+
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, true);
251+
}
238252
}
239253

240254
private markAsDirty(id: string): void

0 commit comments

Comments
 (0)