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