@roots/bud-cache 6.13.0 → 6.14.0

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
@@ -1,9 +1,7 @@
1
1
  /**
2
- * Caching service
2
+ * @roots/bud-cache
3
3
  *
4
4
  * @see {@link https://bud.js.org}
5
5
  * @see {@link https://github.com/roots/bud}
6
6
  */
7
- import './types.js';
8
- import Cache from './service/index.js';
9
- export default Cache;
7
+ export { default } from './service/index.js';
package/lib/index.js CHANGED
@@ -1,11 +1,9 @@
1
1
  // Copyright © Roots Software Foundation LLC
2
2
  // Licensed under the MIT license.
3
3
  /**
4
- * Caching service
4
+ * @roots/bud-cache
5
5
  *
6
6
  * @see {@link https://bud.js.org}
7
7
  * @see {@link https://github.com/roots/bud}
8
8
  */
9
- import './types.js';
10
- import Cache from './service/index.js';
11
- export default Cache;
9
+ export { default } from './service/index.js';
@@ -1,50 +1,55 @@
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
4
  import { Service } from '@roots/bud-framework/service';
3
- import type * as Services from '@roots/bud-framework/services';
4
- import type { Configuration } from '@roots/bud-support/webpack';
5
5
  /**
6
6
  * Cache service class
7
7
  */
8
- export default class Cache extends Service implements Services.Cache.Service {
8
+ export default class Cache extends Service implements BudCache {
9
9
  /**
10
- * Enabled
10
+ * {@link BudCache.enabled}
11
11
  */
12
12
  enabled: boolean;
13
13
  /**
14
- * Type
15
- */
16
- get name(): string;
17
- set name(name: string);
18
- /**
19
- * Type
14
+ * {@link Extension.boot}
20
15
  */
21
- get type(): 'memory' | 'filesystem';
22
- set type(type: 'memory' | 'filesystem');
16
+ boot?(bud: Bud): Promise<void>;
23
17
  /**
24
- * version
18
+ *{@link BudCache.buildDependencies}
25
19
  */
26
- get version(): string;
27
- set version(version: string);
20
+ get buildDependencies(): Record<string, Array<string>>;
21
+ set buildDependencies(dependencies: Record<string, Array<string>>);
28
22
  /**
29
- * Cache directory
23
+ * {@link BudCache.cacheDirectory}
30
24
  */
31
25
  get cacheDirectory(): string;
32
26
  set cacheDirectory(directory: string);
33
27
  /**
34
- * Cache dependencies
28
+ * {@link BudCache.configuration}
29
+ * @readonly
35
30
  */
36
- get buildDependencies(): Record<string, Array<string>>;
37
- set buildDependencies(dependencies: Record<string, Array<string>>);
31
+ get configuration(): Configuration[`cache`];
38
32
  /**
39
- * Webpack configuration
33
+ * {@link BudCache.flush}
40
34
  */
41
- get configuration(): Configuration[`cache`];
35
+ flush(): Promise<void>;
42
36
  /**
43
- * {@link Extension.boot}
37
+ * {@link BudCache.name}
44
38
  */
45
- boot(bud: Bud): Promise<void>;
39
+ get name(): string;
40
+ set name(name: string);
46
41
  /**
47
- * Flush cache
42
+ * {@link BudCache.register}
48
43
  */
49
- flush(): Promise<void>;
44
+ register?(bud: Bud): Promise<void>;
45
+ /**
46
+ * {@link BudCache.type}
47
+ */
48
+ get type(): 'filesystem' | 'memory';
49
+ set type(type: 'filesystem' | 'memory');
50
+ /**
51
+ * {@link BudCache.version}
52
+ */
53
+ get version(): string;
54
+ set version(version: string);
50
55
  }
@@ -1,69 +1,32 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { createHash } from 'node:crypto';
3
2
  import { join } from 'node:path';
4
3
  import { Service } from '@roots/bud-framework/service';
5
4
  import { bind } from '@roots/bud-support/decorators/bind';
6
5
  import isString from '@roots/bud-support/lodash/isString';
7
- import { hash } from '@roots/bud-support/utilities/args';
8
- import InvalidateCacheExtension from '../invalidate-cache/index.js';
9
6
  /**
10
7
  * Cache service class
11
8
  */
12
9
  export default class Cache extends Service {
13
10
  /**
14
- * Enabled
11
+ * {@link BudCache.enabled}
15
12
  */
16
- enabled = true;
13
+ enabled;
17
14
  /**
18
- * Type
19
- */
20
- get name() {
21
- return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)));
22
- }
23
- set name(name) {
24
- this.app.hooks.on(`build.cache.name`, name);
25
- }
26
- /**
27
- * Type
28
- */
29
- get type() {
30
- return this.app.hooks.filter(`build.cache.type`, isString(this.app.context.cache)
31
- ? this.app.context.cache
32
- : `filesystem`);
33
- }
34
- set type(type) {
35
- this.app.hooks.on(`build.cache.type`, type);
36
- }
37
- /**
38
- * version
39
- */
40
- get version() {
41
- const version = createHash(`sha1`);
42
- version.update(hash);
43
- Object.values(this.app.context.files ?? {})
44
- .filter(file => file?.bud || file?.name?.includes(`package.json`))
45
- .map(({ sha1 }) => version.update(sha1));
46
- return this.app.hooks.filter(`build.cache.version`, version.digest(`base64`));
47
- }
48
- set version(version) {
49
- this.app.hooks.on(`build.cache.version`, version);
50
- }
51
- /**
52
- * Cache directory
15
+ * {@link Extension.boot}
53
16
  */
