-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(none): improve @roots/bud-api coverage
- Loading branch information
1 parent
8d16ed5
commit bf57051
Showing
36 changed files
with
523 additions
and
112 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
40 changes: 0 additions & 40 deletions
40
sources/@roots/bud-api/src/methods/compilePaths/compilePaths.ts
This file was deleted.
Oops, something went wrong.
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,6 +1,49 @@ | ||
export {compilePaths} from './compilePaths.js' | ||
import type {Rules} from '@roots/bud-framework' | ||
import type {Bud, Rules} from '@roots/bud-framework' | ||
|
||
type Source = Array<RegExp | string> | RegExp | string | ||
import {InputError} from '@roots/bud-support/errors' | ||
import isArray from '@roots/bud-support/isArray' | ||
import isString from '@roots/bud-support/isString' | ||
|
||
export type Source = Array<RegExp | string> | RegExp | string | ||
|
||
export type Parameters = [Source, Array<`${keyof Rules & string}`>?] | ||
|
||
export interface compilePaths { | ||
(this: Bud, ...value: Parameters): Bud | ||
} | ||
|
||
export const compilePaths: compilePaths = function (sources, rules) { | ||
const sourcesArray = isArray(sources) ? sources : [sources] | ||
|
||
sourcesArray.forEach(source => { | ||
if (!isString(source) && !(source instanceof RegExp)) { | ||
throw new InputError( | ||
`bud.compilePaths: source must be a string or a regular expression.`, | ||
) | ||
} | ||
}) | ||
|
||
this.hooks.action(`build.before`, async bud => { | ||
const keys: Array<`${keyof Rules & string}`> = (rules ?? | ||
Object.keys(bud.build.rules)) as `${keyof Rules & string}`[] | ||
|
||
const matches = keys.map(key => { | ||
const match = bud.build.getRule(key) | ||
|
||
if (!match) { | ||
throw new InputError( | ||
`bud.compilePaths: \`${key}\` is not a valid rule name.`, | ||
) | ||
} | ||
|
||
return match | ||
}) | ||
|
||
matches.map(rule => { | ||
bud.api.logger.log(`setting compile paths for ${rule.getTest()}`) | ||
rule.setInclude(sourcesArray) | ||
}) | ||
}) | ||
|
||
return this | ||
} |
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
Oops, something went wrong.