@roots/bud-cache 6.13.1 → 6.14.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
@@ -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 Cache from './service/index.js';
8
- import './types.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 Cache from './service/index.js';
10
- import './types.js';
11
- export default Cache;
9
+ export { default } from './service/index.js';
@@ -1,49 +1,54 @@
1
1
  import type { Bud } from '@roots/bud-framework';
2
2
  import type { Configuration } from '@roots/bud-framework/config';
3
- import type * as Services from '@roots/bud-framework/services';
3
+ import type { Cache as BudCache } from '@roots/bud-framework/services';
4
4
  import { Service } from '@roots/bud-framework/service';
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
14
  * {@link Extension.boot}
15
15
  */
16
- boot(bud: Bud): Promise<void>;
16
+ boot?(bud: Bud): Promise<void>;
17
17
  /**
18
- * Cache dependencies
18
+ *{@link BudCache.buildDependencies}
19
19
  */
20
20
  get buildDependencies(): Record<string, Array<string>>;
21
21
  set buildDependencies(dependencies: Record<string, Array<string>>);
22
22
  /**
23
- * Cache directory
23
+ * {@link BudCache.cacheDirectory}
24
24
  */
25
25
  get cacheDirectory(): string;
26
26
  set cacheDirectory(directory: string);
27
27
  /**
28
- * Webpack configuration
28
+ * {@link BudCache.configuration}
29
+ * @readonly
29
30
  */
30
31
  get configuration(): Configuration[`cache`];
31
32
  /**
32
- * Flush cache
33
+ * {@link BudCache.flush}
33
34
  */
34
35
  flush(): Promise<void>;
35
36
  /**
36
- * Type
37
+ * {@link BudCache.name}
37
38
  */
38
39
  get name(): string;
39
40
  set name(name: string);
40
41
  /**
41
- * Type
42
+ * {@link BudCache.register}
43
+ */
44
+ register?(bud: Bud): Promise<void>;
45
+ /**
46
+ * {@link BudCache.type}
42
47
  */
43
48
  get type(): 'filesystem' | 'memory';
44
49
  set type(type: 'filesystem' | 'memory');
45
50
  /**
46
- * version
51
+ * {@link BudCache.version}
47
52
  */
48
53
  get version(): string;
49
54
  set version(version: string);
@@ -1,33 +1,32 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
+ import { join } from 'node:path';
2
3
  import { Service } from '@roots/bud-framework/service';
3
4
  import { bind } from '@roots/bud-support/decorators/bind';
4
5
  import isString from '@roots/bud-support/lodash/isString';
5
- import { hash } from '@roots/bud-support/utilities/args';
6
- import { createHash } from 'node:crypto';
7
- import { join } from 'node:path';
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
15
  * {@link Extension.boot}
19
16
  */
20
17
  async boot(bud) {
21
- await bud.extensions.add(InvalidateCacheExtension);
22
- this.logger.success(`cache initialized`);
18
+ if (bud.context.force === true) {
19
+ await this.flush();
20
+ }
21
+ this.enabled = bud.context.cache !== false;
23
22
  }
24
23
  /**
25
- * Cache dependencies
24
+ *{@link BudCache.buildDependencies}
26
25
  */
