@roots/bud-cache 5.0.0-next.2 → 5.0.0-next.20

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,41 +1,25 @@
1
1
  <p align="center">
2
- <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
2
+ <img src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" alt="Bud" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
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"/>
18
- </a>
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
- />
24
- </a>
6
+ <img alt="MIT License" src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square" /> <img alt="npm" src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" /> <img alt="Follow Roots" src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square" />
25
7
  </p>
26
8
 
27
-
28
9
  <h1 align="center">
29
10
  <strong>@roots/bud-cache</strong>
30
11
  </h1>
31
12
 
32
- > Config caching
13
+ <p align="center">
14
+ Config caching
15
+ </p>
16
+
33
17
  ## Installation
34
18
 
35
19
  Install **@roots/bud-cache** to your project.
36
20
 
37
21
  ```shell
38
- yarn add @roots/bud-cache
22
+ yarn add @roots/bud-cache --dev
39
23
  ```
40
24
 
41
25
  ## Documentation
@@ -67,8 +51,4 @@ Help support our open-source development efforts by [becoming a patron](https://
67
51
  <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
68
52
  <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
53
  <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>
54
+ <a href="https://pantheon.io/"><img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/></a>
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bud = exports.writeFile = exports.writeJson = exports.remove = exports.readJson = exports.readFile = exports.ensureFile = exports.createHash = exports.globby = exports.bind = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Bud = (0, tslib_1.__importStar)(require("@roots/bud-framework"));
6
+ exports.Bud = Bud;
7
+ var bud_support_1 = require("@roots/bud-support");
8
+ Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bud_support_1.bind; } });
9
+ Object.defineProperty(exports, "globby", { enumerable: true, get: function () { return bud_support_1.globby; } });
10
+ var crypto_1 = require("crypto");
11
+ Object.defineProperty(exports, "createHash", { enumerable: true, get: function () { return crypto_1.createHash; } });
12
+ const bud_support_2 = require("@roots/bud-support");
13
+ exports.ensureFile = bud_support_2.fs.ensureFile, exports.readFile = bud_support_2.fs.readFile, exports.readJson = bud_support_2.fs.readJson, exports.remove = bud_support_2.fs.remove, exports.writeJson = bud_support_2.fs.writeJson, exports.writeFile = bud_support_2.fs.writeFile;
14
+ //# sourceMappingURL=cache.dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":";;;;AAAA,uEAA2C;AAanC,kBAAG;AAZX,kDAA+C;AAAvC,mGAAA,IAAI,OAAA;AAAE,qGAAA,MAAM,OAAA;AACpB,iCAAiC;AAAzB,oGAAA,UAAU,OAAA;AAElB,oDAAqC;AAEnC,kBAAU,GAMR,gBAAE,aALJ,gBAAQ,GAKN,gBAAE,WAJJ,gBAAQ,GAIN,gBAAE,WAHJ,cAAM,GAGJ,gBAAE,SAFJ,iBAAS,GAEP,gBAAE,YADJ,iBAAS,GACP,gBAAE,WAAA"}
@@ -1,107 +1,105 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Cache = void 0;
3
4
  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 crypto_1 = require("crypto");
7
- const { readFileSync } = bud_support_1.fs;
5
+ const fs_extra_1 = require("fs-extra");
6
+ const helpful_decorators_1 = require("helpful-decorators");
7
+ const lodash_1 = require("lodash");
8
+ const cache_dependencies_1 = require("./cache.dependencies");
8
9
  /**
9
- * Service class handling cache concerns
10
- *
11
- * @remarks
12
- * Interfaces with:
13
- * - {@link @roots/bud-framework#Project} to determine project dependencies for snapshotting/validation.
14
- * - {@link @roots/bud-framework#Build} via {@link @roots/bud-framework#Hooks} to update config.
15
- *
16
- * Facades:
17
- * - {@link @roots/bud-framework#Api} can toggle cache settings with {@link Bud.Persist}
10
+ * Cache service class
18
11
  *
19
12
  * @public
20
13
  */
