@roots/bud-cache 6.11.0 → 6.12.1

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/index.d.ts CHANGED
@@ -3,8 +3,6 @@
3
3
  *
4
4
  * @see {@link https://bud.js.org}
5
5
  * @see {@link https://github.com/roots/bud}
6
- *
7
- * @packageDocumentation
8
6
  */
9
7
  import './types.js';
10
8
  import Cache from './service/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,KAAK,MAAM,oBAAoB,CAAA;AAEtC,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,KAAK,MAAM,oBAAoB,CAAA;AAEtC,eAAe,KAAK,CAAA"}
package/lib/index.js CHANGED
@@ -5,8 +5,6 @@
5
5
  *
6
6
  * @see {@link https://bud.js.org}
7
7
  * @see {@link https://github.com/roots/bud}
8
- *
9
- * @packageDocumentation
10
8
  */
11
9
  import './types.js';
12
10
  import Cache from './service/index.js';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,kCAAkC;AAElC;;;;;;;GAOG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,KAAK,MAAM,oBAAoB,CAAA;AAEtC,eAAe,KAAK,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,kCAAkC;AAElC;;;;;GAKG;AAEH,OAAO,YAAY,CAAA;AAEnB,OAAO,KAAK,MAAM,oBAAoB,CAAA;AAEtC,eAAe,KAAK,CAAA"}
@@ -15,7 +15,7 @@ export default class InvalidateCacheExtension extends Extension {
15
15
  */
16
16
  get invalidationFile(): string;
17
17
  /**
18
- * `register` callback
18
+ * {@link Extension.register}
19
19
  */
20
20
  register(bud: Bud): Promise<void>;
21
21
  }
@@ -20,11 +20,11 @@ let InvalidateCacheExtension = class InvalidateCacheExtension extends Extension
20
20
  return join(this.app.cache.cacheDirectory, `error.json`);
21
21
  }
22
22
  /**
23
- * `register` callback
23
+ * {@link Extension.register}
24
24
  */
25
25
  async register(bud) {
26
26
  const invalidate = await bud.fs?.exists(this.invalidationFile);
27
- if (invalidate || (bud.isCLI() && bud.context.args.flush)) {
27
+ if (invalidate || (bud.isCLI() && bud.context.args.force)) {
28
28
  await bud.fs.remove(this.invalidationFile);
29
29
  await bud.fs.remove(bud.cache.cacheDirectory);
30
30
  }
@@ -30,6 +30,11 @@ export default class Cache extends Service implements Services.Cache.Service {
30
30
  */
31
31
  get cacheDirectory(): string;
32
32
  set cacheDirectory(directory: string);
33
+ /**
34
+ * Cache dependencies
35
+ */
36
+ get buildDependencies(): Record<string, Array<string>>;
37
+ set buildDependencies(dependencies: Record<string, Array<string>>);
33
38
  /**
34
39
  * Webpack configuration
35
40
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,sBAAsB,CAAA;AAC7C,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACpD,OAAO,KAAK,KAAK,QAAQ,MAAM,+BAA+B,CAAA;AAI9D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAA;AAI7D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KACnB,SAAQ,OACR,YAAW,QAAQ,CAAC,KAAK,CAAC,OAAO;IAEjC;;OAEG;IACI,OAAO,EAAE,OAAO,CAAO;IAE9B;;OAEG;IACH,IAAW,IAAI,I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H,IAAW,OAAO,IAAI,MAAM,CAY3B;IACD,IAAW,OAAO,CAAC,OAAO,EAAE,MAAM,EAEjC;IAED;;OAEG;IACH,IAAW,cAAc,IAAI,MAAM,CAKlC;IACD,IAAW,cAAc,CAAC,SAAS,EAAE,MAAM,EAE1C;IAED;;OAEG;IACH,IAAW,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAS5D;IACD,IAAW,iBAAiB,CAC1B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAG5C;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,aAAa,CAAC,OAAO,CAAC,CAgBjD;IAED;;OAEG;IAEmB,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG;IAKtC;;OAEG;IAEU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGpC"}
@@ -1,9 +1,10 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { createHash } from 'node:crypto';
3
+ import { join } from 'node:path';
3
4
  import { Service } from '@roots/bud-framework/service';
4
5
  import { bind } from '@roots/bud-support/decorators';
5
6
  import isString from '@roots/bud-support/lodash/isString';
6
- import join from '@roots/bud-support/lodash/join';
7
+ import { hash } from '@roots/bud-support/utilities/args';
7
8
  import InvalidateCacheExtension from '../invalidate-cache/index.js';
8
9
  /**
9
10
  * Cache service class
@@ -20,7 +21,7 @@ export default class Cache extends Service {
20
21
  * Type
21
22
  */
22
23
  get name() {
23
- return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, this.app.context.label));
24
+ return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)));
24
25
  }
25
26
  set name(name) {
26
27
  this.app.hooks.on(`build.cache.name`, name);
@@ -40,11 +41,12 @@ export default class Cache extends Service {
40
41
  * version
41
42
  */
42
43
  get version() {
43
- const args = this.app.fs.json.stringify(this.app.isCLI() ? this.app.context.args : {});
44
- const files = Object.values(this.app.context.config ?? {}).filter(file => file?.bud && file.sha1);
45
- return this.app.hooks.filter(`build.cache.version`, createHash(`sha1`)
46
- .update(join(args, ...files.map(({ module: { sha1 } }) => sha1)))
47
- .digest(`base64`));
44
+ const version = createHash(`sha1`);
45
+ version.update(hash);
46
+ Object.values(this.app.context.files ?? {})
47
+ .filter(file => file?.bud || file?.name?.includes(`package.json`))
48
+ .map(({ sha1 }) => version.update(sha1));
49
+ return this.app.hooks.filter(`build.cache.version`, version.digest(`base64`));
48
50
  }
49
51
  set version(version) {
50
52
  this.app.hooks.on(`build.cache.version`, version);
@@ -53,37 +55,54 @@ export default class Cache extends Service {
53
55
  * Cache directory
54
56
  */
55
57
  get cacheDirectory() {
56
- return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`, this.app.mode));
58
+ return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`));
57
59
  }
58
60
  set cacheDirectory(directory) {
59
61
  this.app.hooks.on(`build.cache.cacheDirectory`, directory);
60
62
  }
63
+ /**
64
+ * Cache dependencies
65
+ */
66
+ get buildDependencies() {
67
+ return this.app.hooks.filter(`build.cache.buildDependencies`, {
68
+ bud: [
69
+ this.app.context.files?.[`package.json`]?.path,
70
+ ...Object.values(this.app.context.files)
71
+ .filter(({ bud }) => bud)
72
+ .map(({ path }) => path),
73
+ ].filter(Boolean),
74
+ });
75
+ }
76
+ set buildDependencies(dependencies) {
77
+ this.app.hooks.on(`build.cache.buildDependencies`, dependencies);
78
+ }
61
79
  /**
62
80
  * Webpack configuration
63
81
  */
64
82
  get configuration() {
65
83
  if (this.enabled !== true)
66
84
  return false;
67
- return this.type === `memory`
68
- ? true
69
- : {
70
- name: this.name,
71
- type: this.type,
72
- store: `pack`,
73
- allowCollectingMemory: true,
74
- cacheDirectory: this.cacheDirectory,
75
- idleTimeout: 10000,
76
- idleTimeoutForInitialStore: 0,
77
- profile: true,
78
- version: this.version,
79
- };
85
+ if (this.type === `memory`)
86
+ return true;
87
+ return {
88
+ name: this.name,
89
+ type: this.type,
90
+ store: `pack`,
91
+ allowCollectingMemory: true,
92
+ buildDependencies: this.buildDependencies,
93
+ cacheDirectory: this.cacheDirectory,
94
+ idleTimeout: 10000,
95
+ idleTimeoutForInitialStore: 0,
96
+ profile: false,
97
+ version: this.app.hooks.filter(`build.cache.version`, this.version),
98
+ };
80
99
  }
81
100
  /**
82
101
  * {@link Extension.booted}
83
102
  */
84
103
  async booted(bud) {
85
104
  await bud.extensions.add(InvalidateCacheExtension);
86
- this.app.success(`cache initialized`);
105
+ this.logger.success(`cache initialized`);
87
106
  }
88
107
  /**
89
108
  * Flush cache
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AAGtC,OAAO,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAA;AAEpD,OAAO,EAAC,IAAI,EAAC,MAAM,+BAA+B,CAAA;AAClD,OAAO,QAAQ,MAAM,oCAAoC,CAAA;AACzD,OAAO,IAAI,MAAM,gCAAgC,CAAA;AAGjD,OAAO,wBAAwB,MAAM,8BAA8B,CAAA;AAEnE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,KACnB,SAAQ,OAAO;IADjB;;QAIE;;WAEG;QACI,YAAO,GAAY,IAAI,CAAA;IAsGhC,CAAC;IApGC;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAC1B,kBAAkB,EAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAC5D,CAAA;IACH,CAAC;IACD,IAAW,IAAI,CAAC,IAAY;QAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,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AAI,CAAC,cAAc;YACnC,WAAW,EAAE,KAAK;YAClB,0BAA0B,EAAE,CAAC;YAC7B,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,qBAAqB,EAAE,IAAI,CAAC,OAAO,CAAC;SACpE,CAAA;IACH,CAAC;IAED;;OAEG;IAEmB,AAAN,KAAK,CAAC,MAAM,CAAE,GAAQ;QACpC,MAAM,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;QAClD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAC1C,CAAC;IAED;;OAEG;IAEU,AAAN,KAAK,CAAC,KAAK;QAChB,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC/C,CAAC;CACF;AAZuB;IADrB,IAAI;;;;mCAIJ;AAMY;IADZ,IAAI;;;;kCAGJ"}
package/lib/types.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @package @roots/bud-cache
3
+ */
1
4
  import type InvalidateCacheExtension from './invalidate-cache/index.js';
2
5
  declare module '@roots/bud-framework' {
3
6
  interface Modules {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,wBAAwB,MAAM,6BAA6B,CAAA;AAEvE,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,OAAO;QACf,mCAAmC,EAAE,wBAAwB,CAAA;KAC9D;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,wBAAwB,MAAM,6BAA6B,CAAA;AAEvE,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,OAAO;QACf,mCAAmC,EAAE,wBAAwB,CAAA;KAC9D;CACF"}
package/lib/types.js CHANGED
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @package @roots/bud-cache
3
+ */
1
4
  export {};
2
5
  //# sourceMappingURL=types.js.map
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
package/package.json CHANGED
@@ -1,12 +1,9 @@
1
1
  {
2
2
  "name": "@roots/bud-cache",
3
+ "version": "6.12.1",
3
4
  "description": "Config caching",
4
- "version": "6.11.0",
5
- "homepage": "https://roots.io/bud",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/roots/bud.git",
9
- "directory": "sources/@roots/bud-cache"
5
+ "engines": {
6
+ "node": ">=16"
10
7
  },
11
8
  "contributors": [
12
9
  {
@@ -25,20 +22,21 @@
25
22
  }
26
23
  ],
27
24
  "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/roots/bud/issues"
30
- },
25
+ "homepage": "https://roots.io/bud",
31
26
  "funding": {
32
27
  "type": "github sponsors",
33
28
  "url": "https://github.com/sponsors/roots"
34
29
  },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/roots/bud.git",
33
+ "directory": "sources/@roots/bud-cache"
34
+ },
35
+ "bugs": "https://github.com/roots/bud/issues",
35
36
  "keywords": [
36
37
  "bud",
37
38
  "bud-framework"
38
39
  ],
39
- "engines": {
40
- "node": ">=16"
41
- },
42
40
  "files": [
43
41
  "docs",
44
42
  "lib",
@@ -47,20 +45,20 @@
47
45
  "type": "module",
48
46
  "exports": {
49
47
  ".": {
50
- "types": "./lib/index.d.ts",
51
- "import": "./lib/index.js"
48
+ "import": "./lib/index.js",
49
+ "default": "./lib/index.js"
52
50
  },
53
51
  "./service": {
54
- "types": "./lib/service/index.js",
55
- "import": "./lib/service.js"
52
+ "import": "./lib/service.js",
53
+ "default": "./lib/service.js"
56
54
  },
57
55
  "./invalidate-cache": {
58
- "types": "./lib/invalidate-cache/index.d.ts",
59
- "import": "./lib/invalidate-cache/index.js"
56
+ "import": "./lib/invalidate-cache/index.js",
57
+ "default": "./lib/invalidate-cache/index.js"
60
58
  },
61
59
  "./types": {
62
- "types": "./lib/types.d.ts",
63
- "import": "./lib/types.js"
60
+ "import": "./lib/types.js",
61
+ "default": "./lib/types.js"
64
62
  }
65
63
  },
66
64
  "typesVersions": {
@@ -68,23 +66,24 @@
68
66
  ".": [
69
67
  "./lib/index.d.ts"
70
68
  ],
71
- "./service": [
69
+ "service": [
72
70
  "./lib/service.d.ts"
73
71
  ],
74
- "./types": [
72
+ "types": [
75
73
  "./lib/types.d.ts"
76
74
  ]
77
75
  }
78
76
  },
79
- "module": "./lib/index.js",
80
77
  "types": "./lib/index.d.ts",
78
+ "module": "./lib/index.js",
81
79
  "devDependencies": {
82
80
  "@skypack/package-check": "0.2.2"
83
81
  },
84
82
  "dependencies": {
85
- "@roots/bud-framework": "6.11.0",
86
- "@roots/bud-support": "6.11.0",
87
- "strip-ansi": "7.0.1"
83
+ "@roots/bud-framework": "6.12.1",
84
+ "@roots/bud-support": "6.12.1",
85
+ "strip-ansi": "7.0.1",
86
+ "tslib": "2.5.0"
88
87
  },
89
88
  "volta": {
90
89
  "extends": "../../../package.json"
package/src/index.ts CHANGED
@@ -6,8 +6,6 @@
6
6
  *
7
7
  * @see {@link https://bud.js.org}
8
8
  * @see {@link https://github.com/roots/bud}
9
- *
10
- * @packageDocumentation
11
9
  */
12
10
 
13
11
  import './types.js'
@@ -24,13 +24,13 @@ export default class InvalidateCacheExtension extends Extension {
24
24
  }
25
25
 
26
26
  /**
27
- * `register` callback
27
+ * {@link Extension.register}
28
28
  */
29
29
  @bind
30
30
  public override async register(bud: Bud) {
31
31
  const invalidate = await bud.fs?.exists(this.invalidationFile)
32
32
 
33
- if (invalidate || (bud.isCLI() && bud.context.args.flush)) {
33
+ if (invalidate || (bud.isCLI() && bud.context.args.force)) {
34
34
  await bud.fs.remove(this.invalidationFile)
35
35
  await bud.fs.remove(bud.cache.cacheDirectory)
36
36
  }
@@ -1,11 +1,12 @@
1
1
  import {createHash} from 'node:crypto'
2
+ import {join} from 'node:path'
2
3
 
3
4
  import type {Bud} from '@roots/bud-framework'
4
5
  import {Service} from '@roots/bud-framework/service'
5
6
  import type * as Services from '@roots/bud-framework/services'
6
7
  import {bind} from '@roots/bud-support/decorators'
7
8
  import isString from '@roots/bud-support/lodash/isString'
8
- import join from '@roots/bud-support/lodash/join'
9
+ import {hash} from '@roots/bud-support/utilities/args'
9
10
  import type {Configuration} from '@roots/bud-support/webpack'
10
11
 
11
12
  import InvalidateCacheExtension from '../invalidate-cache/index.js'
@@ -28,7 +29,7 @@ export default class Cache
28
29
  public get name(): string {
29
30
  return this.app.hooks.filter(
30
31
  `build.cache.name`,
31
- this.app.hooks.filter(`build.name`, this.app.context.label),
32
+ this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)),
32
33
  )
33
34
  }
34
35
  public set name(name: string) {
@@ -46,7 +47,6 @@ export default class Cache
46
47
  : `filesystem`,
47
48
  )
48
49
  }
49
-
50
50
  public set type(type: 'memory' | 'filesystem') {
51
51
  this.app.hooks.on(`build.cache.type`, type)
52
52
  }
@@ -55,18 +55,16 @@ export default class Cache
55
55
  * version
56
56
  */
57
57
  public get version(): string {
58
- const args = this.app.fs.json.stringify(
59
- this.app.isCLI() ? this.app.context.args : {},
60
- )
61
- const files = Object.values(this.app.context.config ?? {}).filter(
62
- file => file?.bud && file.sha1,
63
- )
58
+ const version = createHash(`sha1`)
59
+ version.update(hash)
60
+
61
+ Object.values(this.app.context.files ?? {})
62
+ .filter(file => file?.bud || file?.name?.includes(`package.json`))
63
+ .map(({sha1}) => version.update(sha1))
64
64
 
65
65
  return this.app.hooks.filter(
66
66
  `build.cache.version`,
67
- createHash(`sha1`)
68
- .update(join(args, ...files.map(({module: {sha1}}) => sha1)))
69
- .digest(`base64`),
67
+ version.digest(`base64`),
70
68
  )
71
69
  }
72
70
  public set version(version: string) {
@@ -79,31 +77,51 @@ export default class Cache
79
77
  public get cacheDirectory(): string {
80
78
  return this.app.hooks.filter(
81
79
  `build.cache.cacheDirectory`,
82
- this.app.path(`@storage`, this.app.label, `cache`, this.app.mode),
80
+ this.app.path(`@storage`, this.app.label, `cache`),
83
81
  )
84
82
  }
85
83
  public set cacheDirectory(directory: string) {
86
84
  this.app.hooks.on(`build.cache.cacheDirectory`, directory)
87
85
  }
88
86
 
87
+ /**
88
+ * Cache dependencies
89
+ */
90
+ public get buildDependencies(): Record<string, Array<string>> {
91
+ return this.app.hooks.filter(`build.cache.buildDependencies`, {
92
+ bud: [
93
+ this.app.context.files?.[`package.json`]?.path,
94
+ ...Object.values(this.app.context.files)
95
+ .filter(({bud}) => bud)
96
+ .map(({path}) => path),
97
+ ].filter(Boolean),
98
+ })
99
+ }
100
+ public set buildDependencies(
101
+ dependencies: Record<string, Array<string>>,
102
+ ) {
103
+ this.app.hooks.on(`build.cache.buildDependencies`, dependencies)
104
+ }
105
+
89
106
  /**
90
107
  * Webpack configuration
91
108
  */
92
109
  public get configuration(): Configuration[`cache`] {
93
110
  if (this.enabled !== true) return false
94
- return this.type === `memory`
95
- ? true
96
- : {
97
- name: this.name,
98
- type: this.type,
99
- store: `pack` as `pack`,
100
- allowCollectingMemory: true,
101
- cacheDirectory: this.cacheDirectory,
102
- idleTimeout: 10000,
103
- idleTimeoutForInitialStore: 0,
104
- profile: true,
105
- version: this.version,
106
- }
111
+ if (this.type === `memory`) return true
112
+
113
+ return {
114
+ name: this.name,
115
+ type: this.type,
116
+ store: `pack` as `pack`,
117
+ allowCollectingMemory: true,
118
+ buildDependencies: this.buildDependencies,
119
+ cacheDirectory: this.cacheDirectory,
120
+ idleTimeout: 10000,
121
+ idleTimeoutForInitialStore: 0,
122
+ profile: false,
123
+ version: this.app.hooks.filter(`build.cache.version`, this.version),
124
+ }
107
125
  }
108
126
 
109
127
  /**
@@ -112,7 +130,7 @@ export default class Cache
112
130
  @bind
113
131
  public override async booted?(bud: Bud) {
114
132
  await bud.extensions.add(InvalidateCacheExtension)
115
- this.app.success(`cache initialized`)
133
+ this.logger.success(`cache initialized`)
116
134
  }
117
135
 
118
136
  /**
package/src/types.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @package @roots/bud-cache
3
+ */
4
+
1
5
  import type InvalidateCacheExtension from './invalidate-cache/index.js'
2
6
 
3
7
  declare module '@roots/bud-framework' {