27
26
  get buildDependencies() {
28
27
  return this.app.hooks.filter(`build.cache.buildDependencies`, {
29
28
  bud: [
30
- this.app.context.files?.[`package.json`]?.path,
29
+ this.app.context.files[`package`]?.path,
31
30
  ...Object.values(this.app.context.files)
32
31
  .filter(({ bud }) => bud)
33
32
  .map(({ path }) => path),
@@ -38,7 +37,7 @@ export default class Cache extends Service {
38
37
  this.app.hooks.on(`build.cache.buildDependencies`, dependencies);
39
38
  }
40
39
  /**
41
- * Cache directory
40
+ * {@link BudCache.cacheDirectory}
42
41
  */
43
42
  get cacheDirectory() {
44
43
  return this.app.hooks.filter(`build.cache.cacheDirectory`, this.app.path(`@storage`, this.app.label, `cache`));
@@ -47,7 +46,8 @@ export default class Cache extends Service {
47
46
  this.app.hooks.on(`build.cache.cacheDirectory`, directory);
48
47
  }
49
48
  /**
50
- * Webpack configuration
49
+ * {@link BudCache.configuration}
50
+ * @readonly
51
51
  */
52
52
  get configuration() {
53
53
  if (this.enabled !== true)
@@ -58,32 +58,41 @@ export default class Cache extends Service {
58
58
  allowCollectingMemory: true,
59
59
  buildDependencies: this.buildDependencies,
60
60
  cacheDirectory: this.cacheDirectory,
61
- idleTimeout: 10000,
61
+ compression: this.app.isDevelopment ? false : `brotli`,
62
+ hashAlgorithm: `xxhash64`,
63
+ idleTimeout: 100,
62
64
  idleTimeoutForInitialStore: 0,
65
+ managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
63
66
  name: this.name,
64
67
  profile: this.app.context.debug === true,
65
68
  store: `pack`,
66
69
  type: this.type,
67
- version: this.app.hooks.filter(`build.cache.version`, this.version),
68
70
  };
69
71
  }
70
72
  /**
71
- * Flush cache
73
+ * {@link BudCache.flush}
72
74
  */
73
75
  async flush() {
74
76
  await this.app.fs.remove(this.cacheDirectory);
75
77
  }
76
78
  /**
77
- * Type
79
+ * {@link BudCache.name}
78
80
  */
79
81
  get name() {
80
- return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)));
82
+ return this.app.hooks.filter(`build.cache.name`, this.app.hooks.filter(`build.name`, join(this.app.mode, ...Object.values(this.app.context._ ?? {}))));
81
83
  }
82
84
  set name(name) {
83
85
  this.app.hooks.on(`build.cache.name`, name);
84
86
  }
85
87
  /**
86
- * Type
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}
87
96
  */
88
97
  get type() {
89
98
  return this.app.hooks.filter(`build.cache.type`, isString(this.app.context.cache)
@@ -94,26 +103,15 @@ export default class Cache extends Service {
94
103
  this.app.hooks.on(`build.cache.type`, type);
95
104
  }
96
105
  /**
97
- * version
106
+ * {@link BudCache.version}
98
107
  */
99
108
  get version() {
100
- const version = createHash(`sha1`);
101
- version.update(hash);
102
- Object.values(this.app.context.files ?? {})
103
- .filter(file => file?.bud || file?.name?.includes(`package.json`))
104
- .map(({ sha1 }) => version.update(sha1));
105
- return this.app.hooks.filter(`build.cache.version`, version.digest(`base64`));
109
+ return this.app.hooks.filter(`build.cache.version`, undefined);
106
110
  }
107
111
  set version(version) {
108
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.1",
3
+ "version": "6.14.1",
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.1",
89
- "@roots/bud-support": "6.13.1",
88
+ "@roots/bud-framework": "6.14.1",
89
+ "@roots/bud-support": "6.14.1",
90
90
  "strip-ansi": "7.1.0",
91
- "tslib": "2.5.3"
91
+ "tslib": "2.6.0"
92
92
  },
93
93
  "volta": {
94
94
  "extends": "../../../package.json"
package/src/index.ts CHANGED
@@ -2,13 +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 Cache from './service/index.js'
12
- import './types.js'
13
-
14
- export default Cache
11
+ export {default} from './service/index.js'
@@ -1,57 +1,53 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
  import type {Configuration} from '@roots/bud-framework/config'
3
- import type * as Services from '@roots/bud-framework/services'
3
+ import type {Cache as BudCache} from '@roots/bud-framework/services'
4
+
5
+ import {join} from 'node:path'
4
6
 
5
7
  import {Service} from '@roots/bud-framework/service'
6
8
  import {bind} from '@roots/bud-support/decorators/bind'
7
9
  import isString from '@roots/bud-support/lodash/isString'
8
- import {hash} from '@roots/bud-support/utilities/args'
9
- import {createHash} from 'node:crypto'
10
- import {join} from 'node:path'
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
- {
14
+ export default class Cache extends Service implements BudCache {
21
15
  /**
22
- * Enabled
16
+ * {@link BudCache.enabled}
23
17
  */
24
- public enabled: boolean = true
18
+ public enabled: boolean
25
19
 
26
20
  /**
27
21
  * {@link Extension.boot}
28
22
  */
29
- @bind
30
- public override async boot(bud: Bud) {
31
- await bud.extensions.add(InvalidateCacheExtension)
32
- this.logger.success(`cache initialized`)
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
33
28
  }
29
+
34
30
  /**
35
- * Cache dependencies
31
+ *{@link BudCache.buildDependencies}
36
32
  */
37
33
  public get buildDependencies(): Record<string, Array<string>> {
38
34
  return this.app.hooks.filter(`build.cache.buildDependencies`, {
39
35
  bud: [
40
- this.app.context.files?.[`package.json`]?.path,
36
+ this.app.context.files[`package`]?.path,
41
37
  ...Object.values(this.app.context.files)
42
38
  .filter(({bud}) => bud)
43
39
  .map(({path}) => path),
44
40
  ].filter(Boolean),
45
41
  })
46
42
  }
47
-
48
43
  public set buildDependencies(
49
44
  dependencies: Record<string, Array<string>>,
50
45
  ) {
51
46
  this.app.hooks.on(`build.cache.buildDependencies`, dependencies)
52
47
  }
48
+
53
49
  /**
54
- * Cache directory
50
+ * {@link BudCache.cacheDirectory}
55
51
  */
56
52
  public get cacheDirectory(): string {
57
53
  return this.app.hooks.filter(
@@ -59,12 +55,13 @@ export default class Cache
59
55
  this.app.path(`@storage`, this.app.label, `cache`),
60
56
  )
61
57
  }
62
-
63
58
  public set cacheDirectory(directory: string) {
64
59
  this.app.hooks.on(`build.cache.cacheDirectory`, directory)
65
60
  }
61
+
66
62
  /**
67
- * Webpack configuration
63
+ * {@link BudCache.configuration}
64
+ * @readonly
68
65
  */
69
66
  public get configuration(): Configuration[`cache`] {
70
67
  if (this.enabled !== true) return false
@@ -74,38 +71,52 @@ export default class Cache
74
71
  allowCollectingMemory: true,
75
72
  buildDependencies: this.buildDependencies,
76
73
  cacheDirectory: this.cacheDirectory,
77
- idleTimeout: 10000,
74
+ compression: this.app.isDevelopment ? false : `brotli`,
75
+ hashAlgorithm: `xxhash64`,
76
+ idleTimeout: 100,
78
77
  idleTimeoutForInitialStore: 0,
78
+ managedPaths: [this.cacheDirectory, this.app.path(`@modules`)],
79
79
  name: this.name,
80
80
  profile: this.app.context.debug === true,
81
- store: `pack` as `pack`,
81
+ store: `pack`,
82
82
  type: this.type,
83
- version: this.app.hooks.filter(`build.cache.version`, this.version),
84
83
  }
85
84
  }
86
85
 
87
86
  /**
88
- * Flush cache
87
+ * {@link BudCache.flush}
89
88
  */
90
89
  @bind
91
90
  public async flush(): Promise<void> {
92
91
  await this.app.fs.remove(this.cacheDirectory)
93
92
  }
93
+
94
94
  /**
95
- * Type
95
+ * {@link BudCache.name}
96
96
  */
97
97
  public get name(): string {
98
98
  return this.app.hooks.filter(
99
99
  `build.cache.name`,
100
- this.app.hooks.filter(`build.name`, join(`webpack`, this.app.mode)),
100
+ this.app.hooks.filter(
101
+ `build.name`,
102
+ join(this.app.mode, ...Object.values(this.app.context._ ?? {})),
103
+ ),
101
104
  )
102
105
  }
103
-
104
106
  public set name(name: string) {
105
107
  this.app.hooks.on(`build.cache.name`, name)
106
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
+
107
118
  /**
108
- * Type
119
+ * {@link BudCache.type}
109
120
  */
110
121
  public get type(): 'filesystem' | 'memory' {
111
122
  return this.app.hooks.filter(
@@ -115,28 +126,16 @@ export default class Cache
115
126
  : `filesystem`,
116
127
  )
117
128
  }
118
-
119
129
  public set type(type: 'filesystem' | 'memory') {
120
130
  this.app.hooks.on(`build.cache.type`, type)
121
131
  }
122
132
 
123
133
  /**
124
- * version
134
+ * {@link BudCache.version}
125
135
  */
126
136
  public get version(): string {
127
- const version = createHash(`sha1`)
128
- version.update(hash)
129
-
130
- Object.values(this.app.context.files ?? {})
131
- .filter(file => file?.bud || file?.name?.includes(`package.json`))
132
- .map(({sha1}) => version.update(sha1))
133
-
134
- return this.app.hooks.filter(
135
- `build.cache.version`,
136
- version.digest(`base64`),
137
- )
137
+ return this.app.hooks.filter(`build.cache.version`, undefined)
138
138
  }
139
-
140
139
  public set version(version: string) {
141
140
  this.app.hooks.on(`build.cache.version`, version)
142
141
  }
@@ -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 { Extension } from '@roots/bud-framework/extension';
3
- import { bind, label } from '@roots/bud-framework/extension/decorators';
4
- import { join } from 'node:path';
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
- errors: compiler.stats.flatMap(stats => stats
38
- .toString({ colors: false, preset: `errors-warnings` })
39
- .split(/\n/)
40
- .map(stripAnsi)),
41
- hash: compiler.hash,
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 type {Bud} from '@roots/bud-framework'
2
-
3
- import {Extension} from '@roots/bud-framework/extension'
4
- import {bind, label} from '@roots/bud-framework/extension/decorators'
5
- import {join} from 'node:path'
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
- errors: compiler.stats.flatMap(stats =>
45
- stats
46
- .toString({colors: false, preset: `errors-warnings`})
47
- .split(/\n/)
48
- .map(stripAnsi),
49
- ),
50
- hash: compiler.hash,
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
- }