21
- class default_1 extends bud_framework_1.Cache.Abstract {
22
- constructor() {
23
- super(...arguments);
24
- /**
25
- * {@inheritDoc}
26
- */
27
- this.name = 'cache';
28
- }
14
+ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
29
15
  /**
30
- * {@inheritDoc}
16
+ * True if cache is enabled
31
17
  *
32
- * @decorator `@bind`
18
+ * @public
33
19
  */
34
- register(app) {
35
- app.hooks
36
- .on('build/cache', () => ({
37
- type: app.hooks.filter('build/cache/type'),
38
- }))
39
- .hooks.on('build/cache/type', () => 'memory');
20
+ get enabled() {
21
+ this.log('info', {
22
+ message: `cache feature flag: ${this.app.store.get('features.cache')}`,
23
+ });
24
+ this.log('info', {
25
+ message: `--cache flag: ${this.app.store.get('cli.flags.cache')}`,
26
+ });
27
+ return this.app.store.get('features.cache') ? true : false;
40
28
  }
41
29
  /**
42
- * Returns sha1 hash as a version string
30
+ * Type
43
31
  *
44
- * @decorator `@bind`
32
+ * @public
45
33
  */
46
- version() {
47
- return (0, crypto_1.createHash)('sha1')
48
- .update(this.hash())
49
- .digest('base64')
50
- .replace(/[^a-z0-9]/gi, '_')
51
- .toLowerCase();
34
+ get type() {
35
+ const flags = this.app.store.get('cli.flags');
36
+ const cache = this.app.store.get('cache');
37
+ if (!(0, lodash_1.isUndefined)(flags['cache.type'])) {
38
+ this.log('log', {
39
+ message: '--cache.type flag',
40
+ suffix: flags['cache.type'],
41
+ });
42
+ return flags['cache.type'];
43
+ }
44
+ if (!(0, lodash_1.isUndefined)(cache.type)) {
45
+ this.log('log', {
46
+ message: 'bud.store',
47
+ suffix: cache.type,
48
+ });
49
+ return cache.type;
50
+ }
51
+ this.log('warn', 'no cache setting was passed from cli flags or from settings');
52
+ return false;
52
53
  }
53
54
  /**
54
- * Returns cache storage directory
55
- *
56
- * @decorator `@bind`
55
+ * @public
57
56
  */
58
- directory() {
59
- return this.app.path('storage', 'cache');
57
+ boot() {
58
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
59
+ this.version = yield this.hashFileContents();
60
+ if (this.enabled) {
61
+ this.app.api.call('persist', this.type);
62
+ }
63
+ });
60
64
  }
61
65
  /**
62
- * Returns array of build dependency paths
63
- *
64
- * @remarks
65
- * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
66
- *
67
- * @decorator `@bind`
66
+ * @public
68
67
  */
69
- buildDependencies() {
70
- var _a, _b, _c, _d, _e, _f, _g;
71
- return [
72
- ...new Set(bud_support_1.globby.globbySync([
73
- this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
74
- this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
75
- this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
76
- ...((_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 : []),
77
- this.app.path('storage', 'cache/*'),
78
- ])),
79
- ];
80
- }
81
- /**
82
- * Returns hash of all build dependencies and parsed CLI arguments
83
- *
84
- * @decorator `@bind`
85
- */
86
- hash() {
87
- var _a;
88
- return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat(readFileSync(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
68
+ hashFileContents() {
69
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
70
+ const makeHash = (str) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
71
+ return (0, cache_dependencies_1.createHash)('sha1')
72
+ .update(str)
73
+ .digest('base64')
74
+ .replace(/[^a-z0-9]/gi, '_')
75
+ .toLowerCase();
76
+ });
77
+ try {
78
+ const paths = this.app.project.get('dependencies');
79
+ const strings = yield Promise.all(paths.map((path) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () { return (0, fs_extra_1.readFile)(path, 'utf8'); })));
80
+ const hash = yield makeHash(`${strings}${JSON.stringify(this.app.project.get('cli'))}`);
81
+ this.log('info', {
82
+ message: 'cache hash generated',
83
+ suffix: hash,
84
+ });
85
+ this.app.hooks.async('event.project.write', (project) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
86
+ project.set('cache.hash', hash);
87
+ return project;
88
+ }));
89
+ return hash;
90
+ }
91
+ catch (e) {
92
+ this.app.error('error hashing file contents for cache');
93
+ throw new Error(e);
94
+ }
95
+ });
89
96
  }
90
97
  }
91
98
  (0, tslib_1.__decorate)([
92
- bud_support_1.bind
93
- ], default_1.prototype, "register", null);
94
- (0, tslib_1.__decorate)([
95
- bud_support_1.bind
96
- ], default_1.prototype, "version", null);
97
- (0, tslib_1.__decorate)([
98
- bud_support_1.bind
99
- ], default_1.prototype, "directory", null);
100
- (0, tslib_1.__decorate)([
101
- bud_support_1.bind
102
- ], default_1.prototype, "buildDependencies", null);
99
+ helpful_decorators_1.bind
100
+ ], Cache.prototype, "boot", null);
103
101
  (0, tslib_1.__decorate)([
104
- bud_support_1.bind
105
- ], default_1.prototype, "hash", null);
106
- exports.default = default_1;
102
+ helpful_decorators_1.bind
103
+ ], Cache.prototype, "hashFileContents", null);
104
+ exports.Cache = Cache;
107
105
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Cache/index.ts"],"names":[],"mappings":";;;AAAA,wDAAqD;AACrD,oDAAmD;AACnD,mCAAiC;AAEjC,MAAM,EAAC,YAAY,EAAC,GAAG,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AAC,CAAA,CACF,CAAA;gBAED,OAAO,IAAI,CAAA;aACZ;YAAC,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAA;gBACvD,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAA;aACnB;QACH,CAAC;KAAA;CACF;AArDC;IADC,yBAAI;iCAOJ;AAMD;IADC,yBAAI;6CAyCJ;AA9HH,sBA+HC"}
package/lib/cjs/index.js CHANGED
@@ -3,15 +3,14 @@
3
3
  // Licensed under the MIT license.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.Cache = void 0;
