Skip to content

Commit

Permalink
Add tooling script to cache key (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Nov 16, 2023
1 parent f597bd1 commit c831309
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/upstream-protobuf/bin/upstream-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ async function main(args) {
exitUsage();
}
stdout.write(protoInclude.files.join(" "));
exit(0);
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/upstream-protobuf/bin/upstream-include.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ async function main(args) {
exitUsage();
}
stdout.write(protoInclude.dir);
exit(0);
}

/**
Expand Down
16 changes: 11 additions & 5 deletions packages/upstream-protobuf/lib.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
chmodSync,
readdirSync,
} from "node:fs";
import { createHash } from "node:crypto";
import { join as joinPath, dirname, relative as relativePath } from "node:path";
import os from "node:os";
import { unzipSync } from "fflate";
Expand Down Expand Up @@ -87,17 +88,22 @@ export class UpstreamProtobuf {
* @param {string} [version]
*/
constructor(temp, version) {
if (typeof temp !== "string") {
temp = new URL(".tmp", import.meta.url).pathname;
}
this.#temp = temp;
if (typeof version !== "string") {
version = readFileSync(
new URL("version.txt", import.meta.url).pathname,
"utf-8",
).trim();
}
this.#version = version;
if (typeof temp !== "string") {
const thisFilePath = new URL(import.meta.url).pathname;
const thisFileContent = readFileSync(new URL(import.meta.url).pathname);
const hashObj = createHash("sha256");
hashObj.update(thisFileContent);
const digest = hashObj.digest("hex");
temp = joinPath(thisFilePath, "..", ".tmp", this.#version + "-" + digest);
}
this.#temp = temp;
}

/**
Expand Down Expand Up @@ -154,7 +160,7 @@ export class UpstreamProtobuf {
* @param {...string[]} paths
*/
#getTempPath(...paths) {
const p = joinPath(this.#temp, this.#version, ...paths);
const p = joinPath(this.#temp, ...paths);
if (!existsSync(dirname(p))) {
mkdirSync(dirname(p), { recursive: true });
}
Expand Down

0 comments on commit c831309

Please sign in to comment.