Fix tgui being built too often/not often enough (#2749)

Co-authored-by: Tad Hardesty <tad@platymuus.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
This commit is contained in:
SkyratBot
2021-01-18 20:27:42 +01:00
committed by GitHub
parent 5b4f24be26
commit ced918038e
3 changed files with 24 additions and 11 deletions

View File

@@ -21,8 +21,11 @@ const taskTgui = new Task('tgui')
.depends('tgui/**/package.json')
.depends('tgui/packages/**/*.js')
.depends('tgui/packages/**/*.jsx')
.provides('tgui/public/*.bundle.*')
.provides('tgui/public/*.chunk.*')
.provides('tgui/public/tgui.bundle.css')
.provides('tgui/public/tgui.bundle.js')
.provides('tgui/public/tgui-common.bundle.js')
.provides('tgui/public/tgui-panel.bundle.css')
.provides('tgui/public/tgui-panel.bundle.js')
.build(async () => {
// Instead of calling `tgui/bin/tgui`, we reproduce the whole pipeline
// here for maximum compilation speed.
@@ -36,9 +39,11 @@ const taskTgui = new Task('tgui')
});
const taskDm = new Task('dm')
.depends('_maps/map_files/generic/**')
.depends('code/**')
.depends('goon/**')
.depends('html/**')
.depends('icons/**')
.depends('interface/**')
.depends('tgui/public/tgui.html')
.depends('tgui/public/*.bundle.*')
@@ -77,4 +82,4 @@ if (process.env['TG_BUILD_TGS_MODE']) {
tasksToRun.pop();
}
runTasks(tasksToRun);
runTasks(tasksToRun);

View File

@@ -56,7 +56,7 @@ const compareFiles = nodes => {
}
} catch {
// Always needs a rebuild if any target doesn't exist.
return true;
return `target '${node.path}' is missing`;
}
continue;
}
@@ -83,14 +83,21 @@ const compareFiles = nodes => {
}
// Doesn't need rebuild if there is no source, but target exists.
if (!bestSource) {
return !bestTarget;
if (bestTarget) {
return false;
} else {
return 'no known sources or targets';
}
}
// Always needs a rebuild if no targets were specified (e.g. due to GLOB).
if (!bestTarget) {
return true;
return 'no targets were specified';
}
// Needs rebuild if source is newer than target
return bestSource.mtime > bestTarget.mtime;
if (bestSource.mtime > bestTarget.mtime) {
return `source '${bestSource.path}' is newer than target '${bestTarget.path}'`;
}
return false;
};
/**
@@ -131,4 +138,4 @@ module.exports = {
stat,
resolveGlob,
compareFiles,
};
};

View File

@@ -35,8 +35,9 @@ class Task {
async run() {
// Consider dependencies first, and skip the task if it
// doesn't need a rebuild.
let needsRebuild = 'empty dependency list';
if (this.deps.length > 0) {
const needsRebuild = compareFiles(this.deps);
needsRebuild = compareFiles(this.deps);
if (!needsRebuild) {
console.warn(` => Skipping '${this.name}'`);
return;
@@ -45,7 +46,7 @@ class Task {
if (!this.script) {
return;
}
console.warn(` => Starting '${this.name}'`);
console.warn(` => Starting '${this.name}': ${needsRebuild}`);
const startedAt = Date.now();
await this.script();
const time = ((Date.now() - startedAt) / 1000) + 's';
@@ -68,4 +69,4 @@ const runTasks = async tasks => {
module.exports = {
Task,
runTasks,
};
};