@roots/bud-cache 6.15.1 → 6.15.2
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/helpers.d.ts +2 -0
- package/lib/helpers.js +9 -0
- package/lib/service.d.ts +46 -7
- package/lib/service.js +88 -18
- package/package.json +7 -3
- package/src/helpers.ts +11 -0
- package/src/service.ts +131 -37
package/lib/helpers.d.ts
ADDED
package/lib/helpers.js
ADDED
package/lib/service.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Bud } from '@roots/bud-framework';
|
|
2
|
-
import type { Configuration } from '@roots/bud-framework/config';
|
|
3
|
-
import type { Cache as BudCache } from '@roots/bud-framework/services';
|
|
2
|
+
import type { Configuration, FileCacheOptions } from '@roots/bud-framework/config';
|
|
3
|
+
import type { Cache as BudCache, CacheCallback as Callback } from '@roots/bud-framework/services/cache';
|
|
4
4
|
import { Service } from '@roots/bud-framework/service';
|
|
5
5
|
/**
|
|
6
6
|
* {@link Bud.cache}
|
|
@@ -10,6 +10,11 @@ export default class Cache extends Service implements BudCache {
|
|
|
10
10
|
* {@link BudCache.enabled}
|
|
11
11
|
*/
|
|
12
12
|
enabled: boolean;
|
|
13
|
+
set allowCollectingMemory(value: Callback<FileCacheOptions[`allowCollectingMemory`]>);
|
|
14
|
+
/**
|
|
15
|
+
* {@link BudCache.allowCollectingMemory}
|
|
16
|
+
*/
|
|
17
|
+
get allowCollectingMemory(): FileCacheOptions[`allowCollectingMemory`];
|
|
13
18
|
/**
|
|
14
19
|
* {@link Service.boot}
|
|
15
20
|
*/
|
|
@@ -17,13 +22,13 @@ export default class Cache extends Service implements BudCache {
|
|
|
17
22
|
/**
|
|
18
23
|
*{@link BudCache.buildDependencies}
|
|
19
24
|
*/
|
|
20
|
-
get buildDependencies():
|
|
21
|
-
set buildDependencies(dependencies:
|
|
25
|
+
get buildDependencies(): FileCacheOptions[`buildDependencies`];
|
|
26
|
+
set buildDependencies(dependencies: Callback<FileCacheOptions[`buildDependencies`]>);
|
|
22
27
|
/**
|
|
23
28
|
* {@link BudCache.cacheDirectory}
|
|
24
29
|
*/
|
|
25
30
|
get cacheDirectory(): string;
|
|
26
|
-
set cacheDirectory(directory:
|
|
31
|
+
set cacheDirectory(directory: Callback<FileCacheOptions[`cacheDirectory`]>);
|
|
27
32
|
/**
|
|
28
33
|
* {@link BudCache.configuration}
|
|
29
34
|
* @readonly
|
|
@@ -33,6 +38,24 @@ export default class Cache extends Service implements BudCache {
|
|
|
33
38
|
* {@link BudCache.flush}
|
|
34
39
|
*/
|
|
35
40
|
flush(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Get {@link BudCache.allowCollectingMemory}
|
|
43
|
+
*/
|
|
44
|
+
getAllowCollectingMemory(): boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get {@link BudCache.buildDependencies}
|
|
47
|
+
*/
|
|
48
|
+
getBuildDependencies(): {
|
|
49
|
+
[index: string]: string[];
|
|
50
|
+
} | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Get {@link BudCache.cacheDirectory}
|
|
53
|
+
*/
|
|
54
|
+
getCacheDirectory(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Get {@link BudCache.type}
|
|
57
|
+
*/
|
|
58
|
+
getType(): "filesystem" | "memory";
|
|
36
59
|
/**
|
|
37
60
|
* {@link BudCache.name}
|
|
38
61
|
*/
|
|
@@ -42,14 +65,30 @@ export default class Cache extends Service implements BudCache {
|
|
|
42
65
|
* {@link BudCache.register}
|
|
43
66
|
*/
|
|
44
67
|
register?(bud: Bud): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Set {@link BudCache.allowCollectingMemory}
|
|
70
|
+
*/
|
|
71
|
+
setAllowCollectingMemory(value: Callback<FileCacheOptions[`allowCollectingMemory`]>): this;
|
|
72
|
+
/**
|
|
73
|
+
* Set {@link BudCache.buildDependencies}
|
|
74
|
+
*/
|
|
75
|
+
setBuildDependencies(dependencies: ((records?: Record<string, Array<string>>) => Record<string, Array<string>>) | Record<string, Array<string>>): this;
|
|
76
|
+
/**
|
|
77
|
+
* Set {@link BudCache.cacheDirectory}
|
|
78
|
+
*/
|
|
79
|
+
setCacheDirectory(directory: Callback<FileCacheOptions[`cacheDirectory`]>): this;
|
|
80
|
+
/**
|
|
81
|
+
* Set {@link BudCache.type}
|
|
82
|
+
*/
|
|
83
|
+
setType(type: Callback<FileCacheOptions[`type`]>): this;
|
|
84
|
+
set type(type: Callback<FileCacheOptions[`type`]>);
|
|
45
85
|
/**
|
|
46
86
|
* {@link BudCache.type}
|
|
47
87
|
*/
|
|
48
88
|
get type(): 'filesystem' | 'memory';
|
|
49
|
-
set
|
|
89
|
+
set version(version: string);
|
|
50
90
|
/**
|
|
51
91
|
* {@link BudCache.version}
|
|
52
92
|
*/
|
|
53
93
|
get version(): string | undefined;
|
|
54
|
-
set version(version: string);
|
|
55
94
|
}
|
package/lib/service.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import { isBuildDependency } from '@roots/bud-cache/helpers';
|
|
3
4
|
import { Service } from '@roots/bud-framework/service';
|
|
4
5
|
import { bind } from '@roots/bud-support/decorators/bind';
|
|
5
6
|
import isString from '@roots/bud-support/lodash/isString';
|
|
@@ -7,6 +8,17 @@ import isString from '@roots/bud-support/lodash/isString';
|
|
|
7
8
|
* {@link Bud.cache}
|
|
8
9
|
*/
|
|
9
10
|
export default class Cache extends Service {
|
|
11
|
+
set allowCollectingMemory(value) {
|
|
12
|
+
this.app.hooks.on(`build.cache.allowCollectingMemory`, value);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* {@link BudCache.allowCollectingMemory}
|
|
16
|
+
*/
|
|
17
|
+
get allowCollectingMemory() {
|
|
18
|
+
const fallback = true;
|
|
19
|
+
const value = this.app.hooks.filter(`build.cache.allowCollectingMemory`, fallback);
|
|
20
|
+
return typeof value === `boolean` ? value : fallback;
|
|
21
|
+
}
|
|
10
22
|
/**
|
|
11
23
|
* {@link Service.boot}
|
|
12
24
|
*/
|
|
@@ -20,15 +32,17 @@ export default class Cache extends Service {
|
|
|
20
32
|
*{@link BudCache.buildDependencies}
|
|
21
33
|
*/
|
|
22
34
|
get buildDependencies() {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
const dependencies = new Set([
|
|
36
|
+
this.app.context.files[`package`]?.path,
|
|
37
|
+
...Object.values(this.app.context.files)
|
|
38
|
+
.filter(isBuildDependency)
|
|
39
|
+
.map(({ path }) => path),
|
|
40
|
+
].filter(Boolean));
|
|
41
|
+
const records = {
|
|
42
|
+
bud: [...dependencies],
|
|
30
43
|
};
|
|
31
|
-
return (this.app.hooks.filter(`build.cache.buildDependencies`,
|
|
44
|
+
return (this.app.hooks.filter(`build.cache.buildDependencies`, records) ??
|
|
45
|
+
records);
|
|
32
46
|
}
|
|
33
47
|
set buildDependencies(dependencies) {
|
|
34
48
|
this.app.hooks.on(`build.cache.buildDependencies`, dependencies);
|
|
@@ -37,7 +51,9 @@ export default class Cache extends Service {
|
|
|
37
51
|
* {@link BudCache.cacheDirectory}
|
|
38
52
|
*/
|
|
39
53
|
get cacheDirectory() {
|
|
40
|
-
|
|
54
|
+
const fallback = this.app.path(`@storage`, this.app.label, `cache`);
|
|
55
|
+
return (this.app.hooks.filter(`build.cache.cacheDirectory`, fallback) ??
|
|
56
|
+
fallback);
|
|
41
57
|
}
|
|
42
58
|
set cacheDirectory(directory) {
|
|
43
59
|
this.app.hooks.on(`build.cache.cacheDirectory`, directory);
|
|
@@ -52,7 +68,7 @@ export default class Cache extends Service {
|
|
|
52
68
|
if (this.type === `memory`)
|
|
53
69
|
return true;
|
|
54
70
|
return {
|
|
55
|
-
allowCollectingMemory:
|
|
71
|
+
allowCollectingMemory: this.allowCollectingMemory,
|
|
56
72
|
buildDependencies: this.buildDependencies,
|
|
57
73
|
cacheDirectory: this.cacheDirectory,
|
|
58
74
|
compression: this.app.isDevelopment ? false : `brotli`,
|
|
@@ -72,11 +88,36 @@ export default class Cache extends Service {
|
|
|
72
88
|
async flush() {
|
|
73
89
|
await this.app.fs.remove(this.cacheDirectory);
|
|
74
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Get {@link BudCache.allowCollectingMemory}
|
|
93
|
+
*/
|
|
94
|
+
getAllowCollectingMemory() {
|
|
95
|
+
return this.allowCollectingMemory;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get {@link BudCache.buildDependencies}
|
|
99
|
+
*/
|
|
100
|
+
getBuildDependencies() {
|
|
101
|
+
return this.buildDependencies;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get {@link BudCache.cacheDirectory}
|
|
105
|
+
*/
|
|
106
|
+
getCacheDirectory() {
|
|
107
|
+
return this.cacheDirectory;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get {@link BudCache.type}
|
|
111
|
+
*/
|
|
112
|
+
getType() {
|
|
113
|
+
return this.type;
|
|
114
|
+
}
|
|
75
115
|
/**
|
|
76
116
|
* {@link BudCache.name}
|
|
77
117
|
*/
|
|
78
118
|
get name() {
|
|
79
|
-
|
|
119
|
+
const fallback = join(this.app.mode, ...Object.values(this.app.context._ ?? {}));
|
|
120
|
+
return (this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, fallback)) ?? fallback);
|
|
80
121
|
}
|
|
81
122
|
set name(name) {
|
|
82
123
|
this.app.hooks.on(`build.cache.name`, name);
|
|
@@ -88,16 +129,48 @@ export default class Cache extends Service {
|
|
|
88
129
|
this.enabled = bud.context.cache !== false;
|
|
89
130
|
this.version = bud.context.bud.version;
|
|
90
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Set {@link BudCache.allowCollectingMemory}
|
|
134
|
+
*/
|
|
135
|
+
setAllowCollectingMemory(value) {
|
|
136
|
+
this.allowCollectingMemory = value;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set {@link BudCache.buildDependencies}
|
|
141
|
+
*/
|
|
142
|
+
setBuildDependencies(dependencies) {
|
|
143
|
+
this.buildDependencies = dependencies;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Set {@link BudCache.cacheDirectory}
|
|
148
|
+
*/
|
|
149
|
+
setCacheDirectory(directory) {
|
|
150
|
+
this.cacheDirectory = directory;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set {@link BudCache.type}
|
|
155
|
+
*/
|
|
156
|
+
setType(type) {
|
|
157
|
+
this.type = type;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
set type(type) {
|
|
161
|
+
this.app.hooks.on(`build.cache.type`, type);
|
|
162
|
+
}
|
|
91
163
|
/**
|
|
92
164
|
* {@link BudCache.type}
|
|
93
165
|
*/
|
|
94
166
|
get type() {
|
|
95
|
-
|
|
167
|
+
const fallback = isString(this.app.context.cache)
|
|
96
168
|
? this.app.context.cache
|
|
97
|
-
: `filesystem
|
|
169
|
+
: `filesystem`;
|
|
170
|
+
return this.app.hooks.filter(`build.cache.type`) ?? fallback;
|
|
98
171
|
}
|
|
99
|
-
set
|
|
100
|
-
this.app.hooks.on(`build.cache.
|
|
172
|
+
set version(version) {
|
|
173
|
+
this.app.hooks.on(`build.cache.version`, version);
|
|
101
174
|
}
|
|
102
175
|
/**
|
|
103
176
|
* {@link BudCache.version}
|
|
@@ -105,9 +178,6 @@ export default class Cache extends Service {
|
|
|
105
178
|
get version() {
|
|
106
179
|
return this.app.hooks.filter(`build.cache.version`, undefined);
|
|
107
180
|
}
|
|
108
|
-
set version(version) {
|
|
109
|
-
this.app.hooks.on(`build.cache.version`, version);
|
|
110
|
-
}
|
|
111
181
|
}
|
|
112
182
|
__decorate([
|
|
113
183
|
bind
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roots/bud-cache",
|
|
3
|
-
"version": "6.15.
|
|
3
|
+
"version": "6.15.2",
|
|
4
4
|
"description": "Config caching",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"type": "module",
|
|
51
51
|
"exports": {
|
|
52
52
|
".": "./lib/index.js",
|
|
53
|
+
"./helpers": "./lib/helpers.js",
|
|
53
54
|
"./service": "./lib/service.js"
|
|
54
55
|
},
|
|
55
56
|
"typesVersions": {
|
|
@@ -57,6 +58,9 @@
|
|
|
57
58
|
".": [
|
|
58
59
|
"./lib/index.d.ts"
|
|
59
60
|
],
|
|
61
|
+
"./helpers": [
|
|
62
|
+
"./lib/helpers.d.ts"
|
|
63
|
+
],
|
|
60
64
|
"service": [
|
|
61
65
|
"./lib/service.d.ts"
|
|
62
66
|
]
|
|
@@ -68,8 +72,8 @@
|
|
|
68
72
|
"@skypack/package-check": "0.2.2"
|
|
69
73
|
},
|
|
70
74
|
"dependencies": {
|
|
71
|
-
"@roots/bud-framework": "6.15.
|
|
72
|
-
"@roots/bud-support": "6.15.
|
|
75
|
+
"@roots/bud-framework": "6.15.2",
|
|
76
|
+
"@roots/bud-support": "6.15.2",
|
|
73
77
|
"strip-ansi": "7.1.0",
|
|
74
78
|
"tslib": "2.6.1"
|
|
75
79
|
},
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { File } from "@roots/bud-framework/context";
|
|
2
|
+
|
|
3
|
+
export const isBuildDependency = (file: File): boolean => [
|
|
4
|
+
`.npmrc`,
|
|
5
|
+
`.pnpmfile`,
|
|
6
|
+
`.yarnrc`,
|
|
7
|
+
`jsconfig`,
|
|
8
|
+
`package`,
|
|
9
|
+
`pnpm-workspace`,
|
|
10
|
+
`tsconfig`,
|
|
11
|
+
].includes(file.name) || file.bud
|
package/src/service.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import type {Bud} from '@roots/bud-framework'
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
Configuration,
|
|
4
|
+
FileCacheOptions,
|
|
5
|
+
} from '@roots/bud-framework/config'
|
|
6
|
+
import type {
|
|
7
|
+
Cache as BudCache,
|
|
8
|
+
CacheCallback as Callback,
|
|
9
|
+
} from '@roots/bud-framework/services/cache'
|
|
4
10
|
|
|
5
11
|
import {join} from 'node:path'
|
|
6
12
|
|
|
13
|
+
import {isBuildDependency} from '@roots/bud-cache/helpers'
|
|
7
14
|
import {Service} from '@roots/bud-framework/service'
|
|
8
15
|
import {bind} from '@roots/bud-support/decorators/bind'
|
|
9
16
|
import isString from '@roots/bud-support/lodash/isString'
|
|
@@ -16,6 +23,24 @@ export default class Cache extends Service implements BudCache {
|
|
|
16
23
|
* {@link BudCache.enabled}
|
|
17
24
|
*/
|
|
18
25
|
public declare enabled: boolean
|
|
26
|
+
public set allowCollectingMemory(
|
|
27
|
+
value: Callback<FileCacheOptions[`allowCollectingMemory`]>,
|
|
28
|
+
) {
|
|
29
|
+
this.app.hooks.on(`build.cache.allowCollectingMemory`, value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* {@link BudCache.allowCollectingMemory}
|
|
34
|
+
*/
|
|
35
|
+
public get allowCollectingMemory(): FileCacheOptions[`allowCollectingMemory`] {
|
|
36
|
+
const fallback = true
|
|
37
|
+
|
|
38
|
+
const value = this.app.hooks.filter(
|
|
39
|
+
`build.cache.allowCollectingMemory`,
|
|
40
|
+
fallback,
|
|
41
|
+
)
|
|
42
|
+
return typeof value === `boolean` ? value : fallback
|
|
43
|
+
}
|
|
19
44
|
|
|
20
45
|
/**
|
|
21
46
|
* {@link Service.boot}
|
|
@@ -30,25 +55,26 @@ export default class Cache extends Service implements BudCache {
|
|
|
30
55
|
/**
|
|
31
56
|
*{@link BudCache.buildDependencies}
|
|
32
57
|
*/
|
|
33
|
-
public get buildDependencies():
|
|
34
|
-
const
|
|
35
|
-
|
|
58
|
+
public get buildDependencies(): FileCacheOptions[`buildDependencies`] {
|
|
59
|
+
const dependencies = new Set(
|
|
60
|
+
[
|
|
36
61
|
this.app.context.files[`package`]?.path,
|
|
37
62
|
...Object.values(this.app.context.files)
|
|
38
|
-
.filter(
|
|
63
|
+
.filter(isBuildDependency)
|
|
39
64
|
.map(({path}) => path),
|
|
40
65
|
].filter(Boolean),
|
|
66
|
+
)
|
|
67
|
+
const records = {
|
|
68
|
+
bud: [...dependencies],
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
return (
|
|
44
|
-
this.app.hooks.filter(
|
|
45
|
-
|
|
46
|
-
baseDependencies,
|
|
47
|
-
) ?? baseDependencies
|
|
72
|
+
this.app.hooks.filter(`build.cache.buildDependencies`, records) ??
|
|
73
|
+
records
|
|
48
74
|
)
|
|
49
75
|
}
|
|
50
76
|
public set buildDependencies(
|
|
51
|
-
dependencies:
|
|
77
|
+
dependencies: Callback<FileCacheOptions[`buildDependencies`]>,
|
|
52
78
|
) {
|
|
53
79
|
this.app.hooks.on(`build.cache.buildDependencies`, dependencies)
|
|
54
80
|
}
|
|
@@ -57,14 +83,16 @@ export default class Cache extends Service implements BudCache {
|
|
|
57
83
|
* {@link BudCache.cacheDirectory}
|
|
58
84
|
*/
|
|
59
85
|
public get cacheDirectory(): string {
|
|
86
|
+
const fallback = this.app.path(`@storage`, this.app.label, `cache`)
|
|
60
87
|
return (
|
|
61
|
-
this.app.hooks.filter(
|
|
62
|
-
|
|
63
|
-
this.app.path(`@storage`, this.app.label, `cache`),
|
|
64
|
-
) ?? this.app.path(`@storage`, this.app.label, `cache`)
|
|
88
|
+
this.app.hooks.filter(`build.cache.cacheDirectory`, fallback) ??
|
|
89
|
+
fallback
|
|
65
90
|
)
|
|
66
91
|
}
|
|
67
|
-
|
|
92
|
+
|
|
93
|
+
public set cacheDirectory(
|
|
94
|
+
directory: Callback<FileCacheOptions[`cacheDirectory`]>,
|
|
95
|
+
) {
|
|
68
96
|
this.app.hooks.on(`build.cache.cacheDirectory`, directory)
|
|
69
97
|
}
|
|
70
98
|
|
|
@@ -77,7 +105,7 @@ export default class Cache extends Service implements BudCache {
|
|
|
77
105
|
if (this.type === `memory`) return true
|
|
78
106
|
|
|
79
107
|
return {
|
|
80
|
-
allowCollectingMemory:
|
|
108
|
+
allowCollectingMemory: this.allowCollectingMemory,
|
|
81
109
|
buildDependencies: this.buildDependencies,
|
|
82
110
|
cacheDirectory: this.cacheDirectory,
|
|
83
111
|
compression: this.app.isDevelopment ? false : `brotli`,
|
|
@@ -91,7 +119,6 @@ export default class Cache extends Service implements BudCache {
|
|
|
91
119
|
type: this.type,
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
|
-
|
|
95
122
|
/**
|
|
96
123
|
* {@link BudCache.flush}
|
|
97
124
|
*/
|
|
@@ -100,20 +127,48 @@ export default class Cache extends Service implements BudCache {
|
|
|
100
127
|
await this.app.fs.remove(this.cacheDirectory)
|
|
101
128
|
}
|
|
102
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Get {@link BudCache.allowCollectingMemory}
|
|
132
|
+
*/
|
|
133
|
+
public getAllowCollectingMemory() {
|
|
134
|
+
return this.allowCollectingMemory
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get {@link BudCache.buildDependencies}
|
|
138
|
+
*/
|
|
139
|
+
public getBuildDependencies() {
|
|
140
|
+
return this.buildDependencies
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get {@link BudCache.cacheDirectory}
|
|
145
|
+
*/
|
|
146
|
+
public getCacheDirectory() {
|
|
147
|
+
return this.cacheDirectory
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get {@link BudCache.type}
|
|
151
|
+
*/
|
|
152
|
+
public getType() {
|
|
153
|
+
return this.type
|
|
154
|
+
}
|
|
155
|
+
|
|
103
156
|
/**
|
|
104
157
|
* {@link BudCache.name}
|
|
105
158
|
*/
|
|
106
159
|
public get name(): string {
|
|
160
|
+
const fallback = join(
|
|
161
|
+
this.app.mode,
|
|
162
|
+
...Object.values(this.app.context._ ?? {}),
|
|
163
|
+
)
|
|
107
164
|
return (
|
|
108
165
|
this.app.hooks.filter(
|
|
109
166
|
`build.cache.name`,
|
|
110
|
-
this.app.hooks.filter(
|
|
111
|
-
|
|
112
|
-
join(this.app.mode, ...Object.values(this.app.context._ ?? {})),
|
|
113
|
-
),
|
|
114
|
-
) ?? join(this.app.mode, ...Object.values(this.app.context._ ?? {}))
|
|
167
|
+
this.app.hooks.filter(`build.name`, fallback),
|
|
168
|
+
) ?? fallback
|
|
115
169
|
)
|
|
116
170
|
}
|
|
171
|
+
|
|
117
172
|
public set name(name: string) {
|
|
118
173
|
this.app.hooks.on(`build.cache.name`, name)
|
|
119
174
|
}
|
|
@@ -125,31 +180,70 @@ export default class Cache extends Service implements BudCache {
|
|
|
125
180
|
this.enabled = bud.context.cache !== false
|
|
126
181
|
this.version = bud.context.bud.version
|
|
127
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Set {@link BudCache.allowCollectingMemory}
|
|
185
|
+
*/
|
|
186
|
+
public setAllowCollectingMemory(
|
|
187
|
+
value: Callback<FileCacheOptions[`allowCollectingMemory`]>,
|
|
188
|
+
): this {
|
|
189
|
+
this.allowCollectingMemory = value
|
|
190
|
+
return this
|
|
191
|
+
}
|
|
128
192
|
|
|
129
193
|
/**
|
|
130
|
-
* {@link BudCache.
|
|
194
|
+
* Set {@link BudCache.buildDependencies}
|
|
131
195
|
*/
|
|
132
|
-
public
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
196
|
+
public setBuildDependencies(
|
|
197
|
+
dependencies:
|
|
198
|
+
| ((
|
|
199
|
+
records?: Record<string, Array<string>>,
|
|
200
|
+
) => Record<string, Array<string>>)
|
|
201
|
+
| Record<string, Array<string>>,
|
|
202
|
+
) {
|
|
203
|
+
this.buildDependencies = dependencies
|
|
204
|
+
return this
|
|
141
205
|
}
|
|
142
|
-
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Set {@link BudCache.cacheDirectory}
|
|
209
|
+
*/
|
|
210
|
+
public setCacheDirectory(
|
|
211
|
+
directory: Callback<FileCacheOptions[`cacheDirectory`]>,
|
|
212
|
+
) {
|
|
213
|
+
this.cacheDirectory = directory
|
|
214
|
+
return this
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Set {@link BudCache.type}
|
|
219
|
+
*/
|
|
220
|
+
public setType(type: Callback<FileCacheOptions[`type`]>) {
|
|
221
|
+
this.type = type
|
|
222
|
+
return this
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
public set type(type: Callback<FileCacheOptions[`type`]>) {
|
|
143
226
|
this.app.hooks.on(`build.cache.type`, type)
|
|
144
227
|
}
|
|
145
228
|
|
|
146
229
|
/**
|
|
147
|
-
* {@link BudCache.
|
|
230
|
+
* {@link BudCache.type}
|
|
148
231
|
*/
|
|
149
|
-
public get
|
|
150
|
-
|
|
232
|
+
public get type(): 'filesystem' | 'memory' {
|
|
233
|
+
const fallback = isString(this.app.context.cache)
|
|
234
|
+
? this.app.context.cache
|
|
235
|
+
: `filesystem`
|
|
236
|
+
|
|
237
|
+
return this.app.hooks.filter(`build.cache.type`) ?? fallback
|
|
151
238
|
}
|
|
239
|
+
|
|
152
240
|
public set version(version: string) {
|
|
153
241
|
this.app.hooks.on(`build.cache.version`, version)
|
|
154
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* {@link BudCache.version}
|
|
245
|
+
*/
|
|
246
|
+
public get version(): string | undefined {
|
|
247
|
+
return this.app.hooks.filter(`build.cache.version`, undefined)
|
|
248
|
+
}
|
|
155
249
|
}
|