6
- const tslib_1 = require("tslib");
7
6
  /**
8
7
  * The {@link @roots/bud-cache#} package implements the {@link @roots/bud-framework#Cache | Cache interface}
9
8
  *
10
9
  * @see https://roots.io/bud
11
10
  * @see https://github.com/roots/bud
12
11
  *
13
- * @core @packageDocumentation @betaDocumentation
12
+ * @packageDocumentation
14
13
  */
15
- const Cache_1 = (0, tslib_1.__importDefault)(require("./Cache"));
16
- exports.Cache = Cache_1.default;
14
+ var Cache_1 = require("./Cache");
15
+ Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return Cache_1.Cache; } });
17
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,kCAAkC;;;AAElC;;;;;;;GAOG;AAEH,iCAA6B;AAArB,8FAAA,KAAK,OAAA"}
@@ -0,0 +1,7 @@
1
+ import * as Bud from '@roots/bud-framework';
2
+ export { bind, globby } from '@roots/bud-support';
3
+ export { createHash } from 'crypto';
4
+ import { fs } from '@roots/bud-support';
5
+ export const { ensureFile, readFile, readJson, remove, writeJson, writeFile, } = fs;
6
+ export { Bud };
7
+ //# sourceMappingURL=cache.dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.dependencies.js","sourceRoot":"","sources":["../../../src/Cache/cache.dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAC,EAAE,EAAC,MAAM,oBAAoB,CAAA;AACrC,MAAM,CAAC,MAAM,EACX,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,SAAS,EACT,SAAS,GACV,GAAG,EAAE,CAAA;AACN,OAAO,EAAC,GAAG,EAAC,CAAA"}
@@ -1,104 +1,101 @@
1
- import { __decorate } from "tslib";
2
- import { Cache } from '@roots/bud-framework';
3
- import { bind, fs, globby } from '@roots/bud-support';
4
- import { createHash } from 'crypto';
5
- const { readFileSync } = fs;
1
+ import { __awaiter, __decorate } from "tslib";
2
+ import { readFile } from 'fs-extra';
3
+ import { bind } from 'helpful-decorators';
4
+ import { isUndefined } from 'lodash';
5
+ import { Bud, createHash } from './cache.dependencies';
6
6
  /**
7
- * Service class handling cache concerns
8
- *
9
- * @remarks
10
- * Interfaces with:
11
- * - {@link @roots/bud-framework#Project} to determine project dependencies for snapshotting/validation.
12
- * - {@link @roots/bud-framework#Build} via {@link @roots/bud-framework#Hooks} to update config.
13
- *
14
- * Facades:
15
- * - {@link @roots/bud-framework#Api} can toggle cache settings with {@link Bud.Persist}
7
+ * Cache service class
16
8
  *
17
9
  * @public
18
10
  */
