@roots/bud-cache 2024.6.4-7 → 2024.6.5-7

Sign up to get free protection for your applications and to get access to all the features.
package/lib/helpers.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { File } from '@roots/bud-framework/context';
2
2
  export declare const isBuildDependency: (file: File) => boolean;
3
+ export declare const isBudConfig: (file: File) => boolean;
package/lib/helpers.js CHANGED
@@ -6,4 +6,5 @@ export const isBuildDependency = (file) => [
6
6
  `package`,
7
7
  `pnpm-workspace`,
8
8
  `tsconfig`,
9
- ].includes(file.name) || file.bud;
9
+ ].some(match => file.name.includes(match));
10
+ export const isBudConfig = (file) => file.name.includes(`bud`);
package/lib/service.d.ts CHANGED
@@ -19,7 +19,7 @@ export default class Cache extends Service implements BudCache {
19
19
  *{@link BudCache.buildDependencies}
20
20
  */
21
21
  get buildDependencies(): FileCacheOptions[`buildDependencies`];
22
- set buildDependencies(dependencies: Callback<FileCacheOptions[`buildDependencies`]>);
22
+ set buildDependencies(dependencies: Callback<FileCacheOptions[`buildDependencies`]> | FileCacheOptions[`buildDependencies`]);
23
23
  /**
24
24
  * {@link BudCache.cacheDirectory}
25
25
  */
@@ -71,10 +71,6 @@ export default class Cache extends Service implements BudCache {
71
71
  * Get {@link BudCache.type}
72
72
  */
73
73
  getType(): "filesystem" | "memory";
74
- /**
75
- * {@link BudCache.register}
76
- */
77
- register?(bud: Bud): Promise<void>;
78
74
  /**
79
75
  * Set {@link BudCache.allowCollectingMemory}
80
76
  */
package/lib/service.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { join } from 'node:path';
3
- import { isBuildDependency } from '@roots/bud-cache/helpers';
3
+ import { isBudConfig, isBuildDependency } from '@roots/bud-cache/helpers';
4
4
  import { Service } from '@roots/bud-framework/service';
5
5
  import { bind } from '@roots/bud-support/decorators/bind';
6
6
  /**
@@ -11,7 +11,7 @@ export default class Cache extends Service {
11
11
  * {@link BudCache.allowCollectingMemory}
12
12
  */
13
13
  get allowCollectingMemory() {
14
- const fallback = true;
14
+ const fallback = false;
15
15
  const value = this.app.hooks.filter(`build.cache.allowCollectingMemory`, fallback);
16
16
  return typeof value === `boolean` ? value : fallback;
17
17
  }
@@ -22,17 +22,7 @@ export default class Cache extends Service {
22
22
  *{@link BudCache.buildDependencies}
23
23
  */
24
24
  get buildDependencies() {
25
- const projectDependencies = new Set([
26
- this.app.context.files[`package`]?.path,
27
- ...Object.values(this.app.context.files)
28
- .filter(isBuildDependency)
29
- .map(({ path }) => path),
30
- ]);
31
- const records = {
32
- project: [...projectDependencies].filter(Boolean),
33
- };
34
- return (this.app.hooks.filter(`build.cache.buildDependencies`, records) ??
35
- records);
25
+ return this.app.hooks.filter(`build.cache.buildDependencies`);
36
26
  }
37
27
  set buildDependencies(dependencies) {
38
28
  this.app.hooks.on(`build.cache.buildDependencies`, dependencies);
@@ -85,32 +75,58 @@ export default class Cache extends Service {
85
75
  await this.flush();
86
76
  }
87
77
  this.enabled = bud.context.cache !== false;
78
+ this.setBuildDependencies(deps => ({
79
+ ...(deps ?? {}),
80
+ config: [
81
+ ...new Set([
82
+ ...Object.values(this.app.context.files)
83
+ .filter(isBudConfig)
84
+ .map(({ path }) => path),
85
+ ...(deps?.config ?? []),
86
+ ]),
87
+ ].filter(Boolean),
88
+ project: [
89
+ ...new Set([
90
+ ...Object.values(this.app.context.files)
91
+ .filter(isBuildDependency)
92
+ .map(({ path }) => path),
93
+ ...(deps?.project ?? []),
94
+ ]),
95
+ ].filter(Boolean),
96
+ }));
88
97
  }
89
98
  /**
90
99
  * {@link BudCache.configuration}
91
100
  * @readonly
92
101
  */
93
102
  get configuration() {
94
- if (this.enabled !== true)
103
+ if (this.enabled !== true) {
104
+ this.logger.log(`Cache: disabled`);
95
105
  return false;
96
- if (this.type === `memory`)
106
+ }
107
+ if (this.type === `memory`) {
108
+ this.logger.log(`Cache: memory`);
97
109
  return {
98
110
  cacheUnaffected: true,
99
111
  maxGenerations: Infinity,
100
112
  type: `memory`,
101
113
  };
114
+ }
115
+ this.logger.log(`Cache: filesystem`);
102
116
  return {
103
117
  allowCollectingMemory: this.allowCollectingMemory,
104
118
  buildDependencies: this.buildDependencies,
105
119
  cacheDirectory: this.cacheDirectory,
106
- compression: this.app.isDevelopment ? false : `brotli`,
120
+ compression: false,
107
121
  hashAlgorithm: `xxhash64`,
108
- idleTimeout: 100,
122
+ idleTimeout: 10000,
109
123
  idleTimeoutForInitialStore: 0,
110
- managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
111
- maxMemoryGenerations: Infinity,
124
+ managedPaths: [this.app.path(`@modules`)],
125
+ maxMemoryGenerations: this.app.isDevelopment ? 10 : Infinity,
126
+ memoryCacheUnaffected: true,
112
127
  name: this.name,
113
128
  profile: this.app.context.debug === true,
129
+ readonly: this.app.env.isTrue(`CI`),
114
130
  store: `pack`,
115
131
  type: this.type,
116
132
  };
@@ -145,13 +161,6 @@ export default class Cache extends Service {
145
161
  getType() {
146
162
  return this.type;
147
163
  }
148
- /**
149
- * {@link BudCache.register}
150
- */
151
- async register(bud) {
152
- this.enabled = bud.context.cache !== false;
153
- this.version = bud.context.bud.version;
154
- }
155
164
  /**
156
165
  * Set {@link BudCache.allowCollectingMemory}
157
166
  */
@@ -187,6 +196,3 @@ __decorate([
187
196
  __decorate([
188
197
  bind
189
198
  ], Cache.prototype, "flush", null);
190
- __decorate([
191
- bind
192
- ], Cache.prototype, "register", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-cache",
3
- "version": "2024.6.4-7",
3
+ "version": "2024.6.5-7",
4
4
  "description": "Config caching",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -72,8 +72,8 @@
72
72
  "@skypack/package-check": "0.2.2"
73
73
  },
74
74
  "dependencies": {
75
- "@roots/bud-framework": "2024.6.4-7",
76
- "@roots/bud-support": "2024.6.4-7",
75
+ "@roots/bud-framework": "2024.6.5-7",
76
+ "@roots/bud-support": "2024.6.5-7",
77
77
  "strip-ansi": "7.1.0",
78
78
  "tslib": "2.6.2"
79
79
  },
package/src/helpers.ts CHANGED
@@ -9,4 +9,7 @@ export const isBuildDependency = (file: File): boolean =>
9
9
  `package`,
10
10
  `pnpm-workspace`,
11
11
  `tsconfig`,
12
- ].includes(file.name) || file.bud
12
+ ].some(match => file.name.includes(match))
13
+
14
+ export const isBudConfig = (file: File): boolean =>
15
+ file.name.includes(`bud`)
package/src/service.ts CHANGED
@@ -10,7 +10,7 @@ import type {
10
10
 
11
11
  import {join} from 'node:path'
12
12
 
13
- import {isBuildDependency} from '@roots/bud-cache/helpers'
13
+ import {isBudConfig, isBuildDependency} from '@roots/bud-cache/helpers'
14
14
  import {Service} from '@roots/bud-framework/service'
15
15
  import {bind} from '@roots/bud-support/decorators/bind'
16
16
 
@@ -22,11 +22,12 @@ export default class Cache extends Service implements BudCache {
22
22
  * {@link BudCache.enabled}
23
23
  */
24
24
  public declare enabled: boolean
25
+
25
26
  /**
26
27
  * {@link BudCache.allowCollectingMemory}
27
28
  */
28
29
  public get allowCollectingMemory(): FileCacheOptions[`allowCollectingMemory`] {
29
- const fallback = true
30
+ const fallback = false
30
31
 
31
32
  const value = this.app.hooks.filter(
32
33
  `build.cache.allowCollectingMemory`,
@@ -44,23 +45,13 @@ export default class Cache extends Service implements BudCache {
44
45
  *{@link BudCache.buildDependencies}
45
46
  */
46
47
  public get buildDependencies(): FileCacheOptions[`buildDependencies`] {
47
- const projectDependencies = new Set([
48
- this.app.context.files[`package`]?.path,
49
- ...Object.values(this.app.context.files)
50
- .filter(isBuildDependency)
51
- .map(({path}) => path),
52
- ])
53
- const records = {
54
- project: [...projectDependencies].filter(Boolean),
55
- }
56
-
57
- return (
58
- this.app.hooks.filter(`build.cache.buildDependencies`, records) ??
59
- records
60
- )
48
+ return this.app.hooks.filter(`build.cache.buildDependencies`)
61
49
  }
50
+
62
51
  public set buildDependencies(
63
- dependencies: Callback<FileCacheOptions[`buildDependencies`]>,
52
+ dependencies:
53
+ | Callback<FileCacheOptions[`buildDependencies`]>
54
+ | FileCacheOptions[`buildDependencies`],
64
55
  ) {
65
56
  this.app.hooks.on(`build.cache.buildDependencies`, dependencies)
66
57
  }
@@ -132,6 +123,26 @@ export default class Cache extends Service implements BudCache {
132
123
  await this.flush()
133
124
  }
134
125
  this.enabled = bud.context.cache !== false
126
+
127
+ this.setBuildDependencies(deps => ({
128
+ ...(deps ?? {}),
129
+ config: [
130
+ ...new Set([
131
+ ...Object.values(this.app.context.files)
132
+ .filter(isBudConfig)
133
+ .map(({path}) => path),
134
+ ...(deps?.config ?? []),
135
+ ]),
136
+ ].filter(Boolean),
137
+ project: [
138
+ ...new Set([
139
+ ...Object.values(this.app.context.files)
140
+ .filter(isBuildDependency)
141
+ .map(({path}) => path),
142
+ ...(deps?.project ?? []),
143
+ ]),
144
+ ].filter(Boolean),
145
+ }))
135
146
  }
136
147
 
137
148
  /**
@@ -139,26 +150,34 @@ export default class Cache extends Service implements BudCache {
139
150
  * @readonly
140
151
  */
141
152
  public get configuration(): Configuration[`cache`] {
142
- if (this.enabled !== true) return false
143
- if (this.type === `memory`)
153
+ if (this.enabled !== true) {
154
+ this.logger.log(`Cache: disabled`)
155
+ return false
156
+ }
157
+ if (this.type === `memory`) {
158
+ this.logger.log(`Cache: memory`)
144
159
  return {
145
160
  cacheUnaffected: true,
146
161
  maxGenerations: Infinity,
147
162
  type: `memory`,
148
163
  }
164
+ }
149
165
 
166
+ this.logger.log(`Cache: filesystem`)
150
167
  return {
151
168
  allowCollectingMemory: this.allowCollectingMemory,
152
169
  buildDependencies: this.buildDependencies,
153
170
  cacheDirectory: this.cacheDirectory,
154
- compression: this.app.isDevelopment ? false : `brotli`,
171
+ compression: false,
155
172
  hashAlgorithm: `xxhash64`,
156
- idleTimeout: 100,
173
+ idleTimeout: 10000,
157
174
  idleTimeoutForInitialStore: 0,
158
- managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
159
- maxMemoryGenerations: Infinity,
175
+ managedPaths: [this.app.path(`@modules`)],
176
+ maxMemoryGenerations: this.app.isDevelopment ? 10 : Infinity,
177
+ memoryCacheUnaffected: true,
160
178
  name: this.name,
161
179
  profile: this.app.context.debug === true,
180
+ readonly: this.app.env.isTrue(`CI`),
162
181
  store: `pack`,
163
182
  type: this.type,
164
183
  }
@@ -197,14 +216,6 @@ export default class Cache extends Service implements BudCache {
197
216
  return this.type
198
217
  }
199
218
 
200
- /**
201
- * {@link BudCache.register}
202
- */
203
- @bind
204
- public override async register?(bud: Bud) {
205
- this.enabled = bud.context.cache !== false
206
- this.version = bud.context.bud.version
207
- }
208
219
  /**
209
220
  * Set {@link BudCache.allowCollectingMemory}
210
221
  */