@roots/bud-cache 4.7.0-7 → 5.0.0-next.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/README.md CHANGED
@@ -1,47 +1,74 @@
1
1
  <p align="center">
2
- <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100">
2
+ <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <img alt="MIT License" src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square">
7
- <a href="https://twitter.com/rootswp">
8
- <img alt="Follow Roots" src="https://img.shields.io/twitter/follow/rootswp.svg?style=flat-square&color=1da1f2" />
6
+ <img
7
+ alt="MIT License"
8
+ src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square"
9
+ />
10
+ <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Froots%2Fbud?ref=badge_small" alt="FOSSA Status">
11
+ <img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Froots%2Fbud.svg?type=small"/>
12
+ </a>
13
+ <a href="https://www.npmjs.com/package/@roots/bud">
14
+ <img src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" />
15
+ </a>
16
+ <a href="https://codecov.io/gh/roots/bud">
17
+ <img src="https://codecov.io/gh/roots/bud/branch/next/graph/badge.svg?token=DRJ28OD8XD"/>
9
18
  </a>
10
- <a href="https://www.npmjs.com/package/@roots/bud-cache">
11
- <img src="https://img.shields.io/npm/v/@roots/bud-cache.svg?color=%23525ddc&style=flat-square" />
19
+ <a href="https://twitter.com/rootswp">
20
+ <img
21
+ alt="Follow Roots"
22
+ src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square"
23
+ />
12
24
  </a>
13
25
  </p>
14
26
 
27
+
15
28
  <h1 align="center">
16
29
  <strong>@roots/bud-cache</strong>
17
30
  </h1>
18
31
 
19
- ## Overview
20
-
21
- Config caching utility.
22
-
32
+ > Config caching
23
33
  ## Installation
24
34
 
25
- ```sh
35
+ Install **@roots/bud-cache** to your project.
36
+
37
+ ```shell
26
38
  yarn add @roots/bud-cache