54
- get cacheDirectory() {
55
- return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`));
56
- }
57
- set cacheDirectory(directory) {
58
- this.app.hooks.on(`build.cache.cacheDirectory`, directory);
17
+ async boot(bud) {
18
+ if (bud.context.force === true) {
19
+ await this.flush();
20
+ }
21
+ this.enabled = bud.context.cache !== false;
59
22
  }
60
23
  /**
61
- * Cache dependencies
24
+ *{@link BudCache.buildDependencies}
62
25
  */
63
26
  get buildDependencies() {
64
27
  return this.app.hooks.filter(`build.cache.buildDependencies`, {
65
28
  bud: [
66
- this.app.context.files?.[`package.json`]?.path,
29
+ this.app.context.files[`package`]?.path,
67
30
  ...Object.values(this.app.context.files)
68
31
  .filter(({ bud }) => bud)
69
32
  .map(({ path }) => path),
@@ -74,7 +37,17 @@ export default class Cache extends Service {
74
37
  this.app.hooks.on(`build.cache.buildDependencies`, dependencies);
75
38
  }
76
39
  /**
77
- * Webpack configuration
40
+ * {@link BudCache.cacheDirectory}
41
+ */
42
+ get cacheDirectory() {
43
+ return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`));
44
+ }
45
+ set cacheDirectory(directory) {
46
+ this.app.hooks.on(`build.cache.cacheDirectory`, directory);
47
+ }
48
+ /**
49
+ * {@link BudCache.configuration}
50
+ * @readonly
78
51
  */
79
52
  get configuration() {
80
53
  if (this.enabled !== true)
@@ -82,38 +55,63 @@ export default class Cache extends Service {
82
55
  if (this.type === `memory`)
83
56
  return true;
84
57
  return {
85
- name: this.name,
86
- type: this.type,
87
- store: `pack`,
88
58
  allowCollectingMemory: true,
89
59
  buildDependencies: this.buildDependencies,
90
60
  cacheDirectory: this.cacheDirectory,
91
- idleTimeout: 10000,
61
+ compression: this.app.isDevelopment ? false : `brotli`,
62
+ hashAlgorithm: `xxhash64`,
63
+ idleTimeout: 100,
92
64
  idleTimeoutForInitialStore: 0,
65
+ managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
66
+ name: this.name,
93
67
  profile: this.app.context.debug === true,
94
- version: this.app.hooks.filter(`build.cache.version`, this.version),
68
+ store: `pack`,
69
+ type: this.type,
95
70
  };
96
71
  }
97
72
  /**
98
- * {@link Extension.boot}
73
+ * {@link BudCache.flush}
99
74
  */
100
- async boot(bud) {
101
- await bud.extensions.add(InvalidateCacheExtension);
102
- this.logger.success(`cache initialized`);
75
+ async flush() {
76
+ await this.app.fs.remove(this.cacheDirectory);
103
77
  }
104
78
  /**
105
- * Flush cache
79
+ * {@link BudCache.name}
106
80
  */
107
- async flush() {
108
- await this.app.fs.remove(this.cacheDirectory);
81
+ get name() {
82
+ return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, join(this.app.mode, ...Object.values(this.app.context._ ?? {}))));
83
+ }
84
+ set name(name) {
85
+ this.app.hooks.on(`build.cache.name`, name);
86
+ }
87
+ /**
88
+ * {@link BudCache.register}
89
+ */
90
+ async register(bud) {
91
+ this.enabled = bud.context.cache !== false;
92
+ this.version = bud.context.bud.version;
93
+ }
94
+ /**
95
+ * {@link BudCache.type}
96
+ */
97
+ get type() {
98
+ return this.app.hooks.filter(`build.cache.type`, isString(this.app.context.cache)
99
+ ? this.app.context.cache
100
+ : `filesystem`);
101
+ }
102
+ set type(type) {
103
+ this.app.hooks.on(`build.cache.type`, type);
104
+ }
105
+ /**
106
+ * {@link BudCache.version}
107
+ */
108
+ get version() {
109
+ return this.app.hooks.filter(`build.cache.version`, undefined);
110
+ }
111
+ set version(version) {
112
+ this.app.hooks.on(`build.cache.version`, version);
109
113
  }
110
114
  }
