@atlaspack/cache 3.1.1-canary.125 → 3.1.1-canary.127
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/lib/LMDBLiteCache.js +12 -25
- package/package.json +8 -8
- package/src/LMDBLiteCache.js +9 -13
package/lib/LMDBLiteCache.js
CHANGED
@@ -26,13 +26,6 @@ function _rust() {
|
|
26
26
|
};
|
27
27
|
return data;
|
28
28
|
}
|
29
|
-
function _fs() {
|
30
|
-
const data = _interopRequireDefault(require("fs"));
|
31
|
-
_fs = function () {
|
32
|
-
return data;
|
33
|
-
};
|
34
|
-
return data;
|
35
|
-
}
|
36
29
|
function _ncp() {
|
37
30
|
const data = _interopRequireDefault(require("ncp"));
|
38
31
|
_ncp = function () {
|
@@ -61,9 +54,9 @@ function _path() {
|
|
61
54
|
};
|
62
55
|
return data;
|
63
56
|
}
|
64
|
-
function
|
57
|
+
function _fs() {
|
65
58
|
const data = require("@atlaspack/fs");
|
66
|
-
|
59
|
+
_fs = function () {
|
67
60
|
return data;
|
68
61
|
};
|
69
62
|
return data;
|
@@ -128,7 +121,7 @@ class LMDBLiteCache {
|
|
128
121
|
*/
|
129
122
|
|
130
123
|
constructor(cacheDir) {
|
131
|
-
this.fs = new (
|
124
|
+
this.fs = new (_fs().NodeFS)();
|
132
125
|
this.dir = cacheDir;
|
133
126
|
this.cacheFilesDirectory = _path().default.join(cacheDir, 'files');
|
134
127
|
this.fsCache = new _FSCache.FSCache(this.fs, cacheDir);
|
@@ -177,17 +170,15 @@ class LMDBLiteCache {
|
|
177
170
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
178
171
|
return this.fs.createReadStream(_path().default.join(this.dir, key));
|
179
172
|
}
|
180
|
-
return
|
173
|
+
return this.fs.createReadStream(this.getFileKey(key));
|
181
174
|
}
|
182
175
|
async setStream(key, stream) {
|
183
176
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
184
177
|
return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
|
185
178
|
}
|
186
179
|
const filePath = this.getFileKey(key);
|
187
|
-
await
|
188
|
-
|
189
|
-
});
|
190
|
-
return pipeline(stream, _fs().default.createWriteStream(filePath));
|
180
|
+
await this.fs.mkdirp(_path().default.dirname(filePath));
|
181
|
+
return pipeline(stream, this.fs.createWriteStream(filePath));
|
191
182
|
}
|
192
183
|
|
193
184
|
// eslint-disable-next-line require-await
|
@@ -211,23 +202,21 @@ class LMDBLiteCache {
|
|
211
202
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
212
203
|
return this.fsCache.hasLargeBlob(key);
|
213
204
|
}
|
214
|
-
return
|
205
|
+
return this.fs.exists(this.getFileKey(key));
|
215
206
|
}
|
216
207
|
getLargeBlob(key) {
|
217
208
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
218
209
|
return this.fsCache.getLargeBlob(key);
|
219
210
|
}
|
220
|
-
return
|
211
|
+
return this.fs.readFile(this.getFileKey(key));
|
221
212
|
}
|
222
213
|
async setLargeBlob(key, contents, options) {
|
223
214
|
if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
|
224
215
|
return this.fsCache.setLargeBlob(key, contents, options);
|
225
216
|
}
|
226
217
|
const targetPath = this.getFileKey(key);
|
227
|
-
await
|
228
|
-
|
229
|
-
});
|
230
|
-
return _fs().default.promises.writeFile(targetPath, contents);
|
218
|
+
await this.fs.mkdirp(_path().default.dirname(targetPath));
|
219
|
+
return this.fs.writeFile(targetPath, contents);
|
231
220
|
}
|
232
221
|
|
233
222
|
/**
|
@@ -243,10 +232,8 @@ class LMDBLiteCache {
|
|
243
232
|
return this.store.keys();
|
244
233
|
}
|
245
234
|
async compact(targetPath) {
|
246
|
-
await
|
247
|
-
|
248
|
-
});
|
249
|
-
const files = await _fs().default.promises.readdir(this.dir);
|
235
|
+
await this.fs.mkdirp(targetPath);
|
236
|
+
const files = await this.fs.readdir(this.dir);
|
250
237
|
// copy all files except data.mdb and lock.mdb to the target path (recursive)
|
251
238
|
for (const file of files) {
|
252
239
|
const filePath = _path().default.join(this.dir, file);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/cache",
|
3
3
|
"description": "Interface for defining caches and file-system, IDB and LMDB implementations.",
|
4
|
-
"version": "3.1.1-canary.
|
4
|
+
"version": "3.1.1-canary.127+969b3de9a",
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
6
6
|
"type": "commonjs",
|
7
7
|
"publishConfig": {
|
@@ -23,12 +23,12 @@
|
|
23
23
|
"check-ts": "tsc --noEmit index.d.ts"
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
|
-
"@atlaspack/build-cache": "2.13.3-canary.
|
27
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
28
|
-
"@atlaspack/fs": "2.14.5-canary.
|
29
|
-
"@atlaspack/logger": "2.14.5-canary.
|
30
|
-
"@atlaspack/rust": "3.2.1-canary.
|
31
|
-
"@atlaspack/utils": "2.14.5-canary.
|
26
|
+
"@atlaspack/build-cache": "2.13.3-canary.195+969b3de9a",
|
27
|
+
"@atlaspack/feature-flags": "2.14.1-canary.195+969b3de9a",
|
28
|
+
"@atlaspack/fs": "2.14.5-canary.127+969b3de9a",
|
29
|
+
"@atlaspack/logger": "2.14.5-canary.127+969b3de9a",
|
30
|
+
"@atlaspack/rust": "3.2.1-canary.127+969b3de9a",
|
31
|
+
"@atlaspack/utils": "2.14.5-canary.127+969b3de9a",
|
32
32
|
"ncp": "^2.0.0"
|
33
33
|
},
|
34
34
|
"devDependencies": {
|
@@ -37,5 +37,5 @@
|
|
37
37
|
"browser": {
|
38
38
|
"./src/IDBCache.js": "./src/IDBCache.browser.js"
|
39
39
|
},
|
40
|
-
"gitHead": "
|
40
|
+
"gitHead": "969b3de9a78423f3ca7ebb3b2cbd8c2679b48462"
|
41
41
|
}
|
package/src/LMDBLiteCache.js
CHANGED
@@ -10,7 +10,6 @@ import {Lmdb} from '@atlaspack/rust';
|
|
10
10
|
import type {FilePath} from '@atlaspack/types';
|
11
11
|
import type {Cache} from './types';
|
12
12
|
import type {Readable, Writable} from 'stream';
|
13
|
-
import fs from 'fs';
|
14
13
|
import ncp from 'ncp';
|
15
14
|
import {promisify} from 'util';
|
16
15
|
import stream from 'stream';
|
@@ -168,7 +167,7 @@ export class LMDBLiteCache implements Cache {
|
|
168
167
|
return this.fs.createReadStream(path.join(this.dir, key));
|
169
168
|
}
|
170
169
|
|
171
|
-
return fs.createReadStream(this.getFileKey(key));
|
170
|
+
return this.fs.createReadStream(this.getFileKey(key));
|
172
171
|
}
|
173
172
|
|
174
173
|
async setStream(key: string, stream: Readable): Promise<void> {
|
@@ -180,8 +179,8 @@ export class LMDBLiteCache implements Cache {
|
|
180
179
|
}
|
181
180
|
|
182
181
|
const filePath = this.getFileKey(key);
|
183
|
-
await fs.
|
184
|
-
return pipeline(stream, fs.createWriteStream(filePath));
|
182
|
+
await this.fs.mkdirp(path.dirname(filePath));
|
183
|
+
return pipeline(stream, this.fs.createWriteStream(filePath));
|
185
184
|
}
|
186
185
|
|
187
186
|
// eslint-disable-next-line require-await
|
@@ -210,17 +209,14 @@ export class LMDBLiteCache implements Cache {
|
|
210
209
|
return this.fsCache.hasLargeBlob(key);
|
211
210
|
}
|
212
211
|
|
213
|
-
return fs.
|
214
|
-
.access(this.getFileKey(key), fs.constants.F_OK)
|
215
|
-
.then(() => true)
|
216
|
-
.catch(() => false);
|
212
|
+
return this.fs.exists(this.getFileKey(key));
|
217
213
|
}
|
218
214
|
|
219
215
|
getLargeBlob(key: string): Promise<Buffer> {
|
220
216
|
if (!getFeatureFlag('cachePerformanceImprovements')) {
|
221
217
|
return this.fsCache.getLargeBlob(key);
|
222
218
|
}
|
223
|
-
return fs.
|
219
|
+
return this.fs.readFile(this.getFileKey(key));
|
224
220
|
}
|
225
221
|
|
226
222
|
async setLargeBlob(
|
@@ -233,8 +229,8 @@ export class LMDBLiteCache implements Cache {
|
|
233
229
|
}
|
234
230
|
|
235
231
|
const targetPath = this.getFileKey(key);
|
236
|
-
await fs.
|
237
|
-
return fs.
|
232
|
+
await this.fs.mkdirp(path.dirname(targetPath));
|
233
|
+
return this.fs.writeFile(targetPath, contents);
|
238
234
|
}
|
239
235
|
|
240
236
|
/**
|
@@ -253,9 +249,9 @@ export class LMDBLiteCache implements Cache {
|
|
253
249
|
}
|
254
250
|
|
255
251
|
async compact(targetPath: string): Promise<void> {
|
256
|
-
await fs.
|
252
|
+
await this.fs.mkdirp(targetPath);
|
257
253
|
|
258
|
-
const files = await fs.
|
254
|
+
const files = await this.fs.readdir(this.dir);
|
259
255
|
// copy all files except data.mdb and lock.mdb to the target path (recursive)
|
260
256
|
for (const file of files) {
|
261
257
|
const filePath = path.join(this.dir, file);
|