27
39
  ```
28
40
 
29
- ## Contributing
30
-
31
- Contributions are welcome from everyone.
32
-
33
- We have [contributing guidelines](https://github.com/roots/guidelines/blob/master/CONTRIBUTING.md) to help you get started.
41
+ ## Documentation
34
42
 
35
- ## Bud sponsors
36
-
37
- Help support our open-source development efforts by [becoming a patron](https://www.patreon.com/rootsdev).
43
+ For more information on utilizing this package [check out our dedicated docs](https://budjs.netlify.app)
38
44
 
39
45
  ## Community
40
46
 
41
47
  Keep track of development and community news.
42
48
 
43
- - Participate on the [Roots Discourse](https://discourse.roots.io/)
49
+ - Participate on the [Roots Discourse](https://discourse.roots.io)
44
50
  - Follow [@rootswp on Twitter](https://twitter.com/rootswp)
45
- - Read and subscribe to the [Roots Blog](https://roots.io/blog/)
51
+ - Read and subscribe to the [Roots blog](https://roots.io/blog/)
46
52
  - Subscribe to the [Roots Newsletter](https://roots.io/subscribe/)
47
53
  - Listen to the [Roots Radio podcast](https://roots.io/podcast/)
54
+
55
+ ## Contributing
56
+
57
+ Contributions are welcome from everyone.
58
+
59
+ We have [contribution guidelines](https://github.com/roots/guidelines/blob/master/CONTRIBUTING.md) to help you get started.
60
+
61
+ ## Sponsors
62
+
63
+ Help support our open-source development efforts by [becoming a patron](https://www.patreon.com/rootsdev).
64
+
65
+ <a href="https://kinsta.com/?kaid=OFDHAJIXUDIV"><img src="https://cdn.roots.io/app/uploads/kinsta.svg" alt="Kinsta" width="200" height="150"/></a>
66
+ <a href="https://k-m.com/"><img src="https://cdn.roots.io/app/uploads/km-digital.svg" alt="KM Digital" width="200" height="150"/></a>
67
+ <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
68
+ <a href="https://www.c21redwood.com/"><img src="https://cdn.roots.io/app/uploads/c21redwood.svg" alt="C21 Redwood Realty" width="200" height="150"/></a>
69
+ <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/></a>
70
+ <a href="https://icons8.com/"><img src="https://cdn.roots.io/app/uploads/icons8.svg" alt="Icons8" width="200" height="150"/></a>
71
+ <a href="https://www.harnessup.com/"><img src="https://cdn.roots.io/app/uploads/harness-software.svg" alt="Harness Software" width="200" height="150"/></a>
72
+ <a href="https://www.codersclan.com/"><img src="https://cdn.roots.io/app/uploads/coders-clan.svg" alt="Coders Clan" width="200" height="150"/></a>
73
+ <a href="https://generodigital.com/"><img src="https://cdn.roots.io/app/uploads/genero.svg" alt="Genero" width="200" height="150"/></a>
74
+ <a href="https://motto.ca/roots"><img src="https://cdn.roots.io/app/uploads/motto.svg" alt="Motto" width="200" height="150"/></a>
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const bud_framework_1 = require("@roots/bud-framework");
5
+ const bud_support_1 = require("@roots/bud-support");
6
+ const autobind_decorator_1 = require("autobind-decorator");
7
+ const crypto_1 = require("crypto");
8
+ const fs_extra_1 = require("fs-extra");
9
+ /**
10
+ * Service class handling cache concerns
11
+ *
12
+ * @remarks
13
+ * Interfaces with:
14
+ * - {@link @roots/bud-framework#Project} to determine project dependencies for snapshotting/validation.
15
+ * - {@link @roots/bud-framework#Build} via {@link @roots/bud-framework#Hooks} to update config.
16
+ *
17
+ * Facades:
18
+ * - {@link @roots/bud-framework#Api} can toggle cache settings with {@link Bud.Persist}
19
+ *
20
+ * @public
21
+ */
22
+ class default_1 extends bud_framework_1.Cache.Abstract {
23
+ constructor() {
24
+ super(...arguments);
25
+ /**
26
+ * {@inheritDoc}
27
+ */
28
+ this.name = 'cache';
29
+ }
30
+ /**
31
+ * {@inheritDoc}
32
+ *
33
+ * @decorator `@bind`
34
+ */
35
+ register(app) {
36
+ app.hooks
37
+ .on('build/cache', () => ({
38
+ type: app.hooks.filter('build/cache/type'),
39
+ }))
40
+ .hooks.on('build/cache/type', () => 'memory');
41
+ }
42
+ /**
43
+ * Returns sha1 hash as a version string
44
+ *
45
+ * @decorator `@bind`
46
+ */
47
+ version() {
48
+ return (0, crypto_1.createHash)('sha1')
49
+ .update(this.hash())
50
+ .digest('base64')
51
+ .replace(/[^a-z0-9]/gi, '_')
52
+ .toLowerCase();
53
+ }
54
+ /**
55
+ * Returns cache storage directory
56
+ *
57
+ * @decorator `@bind`
58
+ */
59
+ directory() {
60
+ return this.app.path('storage', 'cache');
61
+ }
62
+ /**
63
+ * Returns array of build dependency paths
64
+ *
65
+ * @remarks
66
+ * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
67
+ *
68
+ * @decorator `@bind`
69
+ */
70
+ buildDependencies() {
71
+ var _a, _b, _c, _d, _e, _f, _g;
72
+ return [
73
+ ...new Set(bud_support_1.globby.globbySync([
74
+ this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
75
+ this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
76
+ this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
77
+ ...((_g = (_c = (_b = (_a = this.app.project) === null || _a === void 0 ? void 0 : _a.resolveFrom) === null || _b === void 0 ? void 0 : _b.map(dep => `${dep}/lib/cjs/index.js`)) !== null && _c !== void 0 ? _c : (_f = (_e = (_d = this.app.parent) === null || _d === void 0 ? void 0 : _d.project) === null || _e === void 0 ? void 0 : _e.resolveFrom) === null || _f === void 0 ? void 0 : _f.map(dep => `${dep}/lib/cjs/index.js`)) !== null && _g !== void 0 ? _g : []),
78
+ this.app.path('storage', 'cache/*'),
79
+ ])),
80
+ ];
81
+ }
82
+ /**
83
+ * Returns hash of all build dependencies and parsed CLI arguments
84
+ *
85
+ * @decorator `@bind`
86
+ */
87
+ hash() {
88
+ var _a;
89
+ return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat((0, fs_extra_1.readFileSync)(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
90
+ }
91
+ }
92
+ (0, tslib_1.__decorate)([
93
+ autobind_decorator_1.boundMethod
94
+ ], default_1.prototype, "register", null);
95
+ (0, tslib_1.__decorate)([
96
+ autobind_decorator_1.boundMethod
97
+ ], default_1.prototype, "version", null);
98
+ (0, tslib_1.__decorate)([
99
+ autobind_decorator_1.boundMethod
100
+ ], default_1.prototype, "directory", null);
101
+ (0, tslib_1.__decorate)([
102
+ autobind_decorator_1.boundMethod
103
+ ], default_1.prototype, "buildDependencies", null);
104
+ (0, tslib_1.__decorate)([
105
+ autobind_decorator_1.boundMethod
106
+ ], default_1.prototype, "hash", null);
107
+ exports.default = default_1;
108
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Cache/index.ts"],"names":[],"mappings":";;;AAAA,wDAAqD;AACrD,oDAAyC;AACzC,2DAAsD;AACtD,mCAAiC;AACjC,uCAAqC;AAErC;;;;;;;;;;;;GAYG;AACH,eACE,SAAQ,qBAAK,CAAC,QAAQ;IADxB;;QAIE;;WAEG;QACI,SAAI,GAAG,OAAO,CAAA;IA+FvB,CAAC;IA7FC;;;;OAIG;IAEI,QAAQ,CAAC,GAAc;QAC5B,GAAG,CAAC,KAAK;aACN,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC;SAC3C,CAAC,CAAC;aACF,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC;IAED;;;;OAIG;IAEI,OAAO;QACZ,OAAO,IAAA,mBAAU,EAAC,MAAM,CAAC;aACtB,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;aACnB,MAAM,CAAC,QAAQ,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AAG,CAAC,MAAM,CAAC,IAAA,uBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EACrD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC/B,mCAAI,IAAI,CACV,CAAA;IACH,CAAC;CACF;AAvFC;IADC,gCAAI;yCAOJ;AAQD;IADC,gCAAI;wCAOJ;AAQD;IADC,gCAAI;0CAGJ;AAWD;IADC,gCAAI;kDA+BJ;AAQD;IADC,gCAAI;qCAQJ;AArGH,4BAsGC"}
package/lib/cjs/index.js CHANGED
@@ -1,85 +1,17 @@
1
1
  "use strict";
2
+ // Copyright (c) Roots Foundation, LLC. All rights reserved.
3
+ // Licensed under the MIT license.
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
5
  exports.Cache = void 0;
4
6
  const tslib_1 = require("tslib");
5
- const bud_framework_1 = require("@roots/bud-framework");
6
- const crypto_1 = tslib_1.__importDefault(require("crypto"));
7
- const fs_extra_1 = require("fs-extra");
8
- const autobind_decorator_1 = require("autobind-decorator");
9
- const globby_1 = require("globby");
10
- const lodash_1 = require("lodash");
11
- class Cache extends bud_framework_1.Service {
12
- constructor() {
13
- super(...arguments);
14
- this.name = '@roots/bud-cache';
15
- }
16
- register() {
17
- this.app.hooks.on('build', config => {
18
- if (lodash_1.isEqual(config.cache.type, 'memory')) {
19
- config.cache = {
20
- type: 'memory',
21
- };
22
- }
23
- return config;
24
- });
25
- this.app.hooks
26
- .on('build/cache/name', () => undefined)
27
- .hooks.on('build/cache/version', () => undefined)
28
- .hooks.on('build/cache/type', () => 'memory')
29
- .hooks.on('build/cache/cacheDirectory', () => undefined)
30
- .hooks.on('build/cache/cacheLocation', () => undefined)
31
- .hooks.on('build/cache/managedPaths', () => undefined);
32
- }
33
- booted() {
34
- this.app.hooks.filter('build/cache/type') == 'filesystem' &&
35
- !fs_extra_1.pathExistsSync(this.app.path('storage')) &&
36
- fs_extra_1.mkdirSync(this.app.path('storage'));
37
- }
38
- version() {
39
- const version = crypto_1.default
40
- .createHash('sha1')
41
- .update(this.hash())
42
- .digest('base64')
43
- .replace(/[^a-z0-9]/gi, '_')
44
- .toLowerCase();
45
- return version;
46
- }
47
- directory() {
48
- return this.app.path('storage', 'cache');
49
- }
50
- buildDependencies() {
51
- return [
52
- ...new Set(globby_1.sync([
53
- this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
54
- this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
55
- this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
56
- ...this.app.discovery.resolveFrom.map(dep => `${dep}/lib/cjs/index.js`),
57
- this.app.path('storage', 'cache/*'),
58
- ])),
59
- ];
60
- }
61
- hash() {
62
- var _a;
63
- return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat(fs_extra_1.readFileSync(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
64
- }
65
- }
66
- tslib_1.__decorate([
67
- autobind_decorator_1.boundMethod
68
- ], Cache.prototype, "register", null);
69
- tslib_1.__decorate([
70
- autobind_decorator_1.boundMethod
71
- ], Cache.prototype, "booted", null);
72
- tslib_1.__decorate([
73
- autobind_decorator_1.boundMethod
74
- ], Cache.prototype, "version", null);
75
- tslib_1.__decorate([
76
- autobind_decorator_1.boundMethod
77
- ], Cache.prototype, "directory", null);
78
- tslib_1.__decorate([
79
- autobind_decorator_1.boundMethod
80
- ], Cache.prototype, "buildDependencies", null);
81
- tslib_1.__decorate([
82
- autobind_decorator_1.boundMethod
83
- ], Cache.prototype, "hash", null);
84
- exports.Cache = Cache;
7
+ /**
8
+ * The {@link @roots/bud-cache#} package implements the {@link @roots/bud-framework#Cache | Cache interface}
9
+ *
10
+ * @see https://roots.io/bud
11
+ * @see https://github.com/roots/bud
12
+ *
13
+ * @core @packageDocumentation @betaDocumentation
14
+ */
15
+ const Cache_1 = (0, tslib_1.__importDefault)(require("./Cache"));
16
+ exports.Cache = Cache_1.default;
85
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,wDAA2D;AAC3D,4DAA2B;AAC3B,uCAAgE;AAChE,2DAAsD;AACtD,mCAA2B;AAC3B,mCAA8B;AAE9B,MAAM,KAAM,SAAQ,uBAAO;IAA3B;;QACS,SAAI,GAAG,kBAAkB,CAAA;IAkFlC,CAAC;IA/EQ,QAAQ;QACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAClC,IAAI,gBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE;gBACxC,MAAM,CAAC,KAAK,GAAG;oBACb,IAAI,EAAE,QAAQ;iBACf,CAAA;aACF;YAED,OAAO,MAAM,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,GAAG,CAAC,KAAK;aACX,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;aACvC,KAAK,CAAC,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;aAChD,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;aAC5C,KAAK,CAAC,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;aACvD,KAAK,CAAC,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC;aACtD,KAAK,CAAC,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAC1D,CAAC;IAGM,MAAM;QACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,YAAY;YACvD,CAAC,yBAAc,CAAC,IAAI,CAAC,GAAG,CAAC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EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,EACrD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC/B,mCAAI,IAAI,CACV,CAAA;IACH,CAAC;CACF;AA/EC;IADC,gCAAI;qCAmBJ;AAGD;IADC,gCAAI;mCAKJ;AAGD;IADC,gCAAI;oCAUJ;AAGD;IADC,gCAAI;sCAGJ;AAGD;IADC,gCAAI;8CAwBJ;AAGD;IADC,gCAAI;iCAQJ;AAGK,sBAAK"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;;AAElC;;;;;;;GAOG;AAEH,iEAA2B;AAEnB,gBAFD,eAAK,CAEC"}
@@ -0,0 +1,105 @@
1
+ import { __decorate } from "tslib";
2
+ import { Cache } from '@roots/bud-framework';
3
+ import { globby } from '@roots/bud-support';
4
+ import { boundMethod as bind } from 'autobind-decorator';
5
+ import { createHash } from 'crypto';
6
+ import { readFileSync } from 'fs-extra';
7
+ /**
8
+ * Service class handling cache concerns
9
+ *
10
+ * @remarks
11
+ * Interfaces with:
12
+ * - {@link @roots/bud-framework#Project} to determine project dependencies for snapshotting/validation.
13
+ * - {@link @roots/bud-framework#Build} via {@link @roots/bud-framework#Hooks} to update config.
14
+ *
15
+ * Facades:
16
+ * - {@link @roots/bud-framework#Api} can toggle cache settings with {@link Bud.Persist}
17
+ *
18
+ * @public
19
+ */
20
+ export default class default_1 extends Cache.Abstract {
21
+ constructor() {
22
+ super(...arguments);
23
+ /**
24
+ * {@inheritDoc}
25
+ */
26
+ this.name = 'cache';
27
+ }
28
+ /**
29
+ * {@inheritDoc}
30
+ *
31
+ * @decorator `@bind`
32
+ */
33
+ register(app) {
34
+ app.hooks
35
+ .on('build/cache', () => ({
36
+ type: app.hooks.filter('build/cache/type'),
37
+ }))
38
+ .hooks.on('build/cache/type', () => 'memory');
39
+ }
40
+ /**
41
+ * Returns sha1 hash as a version string
42
+ *
43
+ * @decorator `@bind`
44
+ */
45
+ version() {
46
+ return createHash('sha1')
47
+ .update(this.hash())
48
+ .digest('base64')
49
+ .replace(/[^a-z0-9]/gi, '_')
50
+ .toLowerCase();
51
+ }
52
+ /**
53
+ * Returns cache storage directory
54
+ *
55
+ * @decorator `@bind`
56
+ */
57
+ directory() {
58
+ return this.app.path('storage', 'cache');
59
+ }
60
+ /**
61
+ * Returns array of build dependency paths
62
+ *
63
+ * @remarks
64
+ * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
65
+ *
66
+ * @decorator `@bind`
67
+ */
68
+ buildDependencies() {
69
+ var _a, _b, _c, _d, _e, _f, _g;
70
+ return [
71
+ ...new Set(globby.globbySync([
72
+ this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
73
+ this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
74
+ this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
75
+ ...((_g = (_c = (_b = (_a = this.app.project) === null || _a === void 0 ? void 0 : _a.resolveFrom) === null || _b === void 0 ? void 0 : _b.map(dep => `${dep}/lib/cjs/index.js`)) !== null && _c !== void 0 ? _c : (_f = (_e = (_d = this.app.parent) === null || _d === void 0 ? void 0 : _d.project) === null || _e === void 0 ? void 0 : _e.resolveFrom) === null || _f === void 0 ? void 0 : _f.map(dep => `${dep}/lib/cjs/index.js`)) !== null && _g !== void 0 ? _g : []),
76
+ this.app.path('storage', 'cache/*'),
77
+ ])),
78
+ ];
79
+ }
80
+ /**
81
+ * Returns hash of all build dependencies and parsed CLI arguments
82
+ *
83
+ * @decorator `@bind`
84
+ */
85
+ hash() {
86
+ var _a;
87
+ return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat(readFileSync(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
88
+ }
89
+ }
90
+ __decorate([
91
+ bind
92
+ ], default_1.prototype, "register", null);
93
+ __decorate([
94
+ bind
95
+ ], default_1.prototype, "version", null);
96
+ __decorate([
97
+ bind
98
+ ], default_1.prototype, "directory", null);
99
+ __decorate([
100
+ bind
101
+ ], default_1.prototype, "buildDependencies", null);
102
+ __decorate([
103
+ bind
104
+ ], default_1.prototype, "hash", null);
105
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Cache/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAY,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAC,WAAW,IAAI,IAAI,EAAC,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAA;AAErC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,gBACZ,SAAQ,KAAK,CAAC,QAAQ;IADxB;;QAIE;;WAEG;QACI,SAAI,GAAG,OAAO,CAAA;IA+FvB,CAAC;IA7FC;;;;OAIG;IAEI,QAAQ,CAAC,GAAc;QAC5B,GAAG,CAAC,KAAK;aACN,EAAE,CAAC,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC;SAC3C,CAAC,CAAC;aACF,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC;IAED;;;;OAIG;IAEI,OAAO;QACZ,OAAO,UAAU,CAAC,MAAM,CAAC;aACtB,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;aACnB,MAAM,CAAC,QAAQ,CAAC;aAChB,OAAO,CAAC,aAAa,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AC,IAAI,EAAE,MAAM,CAAC,CAAC,EACrD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAC/B,mCAAI,IAAI,CACV,CAAA;IACH,CAAC;CACF;AAvFC;IADC,IAAI;yCAOJ;AAQD;IADC,IAAI;wCAOJ;AAQD;IADC,IAAI;0CAGJ;AAWD;IADC,IAAI;kDA+BJ;AAQD;IADC,IAAI;qCAQJ"}
package/lib/esm/index.js CHANGED
@@ -1,82 +1,13 @@
1
- import { __decorate } from "tslib";
2
- import { Service } from '@roots/bud-framework';
3
- import crypto from 'crypto';
4
- import { mkdirSync, pathExistsSync, readFileSync } from 'fs-extra';
5
- import { boundMethod as bind } from 'autobind-decorator';
6
- import { sync } from 'globby';
7
- import { isEqual } from 'lodash';
8
- class Cache extends Service {
9
- constructor() {
10
- super(...arguments);
11
- this.name = '@roots/bud-cache';
12
- }
13
- register() {
14
- this.app.hooks.on('build', config => {
15
- if (isEqual(config.cache.type, 'memory')) {
16
- config.cache = {
17
- type: 'memory',
18
- };
19
- }
20
- return config;
21
- });
22
- this.app.hooks
23
- .on('build/cache/name', () => undefined)
24
- .hooks.on('build/cache/version', () => undefined)
25
- .hooks.on('build/cache/type', () => 'memory')
26
- .hooks.on('build/cache/cacheDirectory', () => undefined)
27
- .hooks.on('build/cache/cacheLocation', () => undefined)
28
- .hooks.on('build/cache/managedPaths', () => undefined);
29
- }
30
- booted() {
31
- this.app.hooks.filter('build/cache/type') == 'filesystem' &&
32
- !pathExistsSync(this.app.path('storage')) &&
33
- mkdirSync(this.app.path('storage'));
34
- }
35
- version() {
36
- const version = crypto
37
- .createHash('sha1')
38
- .update(this.hash())
39
- .digest('base64')
40
- .replace(/[^a-z0-9]/gi, '_')
41
- .toLowerCase();
42
- return version;
43
- }
44
- directory() {
45
- return this.app.path('storage', 'cache');
46
- }
47
- buildDependencies() {
48
- return [
49
- ...new Set(sync([
50
- this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
51
- this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
52
- this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
53
- ...this.app.discovery.resolveFrom.map(dep => `${dep}/lib/cjs/index.js`),
54
- this.app.path('storage', 'cache/*'),
55
- ])),
56
- ];
57
- }
58
- hash() {
59
- var _a;
60
- return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat(readFileSync(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
61
- }
62
- }
63
- __decorate([
64
- bind
65
- ], Cache.prototype, "register", null);
66
- __decorate([
67
- bind
68
- ], Cache.prototype, "booted", null);
69
- __decorate([
70
- bind
71
- ], Cache.prototype, "version", null);
72
- __decorate([
73
- bind
74
- ], Cache.prototype, "directory", null);
75
- __decorate([
76
- bind
77
- ], Cache.prototype, "buildDependencies", null);
78
- __decorate([
79
- bind
80
- ], Cache.prototype, "hash", null);
1
+ // Copyright (c) Roots Foundation, LLC. All rights reserved.
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * The {@link @roots/bud-cache#} package implements the {@link @roots/bud-framework#Cache | Cache interface}
5
+ *
6
+ * @see https://roots.io/bud
7
+ * @see https://github.com/roots/bud
8
+ *
9
+ * @core @packageDocumentation @betaDocumentation
10
+ */
11
+ import Cache from './Cache';
81
12
  export { Cache };
82
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,OAAO,EAAgB,MAAM,sBAAsB,CAAA;AAC3D,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAC,SAAS,EAAE,cAAc,EAAE,YAAY,EAAC,MAAM,UAAU,CAAA;AAChE,OAAO,EAAC,WAAW,IAAI,IAAI,EAAC,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,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