Skip to content

Commit b471b98

Browse files
committed
- using active rollup config as part of cache hash
Partial solution for #15 and a number of other potential conflicts.
1 parent 7a815cf commit b471b98

File tree

4 files changed

+96
-63
lines changed

4 files changed

+96
-63
lines changed

dist/rollup-plugin-typescript2.cjs.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ var RollingCache = (function () {
219219
return;
220220
if (data === undefined)
221221
return;
222-
if (this.rolled)
223-
fs.writeJsonSync(this.oldCacheRoot + "/" + name, data);
224-
else
225-
fs.writeJsonSync(this.newCacheRoot + "/" + name, data);
222+
fs.writeJsonSync(this.newCacheRoot + "/" + name, data);
226223
};
227224
RollingCache.prototype.touch = function (name) {
228225
if (this.rolled)
@@ -258,27 +255,29 @@ function convertDiagnostic(type, data) {
258255
});
259256
}
260257
var TsCache = (function () {
261-
function TsCache(host, cache, options, rootFilenames, context) {
258+
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
262259
var _this = this;
263260
this.host = host;
264261
this.options = options;
262+
this.rollupConfig = rollupConfig;
265263
this.context = context;
266-
this.cacheVersion = "4";
264+
this.cacheVersion = "5";
267265
this.ambientTypesDirty = false;
268266
this.cacheDir = cache + "/" + hash.sha1({
269267
version: this.cacheVersion,
270268
rootFilenames: rootFilenames,
271269
options: this.options,
270+
rollupConfig: this.rollupConfig,
272271
tsVersion: ts.version,
273272
});
274273
this.dependencyTree = new graph.Graph({ directed: true });
275-
this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; });
274+
this.dependencyTree.setDefaultNodeLabel(function (_node) { return ({ dirty: false }); });
276275
var automaticTypes = _.map(ts.getAutomaticTypeDirectiveNames(options, ts.sys), function (entry) { return ts.resolveTypeReferenceDirective(entry, undefined, options, ts.sys); })
277276
.filter(function (entry) { return entry.resolvedTypeReferenceDirective && entry.resolvedTypeReferenceDirective.resolvedFileName; })
278277
.map(function (entry) { return entry.resolvedTypeReferenceDirective.resolvedFileName; });
279278
this.ambientTypes = _.filter(rootFilenames, function (file) { return _.endsWith(file, ".d.ts"); })
280279
.concat(automaticTypes)
281-
.map(function (id) { return { id: id, snapshot: _this.host.getScriptSnapshot(id) }; });
280+
.map(function (id) { return ({ id: id, snapshot: _this.host.getScriptSnapshot(id) }); });
282281
this.init();
283282
this.checkAmbientTypes();
284283
}
@@ -463,7 +462,6 @@ function printDiagnostics(context, diagnostics) {
463462
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
464463
});
465464
}
466-
467465
function typescript(options) {
468466
options = __assign({}, options);
469467
_.defaults(options, {
@@ -476,6 +474,7 @@ function typescript(options) {
476474
abortOnError: true,
477475
rollupCommonJSResolveHack: false,
478476
});
477+
var rollupConfig;
479478
var watchMode = false;
480479
var round = 0;
481480
var targetCount = 0;
@@ -486,14 +485,23 @@ function typescript(options) {
486485
var parsedConfig = parseTsConfig(context);
487486
var servicesHost = new LanguageServiceHost(parsedConfig);
488487
var service = ts.createLanguageService(servicesHost, ts.createDocumentRegistry());
489-
var cache = new TsCache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);
488+
var _cache;
489+
var cache = function () {
490+
if (!_cache)
491+
_cache = new TsCache(servicesHost, options.cacheRoot, parsedConfig.options, rollupConfig, parsedConfig.fileNames, context);
492+
return _cache;
493+
};
490494
var noErrors = true;
491-
if (options.clean)
492-
cache.clean();
493495
// printing compiler option errors
494496
if (options.check)
495497
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
496498
return {
499+
options: function (config) {
500+
rollupConfig = config;
501+
context.debug("rollupConfig: " + JSON.stringify(rollupConfig, undefined, 4));
502+
if (options.clean)
503+
cache().clean();
504+
},
497505
resolveId: function (importee, importer) {
498506
if (importee === TSLIB)
499507
return "\0" + TSLIB;
@@ -504,7 +512,7 @@ function typescript(options) {
504512
var result = ts.nodeModuleNameResolver(importee, importer, parsedConfig.options, ts.sys);
505513
if (result.resolvedModule && result.resolvedModule.resolvedFileName) {
506514
if (filter$$1(result.resolvedModule.resolvedFileName))
507-
cache.setDependency(result.resolvedModule.resolvedFileName, importer);
515+
cache().setDependency(result.resolvedModule.resolvedFileName, importer);
508516
if (_.endsWith(result.resolvedModule.resolvedFileName, ".d.ts"))
509517
return null;
510518
var resolved = options.rollupCommonJSResolveHack
@@ -528,19 +536,19 @@ function typescript(options) {
528536
var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rpt2: ");
529537
var snapshot = servicesHost.setSnapshot(id, code);
530538
// getting compiled file from cache or from ts
531-
var result = cache.getCompiled(id, snapshot, function () {
539+
var result = cache().getCompiled(id, snapshot, function () {
532540
var output = service.getEmitOutput(id);
533541
if (output.emitSkipped) {
534542
noErrors = false;
535543
// always checking on fatal errors, even if options.check is set to false
536-
var diagnostics = _.concat(cache.getSyntacticDiagnostics(id, snapshot, function () {
544+
var diagnostics = _.concat(cache().getSyntacticDiagnostics(id, snapshot, function () {
537545
return service.getSyntacticDiagnostics(id);
538-
}), cache.getSemanticDiagnostics(id, snapshot, function () {
546+
}), cache().getSemanticDiagnostics(id, snapshot, function () {
539547
return service.getSemanticDiagnostics(id);
540548
}));
541549
printDiagnostics(contextWrapper, diagnostics);
542550
// since no output was generated, aborting compilation
543-
cache.done();
551+
cache().done();
544552
if (_.isFunction(_this.error))
545553
_this.error(colors.red("failed to transpile '" + id + "'"));
546554
}
@@ -552,9 +560,9 @@ function typescript(options) {
552560
};
553561
});
554562
if (options.check) {
555-
var diagnostics = _.concat(cache.getSyntacticDiagnostics(id, snapshot, function () {
563+
var diagnostics = _.concat(cache().getSyntacticDiagnostics(id, snapshot, function () {
556564
return service.getSyntacticDiagnostics(id);
557-
}), cache.getSemanticDiagnostics(id, snapshot, function () {
565+
}), cache().getSemanticDiagnostics(id, snapshot, function () {
558566
return service.getSemanticDiagnostics(id);
559567
}));
560568
if (diagnostics.length > 0)
@@ -572,14 +580,14 @@ function typescript(options) {
572580
context.debug("generating target " + (round + 1) + " of " + targetCount);
573581
if (watchMode && round === 0) {
574582
context.debug("running in watch mode");
575-
cache.walkTree(function (id) {
583+
cache().walkTree(function (id) {
576584
var diagnostics = _.concat(convertDiagnostic("syntax", service.getSyntacticDiagnostics(id)), convertDiagnostic("semantic", service.getSemanticDiagnostics(id)));
577585
printDiagnostics(context, diagnostics);
578586
});
579587
}
580588
if (!watchMode && !noErrors)
581589
context.info(colors.yellow("there were errors or warnings above."));
582-
cache.done();
590+
cache().done();
583591
round++;
584592
},
585593
};

dist/rollup-plugin-typescript2.es.js

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ var RollingCache = (function () {
225225
return;
226226
if (data === undefined)
227227
return;
228-
if (this.rolled)
229-
writeJsonSync(this.oldCacheRoot + "/" + name, data);
230-
else
231-
writeJsonSync(this.newCacheRoot + "/" + name, data);
228+
writeJsonSync(this.newCacheRoot + "/" + name, data);
232229
};
233230
RollingCache.prototype.touch = function (name) {
234231
if (this.rolled)
@@ -264,27 +261,29 @@ function convertDiagnostic(type, data) {
264261
});
265262
}
266263
var TsCache = (function () {
267-
function TsCache(host, cache, options, rootFilenames, context) {
264+
function TsCache(host, cache, options, rollupConfig, rootFilenames, context) {
268265
var _this = this;
269266
this.host = host;
270267
this.options = options;
268+
this.rollupConfig = rollupConfig;
271269
this.context = context;
272-
this.cacheVersion = "4";
270+
this.cacheVersion = "5";
273271
this.ambientTypesDirty = false;
274272
this.cacheDir = cache + "/" + sha1({
275273
version: this.cacheVersion,
276274
rootFilenames: rootFilenames,
277275
options: this.options,
276+
rollupConfig: this.rollupConfig,
278277
tsVersion: version,
279278
});
280279
this.dependencyTree = new Graph({ directed: true });
281-
this.dependencyTree.setDefaultNodeLabel(function (_node) { return { dirty: false }; });
280+
this.dependencyTree.setDefaultNodeLabel(function (_node) { return ({ dirty: false }); });
282281
var automaticTypes = map(getAutomaticTypeDirectiveNames(options, sys), function (entry) { return resolveTypeReferenceDirective(entry, undefined, options, sys); })
283282
.filter(function (entry) { return entry.resolvedTypeReferenceDirective && entry.resolvedTypeReferenceDirective.resolvedFileName; })
284283
.map(function (entry) { return entry.resolvedTypeReferenceDirective.resolvedFileName; });
285284
this.ambientTypes = filter(rootFilenames, function (file) { return endsWith(file, ".d.ts"); })
286285
.concat(automaticTypes)
287-
.map(function (id) { return { id: id, snapshot: _this.host.getScriptSnapshot(id) }; });
286+
.map(function (id) { return ({ id: id, snapshot: _this.host.getScriptSnapshot(id) }); });
288287
this.init();
289288
this.checkAmbientTypes();
290289
}
@@ -469,7 +468,6 @@ function printDiagnostics(context, diagnostics) {
469468
print.call(context, ["" + type + category + " TS" + diagnostic.code + " " + color(diagnostic.flatMessage)]);
470469
});
471470
}
472-
473471
function typescript(options) {
474472
options = __assign({}, options);
475473
defaults(options, {
@@ -482,6 +480,7 @@ function typescript(options) {
482480
abortOnError: true,
483481
rollupCommonJSResolveHack: false,
484482
});
483+
var rollupConfig;
485484
var watchMode = false;
486485
var round = 0;
487486
var targetCount = 0;
@@ -492,14 +491,23 @@ function typescript(options) {
492491
var parsedConfig = parseTsConfig(context);
493492
var servicesHost = new LanguageServiceHost(parsedConfig);
494493
var service = createLanguageService(servicesHost, createDocumentRegistry());
495-
var cache = new TsCache(servicesHost, options.cacheRoot, parsedConfig.options, parsedConfig.fileNames, context);
494+
var _cache;
495+
var cache = function () {
496+
if (!_cache)
497+
_cache = new TsCache(servicesHost, options.cacheRoot, parsedConfig.options, rollupConfig, parsedConfig.fileNames, context);
498+
return _cache;
499+
};
496500
var noErrors = true;
497-
if (options.clean)
498-
cache.clean();
499501
// printing compiler option errors
500502
if (options.check)
501503
printDiagnostics(context, convertDiagnostic("options", service.getCompilerOptionsDiagnostics()));
502504
return {
505+
options: function (config) {
506+
rollupConfig = config;
507+
context.debug("rollupConfig: " + JSON.stringify(rollupConfig, undefined, 4));
508+
if (options.clean)
509+
cache().clean();
510+
},
503511
resolveId: function (importee, importer) {
504512
if (importee === TSLIB)
505513
return "\0" + TSLIB;
@@ -510,7 +518,7 @@ function typescript(options) {
510518
var result = nodeModuleNameResolver(importee, importer, parsedConfig.options, sys);
511519
if (result.resolvedModule && result.resolvedModule.resolvedFileName) {
512520
if (filter$$1(result.resolvedModule.resolvedFileName))
513-
cache.setDependency(result.resolvedModule.resolvedFileName, importer);
521+
cache().setDependency(result.resolvedModule.resolvedFileName, importer);
514522
if (endsWith(result.resolvedModule.resolvedFileName, ".d.ts"))
515523
return null;
516524
var resolved = options.rollupCommonJSResolveHack
@@ -534,19 +542,19 @@ function typescript(options) {
534542
var contextWrapper = new RollupContext(options.verbosity, options.abortOnError, this, "rpt2: ");
535543
var snapshot = servicesHost.setSnapshot(id, code);
536544
// getting compiled file from cache or from ts
537-
var result = cache.getCompiled(id, snapshot, function () {
545+
var result = cache().getCompiled(id, snapshot, function () {
538546
var output = service.getEmitOutput(id);
539547
if (output.emitSkipped) {
540548
noErrors = false;
541549
// always checking on fatal errors, even if options.check is set to false
542-
var diagnostics = concat(cache.getSyntacticDiagnostics(id, snapshot, function () {
550+
var diagnostics = concat(cache().getSyntacticDiagnostics(id, snapshot, function () {
543551
return service.getSyntacticDiagnostics(id);
544-
}), cache.getSemanticDiagnostics(id, snapshot, function () {
552+
}), cache().getSemanticDiagnostics(id, snapshot, function () {
545553
return service.getSemanticDiagnostics(id);
546554
}));
547555
printDiagnostics(contextWrapper, diagnostics);
548556
// since no output was generated, aborting compilation
549-
cache.done();
557+
cache().done();
550558
if (isFunction(_this.error))
551559
_this.error(red("failed to transpile '" + id + "'"));
552560
}
@@ -558,9 +566,9 @@ function typescript(options) {
558566
};
559567
});
560568
if (options.check) {
561-
var diagnostics = concat(cache.getSyntacticDiagnostics(id, snapshot, function () {
569+
var diagnostics = concat(cache().getSyntacticDiagnostics(id, snapshot, function () {
562570
return service.getSyntacticDiagnostics(id);
563-
}), cache.getSemanticDiagnostics(id, snapshot, function () {
571+
}), cache().getSemanticDiagnostics(id, snapshot, function () {
564572
return service.getSemanticDiagnostics(id);
565573
}));
566574
if (diagnostics.length > 0)
@@ -578,14 +586,14 @@ function typescript(options) {
578586
context.debug("generating target " + (round + 1) + " of " + targetCount);
579587
if (watchMode && round === 0) {
580588
context.debug("running in watch mode");
581-
cache.walkTree(function (id) {
589+
cache().walkTree(function (id) {
582590
var diagnostics = concat(convertDiagnostic("syntax", service.getSyntacticDiagnostics(id)), convertDiagnostic("semantic", service.getSemanticDiagnostics(id)));
583591
printDiagnostics(context, diagnostics);
584592
});
585593
}
586594
if (!watchMode && !noErrors)
587595
context.info(yellow("there were errors or warnings above."));
588-
cache.done();
596+
cache().done();
589597
round++;
590598
},
591599
};

0 commit comments

Comments
 (0)