@roots/bud-build 0.0.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/LICENSE.md +19 -0
- package/README.md +120 -0
- package/docs/exports.md +13 -0
- package/docs/rules.md +32 -0
- package/lib/config/bail.d.ts +3 -0
- package/lib/config/bail.d.ts.map +1 -0
- package/lib/config/bail.js +2 -0
- package/lib/config/bail.js.map +1 -0
- package/lib/config/cache.d.ts +3 -0
- package/lib/config/cache.d.ts.map +1 -0
- package/lib/config/cache.js +2 -0
- package/lib/config/cache.js.map +1 -0
- package/lib/config/context.d.ts +3 -0
- package/lib/config/context.d.ts.map +1 -0
- package/lib/config/context.js +2 -0
- package/lib/config/context.js.map +1 -0
- package/lib/config/dependencies.d.ts +3 -0
- package/lib/config/dependencies.d.ts.map +1 -0
- package/lib/config/dependencies.js +5 -0
- package/lib/config/dependencies.js.map +1 -0
- package/lib/config/devtool.d.ts +3 -0
- package/lib/config/devtool.d.ts.map +1 -0
- package/lib/config/devtool.js +2 -0
- package/lib/config/devtool.js.map +1 -0
- package/lib/config/entry.d.ts +3 -0
- package/lib/config/entry.d.ts.map +1 -0
- package/lib/config/entry.js +2 -0
- package/lib/config/entry.js.map +1 -0
- package/lib/config/experiments.d.ts +3 -0
- package/lib/config/experiments.d.ts.map +1 -0
- package/lib/config/experiments.js +2 -0
- package/lib/config/experiments.js.map +1 -0
- package/lib/config/externals.d.ts +3 -0
- package/lib/config/externals.d.ts.map +1 -0
- package/lib/config/externals.js +2 -0
- package/lib/config/externals.js.map +1 -0
- package/lib/config/externalsType.d.ts +3 -0
- package/lib/config/externalsType.d.ts.map +1 -0
- package/lib/config/externalsType.js +2 -0
- package/lib/config/externalsType.js.map +1 -0
- package/lib/config/index.d.ts +35 -0
- package/lib/config/index.d.ts.map +1 -0
- package/lib/config/index.js +27 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/infrastructureLogging.d.ts +3 -0
- package/lib/config/infrastructureLogging.d.ts.map +1 -0
- package/lib/config/infrastructureLogging.js +14 -0
- package/lib/config/infrastructureLogging.js.map +1 -0
- package/lib/config/loader.d.ts +3 -0
- package/lib/config/loader.d.ts.map +1 -0
- package/lib/config/loader.js +2 -0
- package/lib/config/loader.js.map +1 -0
- package/lib/config/mode.d.ts +3 -0
- package/lib/config/mode.d.ts.map +1 -0
- package/lib/config/mode.js +2 -0
- package/lib/config/mode.js.map +1 -0
- package/lib/config/module.d.ts +3 -0
- package/lib/config/module.d.ts.map +1 -0
- package/lib/config/module.js +23 -0
- package/lib/config/module.js.map +1 -0
- package/lib/config/name.d.ts +3 -0
- package/lib/config/name.d.ts.map +1 -0
- package/lib/config/name.js +2 -0
- package/lib/config/name.js.map +1 -0
- package/lib/config/node.d.ts +3 -0
- package/lib/config/node.d.ts.map +1 -0
- package/lib/config/node.js +2 -0
- package/lib/config/node.js.map +1 -0
- package/lib/config/optimization.d.ts +3 -0
- package/lib/config/optimization.d.ts.map +1 -0
- package/lib/config/optimization.js +11 -0
- package/lib/config/optimization.js.map +1 -0
- package/lib/config/output/assetModuleFilename.d.ts +8 -0
- package/lib/config/output/assetModuleFilename.d.ts.map +1 -0
- package/lib/config/output/assetModuleFilename.js +2 -0
- package/lib/config/output/assetModuleFilename.js.map +1 -0
- package/lib/config/output/chunkFilename.d.ts +8 -0
- package/lib/config/output/chunkFilename.d.ts.map +1 -0
- package/lib/config/output/chunkFilename.js +4 -0
- package/lib/config/output/chunkFilename.js.map +1 -0
- package/lib/config/output/filename.d.ts +8 -0
- package/lib/config/output/filename.d.ts.map +1 -0
- package/lib/config/output/filename.js +3 -0
- package/lib/config/output/filename.js.map +1 -0
- package/lib/config/output/index.d.ts +3 -0
- package/lib/config/output/index.d.ts.map +1 -0
- package/lib/config/output/index.js +18 -0
- package/lib/config/output/index.js.map +1 -0
- package/lib/config/parallelism.d.ts +3 -0
- package/lib/config/parallelism.d.ts.map +1 -0
- package/lib/config/parallelism.js +3 -0
- package/lib/config/parallelism.js.map +1 -0
- package/lib/config/performance.d.ts +3 -0
- package/lib/config/performance.d.ts.map +1 -0
- package/lib/config/performance.js +2 -0
- package/lib/config/performance.js.map +1 -0
- package/lib/config/plugins.d.ts +3 -0
- package/lib/config/plugins.d.ts.map +1 -0
- package/lib/config/plugins.js +2 -0
- package/lib/config/plugins.js.map +1 -0
- package/lib/config/profile.d.ts +3 -0
- package/lib/config/profile.d.ts.map +1 -0
- package/lib/config/profile.js +2 -0
- package/lib/config/profile.js.map +1 -0
- package/lib/config/recordsPath.d.ts +3 -0
- package/lib/config/recordsPath.d.ts.map +1 -0
- package/lib/config/recordsPath.js +2 -0
- package/lib/config/recordsPath.js.map +1 -0
- package/lib/config/resolve.d.ts +3 -0
- package/lib/config/resolve.d.ts.map +1 -0
- package/lib/config/resolve.js +30 -0
- package/lib/config/resolve.js.map +1 -0
- package/lib/config/stats.d.ts +3 -0
- package/lib/config/stats.d.ts.map +1 -0
- package/lib/config/stats.js +17 -0
- package/lib/config/stats.js.map +1 -0
- package/lib/config/target.d.ts +3 -0
- package/lib/config/target.d.ts.map +1 -0
- package/lib/config/target.js +4 -0
- package/lib/config/target.js.map +1 -0
- package/lib/handlers/index.d.ts +19 -0
- package/lib/handlers/index.d.ts.map +1 -0
- package/lib/handlers/index.js +6 -0
- package/lib/handlers/index.js.map +1 -0
- package/lib/handlers/items/items.d.ts +47 -0
- package/lib/handlers/items/items.d.ts.map +1 -0
- package/lib/handlers/items/items.js +69 -0
- package/lib/handlers/items/items.js.map +1 -0
- package/lib/handlers/loaders/loaders.d.ts +12 -0
- package/lib/handlers/loaders/loaders.d.ts.map +1 -0
- package/lib/handlers/loaders/loaders.js +11 -0
- package/lib/handlers/loaders/loaders.js.map +1 -0
- package/lib/handlers/register.d.ts +14 -0
- package/lib/handlers/register.d.ts.map +1 -0
- package/lib/handlers/register.js +26 -0
- package/lib/handlers/register.js.map +1 -0
- package/lib/handlers/rules/css.d.ts +3 -0
- package/lib/handlers/rules/css.d.ts.map +1 -0
- package/lib/handlers/rules/css.js +5 -0
- package/lib/handlers/rules/css.js.map +1 -0
- package/lib/handlers/rules/css.module.d.ts +3 -0
- package/lib/handlers/rules/css.module.d.ts.map +1 -0
- package/lib/handlers/rules/css.module.js +5 -0
- package/lib/handlers/rules/css.module.js.map +1 -0
- package/lib/handlers/rules/csv.d.ts +3 -0
- package/lib/handlers/rules/csv.d.ts.map +1 -0
- package/lib/handlers/rules/csv.js +5 -0
- package/lib/handlers/rules/csv.js.map +1 -0
- package/lib/handlers/rules/font.d.ts +3 -0
- package/lib/handlers/rules/font.d.ts.map +1 -0
- package/lib/handlers/rules/font.inline.d.ts +3 -0
- package/lib/handlers/rules/font.inline.d.ts.map +1 -0
- package/lib/handlers/rules/font.inline.js +6 -0
- package/lib/handlers/rules/font.inline.js.map +1 -0
- package/lib/handlers/rules/font.js +5 -0
- package/lib/handlers/rules/font.js.map +1 -0
- package/lib/handlers/rules/html.d.ts +3 -0
- package/lib/handlers/rules/html.d.ts.map +1 -0
- package/lib/handlers/rules/html.js +5 -0
- package/lib/handlers/rules/html.js.map +1 -0
- package/lib/handlers/rules/image.d.ts +3 -0
- package/lib/handlers/rules/image.d.ts.map +1 -0
- package/lib/handlers/rules/image.inline.d.ts +3 -0
- package/lib/handlers/rules/image.inline.d.ts.map +1 -0
- package/lib/handlers/rules/image.inline.js +6 -0
- package/lib/handlers/rules/image.inline.js.map +1 -0
- package/lib/handlers/rules/image.js +5 -0
- package/lib/handlers/rules/image.js.map +1 -0
- package/lib/handlers/rules/index.d.ts +19 -0
- package/lib/handlers/rules/index.d.ts.map +1 -0
- package/lib/handlers/rules/index.js +35 -0
- package/lib/handlers/rules/index.js.map +1 -0
- package/lib/handlers/rules/js.d.ts +3 -0
- package/lib/handlers/rules/js.d.ts.map +1 -0
- package/lib/handlers/rules/js.js +5 -0
- package/lib/handlers/rules/js.js.map +1 -0
- package/lib/handlers/rules/json.d.ts +3 -0
- package/lib/handlers/rules/json.d.ts.map +1 -0
- package/lib/handlers/rules/json.js +7 -0
- package/lib/handlers/rules/json.js.map +1 -0
- package/lib/handlers/rules/svg.d.ts +3 -0
- package/lib/handlers/rules/svg.d.ts.map +1 -0
- package/lib/handlers/rules/svg.inline.d.ts +5 -0
- package/lib/handlers/rules/svg.inline.d.ts.map +1 -0
- package/lib/handlers/rules/svg.inline.js +9 -0
- package/lib/handlers/rules/svg.inline.js.map +1 -0
- package/lib/handlers/rules/svg.js +5 -0
- package/lib/handlers/rules/svg.js.map +1 -0
- package/lib/handlers/rules/toml.d.ts +3 -0
- package/lib/handlers/rules/toml.d.ts.map +1 -0
- package/lib/handlers/rules/toml.js +7 -0
- package/lib/handlers/rules/toml.js.map +1 -0
- package/lib/handlers/rules/webp.d.ts +3 -0
- package/lib/handlers/rules/webp.d.ts.map +1 -0
- package/lib/handlers/rules/webp.js +5 -0
- package/lib/handlers/rules/webp.js.map +1 -0
- package/lib/handlers/rules/xml.d.ts +3 -0
- package/lib/handlers/rules/xml.d.ts.map +1 -0
- package/lib/handlers/rules/xml.js +5 -0
- package/lib/handlers/rules/xml.js.map +1 -0
- package/lib/handlers/rules/yml.d.ts +3 -0
- package/lib/handlers/rules/yml.d.ts.map +1 -0
- package/lib/handlers/rules/yml.js +5 -0
- package/lib/handlers/rules/yml.js.map +1 -0
- package/lib/helpers/isMjs.d.ts +3 -0
- package/lib/helpers/isMjs.d.ts.map +1 -0
- package/lib/helpers/isMjs.js +2 -0
- package/lib/helpers/isMjs.js.map +1 -0
- package/lib/helpers/scriptExtension.d.ts +3 -0
- package/lib/helpers/scriptExtension.d.ts.map +1 -0
- package/lib/helpers/scriptExtension.js +5 -0
- package/lib/helpers/scriptExtension.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +14 -0
- package/lib/index.js.map +1 -0
- package/lib/item/index.d.ts +84 -0
- package/lib/item/index.d.ts.map +1 -0
- package/lib/item/index.js +165 -0
- package/lib/item/index.js.map +1 -0
- package/lib/loader/index.d.ts +26 -0
- package/lib/loader/index.d.ts.map +1 -0
- package/lib/loader/index.js +28 -0
- package/lib/loader/index.js.map +1 -0
- package/lib/rule/index.d.ts +118 -0
- package/lib/rule/index.d.ts.map +1 -0
- package/lib/rule/index.js +261 -0
- package/lib/rule/index.js.map +1 -0
- package/lib/service.d.ts +84 -0
- package/lib/service.d.ts.map +1 -0
- package/lib/service.js +212 -0
- package/lib/service.js.map +1 -0
- package/lib/shared/base.d.ts +20 -0
- package/lib/shared/base.d.ts.map +1 -0
- package/lib/shared/base.js +43 -0
- package/lib/shared/base.js.map +1 -0
- package/lib/types.d.ts +52 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +4 -0
- package/lib/types.js.map +1 -0
- package/package.json +97 -0
- package/src/config/bail.ts +4 -0
- package/src/config/cache.ts +4 -0
- package/src/config/context.ts +3 -0
- package/src/config/dependencies.ts +11 -0
- package/src/config/devtool.ts +4 -0
- package/src/config/entry.ts +4 -0
- package/src/config/experiments.ts +4 -0
- package/src/config/externals.ts +4 -0
- package/src/config/externalsType.ts +3 -0
- package/src/config/index.test.ts +129 -0
- package/src/config/index.ts +67 -0
- package/src/config/infrastructureLogging.ts +18 -0
- package/src/config/loader.ts +4 -0
- package/src/config/mode.ts +4 -0
- package/src/config/module.ts +45 -0
- package/src/config/name.ts +4 -0
- package/src/config/node.ts +4 -0
- package/src/config/optimization.ts +20 -0
- package/src/config/output/assetModuleFilename.ts +9 -0
- package/src/config/output/chunkFilename.ts +18 -0
- package/src/config/output/filename.ts +14 -0
- package/src/config/output/index.ts +28 -0
- package/src/config/parallelism.ts +6 -0
- package/src/config/performance.ts +4 -0
- package/src/config/plugins.ts +4 -0
- package/src/config/profile.ts +4 -0
- package/src/config/recordsPath.ts +7 -0
- package/src/config/resolve.ts +45 -0
- package/src/config/stats.ts +22 -0
- package/src/config/target.ts +9 -0
- package/src/handlers/index.ts +22 -0
- package/src/handlers/items/items.ts +93 -0
- package/src/handlers/loaders/loaders.ts +31 -0
- package/src/handlers/register.ts +47 -0
- package/src/handlers/rules/css.module.ts +7 -0
- package/src/handlers/rules/css.ts +7 -0
- package/src/handlers/rules/csv.test.ts +28 -0
- package/src/handlers/rules/csv.ts +7 -0
- package/src/handlers/rules/font.inline.ts +8 -0
- package/src/handlers/rules/font.ts +7 -0
- package/src/handlers/rules/html.ts +7 -0
- package/src/handlers/rules/image.inline.ts +8 -0
- package/src/handlers/rules/image.ts +7 -0
- package/src/handlers/rules/index.ts +35 -0
- package/src/handlers/rules/js.ts +7 -0
- package/src/handlers/rules/json.ts +10 -0
- package/src/handlers/rules/svg.inline.test.ts +30 -0
- package/src/handlers/rules/svg.inline.ts +13 -0
- package/src/handlers/rules/svg.ts +7 -0
- package/src/handlers/rules/toml.test.ts +22 -0
- package/src/handlers/rules/toml.ts +10 -0
- package/src/handlers/rules/webp.ts +7 -0
- package/src/handlers/rules/xml.test.ts +27 -0
- package/src/handlers/rules/xml.ts +7 -0
- package/src/handlers/rules/yml.ts +7 -0
- package/src/helpers/isMjs.ts +4 -0
- package/src/helpers/scriptExtension.ts +11 -0
- package/src/index.ts +17 -0
- package/src/item/index.ts +179 -0
- package/src/loader/index.ts +38 -0
- package/src/rule/index.test.ts +88 -0
- package/src/rule/index.ts +257 -0
- package/src/service.ts +204 -0
- package/src/shared/base.ts +37 -0
- package/src/types.ts +57 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type {Bud} from '@roots/bud-framework'
|
|
2
|
+
|
|
3
|
+
import type {Factory} from './index.js'
|
|
4
|
+
import * as items from './items/items.js'
|
|
5
|
+
import * as loaders from './loaders/loaders.js'
|
|
6
|
+
import {rules} from './rules/index.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registry factory curry function
|
|
10
|
+
*/
|
|
11
|
+
export interface makeRegister {
|
|
12
|
+
<T, F extends CallableFunction>(props: Partial<Bud>, setRule: F): <
|
|
13
|
+
K extends keyof T & string,
|
|
14
|
+
>([key, factory]: [K, Factory<T[K]>]) => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register built-in {@link loaders}, {@link items} and {@link rules}
|
|
19
|
+
*/
|
|
20
|
+
export async function register(bud: Bud) {
|
|
21
|
+
Object.entries(loaders).map(makeRegister(bud, bud.build.setLoader))
|
|
22
|
+
Object.entries(items).map(makeRegister(bud, bud.build.setItem))
|
|
23
|
+
|
|
24
|
+
// this is a bit of a hack
|
|
25
|
+
// that sets the base stylesheet loader
|
|
26
|
+
// to minicss in production and style-loader in development
|
|
27
|
+
bud.build.items.precss = bud.isProduction
|
|
28
|
+
? bud.build.items.minicss
|
|
29
|
+
: bud.build.items.style
|
|
30
|
+
|
|
31
|
+
Object.entries(rules).map(makeRegister(bud, bud.build.setRule))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const makeRegister: makeRegister =
|
|
35
|
+
({build, hooks, isProduction, path}, setRule) =>
|
|
36
|
+
([key, factory]) =>
|
|
37
|
+
setRule(
|
|
38
|
+
key,
|
|
39
|
+
factory({
|
|
40
|
+
filter: hooks.filter,
|
|
41
|
+
makeItem: build.makeItem,
|
|
42
|
+
makeLoader: build.makeLoader,
|
|
43
|
+
makeRule: build.makeRule,
|
|
44
|
+
isProduction,
|
|
45
|
+
path,
|
|
46
|
+
}),
|
|
47
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {factory} from '@repo/test-kit/bud'
|
|
2
|
+
import {describe, expect, it} from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {csv} from './csv.js'
|
|
5
|
+
|
|
6
|
+
describe(`csv loader`, () => {
|
|
7
|
+
it(`should return a rule`, async () => {
|
|
8
|
+
const bud = await factory()
|
|
9
|
+
|
|
10
|
+
const result = csv({
|
|
11
|
+
filter: bud.hooks.filter,
|
|
12
|
+
makeItem: bud.build.makeItem,
|
|
13
|
+
makeLoader: bud.build.makeLoader,
|
|
14
|
+
makeRule: bud.build.makeRule,
|
|
15
|
+
isProduction: bud.isProduction,
|
|
16
|
+
path: bud.path,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const webpackOutput = result.toWebpack()
|
|
20
|
+
|
|
21
|
+
expect(webpackOutput.use?.[0]).toEqual(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
ident: `csv`,
|
|
24
|
+
loader: `@roots/bud-support/csv-loader`,
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {css} from './css.js'
|
|
2
|
+
import {cssModule} from './css.module.js'
|
|
3
|
+
import {csv} from './csv.js'
|
|
4
|
+
import {inlineFont} from './font.inline.js'
|
|
5
|
+
import {font} from './font.js'
|
|
6
|
+
import {html} from './html.js'
|
|
7
|
+
import {inlineImage} from './image.inline.js'
|
|
8
|
+
import {image} from './image.js'
|
|
9
|
+
import {js} from './js.js'
|
|
10
|
+
import {json} from './json.js'
|
|
11
|
+
import {inlineSvg} from './svg.inline.js'
|
|
12
|
+
import {svg} from './svg.js'
|
|
13
|
+
import {toml} from './toml.js'
|
|
14
|
+
import {webp} from './webp.js'
|
|
15
|
+
import {xml} from './xml.js'
|
|
16
|
+
import {yml} from './yml.js'
|
|
17
|
+
|
|
18
|
+
export const rules = {
|
|
19
|
+
toml,
|
|
20
|
+
xml,
|
|
21
|
+
csv,
|
|
22
|
+
yml,
|
|
23
|
+
html,
|
|
24
|
+
json,
|
|
25
|
+
font,
|
|
26
|
+
svg,
|
|
27
|
+
webp,
|
|
28
|
+
image,
|
|
29
|
+
inlineFont,
|
|
30
|
+
inlineSvg,
|
|
31
|
+
inlineImage,
|
|
32
|
+
cssModule,
|
|
33
|
+
css,
|
|
34
|
+
js,
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import json5 from '@roots/bud-support/json5'
|
|
2
|
+
|
|
3
|
+
import type {Factory} from '../index.js'
|
|
4
|
+
|
|
5
|
+
export const json: Factory = ({filter, makeRule, path}) =>
|
|
6
|
+
makeRule()
|
|
7
|
+
.setType(`json`)
|
|
8
|
+
.setInclude([() => path()])
|
|
9
|
+
.setTest(filter(`pattern.json`))
|
|
10
|
+
.setParser({parse: json5.parse})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {inlineSvg, dataUrl} from './svg.inline.js'
|
|
4
|
+
|
|
5
|
+
describe(`svg-inline`, () => {
|
|
6
|
+
it(`should return a rule`, async () => {
|
|
7
|
+
const bud = await import(`@repo/test-kit/bud`).then(
|
|
8
|
+
async ({factory}) => await factory(),
|
|
9
|
+
)
|
|
10
|
+
const result = inlineSvg({
|
|
11
|
+
filter: bud.hooks.filter,
|
|
12
|
+
makeItem: bud.build.makeItem,
|
|
13
|
+
makeLoader: bud.build.makeLoader,
|
|
14
|
+
makeRule: bud.build.makeRule,
|
|
15
|
+
isProduction: bud.isProduction,
|
|
16
|
+
path: bud.path,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const webpackOutput = result.toWebpack()
|
|
20
|
+
expect(webpackOutput.test).toEqual(bud.hooks.filter(`pattern.svg`))
|
|
21
|
+
expect(webpackOutput.include).toEqual([bud.path(`@src`)])
|
|
22
|
+
expect(webpackOutput.resourceQuery).toEqual(/inline/)
|
|
23
|
+
expect(webpackOutput.type).toEqual(`asset/inline`)
|
|
24
|
+
expect(webpackOutput.generator).toEqual(
|
|
25
|
+
expect.objectContaining({
|
|
26
|
+
dataUrl,
|
|
27
|
+
}),
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import dataUri from '@roots/bud-support/mini-svg-data-uri'
|
|
2
|
+
|
|
3
|
+
import type {Factory} from '../index.js'
|
|
4
|
+
|
|
5
|
+
export const inlineSvg: Factory = ({filter, makeRule, path}) =>
|
|
6
|
+
makeRule()
|
|
7
|
+
.setTest(filter(`pattern.svg`))
|
|
8
|
+
.setInclude([() => path(`@src`)])
|
|
9
|
+
.setResourceQuery(/inline/)
|
|
10
|
+
.setGenerator({dataUrl})
|
|
11
|
+
.setType(`asset/inline`)
|
|
12
|
+
|
|
13
|
+
export const dataUrl = (data: Buffer) => dataUri(data.toString())
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {factory} from '@repo/test-kit/bud'
|
|
2
|
+
import {describe, expect, it} from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {toml} from './toml'
|
|
5
|
+
|
|
6
|
+
describe(`toml loader`, () => {
|
|
7
|
+
let bud
|
|
8
|
+
|
|
9
|
+
it(`should return a rule`, async () => {
|
|
10
|
+
bud = await factory()
|
|
11
|
+
const result = toml({
|
|
12
|
+
filter: bud.hooks.filter,
|
|
13
|
+
makeItem: bud.build.makeItem,
|
|
14
|
+
makeLoader: bud.build.makeLoader,
|
|
15
|
+
makeRule: bud.build.makeRule,
|
|
16
|
+
isProduction: bud.isProduction,
|
|
17
|
+
path: bud.path,
|
|
18
|
+
})
|
|
19
|
+
const webpackOutput = result.toWebpack()
|
|
20
|
+
expect(webpackOutput.type).toEqual(`json`)
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import tomlParser from '@roots/bud-support/toml'
|
|
2
|
+
|
|
3
|
+
import type {Factory} from '../index.js'
|
|
4
|
+
|
|
5
|
+
export const toml: Factory = ({filter, makeRule, path}) =>
|
|
6
|
+
makeRule()
|
|
7
|
+
.setType(`json`)
|
|
8
|
+
.setInclude([() => path()])
|
|
9
|
+
.setTest(() => filter(`pattern.toml`))
|
|
10
|
+
.setParser({parse: tomlParser.parse})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {xml} from './xml'
|
|
4
|
+
|
|
5
|
+
describe(`xml loader`, () => {
|
|
6
|
+
it(`should return a rule`, async () => {
|
|
7
|
+
const bud = await import(`@repo/test-kit/bud`).then(
|
|
8
|
+
async ({factory}) => await factory(),
|
|
9
|
+
)
|
|
10
|
+
const result = xml({
|
|
11
|
+
filter: bud.hooks.filter,
|
|
12
|
+
makeItem: bud.build.makeItem,
|
|
13
|
+
makeLoader: bud.build.makeLoader,
|
|
14
|
+
makeRule: bud.build.makeRule,
|
|
15
|
+
isProduction: bud.isProduction,
|
|
16
|
+
path: bud.path,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const webpackOutput = result.toWebpack()
|
|
20
|
+
expect(webpackOutput.use?.[0]).toEqual(
|
|
21
|
+
expect.objectContaining({
|
|
22
|
+
ident: `xml`,
|
|
23
|
+
loader: `@roots/bud-support/xml-loader`,
|
|
24
|
+
}),
|
|
25
|
+
)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {Bud} from '@roots/bud-framework'
|
|
2
|
+
|
|
3
|
+
import {isMjs} from './isMjs.js'
|
|
4
|
+
|
|
5
|
+
export const scriptExtension = (
|
|
6
|
+
filter: Bud[`hooks`][`filter`],
|
|
7
|
+
mjs: `.${string}` = `.mjs`,
|
|
8
|
+
js: `.${string}` = `.js`,
|
|
9
|
+
): `.${string}` => {
|
|
10
|
+
return isMjs(filter) ? mjs : js
|
|
11
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright © Roots Software Foundation LLC
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration builder
|
|
6
|
+
*
|
|
7
|
+
* @see https://bud.js.org
|
|
8
|
+
* @see https://github.com/roots/bud
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import './types.js'
|
|
14
|
+
|
|
15
|
+
import {Build} from './service.js'
|
|
16
|
+
|
|
17
|
+
export default Build
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import type {Bud, Loaders} from '@roots/bud-framework'
|
|
2
|
+
import type * as Build from '@roots/bud-framework/services/build'
|
|
3
|
+
import {bind} from '@roots/bud-support/decorators'
|
|
4
|
+
import isString from '@roots/bud-support/lodash/isString'
|
|
5
|
+
import {basename} from 'path'
|
|
6
|
+
|
|
7
|
+
import {Loader} from '../loader/index.js'
|
|
8
|
+
import Base from '../shared/base.js'
|
|
9
|
+
|
|
10
|
+
export type ConstructorOptions = Build.Item.ConstructorOptions
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Item class
|
|
14
|
+
*/
|
|
15
|
+
class Item extends Base implements Build.Item {
|
|
16
|
+
/**
|
|
17
|
+
* Identifier
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
public ident: string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Loader
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
public loader: Loader | `${keyof Loaders & string}`
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Loader options
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
public options: Build.Item['options']
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Class constructor
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
public constructor(
|
|
42
|
+
public override _app: () => Bud,
|
|
43
|
+
constructorParams?: {
|
|
44
|
+
ident?: string
|
|
45
|
+
loader?: Loader | `${keyof Loaders & string}`
|
|
46
|
+
options?: Item['options']
|
|
47
|
+
},
|
|
48
|
+
) {
|
|
49
|
+
super(_app)
|
|
50
|
+
|
|
51
|
+
constructorParams?.ident && this.setIdent(constructorParams.ident)
|
|
52
|
+
constructorParams?.loader && this.setLoader(constructorParams.loader)
|
|
53
|
+
|
|
54
|
+
!constructorParams?.ident &&
|
|
55
|
+
constructorParams?.loader &&
|
|
56
|
+
this.setIdent(
|
|
57
|
+
isString(constructorParams.loader)
|
|
58
|
+
? constructorParams.loader
|
|
59
|
+
: basename(constructorParams.loader.getSrc()),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
constructorParams?.options &&
|
|
63
|
+
this.setOptions(constructorParams.options)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@bind
|
|
67
|
+
public getIdent(): Build.Item['ident'] {
|
|
68
|
+
return this.ident
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@bind
|
|
72
|
+
public setIdent(ident: Build.Item['ident']): this {
|
|
73
|
+
this.ident = ident
|
|
74
|
+
return this
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get rule set item loader
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
* @decorator `@bind`
|
|
82
|
+
*/
|
|
83
|
+
@bind
|
|
84
|
+
public getLoader(): Loader {
|
|
85
|
+
return this.loader instanceof Loader
|
|
86
|
+
? this.loader
|
|
87
|
+
: this.app.build.loaders[this.loader]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set rule set item loader
|
|
92
|
+
*
|
|
93
|
+
* @public
|
|
94
|
+
* @decorator `@bind`
|
|
95
|
+
*/
|
|
96
|
+
@bind
|
|
97
|
+
public setLoader(loader: Loader | `${keyof Loaders & string}`): this {
|
|
98
|
+
this.loader = loader
|
|
99
|
+
|
|
100
|
+
if (!this.ident)
|
|
101
|
+
this.setIdent(basename(isString(loader) ? loader : loader.getSrc()))
|
|
102
|
+
|
|
103
|
+
return this
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get rule set item options
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
* @decorator `@bind`
|
|
111
|
+
*/
|
|
112
|
+
@bind
|
|
113
|
+
public getOptions(): Item['options'] {
|
|
114
|
+
return this.unwrap(this.options)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Set rule set item options
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
* @decorator `@bind`
|
|
122
|
+
*/
|
|
123
|
+
@bind
|
|
124
|
+
public setOptions(options: Item['options']) {
|
|
125
|
+
this.options = options
|
|
126
|
+
return this
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Merge rule set item options
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
* @decorator `@bind`
|
|
134
|
+
*/
|
|
135
|
+
@bind
|
|
136
|
+
public mergeOptions(options: Build.Item.Options): this {
|
|
137
|
+
this.setOptions({
|
|
138
|
+
...(this.getOptions() ?? {}),
|
|
139
|
+
...options,
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
return this
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Produce rule set item object for Webpack
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
* @decorator `@bind`
|
|
150
|
+
*/
|
|
151
|
+
@bind
|
|
152
|
+
public toWebpack(): Build.Item.Output {
|
|
153
|
+
const output: Build.Item.Output = {
|
|
154
|
+
loader: this.getLoader()?.getSrc(),
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (this.options) {
|
|
158
|
+
output.options = this.getOptions()
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this.ident) {
|
|
162
|
+
output.ident = this.getIdent()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (!output.loader) {
|
|
166
|
+
this.app.error(`error in ${this.ident}`, `no loader registered`)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return Object.entries(output).reduce(
|
|
170
|
+
(output, [key, value]) => ({
|
|
171
|
+
...(output ?? {}),
|
|
172
|
+
...(value ? {[key]: value} : {}),
|
|
173
|
+
}),
|
|
174
|
+
{},
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export {Item}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {Bud} from '@roots/bud-framework'
|
|
2
|
+
|
|
3
|
+
import Base from '../shared/base.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bud Loader
|
|
7
|
+
*/
|
|
8
|
+
class Loader extends Base {
|
|
9
|
+
/**
|
|
10
|
+
* Factory returning the loader path
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
public src: string
|
|
15
|
+
/**
|
|
16
|
+
* Class constructor
|
|
17
|
+
*
|
|
18
|
+
* @param src - Either a factory returning a string or a literal string
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
public constructor(public override _app: () => Bud, src: string) {
|
|
23
|
+
super(_app)
|
|
24
|
+
this._app = _app
|
|
25
|
+
this.src = src
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getSrc(): string {
|
|
29
|
+
return this.src
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public setSrc(src: string) {
|
|
33
|
+
this.src = src
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {Loader}
|