@divriots/jampack 0.12.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache.d.ts +2 -1
- package/dist/cache.js +35 -12
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cache.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
|
|
2
|
+
declare const listOfCategories: readonly ["img", "img-ext"];
|
|
3
|
+
export type Category = (typeof listOfCategories)[number];
|
|
3
4
|
export type CacheData = {
|
|
4
5
|
buffer: Buffer;
|
|
5
6
|
meta: any;
|
package/dist/cache.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import hasha from 'hasha';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
|
-
import { VERSION } from './version.js';
|
|
5
4
|
import $state from './state.js';
|
|
5
|
+
const listOfCategories = ['img', 'img-ext'];
|
|
6
6
|
const CACHE_FOLDER = '.jampack/cache';
|
|
7
|
-
const
|
|
7
|
+
const CACHE_VERSIONS = {
|
|
8
|
+
img: 'v1',
|
|
9
|
+
'img-ext': 'v1',
|
|
10
|
+
};
|
|
8
11
|
async function cleanCache(full) {
|
|
9
12
|
if (full) {
|
|
10
13
|
try {
|
|
@@ -15,19 +18,36 @@ async function cleanCache(full) {
|
|
|
15
18
|
}
|
|
16
19
|
return;
|
|
17
20
|
}
|
|
18
|
-
//
|
|
19
|
-
let
|
|
21
|
+
// Delete old cache category
|
|
22
|
+
let catFolders = [];
|
|
20
23
|
try {
|
|
21
|
-
|
|
24
|
+
catFolders = await fs.readdir(CACHE_FOLDER);
|
|
22
25
|
}
|
|
23
26
|
catch (e) {
|
|
24
|
-
//
|
|
25
|
-
|
|
27
|
+
// No problem
|
|
28
|
+
}
|
|
29
|
+
for (const f of catFolders) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
if (!listOfCategories.includes(f))
|
|
32
|
+
fs.rm(path.join(CACHE_FOLDER, f), { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
// Loop cache folders
|
|
35
|
+
for (const cat of listOfCategories) {
|
|
36
|
+
const location = path.join(CACHE_FOLDER, cat);
|
|
37
|
+
// List versions in cache
|
|
38
|
+
let folders;
|
|
39
|
+
try {
|
|
40
|
+
folders = await fs.readdir(location);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// Delete old cache versions
|
|
46
|
+
for (const f of folders) {
|
|
47
|
+
if (f !== CACHE_VERSIONS[cat])
|
|
48
|
+
fs.rm(path.join(location, f), { recursive: true });
|
|
49
|
+
}
|
|
26
50
|
}
|
|
27
|
-
// Delete old cache versions
|
|
28
|
-
await files
|
|
29
|
-
.filter((f) => f !== VERSION)
|
|
30
|
-
.forEach(async (f) => fs.rm(path.join(CACHE_FOLDER, f), { recursive: true }));
|
|
31
51
|
}
|
|
32
52
|
function computeCacheHash(buffer, options) {
|
|
33
53
|
if ($state.args.nocache) {
|
|
@@ -39,8 +59,11 @@ function computeCacheHash(buffer, options) {
|
|
|
39
59
|
}
|
|
40
60
|
return hash;
|
|
41
61
|
}
|
|
62
|
+
function getVersionOfCategory(category) {
|
|
63
|
+
return CACHE_VERSIONS[category];
|
|
64
|
+
}
|
|
42
65
|
function getLocation(hash, category) {
|
|
43
|
-
return path.join(
|
|
66
|
+
return path.join(CACHE_FOLDER, category, getVersionOfCategory(category), hash);
|
|
44
67
|
}
|
|
45
68
|
async function getFromCache(category, hash) {
|
|
46
69
|
if ($state.args.nocache) {
|
package/dist/index.js
CHANGED