@roots/bud-cache 5.0.0-next.1 → 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.
@@ -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"}
@@ -1,107 +1,111 @@
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 helpful_decorators_1 = require("helpful-decorators");
6
+ const lodash_1 = require("lodash");
7
+ const cache_dependencies_1 = require("./cache.dependencies");
8
8
  /**
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}
9
+ * Cache service class
18
10
  *
19
11
  * @public
20
12
  */
21
- class default_1 extends bud_framework_1.Cache.Abstract {
22
- constructor() {
23
- super(...arguments);
24
- /**
25
- * {@inheritDoc}
26
- */
27
- this.name = 'cache';
28
- }
13
+ class Cache extends cache_dependencies_1.Bud.Cache.Abstract {
29
14
  /**
30
- * {@inheritDoc}
15
+ * True if cache is enabled
31
16
  *
32
- * @decorator `@bind`
17
+ * @public
33
18
  */
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');
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;
40
35
  }
41
36
  /**
42
- * Returns sha1 hash as a version string
37
+ * Type
43
38
  *
44
- * @decorator `@bind`
39
+ * @public
45
40
  */
46
- version() {
47
- return (0, crypto_1.createHash)('sha1')
48
- .update(this.hash())
49
- .digest('base64')
50
- .replace(/[^a-z0-9]/gi, '_')
51
- .toLowerCase();
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;
52
60
  }
53
61
  /**
54
- * Returns cache storage directory
55
- *
56
- * @decorator `@bind`
62
+ * @public
57
63
  */
58
- directory() {
59
- return this.app.path('storage', 'cache');
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
+ });
60
71
  }
61
72
  /**
62
- * Returns array of build dependency paths
63
- *
64
- * @remarks
65
- * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
66
- *
67
- * @decorator `@bind`
73
+ * @public
68
74
  */
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 : '{}');
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
+ });
89
102
  }
90
103
  }
91
104
  (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);
105
+ helpful_decorators_1.bind
106
+ ], Cache.prototype, "boot", null);
103
107
  (0, tslib_1.__decorate)([
104
- bud_support_1.bind
105
- ], default_1.prototype, "hash", null);
106
- exports.default = default_1;
108
+ helpful_decorators_1.bind
109
+ ], Cache.prototype, "hashFileContents", null);
110
+ exports.Cache = Cache;
107
111
  //# 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,gBAAE,CAAA;AAEzB;;;;;;;;;;;;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,CAAC;aAChB,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;aAC3B,WAAW,EAAE,CAAA;IAClB,CAAC;IAED;;;;OAIG;IAEI,SAAS;QACd,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC1C,CAAC;IAED;;;;;;;OAOG;IAEI,iBAAiB;;QACtB,OAAO;YACL,GAAG,IAAI,GAAG,CACR,oBAAM,CAAC,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,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,yBAAI;iCAMJ;AAMD;IADC,yBAAI;6CA2BJ;AApHH,sBAqHC"}
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 @betaDocumentation
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,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"}
@@ -1,104 +1,107 @@
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 { bind } from 'helpful-decorators';
3
+ import { isUndefined } from 'lodash';
4
+ import { Bud, createHash } from './cache.dependencies';
6
5
  /**
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}
6
+ * Cache service class
16
7
  *
17
8
  * @public
18
9
  */
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
- }
10
+ export class Cache extends Bud.Cache.Abstract {
39
11
  /**
40
- * Returns sha1 hash as a version string
12
+ * True if cache is enabled
41
13
  *
42
- * @decorator `@bind`
14
+ * @public
43
15
  */
44
- version() {
45
- return createHash('sha1')
46
- .update(this.hash())
47
- .digest('base64')
48
- .replace(/[^a-z0-9]/gi, '_')
49
- .toLowerCase();
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;
50
32
  }
51
33
  /**
52
- * Returns cache storage directory
34
+ * Type
53
35
  *
54
- * @decorator `@bind`
36
+ * @public
55
37
  */
56
- directory() {
57
- return this.app.path('storage', 'cache');
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;
58
57
  }
59
58
  /**
60
- * Returns array of build dependency paths
61
- *
62
- * @remarks
63
- * @see https://webpack.js.org/configuration/cache/#cachebuilddependencies
64
- *
65
- * @decorator `@bind`
59
+ * @public
66
60
  */
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
- ];
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
+ });
78
68
  }
79
69
  /**
80
- * Returns hash of all build dependencies and parsed CLI arguments
81
- *
82
- * @decorator `@bind`
70
+ * @public
83
71
  */
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 : '{}');
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
+ });
87
99
  }
88
100
  }
89
101
  __decorate([
90
102
  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);
103
+ ], Cache.prototype, "boot", null);
101
104
  __decorate([
102
105
  bind
103
- ], default_1.prototype, "hash", null);
106
+ ], Cache.prototype, "hashFileContents", null);
104
107
  //# 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,C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BACvD,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
@@ -6,8 +6,7 @@
6
6
  * @see https://roots.io/bud
7
7
  * @see https://github.com/roots/bud
8
8
  *
9
- * @core @packageDocumentation @betaDocumentation
9
+ * @packageDocumentation @betaDocumentation
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"}