19
- export default class default_1 extends Cache.Abstract {
20
- constructor() {
21
- super(...arguments);
22
- /**
23
- * {@inheritDoc}
24
- */
25
- this.name = 'cache';
26
- }
27
- /**
28
- * {@inheritDoc}
29
- *
30
- * @decorator `@bind`
31
- */
32
- register(app) {
33
- app.hooks
34
- .on('build/cache', () => ({
35
- type: app.hooks.filter('build/cache/type'),
36
- }))
37
- .hooks.on('build/cache/type', () => 'memory');
38
- }
11
+ export class Cache extends Bud.Cache.Abstract {
39
12
  /**
40
- * Returns sha1 hash as a version string
13
+ * True if cache is enabled
41
14
  *
42
- * @decorator `@bind`
15
+ * @public
43
16
  */
44
- version() {
45
- return createHash('sha1')
46
- .update(this.hash())
47
- .digest('base64')
48
- .replace(/[^a-z0-9]/gi, '_')
49
- .toLowerCase();
17
+ get enabled() {
18
+ this.log('info', {
19
+ message: `cache feature flag: ${this.app.store.get('features.cache')}`,
20
+ });
21
+ this.log('info', {
22
+ message: `--cache flag: ${this.app.store.get('cli.flags.cache')}`,
23
+ });
24
+ return this.app.store.get('features.cache') ? true : false;
50
25
  }
51
26
  /**
52
- * Returns cache storage directory
27
+ * Type
53
28
  *
54
- * @decorator `@bind`
29
+ * @public
55
30
  */
56
- directory() {
57
- return this.app.path('storage', 'cache');
31
+ get type() {
32
+ const flags = this.app.store.get('cli.flags');
33
+ const cache = this.app.store.get('cache');
34
+ if (!isUndefined(flags['cache.type'])) {
35
+ this.log('log', {
36
+ message: '--cache.type flag',
37
+ suffix: flags['cache.type'],
38
+ });
39
+ return flags['cache.type'];
40
+ }
41
+ if (!isUndefined(cache.type)) {
42
+ this.log('log', {
43
+ message: 'bud.store',
44
+ suffix: cache.type,
45
+ });
46
+ return cache.type;
47
+ }
48
+ this.log('warn', 'no cache setting was passed from cli flags or from settings');
49
+ return false;
58
50
  }
59
51
  /**
60
- * Returns array of build dependency paths
61
- *
62
- * @remarks
63
- * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
64
- *
65
- * @decorator `@bind`
52
+ * @public
66
53
  */
67
- buildDependencies() {
68
- var _a, _b, _c, _d, _e, _f, _g;
69
- return [
70
- ...new Set(globby.globbySync([
71
- this.app.path('project', `${this.app.name}.{js,ts,yml,json}`),
72
- this.app.path('project', `${this.app.name}.config.{js,ts,yml,json}`),
73
- this.app.path('project', `${this.app.name}.${this.app.mode}.{js,ts.yml,json}`),
74
- ...((_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 : []),
75
- this.app.path('storage', 'cache/*'),
76
- ])),
77
- ];
54
+ boot() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ this.version = yield this.hashFileContents();
57
+ if (this.enabled) {
58
+ this.app.api.call('persist', this.type);
59
+ }
60
+ });
78
61
  }
79
62
  /**
80
- * Returns hash of all build dependencies and parsed CLI arguments
81
- *
82
- * @decorator `@bind`
63
+ * @public
83
64
  */
84
- hash() {
85
- var _a;
86
- return JSON.stringify((_a = this.buildDependencies().reduce((all, file) => all.concat(readFileSync(file, 'utf8')), process.argv.slice(3).join(''))) !== null && _a !== void 0 ? _a : '{}');
65
+ hashFileContents() {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const makeHash = (str) => __awaiter(this, void 0, void 0, function* () {
68
+ return createHash('sha1')
69
+ .update(str)
70
+ .digest('base64')
71
+ .replace(/[^a-z0-9]/gi, '_')
72
+ .toLowerCase();
73
+ });
74
+ try {
75
+ const paths = this.app.project.get('dependencies');
76
+ const strings = yield Promise.all(paths.map((path) => __awaiter(this, void 0, void 0, function* () { return readFile(path, 'utf8'); })));
77
+ const hash = yield makeHash(`${strings}${JSON.stringify(this.app.project.get('cli'))}`);
78
+ this.log('info', {
79
+ message: 'cache hash generated',
80
+ suffix: hash,
81
+ });
82
+ this.app.hooks.async('event.project.write', (project) => __awaiter(this, void 0, void 0, function* () {
83
+ project.set('cache.hash', hash);
84
+ return project;
85
+ }));
86
+ return hash;
87
+ }
88
+ catch (e) {
89
+ this.app.error('error hashing file contents for cache');
90
+ throw new Error(e);
91
+ }
92
+ });
87
93
  }
88
94
  }
89
95
  __decorate([
90
96
  bind
91
- ], default_1.prototype, "register", null);
92
- __decorate([
93
- bind
94
- ], default_1.prototype, "version", null);
95
- __decorate([
96
- bind
97
- ], default_1.prototype, "directory", null);
98
- __decorate([
99
- bind
100
- ], default_1.prototype, "buildDependencies", null);
97
+ ], Cache.prototype, "boot", null);
101
98
  __decorate([
102
99
  bind
103
- ], default_1.prototype, "hash", null);
100
+ ], Cache.prototype, "hashFileContents", null);
104
101
  //# sourceMappingURL=index.js.map
@@ -1 +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,IAAI,EAAE,EAAE,EAAE,MAAM,EAAC,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAEjC,MAAM,EAAC,YAAY,EAAC,GAAG,EAAE,CAAA;AAEzB;;;;;;;;;;;;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,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aDocumentation
9
+ * @packageDocumentation
10
10
  */
11
- import Cache from './Cache';
12
- export { Cache };
11
+ export { Cache } from './Cache';
13
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,kCAAkC;AAElC;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,SAAS,CAAA;AAE3B,OAAO,EAAC,KAAK,EAAC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,kCAAkC;AAElC;;;;;;;GAOG;AAEH,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAA"}