Skip to content
/ bud Public

Commit 0945f3c

Browse files
authored
✨ improve: typings & tests (#2395)
- typings: enable strict mode for `@roots/bud-cache` - typings: enable strict mode for `@roots/bud-compiler` ## Type of change **PATCH: backwards compatible change**
1 parent 34f984f commit 0945f3c

File tree

32 files changed

+272
-158
lines changed

32 files changed

+272
-158
lines changed

config/eslint.config.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ module.exports = {
2828
],
2929
overrides: [
3030
{
31-
files: [`tests/**/*`, `**/*.spec.ts`, `**/*.test.ts`],
31+
files: [
32+
`**/tests/**`,
33+
`**/*.test.ts`,
34+
`**/*.test.tsx`,
35+
`**/*.test.cts`,
36+
`**/*.test.mts`,
37+
],
3238
rules: {
3339
[`n/no-extraneous-import`]: OFF,
3440
[`n/no-unpublished-import`]: OFF,

config/vitest/alias.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ export default {
1212
...packages.reduce((aliases, packageRoot) => {
1313
const signifier = relative(path(), packageRoot)
1414
aliases[signifier] = join(packageRoot, `src`)
15+
aliases[join(signifier, `*`)] = join(packageRoot, `src`, `*`)
1516
return aliases
1617
}, {}),
18+
'@roots/bud-cache': path(`sources/@roots/bud-cache/src`),
1719
'@roots/filesystem/src/vendor/sdk': path(
1820
`sources/@roots/filesystem/vendor/sdk`,
1921
),

sources/@roots/blade-loader/src/asset-loader.cts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {join} from 'node:path'
2-
31
import type {LoaderDefinitionFunction} from 'webpack'
42

3+
import {join} from 'node:path'
4+
55
const loader: LoaderDefinitionFunction<{publicPath?: string}> =
66
async function (source: string) {
77
const options = this.getOptions()

sources/@roots/blade-loader/src/loaders/index.cts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import * as vue from './vue.cjs'
88

99
export const repository = {
1010
css: {...css, loader: require.resolve(`./css.cjs`)},
11-
scss: {...scss, loader: require.resolve(`./scss.cjs`)},
1211
js: {...js, loader: require.resolve(`./js.cjs`)},
12+
scss: {...scss, loader: require.resolve(`./scss.cjs`)},
1313
ts: {...ts, loader: require.resolve(`./ts.cjs`)},
1414
vue: {...vue, loader: require.resolve(`./vue.cjs`)},
1515
}

sources/@roots/blade-loader/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class BladeWebpackPlugin implements WebpackPluginInstance {
1616
}
1717

1818
/**
19-
* Apply plugin
19+
* {@link WebpackPluginInstance.apply}
2020
*/
2121
public async apply(compiler: Compiler) {
2222
const use = [`@roots/blade-loader/asset-loader`]

sources/@roots/bud-cache/package.json

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,8 @@
4949
],
5050
"type": "module",
5151
"exports": {
52-
".": {
53-
"import": "./lib/index.js",
54-
"default": "./lib/index.js"
55-
},
56-
"./service": {
57-
"import": "./lib/service.js",
58-
"default": "./lib/service.js"
59-
},
60-
"./invalidate-cache": {
61-
"import": "./lib/invalidate-cache/index.js",
62-
"default": "./lib/invalidate-cache/index.js"
63-
},
64-
"./types": {
65-
"import": "./lib/types.js",
66-
"default": "./lib/types.js"
67-
}
52+
".": "./lib/index.js",
53+
"./service": "./lib/service.js"
6854
},
6955
"typesVersions": {
7056
"*": {
@@ -73,9 +59,6 @@
7359
],
7460
"service": [
7561
"./lib/service.d.ts"
76-
],
77-
"types": [
78-
"./lib/types.d.ts"
7962
]
8063
}
8164
},

sources/@roots/bud-cache/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
* @see {@link https://github.com/roots/bud}
99
*/
1010

11-
export {default} from './service/index.js'
11+
export {default} from '@roots/bud-cache/service'

sources/@roots/bud-cache/src/service/index.ts renamed to sources/@roots/bud-cache/src/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import {bind} from '@roots/bud-support/decorators/bind'
99
import isString from '@roots/bud-support/lodash/isString'
1010

1111
/**
12-
* Cache service class
12+
* {@link Bud.cache}
1313
*/
1414
export default class Cache extends Service implements BudCache {
1515
/**
1616
* {@link BudCache.enabled}
1717
*/
18-
public enabled: boolean
18+
public declare enabled: boolean
1919

2020
/**
21-
* {@link Extension.boot}
21+
* {@link Service.boot}
2222
*/
2323
public override async boot?(bud: Bud) {
2424
if (bud.context.force === true) {
Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,74 @@
1-
import {describe, expect, it} from 'vitest'
2-
3-
import Service from '../src/index.js'
1+
import {Bud, factory} from '@repo/test-kit'
2+
import Cache from '@roots/bud-cache/service'
3+
import {Service} from '@roots/bud-framework/service'
4+
import {beforeEach, describe, expect, it} from 'vitest'
45

56
describe(`@roots/bud-cache`, () => {
6-
it(`should be constructable`, () => {
7-
expect(Service).toBeInstanceOf(Function)
7+
let bud: Bud
8+
let cache: Cache
9+
10+
beforeEach(async () => {
11+
bud = await factory({cache: true})
12+
cache = new Cache(() => bud)
13+
})
14+
15+
it(`should be a Service`, async () => {
16+
expect(cache).toBeInstanceOf(Service)
17+
})
18+
19+
it(`should have a boot method`, async () => {
20+
expect(cache.boot).toBeDefined()
21+
expect(cache.boot).toBeInstanceOf(Function)
22+
})
23+
24+
it(`should have a register method`, async () => {
25+
expect(cache.register).toBeDefined()
26+
expect(cache.register).toBeInstanceOf(Function)
27+
})
28+
29+
30+
it(`should have a buildDependencies accessor interface`, async () => {
31+
expect(cache.buildDependencies).toBeDefined()
32+
expect(cache.buildDependencies).toBeInstanceOf(Object)
33+
})
34+
35+
it(`should have a cacheDirectory accessor interface`, async () => {
36+
await cache.register?.(bud)
37+
await cache.boot?.(bud)
38+
expect(cache.cacheDirectory).toBeDefined()
39+
expect(cache.cacheDirectory).toMatch(/@tests\/project\/cache$/)
40+
})
41+
42+
it(`should have a configuration getter`, async () => {
43+
await cache.register?.(bud)
44+
await cache.boot?.(bud)
45+
expect(cache.configuration).toBeDefined()
46+
expect(cache.configuration).toMatchInlineSnapshot(`
47+
{
48+
"allowCollectingMemory": true,
49+
"buildDependencies": {
50+
"bud": [
51+
"${bud.path()}/package.json",
52+
"${bud.path()}/config/bud.config.js",
53+
],
54+
"tailwind": [
55+
"${bud.path()}/config/tailwind.config.js",
56+
],
57+
},
58+
"cacheDirectory": "${bud.context.paths?.[`os-cache`]}/@tests/project/cache",
59+
"compression": "brotli",
60+
"hashAlgorithm": "xxhash64",
61+
"idleTimeout": 100,
62+
"idleTimeoutForInitialStore": 0,
63+
"managedPaths": [
64+
"${bud.context.paths?.[`os-cache`]}/@tests/project/cache",
65+
"${bud.path()}/node_modules",
66+
],
67+
"name": "production",
68+
"profile": false,
69+
"store": "pack",
70+
"type": "filesystem",
71+
}
72+
`)
873
})
974
})

sources/@roots/bud-cache/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
"compilerOptions": {
44
"rootDir": "src",
55
"outDir": "lib",
6-
6+
"strict": true,
77
},
88
"include": ["src"],
9-
"exclude": ["node_modules", "lib", "**/*.test.ts"],
109
"references": [
1110
{"path": "./../bud-framework/tsconfig.json"},
1211
{"path": "./../bud-support/tsconfig.json"}

0 commit comments

Comments
 (0)