@roots/bud-cache 4.7.0-9 → 5.0.0-next.10
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 +48 -21
- package/lib/cjs/Cache/cache.dependencies.js +13 -0
- package/lib/cjs/Cache/cache.dependencies.js.map +1 -0
- package/lib/cjs/Cache/index.js +111 -0
- package/lib/cjs/Cache/index.js.map +1 -0
- package/lib/cjs/index.js +12 -81
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/Cache/cache.dependencies.js +6 -0
- package/lib/esm/Cache/cache.dependencies.js.map +1 -0
- package/lib/esm/Cache/index.js +107 -0
- package/lib/esm/Cache/index.js.map +1 -0
- package/lib/esm/index.js +11 -81
- package/lib/esm/index.js.map +1 -1
- package/lib/tsconfig-esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -11
- package/types/Cache/cache.dependencies.d.ts +6 -0
- package/types/Cache/cache.dependencies.d.ts.map +1 -0
- package/types/Cache/index.d.ts +37 -0
- package/types/Cache/index.d.ts.map +1 -0
- package/types/index.d.ts +9 -11
- package/types/index.d.ts.map +1 -1
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
|
|
7
|
-
|
|
8
|
-
|
|
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://
|
|
11
|
-
<img
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
Config caching utility.
|
|
22
|
-
|
|
32
|
+
> Config caching
|
|
23
33
|
## Installation
|
|
24
34
|
|
|
25
|
-
|
|
35
|
+
Install **@roots/bud-cache** to your project.
|
|
36
|
+
|
|
37
|
+
```shell
|
|
26
38
|
yarn add @roots/bud-cache
|
|
27
39
|
```
|
|
28
40
|
|
|
29
|
-
##
|
|
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
|
-
|
|
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
|
|
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,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFile = exports.writeJson = exports.remove = exports.readJson = exports.readFile = exports.ensureFile = exports.createHash = exports.globby = exports.bind = exports.Bud = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
exports.Bud = (0, tslib_1.__importStar)(require("@roots/bud-framework"));
|
|
6
|
+
var bud_support_1 = require("@roots/bud-support");
|
|
7
|
+
Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bud_support_1.bind; } });
|
|
8
|
+
Object.defineProperty(exports, "globby", { enumerable: true, get: function () { return bud_support_1.globby; } });
|
|
9
|
+
var crypto_1 = require("crypto");
|
|
10
|
+
Object.defineProperty(exports, "createHash", { enumerable: true, get: function () { return crypto_1.createHash; } });
|
|
11
|
+
const bud_support_2 = require("@roots/bud-support");
|
|
12
|
+
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;
|
|
13
|
+
//# 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,yEAA2C;AAC3C,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"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cache = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const helpful_decorators_1 = require("helpful-decorators");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const cache_dependencies_1 = require("./cache.dependencies");
|
|
8
|
+
/**
|
|
9
|
+
* Cache service class
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
|
|
14
|
+
/**
|
|
15
|
+
* True if cache is enabled
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
get enabled() {
|
|
20
|
+
if (this.app.store.is('cli.flags.cache', true)) {
|
|
21
|
+
this.log('info', {
|
|
22
|
+
message: '--cache',
|
|
23
|
+
suffix: this.app.store.get('cli.flags.cache'),
|
|
24
|
+
});
|
|
25
|
+
return this.app.store.get('cli.flags.cache');
|
|
26
|
+
}
|
|
27
|
+
if (this.app.store.is('features.cache', true)) {
|
|
28
|
+
this.log('info', {
|
|
29
|
+
message: 'bud.store',
|
|
30
|
+
suffix: this.app.store.get('features.cache'),
|
|
31
|
+
});
|
|
32
|
+
return this.app.store.get('features.cache');
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Type
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
get type() {
|
|
42
|
+
const flags = this.app.store.get('cli.flags');
|
|
43
|
+
const cache = this.app.store.get('cache');
|
|
44
|
+
if (!(0, lodash_1.isUndefined)(flags['cache.type'])) {
|
|
45
|
+
this.log('info', {
|
|
46
|
+
message: '--cache.type flag',
|
|
47
|
+
suffix: flags['cache.type'],
|
|
48
|
+
});
|
|
49
|
+
return flags['cache.type'];
|
|
50
|
+
}
|
|
51
|
+
if (!(0, lodash_1.isUndefined)(cache.type)) {
|
|
52
|
+
this.log('info', {
|
|
53
|
+
message: 'bud.store',
|
|
54
|
+
suffix: cache.type,
|
|
55
|
+
});
|
|
56
|
+
return cache.type;
|
|
57
|
+
}
|
|
58
|
+
this.log('warn', 'no cache setting was passed from cli flags or from settings');
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
boot() {
|
|
65
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
66
|
+
this.version = yield this.hashFileContents();
|
|
67
|
+
if (this.enabled) {
|
|
68
|
+
this.app.persist(this.type);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
hashFileContents() {
|
|
76
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
77
|
+
const hash = (str) => (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
78
|
+
return (0, cache_dependencies_1.createHash)('sha1')
|
|
79
|
+
.update(str)
|
|
80
|
+
.digest('base64')
|
|
81
|
+
.replace(/[^a-z0-9]/gi, '_')
|
|
82
|
+
.toLowerCase();
|
|
83
|
+
});
|
|
84
|
+
try {
|
|
85
|
+
return yield hash(JSON.stringify({
|
|
86
|
+
checks: [
|
|
87
|
+
this.app.mode,
|
|
88
|
+
this.app.store.get('cli.flags.features'),
|
|
89
|
+
this.app.store.get('cli.flags.location'),
|
|
90
|
+
this.app.project.get('manifest'),
|
|
91
|
+
this.app.project.get('configs'),
|
|
92
|
+
this.app.project.get('resolve'),
|
|
93
|
+
this.app.project.get('dependencies'),
|
|
94
|
+
],
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
this.app.error('error hashing file contents for cache');
|
|
99
|
+
throw new Error(e);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
(0, tslib_1.__decorate)([
|
|
105
|
+
helpful_decorators_1.bind
|
|
106
|
+
], Cache.prototype, "boot", null);
|
|
107
|
+
(0, tslib_1.__decorate)([
|
|
108
|
+
helpful_decorators_1.bind
|
|
109
|
+
], Cache.prototype, "hashFileContents", null);
|
|
110
|
+
exports.Cache = Cache;
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Cache/index.ts"],"names":[],"mappings":";;;;AAAA,2DAAuC;AACvC,mCAAkC;AAElC,6DAAoD;AAEpD;;;;GAIG;AACH,MAAa,KACX,SAAQ,wBAAG,CAAC,KAAK,CAAC,QAAQ;IAG1B;;;;OAIG;IACH,IAAW,OAAO;QAChB,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,EAAE,IAAI,CAAC,EAAE;YAC9C,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;gBACf,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC;aAC9C,CAAC,CAAA;YAEF,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;SAC7C;QAED,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,gBAAgB,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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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
6
|
+
/**
|
|
7
|
+
* The {@link @roots/bud-cache#} package implements the {@link @roots/bud-framework#Cache | Cache interface}
|
|
8
|
+
*
|
|
9
|
+
* @see https://roots.io/bud
|
|
10
|
+
* @see https://github.com/roots/bud
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation @betaDocumentation
|
|
13
|
+
*/
|
|
14
|
+
var Cache_1 = require("./Cache");
|
|
15
|
+
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return Cache_1.Cache; } });
|
|
85
16
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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,6 @@
|
|
|
1
|
+
export * 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
|
+
//# 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"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { __awaiter, __decorate } from "tslib";
|
|
2
|
+
import { bind } from 'helpful-decorators';
|
|
3
|
+
import { isUndefined } from 'lodash';
|
|
4
|
+
import { Bud, createHash } from './cache.dependencies';
|
|
5
|
+
/**
|
|
6
|
+
* Cache service class
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class Cache extends Bud.Cache.Abstract {
|
|
11
|
+
/**
|
|
12
|
+
* True if cache is enabled
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
get enabled() {
|
|
17
|
+
if (this.app.store.is('cli.flags.cache', true)) {
|
|
18
|
+
this.log('info', {
|
|
19
|
+
message: '--cache',
|
|
20
|
+
suffix: this.app.store.get('cli.flags.cache'),
|
|
21
|
+
});
|
|
22
|
+
return this.app.store.get('cli.flags.cache');
|
|
23
|
+
}
|
|
24
|
+
if (this.app.store.is('features.cache', true)) {
|
|
25
|
+
this.log('info', {
|
|
26
|
+
message: 'bud.store',
|
|
27
|
+
suffix: this.app.store.get('features.cache'),
|
|
28
|
+
});
|
|
29
|
+
return this.app.store.get('features.cache');
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
get type() {
|
|
39
|
+
const flags = this.app.store.get('cli.flags');
|
|
40
|
+
const cache = this.app.store.get('cache');
|
|
41
|
+
if (!isUndefined(flags['cache.type'])) {
|
|
42
|
+
this.log('info', {
|
|
43
|
+
message: '--cache.type flag',
|
|
44
|
+
suffix: flags['cache.type'],
|
|
45
|
+
});
|
|
46
|
+
return flags['cache.type'];
|
|
47
|
+
}
|
|
48
|
+
if (!isUndefined(cache.type)) {
|
|
49
|
+
this.log('info', {
|
|
50
|
+
message: 'bud.store',
|
|
51
|
+
suffix: cache.type,
|
|
52
|
+
});
|
|
53
|
+
return cache.type;
|
|
54
|
+
}
|
|
55
|
+
this.log('warn', 'no cache setting was passed from cli flags or from settings');
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
boot() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
this.version = yield this.hashFileContents();
|
|
64
|
+
if (this.enabled) {
|
|
65
|
+
this.app.persist(this.type);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
hashFileContents() {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const hash = (str) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return createHash('sha1')
|
|
76
|
+
.update(str)
|
|
77
|
+
.digest('base64')
|
|
78
|
+
.replace(/[^a-z0-9]/gi, '_')
|
|
79
|
+
.toLowerCase();
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
return yield hash(JSON.stringify({
|
|
83
|
+
checks: [
|
|
84
|
+
this.app.mode,
|
|
85
|
+
this.app.store.get('cli.flags.features'),
|
|
86
|
+
this.app.store.get('cli.flags.location'),
|
|
87
|
+
this.app.project.get('manifest'),
|
|
88
|
+
this.app.project.get('configs'),
|
|
89
|
+
this.app.project.get('resolve'),
|
|
90
|
+
this.app.project.get('dependencies'),
|
|
91
|
+
],
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
catch (e) {
|
|
95
|
+
this.app.error('error hashing file contents for cache');
|
|
96
|
+
throw new Error(e);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
__decorate([
|
|
102
|
+
bind
|
|
103
|
+
], Cache.prototype, "boot", null);
|
|
104
|
+
__decorate([
|
|
105
|
+
bind
|
|
106
|
+
], Cache.prototype, "hashFileContents", null);
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
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,GAAG,CAAC,IAAI;wBACb,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC;wBACxC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,oBAAoB,CAAC;wBACxC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;wBAChC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;wBAC/B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;wBAC/B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;qBACrC;iBACF,CAAC,CACH,CAAA;aACF;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;AAtCC;IADC,IAAI;iCAMJ;AAMD;IADC,IAAI;6CA2BJ"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,82 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
81
|
-
export { Cache };
|
|
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
|
+
* @packageDocumentation @betaDocumentation
|
|
10
|
+
*/
|
|
11
|
+
export { Cache } from './Cache';
|
|
82
12
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
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"}
|