@atlaspack/cache 3.1.1-canary.14 → 3.1.1-canary.141

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/CHANGELOG.md CHANGED
@@ -1,5 +1,166 @@
1
1
  # @atlaspack/cache
2
2
 
3
+ ## 3.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
8
+ - @atlaspack/feature-flags@2.20.0
9
+ - @atlaspack/fs@2.15.16
10
+ - @atlaspack/utils@2.17.3
11
+
12
+ ## 3.2.15
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [[`1c7865a`](https://github.com/atlassian-labs/atlaspack/commit/1c7865a64451116d94015e248302435839d347c0), [`a0b959f`](https://github.com/atlassian-labs/atlaspack/commit/a0b959fbf61fc3f820ff03c7e8988945fe40a91a)]:
17
+ - @atlaspack/feature-flags@2.19.2
18
+ - @atlaspack/fs@2.15.15
19
+ - @atlaspack/utils@2.17.2
20
+
21
+ ## 3.2.14
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
26
+ - @atlaspack/feature-flags@2.19.1
27
+ - @atlaspack/fs@2.15.14
28
+ - @atlaspack/utils@2.17.1
29
+
30
+ ## 3.2.13
31
+
32
+ ### Patch Changes
33
+
34
+ - [#697](https://github.com/atlassian-labs/atlaspack/pull/697) [`c9631af`](https://github.com/atlassian-labs/atlaspack/commit/c9631aff284b2c1c27e8a52f9da392ce65d666e8) Thanks [@yamadapc](https://github.com/yamadapc)! - Fix bug where cache large blob operations were not atomic
35
+
36
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`c4415a4`](https://github.com/atlassian-labs/atlaspack/commit/c4415a455543d984ca28452c2cb87a794d22497c), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
37
+ - @atlaspack/feature-flags@2.19.0
38
+ - @atlaspack/utils@2.17.0
39
+ - @atlaspack/rust@3.4.1
40
+ - @atlaspack/fs@2.15.13
41
+ - @atlaspack/logger@2.14.13
42
+
43
+ ## 3.2.12
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
48
+ - @atlaspack/rust@3.4.0
49
+ - @atlaspack/fs@2.15.12
50
+ - @atlaspack/logger@2.14.12
51
+ - @atlaspack/utils@2.16.1
52
+
53
+ ## 3.2.11
54
+
55
+ ### Patch Changes
56
+
57
+ - Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
58
+ - @atlaspack/feature-flags@2.18.4
59
+ - @atlaspack/utils@2.16.0
60
+ - @atlaspack/fs@2.15.11
61
+
62
+ ## 3.2.10
63
+
64
+ ### Patch Changes
65
+
66
+ - Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
67
+ - @atlaspack/feature-flags@2.18.3
68
+ - @atlaspack/fs@2.15.10
69
+ - @atlaspack/utils@2.15.3
70
+
71
+ ## 3.2.9
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
76
+ - @atlaspack/feature-flags@2.18.2
77
+ - @atlaspack/fs@2.15.9
78
+ - @atlaspack/utils@2.15.2
79
+
80
+ ## 3.2.8
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies [[`ef3d622`](https://github.com/atlassian-labs/atlaspack/commit/ef3d6228f4e006702198a19c61e051d194d325cb), [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
85
+ - @atlaspack/logger@2.14.11
86
+ - @atlaspack/feature-flags@2.18.1
87
+ - @atlaspack/fs@2.15.8
88
+ - @atlaspack/utils@2.15.1
89
+
90
+ ## 3.2.7
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [[`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75), [`85c52d3`](https://github.com/atlassian-labs/atlaspack/commit/85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2), [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
95
+ - @atlaspack/feature-flags@2.18.0
96
+ - @atlaspack/utils@2.15.0
97
+ - @atlaspack/fs@2.15.7
98
+
99
+ ## 3.2.6
100
+
101
+ ### Patch Changes
102
+
103
+ - Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
104
+ - @atlaspack/feature-flags@2.17.0
105
+ - @atlaspack/fs@2.15.6
106
+ - @atlaspack/utils@2.14.11
107
+
108
+ ## 3.2.5
109
+
110
+ ### Patch Changes
111
+
112
+ - Updated dependencies [[`0999fb7`](https://github.com/atlassian-labs/atlaspack/commit/0999fb78da519a6c7582d212883e515fcf6c1252), [`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
113
+ - @atlaspack/fs@2.15.5
114
+ - @atlaspack/rust@3.3.5
115
+ - @atlaspack/logger@2.14.10
116
+ - @atlaspack/utils@2.14.10
117
+
118
+ ## 3.2.4
119
+
120
+ ### Patch Changes
121
+
122
+ - [#583](https://github.com/atlassian-labs/atlaspack/pull/583) [`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa) Thanks [@yamadapc](https://github.com/yamadapc)! - Fix problem where cache writes could start to fail during a V3 build
123
+
124
+ - Updated dependencies [[`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa), [`e052521`](https://github.com/atlassian-labs/atlaspack/commit/e0525210850ed1606146eb86991049cf567c5dec), [`15c6d70`](https://github.com/atlassian-labs/atlaspack/commit/15c6d7000bd89da876bc590aa75b17a619a41896), [`e4d966c`](https://github.com/atlassian-labs/atlaspack/commit/e4d966c3c9c4292c5013372ae65b10d19d4bacc6), [`209692f`](https://github.com/atlassian-labs/atlaspack/commit/209692ffb11eae103a0d65c5e1118a5aa1625818), [`42a775d`](https://github.com/atlassian-labs/atlaspack/commit/42a775de8eec638ad188f3271964170d8c04d84b), [`29c2f10`](https://github.com/atlassian-labs/atlaspack/commit/29c2f106de9679adfb5afa04e1910471dc65a427), [`f4da1e1`](https://github.com/atlassian-labs/atlaspack/commit/f4da1e120e73eeb5e8b8927f05e88f04d6148c7b), [`1ef91fc`](https://github.com/atlassian-labs/atlaspack/commit/1ef91fcc863fdd2831511937083dbbc1263b3d9d)]:
125
+ - @atlaspack/rust@3.3.4
126
+ - @atlaspack/fs@2.15.4
127
+ - @atlaspack/feature-flags@2.16.0
128
+ - @atlaspack/logger@2.14.9
129
+ - @atlaspack/utils@2.14.9
130
+
131
+ ## 3.2.3
132
+
133
+ ### Patch Changes
134
+
135
+ - Updated dependencies [[`30f6017`](https://github.com/atlassian-labs/atlaspack/commit/30f60175ba4d272c5fc193973c63bc298584775b), [`3a3e8e7`](https://github.com/atlassian-labs/atlaspack/commit/3a3e8e7be9e2dffd7304436d792f0f595d59665a), [`1ab0a27`](https://github.com/atlassian-labs/atlaspack/commit/1ab0a275aeca40350415e2b03e7440d1dddc6228), [`b8a4ae8`](https://github.com/atlassian-labs/atlaspack/commit/b8a4ae8f83dc0a83d8b145c5f729936ce52080a3)]:
136
+ - @atlaspack/feature-flags@2.15.1
137
+ - @atlaspack/fs@2.15.3
138
+ - @atlaspack/rust@3.3.3
139
+ - @atlaspack/utils@2.14.8
140
+ - @atlaspack/logger@2.14.8
141
+
142
+ ## 3.2.2
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [[`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929), [`556d6ab`](https://github.com/atlassian-labs/atlaspack/commit/556d6ab8ede759fa7f37fcd3f4da336ef1c55e8f)]:
147
+ - @atlaspack/feature-flags@2.15.0
148
+ - @atlaspack/logger@2.14.7
149
+ - @atlaspack/rust@3.3.2
150
+ - @atlaspack/fs@2.15.2
151
+ - @atlaspack/utils@2.14.7
152
+
153
+ ## 3.2.1
154
+
155
+ ### Patch Changes
156
+
157
+ - Updated dependencies [[`e0f5337`](https://github.com/atlassian-labs/atlaspack/commit/e0f533757bd1019dbd108a04952c87da15286e09)]:
158
+ - @atlaspack/feature-flags@2.14.4
159
+ - @atlaspack/rust@3.3.1
160
+ - @atlaspack/fs@2.15.1
161
+ - @atlaspack/utils@2.14.6
162
+ - @atlaspack/logger@2.14.6
163
+
3
164
  ## 3.2.0
4
165
 
5
166
  ### Minor Changes
@@ -0,0 +1,27 @@
1
+ import type { Readable } from 'stream';
2
+ import type { FilePath } from '@atlaspack/types';
3
+ import type { FileSystem } from '@atlaspack/fs';
4
+ import type { Cache } from './types';
5
+ export declare class FSCache implements Cache {
6
+ #private;
7
+ fs: FileSystem;
8
+ dir: FilePath;
9
+ constructor(fs: FileSystem, cacheDir: FilePath);
10
+ ensure(): Promise<void>;
11
+ _getCachePath(cacheId: string): FilePath;
12
+ getStream(key: string): Readable;
13
+ setStream(key: string, stream: Readable): Promise<void>;
14
+ has(key: string): Promise<boolean>;
15
+ getBlob(key: string): Promise<Buffer>;
16
+ setBlob(key: string, contents: Buffer | string): Promise<void>;
17
+ getBuffer(key: string): Promise<Buffer | null | undefined>;
18
+ hasLargeBlob(key: string): Promise<boolean>;
19
+ getLargeBlob(key: string): Promise<Buffer>;
20
+ setLargeBlob(key: string, contents: Buffer | string, options?: {
21
+ signal?: AbortSignal;
22
+ }): Promise<void>;
23
+ deleteLargeBlob(key: string): Promise<void>;
24
+ get<T>(key: string): Promise<T | null | undefined>;
25
+ set(key: string, value: unknown): Promise<void>;
26
+ refresh(): void;
27
+ }
package/lib/FSCache.js CHANGED
@@ -25,6 +25,20 @@ function _util() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ function _rust() {
29
+ const data = require("@atlaspack/rust");
30
+ _rust = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _featureFlags() {
36
+ const data = require("@atlaspack/feature-flags");
37
+ _featureFlags = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
28
42
  function _logger() {
29
43
  const data = _interopRequireDefault(require("@atlaspack/logger"));
30
44
  _logger = function () {
@@ -43,6 +57,7 @@ var _package = _interopRequireDefault(require("../package.json"));
43
57
  var _constants = require("./constants");
44
58
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
45
59
  // flowlint-next-line untyped-import:off
60
+
46
61
  const pipeline = (0, _util().promisify)(_stream().default.pipeline);
47
62
  class FSCache {
48
63
  constructor(fs, cacheDir) {
@@ -57,11 +72,17 @@ class FSCache {
57
72
  // This speeds up large caches on many file systems since there are fewer files in a single directory.
58
73
  let dirPromises = [];
59
74
  for (let i = 0; i < 256; i++) {
60
- dirPromises.push(this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
75
+ dirPromises.push(
76
+ // @ts-expect-error TS2345
77
+ this.fs.mkdirp(_path().default.join(this.dir, ('00' + i.toString(16)).slice(-2))));
61
78
  }
62
79
  await Promise.all(dirPromises);
63
80
  }
64
81
  _getCachePath(cacheId) {
82
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
83
+ const cleanId = (0, _rust().hashString)(cacheId);
84
+ return _path().default.join(this.dir, cleanId.slice(0, 2), cleanId.slice(2));
85
+ }
65
86
  return _path().default.join(this.dir, cacheId.slice(0, 2), cacheId.slice(2));
66
87
  }
67
88
  getStream(key) {
@@ -91,6 +112,9 @@ class FSCache {
91
112
  }
92
113
  }
93
114
  #getFilePath(key, index) {
115
+ if ((0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
116
+ return _path().default.join(this.dir, `${(0, _rust().hashString)(key)}-${index}`);
117
+ }
94
118
  return _path().default.join(this.dir, `${key}-${index}`);
95
119
  }
96
120
  async #unlinkChunks(key, index) {
@@ -117,12 +141,19 @@ class FSCache {
117
141
  const writePromises = [];
118
142
  if (chunks === 1) {
119
143
  // If there's one chunk, don't slice the content
120
- writePromises.push(this.fs.writeFile(this.#getFilePath(key, 0), contents, {
144
+ writePromises.push(
145
+ // @ts-expect-error TS2345
146
+ this.fs.writeFile(this.#getFilePath(key, 0), contents, {
147
+ // @ts-expect-error TS2353
121
148
  signal: options === null || options === void 0 ? void 0 : options.signal
122
149
  }));
123
150
  } else {
124
151
  for (let i = 0; i < chunks; i += 1) {
125
- writePromises.push(this.fs.writeFile(this.#getFilePath(key, i), typeof contents === 'string' ? contents.slice(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK) : contents.subarray(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK), {
152
+ writePromises.push(
153
+ // @ts-expect-error TS2345
154
+ this.fs.writeFile(this.#getFilePath(key, i), typeof contents === 'string' ? contents.slice(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK) : contents.subarray(i * _constants.WRITE_LIMIT_CHUNK, (i + 1) * _constants.WRITE_LIMIT_CHUNK),
155
+ // @ts-expect-error TS2353
156
+ {
126
157
  signal: options === null || options === void 0 ? void 0 : options.signal
127
158
  }));
128
159
  }
@@ -137,6 +168,7 @@ class FSCache {
137
168
  let i = 0;
138
169
  let filePath = this.#getFilePath(key, i);
139
170
  while (await this.fs.exists(filePath)) {
171
+ // @ts-expect-error TS2345
140
172
  deletePromises.push(this.fs.rimraf(filePath));
141
173
  i += 1;
142
174
  filePath = this.#getFilePath(key, i);
@@ -0,0 +1,22 @@
1
+ import type { Cache } from './types';
2
+ import { Readable } from 'stream';
3
+ export declare class IDBCache implements Cache {
4
+ store: any;
5
+ constructor();
6
+ ensure(): Promise<void>;
7
+ serialize(): Record<any, any>;
8
+ static deserialize(): IDBCache;
9
+ has(key: string): Promise<boolean>;
10
+ get<T>(key: string): Promise<T | null | undefined>;
11
+ set(key: string, value: unknown): Promise<void>;
12
+ getStream(key: string): Readable;
13
+ setStream(key: string, stream: Readable): Promise<void>;
14
+ getBlob(key: string): Promise<Buffer>;
15
+ setBlob(key: string, contents: Buffer | string): Promise<void>;
16
+ getBuffer(key: string): Promise<Buffer | null | undefined>;
17
+ hasLargeBlob(key: string): Promise<boolean>;
18
+ getLargeBlob(key: string): Promise<Buffer>;
19
+ setLargeBlob(key: string, contents: Buffer | string): Promise<void>;
20
+ deleteLargeBlob(key: string): Promise<void>;
21
+ refresh(): void;
22
+ }
@@ -34,12 +34,8 @@ function _idb() {
34
34
  }
35
35
  var _package = _interopRequireDefault(require("../package.json"));
36
36
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
- // $FlowFixMe[untyped-import]
38
- // $FlowFixMe[untyped-import]
39
37
  const STORE_NAME = 'cache';
40
38
  class IDBCache {
41
- // $FlowFixMe
42
-
43
39
  constructor() {
44
40
  this.store = (0, _idb().openDB)('REPL-parcel-cache', 1, {
45
41
  upgrade(db) {
@@ -75,9 +71,14 @@ class IDBCache {
75
71
  await (await this.store).put(STORE_NAME, (0, _buildCache().serialize)(value), key);
76
72
  }
77
73
  getStream(key) {
78
- let dataPromise = this.store.then(s => s.get(STORE_NAME, key)).then(d => Buffer.from(d)).catch(e => e);
74
+ let dataPromise = this.store
75
+ // @ts-expect-error TS7006
76
+ .then(s => s.get(STORE_NAME, key))
77
+ // @ts-expect-error TS7006
78
+ .then(d => Buffer.from(d))
79
+ // @ts-expect-error TS7006
80
+ .catch(e => e);
79
81
  const stream = new (_stream().Readable)({
80
- // $FlowFixMe(incompatible-call)
81
82
  async read() {
82
83
  let data = await dataPromise;
83
84
  if (data instanceof Error) {
@@ -0,0 +1,4 @@
1
+ import type { Cache } from './types';
2
+ export declare class IDBCache implements Cache {
3
+ constructor();
4
+ }
package/lib/IDBCache.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.IDBCache = void 0;
7
- // $FlowFixMe
7
+ // @ts-expect-error TS2420
8
8
  class IDBCache {
9
9
  constructor() {
10
10
  throw new Error('IDBCache is only supported in the browser');
@@ -0,0 +1,78 @@
1
+ import { Lmdb } from '@atlaspack/rust';
2
+ import type { FilePath } from '@atlaspack/types';
3
+ import type { Cache } from './types';
4
+ import type { Readable } from 'stream';
5
+ import { NodeFS } from '@atlaspack/fs';
6
+ import { FSCache } from './FSCache';
7
+ interface DBOpenOptions {
8
+ name: string;
9
+ encoding: string;
10
+ compression: boolean;
11
+ }
12
+ export declare class LmdbWrapper {
13
+ lmdb: Lmdb;
14
+ constructor(lmdb: Lmdb);
15
+ has(key: string): boolean;
16
+ delete(key: string): Promise<void>;
17
+ get(key: string): Buffer | null;
18
+ put(key: string, value: Buffer | string): Promise<void>;
19
+ keys(): Iterable<string>;
20
+ compact(targetPath: string): void;
21
+ }
22
+ export declare function open(directory: string, openOptions: DBOpenOptions): LmdbWrapper;
23
+ export type SerLMDBLiteCache = {
24
+ dir: FilePath;
25
+ };
26
+ export declare class LMDBLiteCache implements Cache {
27
+ fs: NodeFS;
28
+ dir: FilePath;
29
+ store: LmdbWrapper;
30
+ fsCache: FSCache;
31
+ /**
32
+ * Directory where we store raw files.
33
+ */
34
+ cacheFilesDirectory: FilePath;
35
+ constructor(cacheDir: FilePath);
36
+ /**
37
+ * Use this to pass the native LMDB instance back to Rust.
38
+ */
39
+ getNativeRef(): Lmdb;
40
+ ensure(): Promise<void>;
41
+ serialize(): SerLMDBLiteCache;
42
+ static deserialize(cache: SerLMDBLiteCache): LMDBLiteCache;
43
+ has(key: string): Promise<boolean>;
44
+ get<T>(key: string): Promise<T | null | undefined>;
45
+ set(key: string, value: unknown): Promise<void>;
46
+ getStream(key: string): Readable;
47
+ setStream(key: string, stream: Readable): Promise<void>;
48
+ getBlob(key: string): Promise<Buffer>;
49
+ getBlobSync(key: string): Buffer;
50
+ setBlob(key: string, contents: Buffer | string): Promise<void>;
51
+ getBuffer(key: string): Promise<Buffer | null | undefined>;
52
+ hasLargeBlob(key: string): Promise<boolean>;
53
+ getLargeBlob(key: string): Promise<Buffer>;
54
+ setLargeBlob(key: string, contents: Buffer | string, options?: {
55
+ signal?: AbortSignal;
56
+ }): Promise<void>;
57
+ /**
58
+ * @deprecated Use store.delete instead.
59
+ */
60
+ deleteLargeBlob(key: string): Promise<void>;
61
+ keys(): Iterable<string>;
62
+ compact(targetPath: string): Promise<void>;
63
+ refresh(): void;
64
+ /**
65
+ * Streams, packages are stored in files instead of LMDB.
66
+ *
67
+ * On this case, if a cache key happens to have a parent traversal, ../..
68
+ * it is treated specially
69
+ *
70
+ * That is, something/../something and something are meant to be different
71
+ * keys.
72
+ *
73
+ * Plus we do not want to store values outside of the cache directory.
74
+ */
75
+ getFileKey(key: string): string;
76
+ clear(): Promise<void>;
77
+ }
78
+ export {};
@@ -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,26 +54,29 @@ function _path() {
61
54
  };
62
55
  return data;
63
56
  }
64
- function _fs2() {
57
+ function _fs() {
65
58
  const data = require("@atlaspack/fs");
66
- _fs2 = function () {
59
+ _fs = function () {
67
60
  return data;
68
61
  };
69
62
  return data;
70
63
  }
71
64
  var _package = _interopRequireDefault(require("../package.json"));
72
65
  var _FSCache = require("./FSCache");
66
+ function _logger() {
67
+ const data = require("@atlaspack/logger");
68
+ _logger = function () {
69
+ return data;
70
+ };
71
+ return data;
72
+ }
73
73
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
74
- // $FlowFixMe
74
+ // @ts-expect-error TS7016
75
+
75
76
  const ncpAsync = (0, _util().promisify)(_ncp().default);
76
77
  class LmdbWrapper {
77
78
  constructor(lmdb) {
78
79
  this.lmdb = lmdb;
79
-
80
- // $FlowFixMe
81
- this[Symbol.dispose] = () => {
82
- this.lmdb.close();
83
- };
84
80
  }
85
81
  has(key) {
86
82
  return this.lmdb.hasSync(key);
@@ -110,20 +106,25 @@ class LmdbWrapper {
110
106
  }
111
107
  }
112
108
  exports.LmdbWrapper = LmdbWrapper;
113
- function open(directory
109
+ function open(directory,
114
110
  // eslint-disable-next-line no-unused-vars
115
- ) {
111
+ openOptions) {
116
112
  return new LmdbWrapper(new (_rust().Lmdb)({
117
113
  path: directory,
118
114
  asyncWrites: true,
119
- mapSize: 1024 * 1024 * 1024 * 15
115
+ mapSize: process.env.ATLASPACK_BUILD_ENV === 'test' ? 1024 * 1024 * 1024 : 1024 * 1024 * 1024 * 15
120
116
  }));
121
117
  }
122
118
  const pipeline = (0, _util().promisify)(_stream().default.pipeline);
123
119
  class LMDBLiteCache {
120
+ /**
121
+ * Directory where we store raw files.
122
+ */
123
+
124
124
  constructor(cacheDir) {
125
- this.fs = new (_fs2().NodeFS)();
125
+ this.fs = new (_fs().NodeFS)();
126
126
  this.dir = cacheDir;
127
+ this.cacheFilesDirectory = _path().default.join(cacheDir, 'files');
127
128
  this.fsCache = new _FSCache.FSCache(this.fs, cacheDir);
128
129
  this.store = open(cacheDir, {
129
130
  name: 'parcel-cache',
@@ -142,6 +143,7 @@ class LMDBLiteCache {
142
143
  if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
143
144
  await this.fsCache.ensure();
144
145
  }
146
+ await this.fs.mkdirp(this.cacheFilesDirectory);
145
147
  return Promise.resolve();
146
148
  }
147
149
  serialize() {
@@ -166,10 +168,18 @@ class LMDBLiteCache {
166
168
  await this.setBlob(key, (0, _buildCache().serialize)(value));
167
169
  }
168
170
  getStream(key) {
169
- return this.fs.createReadStream(_path().default.join(this.dir, key));
171
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
172
+ return this.fs.createReadStream(_path().default.join(this.dir, key));
173
+ }
174
+ return this.fs.createReadStream(this.getFileKey(key));
170
175
  }
171
- setStream(key, stream) {
172
- return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
176
+ async setStream(key, stream) {
177
+ if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
178
+ return pipeline(stream, this.fs.createWriteStream(_path().default.join(this.dir, key)));
179
+ }
180
+ const filePath = this.getFileKey(key);
181
+ await this.fs.mkdirp(_path().default.dirname(filePath));
182
+ return pipeline(stream, this.fs.createWriteStream(filePath));
173
183
  }
174
184
 
175
185
  // eslint-disable-next-line require-await
@@ -189,34 +199,25 @@ class LMDBLiteCache {
189
199
  getBuffer(key) {
190
200
  return Promise.resolve(this.store.get(key));
191
201
  }
192
- #getFilePath(key, index) {
193
- return _path().default.join(this.dir, `${key}-${index}`);
194
- }
195
202
  hasLargeBlob(key) {
196
203
  if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
197
204
  return this.fsCache.hasLargeBlob(key);
198
205
  }
199
- return this.has(key);
206
+ return this.fs.exists(this.getFileKey(key));
200
207
  }
201
-
202
- /**
203
- * @deprecated Use getBlob instead.
204
- */
205
208
  getLargeBlob(key) {
206
209
  if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
207
210
  return this.fsCache.getLargeBlob(key);
208
211
  }
209
- return Promise.resolve(this.getBlobSync(key));
212
+ return this.fs.readFile(this.getFileKey(key));
210
213
  }
211
-
212
- /**
213
- * @deprecated Use setBlob instead.
214
- */
215
- setLargeBlob(key, contents, options) {
214
+ async setLargeBlob(key, contents, options) {
216
215
  if (!(0, _featureFlags().getFeatureFlag)('cachePerformanceImprovements')) {
217
216
  return this.fsCache.setLargeBlob(key, contents, options);
218
217
  }
219
- return this.setBlob(key, contents);
218
+ const targetPath = this.getFileKey(key);
219
+ await this.fs.mkdirp(_path().default.dirname(targetPath));
220
+ return this.fs.writeFile(targetPath, contents);
220
221
  }
221
222
 
222
223
  /**
@@ -232,10 +233,8 @@ class LMDBLiteCache {
232
233
  return this.store.keys();
233
234
  }
234
235
  async compact(targetPath) {
235
- await _fs().default.promises.mkdir(targetPath, {
236
- recursive: true
237
- });
238
- const files = await _fs().default.promises.readdir(this.dir);
236
+ await this.fs.mkdirp(targetPath);
237
+ const files = await this.fs.readdir(this.dir);
239
238
  // copy all files except data.mdb and lock.mdb to the target path (recursive)
240
239
  for (const file of files) {
241
240
  const filePath = _path().default.join(this.dir, file);
@@ -247,6 +246,37 @@ class LMDBLiteCache {
247
246
  this.store.compact(_path().default.join(targetPath, 'data.mdb'));
248
247
  }
249
248
  refresh() {}
249
+
250
+ /**
251
+ * Streams, packages are stored in files instead of LMDB.
252
+ *
253
+ * On this case, if a cache key happens to have a parent traversal, ../..
254
+ * it is treated specially
255
+ *
256
+ * That is, something/../something and something are meant to be different
257
+ * keys.
258
+ *
259
+ * Plus we do not want to store values outside of the cache directory.
260
+ */
261
+ getFileKey(key) {
262
+ const cleanKey = key.split('/').map(part => {
263
+ if (part === '..') {
264
+ return '$$__parent_dir$$';
265
+ }
266
+ return part;
267
+ }).join('/');
268
+ return _path().default.join(this.cacheFilesDirectory, cleanKey);
269
+ }
270
+ async clear() {
271
+ await (0, _logger().instrumentAsync)('LMDBLiteCache::clear', async () => {
272
+ const keys = await this.keys();
273
+ for (const key of keys) {
274
+ await this.store.delete(key);
275
+ }
276
+ await this.fs.rimraf(this.cacheFilesDirectory);
277
+ await this.fs.mkdirp(this.cacheFilesDirectory);
278
+ });
279
+ }
250
280
  }
251
281
  exports.LMDBLiteCache = LMDBLiteCache;
252
282
  (0, _buildCache().registerSerializableClass)(`${_package.default.version}:LMDBLiteCache`, LMDBLiteCache);
@@ -0,0 +1 @@
1
+ export declare const WRITE_LIMIT_CHUNK: number;
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './FSCache';
2
+ export * from './IDBCache';
3
+ export * from './LMDBLiteCache';
4
+ export type { Cache } from './types';
package/lib/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { Cache } from "@atlaspack/types";
1
+ import type { Cache } from '@atlaspack/types';
2
2
  export type { Cache };