-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- typings: enable strict mode for `@roots/bud-cache` - typings: enable strict mode for `@roots/bud-compiler` ## Type of change **PATCH: backwards compatible change**
- Loading branch information
1 parent
34f984f
commit 0945f3c
Showing
32 changed files
with
272 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,74 @@ | ||
import {describe, expect, it} from 'vitest' | ||
|
||
import Service from '../src/index.js' | ||
import {Bud, factory} from '@repo/test-kit' | ||
import Cache from '@roots/bud-cache/service' | ||
import {Service} from '@roots/bud-framework/service' | ||
import {beforeEach, describe, expect, it} from 'vitest' | ||
|
||
describe(`@roots/bud-cache`, () => { | ||
it(`should be constructable`, () => { | ||
expect(Service).toBeInstanceOf(Function) | ||
let bud: Bud | ||
let cache: Cache | ||
|
||
beforeEach(async () => { | ||
bud = await factory({cache: true}) | ||
cache = new Cache(() => bud) | ||
}) | ||
|
||
it(`should be a Service`, async () => { | ||
expect(cache).toBeInstanceOf(Service) | ||
}) | ||
|
||
it(`should have a boot method`, async () => { | ||
expect(cache.boot).toBeDefined() | ||
expect(cache.boot).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`should have a register method`, async () => { | ||
expect(cache.register).toBeDefined() | ||
expect(cache.register).toBeInstanceOf(Function) | ||
}) | ||
|
||
|
||
it(`should have a buildDependencies accessor interface`, async () => { | ||
expect(cache.buildDependencies).toBeDefined() | ||
expect(cache.buildDependencies).toBeInstanceOf(Object) | ||
}) | ||
|
||
it(`should have a cacheDirectory accessor interface`, async () => { | ||
await cache.register?.(bud) | ||
await cache.boot?.(bud) | ||
expect(cache.cacheDirectory).toBeDefined() | ||
expect(cache.cacheDirectory).toMatch(/@tests\/project\/cache$/) | ||
}) | ||
|
||
it(`should have a configuration getter`, async () => { | ||
await cache.register?.(bud) | ||
await cache.boot?.(bud) | ||
expect(cache.configuration).toBeDefined() | ||
expect(cache.configuration).toMatchInlineSnapshot(` | ||
{ | ||
"allowCollectingMemory": true, | ||
"buildDependencies": { | ||
"bud": [ | ||
"${bud.path()}/package.json", | ||
"${bud.path()}/config/bud.config.js", | ||
], | ||
"tailwind": [ | ||
"${bud.path()}/config/tailwind.config.js", | ||
], | ||
}, | ||
"cacheDirectory": "${bud.context.paths?.[`os-cache`]}/@tests/project/cache", | ||
"compression": "brotli", | ||
"hashAlgorithm": "xxhash64", | ||
"idleTimeout": 100, | ||
"idleTimeoutForInitialStore": 0, | ||
"managedPaths": [ | ||
"${bud.context.paths?.[`os-cache`]}/@tests/project/cache", | ||
"${bud.path()}/node_modules", | ||
], | ||
"name": "production", | ||
"profile": false, | ||
"store": "pack", | ||
"type": "filesystem", | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Calls once document has loaded. | ||
* | ||
* @remarks | ||
* Callback function may be async or sync | ||
* | ||
* @param onReady - callback function | ||
* @returns void | ||
*/ | ||
interface domReady { | ||
(onReady: () => (() => Promise<unknown>) | unknown): void | ||
} | ||
|
||
const domReady: domReady = onReady => { | ||
window.requestAnimationFrame(async function check() { | ||
document.body ? await onReady() : window.requestAnimationFrame(check) | ||
}) | ||
} | ||
|
||
export default domReady |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Lazy import helper | ||
* | ||
* @remarks | ||
* Callback function may be async or sync | ||
* | ||
* @param onReady - callback function | ||
* @returns void | ||
*/ | ||
interface lazy { | ||
<T = any>( | ||
module: Promise<{default: T}>, | ||
handler: (module: T) => Promise<unknown> | unknown, | ||
errorHandler?: (error: unknown) => unknown, | ||
): Promise<unknown> | ||
} | ||
|
||
/** | ||
* Default error handler | ||
* | ||
* @throws Error | ||
*/ | ||
const defaultErrorHandler = (error: unknown) => { | ||
throw error | ||
} | ||
|
||
const lazy: lazy = async function lazy<T = any>( | ||
module: Promise<{default: T}>, | ||
handler: (module: T) => Promise<unknown> | unknown, | ||
errorHandler?: (error: unknown) => unknown, | ||
) { | ||
try { | ||
const {default: request} = await module | ||
return await handler(request) | ||
} catch (error: unknown) { | ||
const handle = errorHandler ? errorHandler : defaultErrorHandler | ||
handle(error) | ||
} | ||
} | ||
|
||
export default lazy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.