Track which files build plugins use the content of

This commit is contained in:
zodern
2021-05-14 16:36:18 -05:00
parent 58017ea4e1
commit 32958e2d34
3 changed files with 50 additions and 16 deletions

View File

@@ -1161,7 +1161,7 @@ class Target {
.computeJsOutputFilesMap(sourceBatches);
sourceBatches.forEach(batch => {
const { unibuild } = batch;
const { unibuild, sourceRoot } = batch;
// Depend on the source files that produced these resources.
this.watchSet.merge(unibuild.watchSet);
@@ -1171,6 +1171,13 @@ class Target {
// XXX assumes that this merges cleanly
this.watchSet.merge(unibuild.pkg.pluginWatchSet);
unibuild.resources.forEach(resource => {
let absPath = files.pathJoin(sourceRoot, resource.path);
if (resource._dataUsed !== false) {
this.watchSet.addFile(absPath, resource.hash);
}
});
const entry = jsOutputFilesMap.get(unibuild.pkg.name || null);
if (entry && entry.importScannerWatchSet) {
// Populated in PackageSourceBatch._watchOutputFiles, based on the

View File

@@ -899,7 +899,9 @@ class OutputResource {
servePath,
// Remember the source hash so that changes to the source that
// disappear after compilation can still contribute to the hash.
_inputHash: resourceSlot.inputResource.hash,
// Bypassing SourceResource.hash getter so if the compiler plugin doesn't
// use the resource's content we don't unnecessarily mark it as used.
_inputHash: resourceSlot.inputResource._hash,
});
}
@@ -1518,6 +1520,7 @@ export class PackageSourceBatch {
}
static _watchOutputFiles(jsOutputFilesMap) {
return jsOutputFilesMap;
// Watch all output files produced by computeJsOutputFilesMap.
jsOutputFilesMap.forEach(entry => {
entry.files.forEach(file => {

View File

@@ -558,13 +558,12 @@ api.addAssets('${relPath}', 'client').`);
const hash = optimisticHashOrNull(absPath);
const file = { contents, hash };
if (fileOptions && ! fileOptions.lazy) {
watchSet.addFile(absPath, hash);
} else {
// Lazy files might not ultimately be used by the current unibuild/bundle,
// so we add them to the watchSet using a provisional status that may be
// updated later, at the end of PackageSourceBatch.computeJsOutputFilesMap.
// When files are handled by a new-style compiler plugin, the SourceResource
// class tracks if each file is actually used.
if (classification.isNonLegacySource()) {
watchSet.addPotentiallyUnusedFile(absPath, hash);
} else {
watchSet.addFile(absPath, hash);
}
Console.nudge(true);
@@ -598,16 +597,13 @@ api.addAssets('${relPath}', 'client').`);
if (classification.isNonLegacySource()) {
// This is source used by a new-style compiler plugin; it will be fully
// processed later in the bundler.
resources.push({
type: "source",
extension: classification.extension || null,
usesDefaultSourceProcessor:
!! classification.usesDefaultSourceProcessor,
resources.push(new SourceResource({
classification,
data: contents,
path: relPath,
hash: hash,
fileOptions: fileOptions
});
hash,
fileOptions
}));
return;
}
@@ -1060,3 +1056,31 @@ export const KNOWN_ISOBUILD_FEATURE_PACKAGES = {
// compilation using fibers and/or futures.
'isobuild:async-plugins': ['1.6.1'],
};
class SourceResource {
type = "source";
constructor({ classification, data, path, hash, fileOptions }) {
this.type = "source";
this.extension = classification.extension || null;
this.usesDefaultSourceProcessor = !!classification.usesDefaultSourceProcessor;
this.path = path;
this.fileOptions = fileOptions;
// Is set to true if the resource's hash or data is accessed, which can be
// used to track if the file's content was used during the build process
this._dataUsed = false;
this._hash = hash;
this._data = data;
}
get hash () {
this._dataUsed = true;
return this._hash;
}
get data () {
this._dataUsed = true;
return this._data;
}
}