Skip to content

Commit 00b1908

Browse files
authored
fix: single build does not cache correctly (#61)
1 parent 4909397 commit 00b1908

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@jotforminc/zenith",
33
"packageManager": "[email protected]",
4-
"version": "2.2.2",
4+
"version": "2.2.3",
55
"description": "",
66
"main": "./build/index.js",
77
"files": [

src/classes/Builder/SingleBuilder.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ export default class SingleBuilder extends BuildHelper {
77
async fetchOrRun(hash: string) {
88
const recoverResponse = await this.anotherJob(hash, 'root', 'stdout', this.command, false, this.logAffected);
99
if (recoverResponse === 'Cache not found') {
10+
Logger.log(2, 'Cache does not exist for command => ', this.command, hash);
1011
await this.runManual({cwd: './', command: this.command, hash});
1112
}
1213
this.totalCount++;
1314
}
1415

1516
async runManual({cwd, command, hash}: {cwd: string, command: string, hash: string}) {
1617
const output = await this.executeManual({cwd, command, hash});
17-
Logger.log(2, 'Cache does not exist for command => ', command, hash);
1818
if (output instanceof Error) {
1919
throw output;
2020
}
@@ -23,11 +23,22 @@ export default class SingleBuilder extends BuildHelper {
2323

2424
async build(): Promise<void> {
2525
const hash = this.hasher.getSingleHash({script: this.command, projects: this.projects});
26-
await this.fetchOrRun(hash);
27-
void this.pool.terminate();
28-
Logger.log(2, this.outputColor, `Zenith completed command: ${this.command}. ${this.noCache ? '(Cache was not used)' : ''}`);
29-
Logger.log(2, this.outputColor, `Total of ${this.totalCount} project${this.totalCount === 1 ? ' is' : 's are'} finished.`);
30-
Logger.log(2, this.outputColor, `Total process took ${formatTimeDiff(process.hrtime(this.startTime))}.`);
31-
return;
26+
try {
27+
await this.fetchOrRun(hash);
28+
} catch (err) {
29+
Logger.log(2, err);
30+
process.exit(1);
31+
}
32+
// eslint-disable-next-line no-constant-condition
33+
while (true) {
34+
const stats = this.pool.stats();
35+
if (!stats.activeTasks && !stats.pendingTasks) {
36+
void this.pool.terminate();
37+
Logger.log(2, this.outputColor, `Zenith completed command: ${this.command}. ${this.noCache ? '(Cache was not used)' : ''}`);
38+
Logger.log(2, this.outputColor, `Total of ${this.totalCount} project${this.totalCount === 1 ? ' is' : 's are'} finished.`);
39+
Logger.log(2, this.outputColor, `Total process took ${formatTimeDiff(process.hrtime(this.startTime))}.`);
40+
return;
41+
}
42+
}
3243
}
3344
}

src/classes/Cache/Cacher.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default abstract class Cacher {
112112
if (configManagerInstance.getConfigValue('ZENITH_READ_ONLY')) return;
113113
try {
114114
const directoryPath = path.join(ROOT_PATH, root, output);
115-
if ((output !== 'stdout' && !existsSync(directoryPath))) {
115+
if (output !== 'stdout' && !existsSync(directoryPath)) {
116116
return;
117117
}
118118
const notFoundFiles = getMissingRequiredFiles(directoryPath, requiredFiles);
@@ -199,10 +199,8 @@ export default abstract class Cacher {
199199
if (nodeError.$metadata.httpStatusCode === 404) {
200200
return 'Cache not found';
201201
}
202-
if (!error) {
203-
return false;
204-
}
205-
Logger.log(2, 'error', );
202+
Logger.log(2, "ERR-C-R ::", error);
203+
throw error;
206204
}
207205
}
208206

src/classes/Runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class Runner {
159159
if (Runner.workspace.size === 0) {
160160
Runner.workspace = deepCloneMap(Builder.getProjects());
161161
}
162-
Logger.log(2, `Zenith ${command} started.`);
162+
Logger.log(2, Builder.outputColor, `Zenith ${command} started.`);
163163
await Builder.build();
164164
}
165165
}

src/classes/WorkerHelper.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ export default class WorkerHelper {
4949
}
5050

5151
async anotherJob(hash: string, root: string, output: string, target: string, compareHashes: boolean, logAffected: boolean): Promise<{output: string} | string | unknown> {
52-
try {
53-
return await this.pool.exec('anotherJob', [hash, root, output, target, compareHashes, logAffected], {
54-
on: message => Logger.log(3, message)
52+
return await this.pool.exec('anotherJob', [hash, root, output, target, compareHashes, logAffected], {
53+
on: message => Logger.log(3, message)
5554
}) as boolean | Error;
56-
} catch (error) {
57-
return error;
58-
}
5955
}
6056
}

src/worker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ const anotherJob = async (hash: string, root: string, output: string, target: st
5959
if (error && typeof error === 'object' && 'stderr' in error) {
6060
const execErr = error as ExecError;
6161
Logger.log(2, 'ERR-W-A :: output => ', execErr.stderr);
62-
return execErr;
62+
throw execErr;
6363
}
6464
Logger.log(2, 'ERR-W-A :: output => ', error);
65-
return new Error(String(error));
65+
throw new Error(String(error));
6666
}
6767
};
6868

0 commit comments

Comments
 (0)