@roots/bud-cache 5.0.0-next.7 → 5.1.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 +8 -28
- package/lib/cjs/Cache/cache.dependencies.js +23 -5
- package/lib/cjs/Cache/index.js +67 -87
- package/lib/cjs/index.js +1 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -24
- package/types/Cache/cache.dependencies.d.ts +3 -3
- package/types/Cache/cache.dependencies.d.ts.map +1 -1
- package/types/Cache/index.d.ts +11 -40
- package/types/Cache/index.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/lib/cjs/Cache/cache.dependencies.js.map +0 -1
- package/lib/cjs/Cache/index.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/esm/Cache/cache.dependencies.js +0 -6
- package/lib/esm/Cache/cache.dependencies.js.map +0 -1
- package/lib/esm/Cache/index.js +0 -105
- package/lib/esm/Cache/index.js.map +0 -1
- package/lib/esm/index.js +0 -12
- package/lib/esm/index.js.map +0 -1
- package/lib/tsconfig-esm.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -1,41 +1,25 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img
|
|
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
|
-
>
|
|
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://
|
|
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>
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
exports.Bud =
|
|
22
|
+
exports.Bud = exports.writeFile = exports.writeJson = exports.remove = exports.readJson = exports.readFile = exports.ensureFile = exports.createHash = exports.globby = exports.bind = void 0;
|
|
23
|
+
const Bud = __importStar(require("@roots/bud-framework"));
|
|
24
|
+
exports.Bud = Bud;
|
|
6
25
|
var bud_support_1 = require("@roots/bud-support");
|
|
7
26
|
Object.defineProperty(exports, "bind", { enumerable: true, get: function () { return bud_support_1.bind; } });
|
|
8
27
|
Object.defineProperty(exports, "globby", { enumerable: true, get: function () { return bud_support_1.globby; } });
|
|
9
28
|
var crypto_1 = require("crypto");
|
|
10
29
|
Object.defineProperty(exports, "createHash", { enumerable: true, get: function () { return crypto_1.createHash; } });
|
|
11
30
|
const bud_support_2 = require("@roots/bud-support");
|
|
12
|
-
exports.
|
|
13
|
-
//# sourceMappingURL=cache.dependencies.js.map
|
|
31
|
+
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;
|
package/lib/cjs/Cache/index.js
CHANGED
|
@@ -1,109 +1,89 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.Cache = void 0;
|
|
4
|
-
const
|
|
10
|
+
const fs_extra_1 = require("fs-extra");
|
|
11
|
+
const helpful_decorators_1 = require("helpful-decorators");
|
|
12
|
+
const lodash_1 = require("lodash");
|
|
5
13
|
const cache_dependencies_1 = require("./cache.dependencies");
|
|
6
14
|
/**
|
|
7
15
|
* Cache service class
|
|
8
16
|
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* Interfaces with:
|
|
11
|
-
*
|
|
12
|
-
* - {@link @roots/bud-framework#Project} to determine project dependencies for snapshotting/validation.
|
|
13
|
-
*
|
|
14
|
-
* - {@link @roots/bud-framework#Build} via {@link @roots/bud-framework#Hooks} to update config.
|
|
15
|
-
*
|
|
16
|
-
* Facades:
|
|
17
|
-
*
|
|
18
|
-
* - {@link @roots/bud-framework#Api} can toggle cache settings with {@link Bud.Persist}
|
|
19
|
-
*
|
|
20
17
|
* @public
|
|
21
18
|
*/
|
|
22
19
|
class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
|
|
23
20
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @decorator `@bind`
|
|
27
|
-
*/
|
|
28
|
-
register(app) {
|
|
29
|
-
app.hooks
|
|
30
|
-
.on('build/cache', () => ({
|
|
31
|
-
type: app.hooks.filter('build/cache/type'),
|
|
32
|
-
}))
|
|
33
|
-
.hooks.on('build/cache/type', () => 'memory');
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Returns sha1 hash as a version string
|
|
37
|
-
*
|
|
38
|
-
* @decorator `@bind`
|
|
39
|
-
*/
|
|
40
|
-
version() {
|
|
41
|
-
return (0, cache_dependencies_1.createHash)('sha1')
|
|
42
|
-
.update(this.hash())
|
|
43
|
-
.digest('base64')
|
|
44
|
-
.replace(/[^a-z0-9]/gi, '_')
|
|
45
|
-
.toLowerCase();
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Returns cache storage directory
|
|
21
|
+
* Type
|
|
49
22
|
*
|
|
50
|
-
* @
|
|
23
|
+
* @public
|
|
51
24
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
25
|
+
get type() {
|
|
26
|
+
const flags = this.app.store.get('cli.flags');
|
|
27
|
+
const cache = this.app.store.get('cache');
|
|
28
|
+
if (!(0, lodash_1.isUndefined)(flags['cache.type'])) {
|
|
29
|
+
this.log('log', {
|
|
30
|
+
message: '--cache.type flag',
|
|
31
|
+
suffix: flags['cache.type'],
|
|
32
|
+
});
|
|
33
|
+
return flags['cache.type'];
|
|
34
|
+
}
|
|
35
|
+
if (!(0, lodash_1.isUndefined)(cache.type)) {
|
|
36
|
+
this.log('log', {
|
|
37
|
+
message: 'bud.store',
|
|
38
|
+
suffix: cache.type,
|
|
39
|
+
});
|
|
40
|
+
return cache.type;
|
|
41
|
+
}
|
|
42
|
+
this.log('warn', 'no cache setting was passed from cli flags or from settings');
|
|
43
|
+
return false;
|
|
54
44
|
}
|
|
55
45
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* @remarks
|
|
59
|
-
* @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
|
|
60
|
-
*
|
|
61
|
-
* @decorator `@bind`
|
|
46
|
+
* @public
|
|
62
47
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
...this.getFrameworkEntrypoints(),
|
|
69
|
-
this.app.path('storage', 'cache', '**', '*'),
|
|
70
|
-
])),
|
|
71
|
-
];
|
|
48
|
+
async boot() {
|
|
49
|
+
this.version = await this.hashFileContents();
|
|
50
|
+
if (this.app.store.get('features.cache')) {
|
|
51
|
+
this.app.api.call('persist', this.type);
|
|
52
|
+
}
|
|
72
53
|
}
|
|
73
54
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @see https://webpack.js.org/configuration/resolve
|
|
55
|
+
* @public
|
|
77
56
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
async hashFileContents() {
|
|
58
|
+
const makeHash = async (str) => (0, cache_dependencies_1.createHash)('sha1')
|
|
59
|
+
.update(str)
|
|
60
|
+
.digest('base64')
|
|
61
|
+
.replace(/[^a-z0-9]/gi, '_')
|
|
62
|
+
.toLowerCase();
|
|
63
|
+
try {
|
|
64
|
+
const paths = this.app.project.get('dependencies');
|
|
65
|
+
const strings = await Promise.all(paths.map(async (path) => (0, fs_extra_1.readFile)(path, 'utf8')));
|
|
66
|
+
const hash = await makeHash(`${strings}${JSON.stringify(this.app.project.get('cli'))}`);
|
|
67
|
+
this.log('info', {
|
|
68
|
+
message: 'cache hash generated',
|
|
69
|
+
suffix: hash,
|
|
70
|
+
});
|
|
71
|
+
this.app.hooks.async('event.project.write', async (project) => {
|
|
72
|
+
project.set('cache.hash', hash);
|
|
73
|
+
return project;
|
|
74
|
+
});
|
|
75
|
+
return hash;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
this.app.error('error hashing file contents for cache');
|
|
79
|
+
throw new Error(e);
|
|
80
|
+
}
|
|
91
81
|
}
|
|
92
82
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
], Cache.prototype, "
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
], Cache.prototype, "
|
|
99
|
-
(0, tslib_1.__decorate)([
|
|
100
|
-
cache_dependencies_1.bind
|
|
101
|
-
], Cache.prototype, "directory", null);
|
|
102
|
-
(0, tslib_1.__decorate)([
|
|
103
|
-
cache_dependencies_1.bind
|
|
104
|
-
], Cache.prototype, "buildDependencies", null);
|
|
105
|
-
(0, tslib_1.__decorate)([
|
|
106
|
-
cache_dependencies_1.bind
|
|
107
|
-
], Cache.prototype, "hash", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
helpful_decorators_1.bind
|
|
85
|
+
], Cache.prototype, "boot", null);
|
|
86
|
+
__decorate([
|
|
87
|
+
helpful_decorators_1.bind
|
|
88
|
+
], Cache.prototype, "hashFileContents", null);
|
|
108
89
|
exports.Cache = Cache;
|
|
109
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js
CHANGED
|
@@ -9,8 +9,7 @@ exports.Cache = void 0;
|
|
|
9
9
|
* @see https://roots.io/bud
|
|
10
10
|
* @see https://github.com/roots/bud
|
|
11
11
|
*
|
|
12
|
-
* @packageDocumentation
|
|
12
|
+
* @packageDocumentation
|
|
13
13
|
*/
|
|
14
14
|
var Cache_1 = require("./Cache");
|
|
15
15
|
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return Cache_1.Cache; } });
|
|
16
|
-
//# sourceMappingURL=index.js.map
|