111
- __decorate([
112
- bind,
113
- __metadata("design:type", Function),
114
- __metadata("design:paramtypes", [Function]),
115
- __metadata("design:returntype", Promise)
116
- ], Cache.prototype, "boot", null);
117
115
  __decorate([
118
116
  bind,
119
117
  __metadata("design:type", Function),
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@roots/bud-cache",
3
- "version": "6.13.0",
3
+ "version": "6.14.0",
4
4
  "description": "Config caching",
5
5
  "engines": {
6
6
  "node": ">=16"
7
7
  },
8
8
  "contributors": [
9
9
  {
10
- "name": "Kelly Mears",
11
10
  "email": "developers@tinypixel.dev",
11
+ "name": "Kelly Mears",
12
12
  "url": "https://github.com/kellymears"
13
13
  },
14
14
  {
15
- "name": "Ben Word",
16
15
  "email": "ben@benword.com",
16
+ "name": "Ben Word",
17
17
  "url": "https://github.com/retlehs"
18
18
  },
19
19
  {
@@ -21,8 +21,8 @@
21
21
  "url": "https://github.com/QWp6t"
22
22
  },
23
23
  {
24
- "name": "Brandon",
25
24
  "email": "brandon@tendency.me",
25
+ "name": "Brandon",
26
26
  "url": "https://github.com/Log1x"
27
27
  }
28
28
  ],
@@ -85,10 +85,10 @@
85
85
  "@skypack/package-check": "0.2.2"
86
86
  },
87
87
  "dependencies": {
88
- "@roots/bud-framework": "6.13.0",
89
- "@roots/bud-support": "6.13.0",
90
- "strip-ansi": "7.0.1",
91
- "tslib": "2.5.0"
88
+ "@roots/bud-framework": "6.14.0",
89
+ "@roots/bud-support": "6.14.0",
90
+ "strip-ansi": "7.1.0",
91
+ "tslib": "2.6.0"
92
92
  },
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
package/src/index.ts CHANGED
@@ -2,14 +2,10 @@
2
2
  // Licensed under the MIT license.
3
3
 
4
4
  /**
5
- * Caching service
5
+ * @roots/bud-cache
6
6
  *
7
7
  * @see {@link https://bud.js.org}
8
8
  * @see {@link https://github.com/roots/bud}
9
9
  */
10
10
 
11
- import './types.js'
12
-
13
- import Cache from './service/index.js'
14
-
15
- export default Cache
11
+ export {default} from './service/index.js'
@@ -1,96 +1,39 @@
1
- import {createHash} from 'node:crypto'
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'
4
+
2
5
  import {join} from 'node:path'
3
6
 
4
- import type {Bud} from '@roots/bud-framework'
5
7
  import {Service} from '@roots/bud-framework/service'
6
- import type * as Services from '@roots/bud-framework/services'
7
8
  import {bind} from '@roots/bud-support/decorators/bind'
8
9
  import isString from '@roots/bud-support/lodash/isString'
9
- import {hash} from '@roots/bud-support/utilities/args'
10
- import type {Configuration} from '@roots/bud-support/webpack'
11
-
12
- import InvalidateCacheExtension from '../invalidate-cache/index.js'
13
10
 
14
11
  /**
15
12
  * Cache service class
16
13
  */
17
- export default class Cache
18
- extends Service
19
- implements Services.Cache.Service
20
- {
21
- /**
22
- * Enabled
23
- */
24
- public enabled: boolean = true
25
-
14
+ export default class Cache extends Service implements BudCache {
26
15
  /**
27
- * Type
16
+ * {@link BudCache.enabled}
28
17
  */
29
- public get name(): string {
30
- return this.app.hooks.filter(
31
- `build.cache.name`,
32
- this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)),
33
- )
34
- }
35
- public set name(name: string) {
36
- this.app.hooks.on(`build.cache.name`, name)
37
- }
18
+ public enabled: boolean
38
19
 
39
20
  /**
40
- * Type
41
- */
42
- public get type(): 'memory' | 'filesystem' {
43
- return this.app.hooks.filter(
44
- `build.cache.type`,
45
- isString(this.app.context.cache)
46
- ? this.app.context.cache
47
- : `filesystem`,
48
- )
49
- }
50
- public set type(type: 'memory' | 'filesystem') {
51
- this.app.hooks.on(`build.cache.type`, type)
52
- }
53
-
54
- /**
55
- * version
56
- */
57
- public get version(): string {
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
-
65
- return this.app.hooks.filter(
66
- `build.cache.version`,
67
- version.digest(`base64`),
68
- )
69
- }
70
- public set version(version: string) {
71
- this.app.hooks.on(`build.cache.version`, version)
72
- }
73
-
74
- /**
75
- * Cache directory
21
+ * {@link Extension.boot}
76
22
  */
77
- public get cacheDirectory(): string {
78
- return this.app.hooks.filter(
79
- `build.cache.cacheDirectory`,
80
- this.app.path(`@storage`, this.app.label, `cache`),
81
- )
82
- }
83
- public set cacheDirectory(directory: string) {
84
- this.app.hooks.on(`build.cache.cacheDirectory`, directory)
23
+ public override async boot?(bud: Bud) {
24
+ if (bud.context.force === true) {
25
+ await this.flush()
26
+ }
27
+ this.enabled = bud.context.cache !== false
85
28
  }
86
29
 
87
30
  /**
88
- * Cache dependencies
31
+ *{@link BudCache.buildDependencies}
89
32
  */
90
33
  public get buildDependencies(): Record<string, Array<string>> {
91
34
  return this.app.hooks.filter(`build.cache.buildDependencies`, {
92
35
  bud: [
93
- this.app.context.files?.[`package.json`]?.path,
36
+ this.app.context.files[`package`]?.path,
94
37
  ...Object.values(this.app.context.files)
95
38
  .filter(({bud}) => bud)
96
39
  .map(({path}) => path),
@@ -104,40 +47,96 @@ export default class Cache
104
47
  }
105
48
 
106
49
  /**
107
- * Webpack configuration
50
+ * {@link BudCache.cacheDirectory}
51
+ */
52
+ public get cacheDirectory(): string {
53
+ return this.app.hooks.filter(
54
+ `build.cache.cacheDirectory`,
55
+ this.app.path(`@storage`, this.app.label, `cache`),
56
+ )
57
+ }
58
+ public set cacheDirectory(directory: string) {
59
+ this.app.hooks.on(`build.cache.cacheDirectory`, directory)
60
+ }
61
+
62
+ /**
63
+ * {@link BudCache.configuration}
64
+ * @readonly
108
65
  */
109
66
  public get configuration(): Configuration[`cache`] {
110
67
  if (this.enabled !== true) return false
111
68
  if (this.type === `memory`) return true
112
69
 
113
70
  return {
114
- name: this.name,
115
- type: this.type,
116
- store: `pack` as `pack`,
117
71
  allowCollectingMemory: true,
118
72
  buildDependencies: this.buildDependencies,
119
73
  cacheDirectory: this.cacheDirectory,
120
- idleTimeout: 10000,
74
+ compression: this.app.isDevelopment ? false : `brotli`,
75
+ hashAlgorithm: `xxhash64`,
76
+ idleTimeout: 100,
121
77
  idleTimeoutForInitialStore: 0,
78
+ managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
79
+ name: this.name,
122
80
  profile: this.app.context.debug === true,
123
- version: this.app.hooks.filter(`build.cache.version`, this.version),
81
+ store: `pack`,
82
+ type: this.type,
124
83
  }
125
84
  }
126
85
 
127
86
  /**
128
- * {@link Extension.boot}
87
+ * {@link BudCache.flush}
129
88
  */
130
89
  @bind
131
- public override async boot(bud: Bud) {
132
- await bud.extensions.add(InvalidateCacheExtension)
133
- this.logger.success(`cache initialized`)
90
+ public async flush(): Promise<void> {
91
+ await this.app.fs.remove(this.cacheDirectory)
134
92
  }
135
93
 
136
94
  /**
137
- * Flush cache
95
+ * {@link BudCache.name}
138
96
  */
139
- @bind
140
- public async flush(): Promise<void> {
141
- await this.app.fs.remove(this.cacheDirectory)
97
+ public get name(): string {
98
+ return this.app.hooks.filter(
99
+ `build.cache.name`,
100
+ this.app.hooks.filter(
101
+ `build.name`,
102
+ join(this.app.mode, ...Object.values(this.app.context._ ?? {})),
103
+ ),
104
+ )
105
+ }
106
+ public set name(name: string) {
107
+ this.app.hooks.on(`build.cache.name`, name)
108
+ }
109
+
110
+ /**
111
+ * {@link BudCache.register}
112
+ */
113
+ public override async register?(bud: Bud) {
114
+ this.enabled = bud.context.cache !== false
115
+ this.version = bud.context.bud.version
116
+ }
117
+
118
+ /**
119
+ * {@link BudCache.type}
120
+ */
121
+ public get type(): 'filesystem' | 'memory' {
122
+ return this.app.hooks.filter(
123
+ `build.cache.type`,
124
+ isString(this.app.context.cache)
125
+ ? this.app.context.cache
126
+ : `filesystem`,
127
+ )
128
+ }
129
+ public set type(type: 'filesystem' | 'memory') {
130
+ this.app.hooks.on(`build.cache.type`, type)
131
+ }
132
+
133
+ /**
134
+ * {@link BudCache.version}
135
+ */
136
+ public get version(): string {
137
+ return this.app.hooks.filter(`build.cache.version`, undefined)
138
+ }
139
+ public set version(version: string) {
140
+ this.app.hooks.on(`build.cache.version`, version)
142
141
  }
143
142
  }
@@ -1,21 +0,0 @@
1
- import type { Bud } from '@roots/bud-framework';
2
- import { Extension } from '@roots/bud-framework/extension';
3
- /**
4
- * Cache invalidation extension
5
- *
6
- * @remarks
7
- * Certain webpack components such as `eslint-webpack-plugin` and
8
- * `ts-loader` have issues with fs caching. This extension writes a file
9
- * to the cache directory which is used to invalidate the cache before
10
- * webpack is invoked on subsequent builds
11
- */
12
- export default class InvalidateCacheExtension extends Extension {
13
- /**
14
- * Invalidation file path
15
- */
16
- get invalidationFile(): string;
17
- /**
18
- * {@link Extension.register}
19
- */
20
- register(bud: Bud): Promise<void>;
21
- }
@@ -1,58 +0,0 @@
1
- import { __decorate, __metadata } from "tslib";
2
- import { join } from 'node:path';
3
- import { Extension } from '@roots/bud-framework/extension';
4
- import { bind, label } from '@roots/bud-framework/extension/decorators';
5
- import stripAnsi from 'strip-ansi';
6
- /**
7
- * Cache invalidation extension
8
- *
9
- * @remarks
10
- * Certain webpack components such as `eslint-webpack-plugin` and
11
- * `ts-loader` have issues with fs caching. This extension writes a file
12
- * to the cache directory which is used to invalidate the cache before
13
- * webpack is invoked on subsequent builds
14
- */
15
- let InvalidateCacheExtension = class InvalidateCacheExtension extends Extension {
16
- /**
17
- * Invalidation file path
18
- */
19
- get invalidationFile() {
20
- return join(this.app.cache.cacheDirectory, `error.json`);
21
- }
22
- /**
23
- * {@link Extension.register}
24
- */
25
- async register(bud) {
26
- const invalidate = await bud.fs?.exists(this.invalidationFile);
27
- if (invalidate || bud.context.force) {
28
- await bud.fs.remove(this.invalidationFile);
29
- await bud.fs.remove(bud.cache.cacheDirectory);
30
- }
31
- bud.after(async () => {
32
- bud.compiler.instance.hooks.done.tap(this.label, async (compiler) => {
33
- try {
34
- if (!compiler.hasErrors())
35
- return;
36
- await bud.fs.json.write(this.invalidationFile, {
37
- hash: compiler.hash,
38
- errors: compiler.stats.flatMap(stats => stats
39
- .toString({ preset: `errors-warnings`, colors: false })
40
- .split(/\n/)
41
- .map(stripAnsi)),
42
- });
43
- }
44
- catch (e) { }
45
- });
46
- });
47
- }
48
- };
49
- __decorate([
50
- bind,
51
- __metadata("design:type", Function),
52
- __metadata("design:paramtypes", [Function]),
53
- __metadata("design:returntype", Promise)
54
- ], InvalidateCacheExtension.prototype, "register", null);
55
- InvalidateCacheExtension = __decorate([
56
- label(`@roots/bud-cache/invalidate-cache`)
57
- ], InvalidateCacheExtension);
58
- export default InvalidateCacheExtension;
package/lib/types.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * @package @roots/bud-cache
3
- */
4
- import type InvalidateCacheExtension from './invalidate-cache/index.js';
5
- declare module '@roots/bud-framework' {
6
- interface Modules {
7
- '@roots/bud-cache/invalidate-cache': InvalidateCacheExtension;
8
- }
9
- }
package/lib/types.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * @package @roots/bud-cache
3
- */
4
- export {};
@@ -1,56 +0,0 @@
1
- import {join} from 'node:path'
2
-
3
- import type {Bud} from '@roots/bud-framework'
4
- import {Extension} from '@roots/bud-framework/extension'
5
- import {bind, label} from '@roots/bud-framework/extension/decorators'
6
- import stripAnsi from 'strip-ansi'
7
-
8
- /**
9
- * Cache invalidation extension
10
- *
11
- * @remarks
12
- * Certain webpack components such as `eslint-webpack-plugin` and
13
- * `ts-loader` have issues with fs caching. This extension writes a file
14
- * to the cache directory which is used to invalidate the cache before
15
- * webpack is invoked on subsequent builds
16
- */
17
- @label(`@roots/bud-cache/invalidate-cache`)
18
- export default class InvalidateCacheExtension extends Extension {
19
- /**
20
- * Invalidation file path
21
- */
22
- public get invalidationFile(): string {
23
- return join(this.app.cache.cacheDirectory, `error.json`)
24
- }
25
-
26
- /**
27
- * {@link Extension.register}
28
- */
29
- @bind
30
- public override async register(bud: Bud) {
31
- const invalidate = await bud.fs?.exists(this.invalidationFile)
32
-
33
- if (invalidate || bud.context.force) {
34
- await bud.fs.remove(this.invalidationFile)
35
- await bud.fs.remove(bud.cache.cacheDirectory)
36
- }
37
-
38
- bud.after(async () => {
39
- bud.compiler.instance.hooks.done.tap(this.label, async compiler => {
40
- try {
41
- if (!compiler.hasErrors()) return
42
-
43
- await bud.fs.json.write(this.invalidationFile, {
44
- hash: compiler.hash,
45
- errors: compiler.stats.flatMap(stats =>
46
- stats
47
- .toString({preset: `errors-warnings`, colors: false})
48
- .split(/\n/)
49
- .map(stripAnsi),
50
- ),
51
- })
52
- } catch (e) {}
53
- })
54
- })
55
- }
56
- }
package/src/types.ts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * @package @roots/bud-cache
3
- */
4
-
5
- import type InvalidateCacheExtension from './invalidate-cache/index.js'
6
-
7
- declare module '@roots/bud-framework' {
8
- interface Modules {
9
- '@roots/bud-cache/invalidate-cache': InvalidateCacheExtension
10
- }
11
- }