Skip to content

Commit 27199d5

Browse files
authored
fix: updatedAt timestamp breaks bundle caching (#75, #60)
Introduce separate meta.json. Fixes #60.
1 parent 88cdc19 commit 27199d5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/build-tries.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const serializeTrie = require("../lib/tries/serializeTrie");
2626
const PUBLIC_SUFFIX_URL = "https://publicsuffix.org/list/public_suffix_list.dat";
2727
const rootPath = path.resolve(__dirname, "..");
2828
const triesPath = path.resolve(rootPath, "build", "tries");
29+
const metaJsonFilename = path.resolve(triesPath, "meta.json");
2930
const tries = [
3031
{
3132
listName: "icann",
@@ -59,7 +60,6 @@ got(PUBLIC_SUFFIX_URL, {timeout: 60 * 1000})
5960
return {
6061
path: path.resolve(triesPath, trie.filename),
6162
content: JSON.stringify({
62-
updatedAt: new Date().toISOString(),
6363
trie: serializeTrie(parsedList, trie.type),
6464
}),
6565
};
@@ -80,14 +80,22 @@ got(PUBLIC_SUFFIX_URL, {timeout: 60 * 1000})
8080
});
8181

8282
process.stderr.write("ok" + os.EOL);
83+
84+
fs.writeFileSync(
85+
metaJsonFilename,
86+
JSON.stringify({
87+
updatedAt: new Date().toISOString(),
88+
}),
89+
"utf8"
90+
);
8391
})
8492
.catch(err => {
8593
console.error("");
8694
console.error(`Could not update list of known top-level domains for parse-domain because of "${err.message}"`);
8795

88-
const prebuiltList = JSON.parse(fs.readFileSync(path.resolve(triesPath, tries[0].filename), "utf8"));
96+
const metaJson = JSON.parse(fs.readFileSync(metaJsonFilename, "utf8"));
8997

90-
console.error("Using possibly outdated prebuilt list from " + new Date(prebuiltList.updatedAt).toDateString());
98+
console.error("Using possibly outdated prebuilt list from " + new Date(metaJson.updatedAt).toDateString());
9199

92100
// We can recover using the (possibly outdated) prebuilt list, hence exit code 0
93101
process.exit(0); // eslint-disable-line no-process-exit

0 commit comments

Comments
 (0)