@roots/bud-build 6.6.5 → 6.6.6
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/README.md +28 -19
- package/docs/exports.md +13 -0
- package/docs/rules.md +32 -0
- package/lib/config/bail.d.ts +2 -2
- package/lib/config/bail.d.ts.map +1 -1
- package/lib/config/bail.js +1 -1
- package/lib/config/bail.js.map +1 -1
- package/lib/config/cache.d.ts +2 -2
- package/lib/config/cache.d.ts.map +1 -1
- package/lib/config/cache.js +1 -1
- package/lib/config/cache.js.map +1 -1
- package/lib/config/context.d.ts +2 -2
- package/lib/config/context.d.ts.map +1 -1
- package/lib/config/context.js +1 -1
- package/lib/config/context.js.map +1 -1
- 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 +2 -2
- package/lib/config/devtool.d.ts.map +1 -1
- package/lib/config/devtool.js +1 -1
- package/lib/config/devtool.js.map +1 -1
- 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 +2 -2
- package/lib/config/experiments.d.ts.map +1 -1
- package/lib/config/experiments.js +1 -1
- package/lib/config/experiments.js.map +1 -1
- 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 +2 -2
- package/lib/config/infrastructureLogging.d.ts.map +1 -1
- package/lib/config/infrastructureLogging.js +12 -3
- package/lib/config/infrastructureLogging.js.map +1 -1
- 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 +2 -6
- package/lib/config/module.d.ts.map +1 -1
- package/lib/config/module.js +20 -18
- package/lib/config/module.js.map +1 -1
- 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 +2 -2
- package/lib/config/optimization.d.ts.map +1 -1
- package/lib/config/optimization.js +8 -7
- package/lib/config/optimization.js.map +1 -1
- 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 +4 -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 +2 -3
- package/lib/config/resolve.d.ts.map +1 -1
- package/lib/config/resolve.js +16 -9
- package/lib/config/resolve.js.map +1 -1
- 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 +69 -0
- package/lib/handlers/items/items.d.ts.map +1 -0
- package/lib/handlers/items/items.js +93 -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 +18 -0
- package/lib/handlers/register.d.ts.map +1 -0
- package/lib/handlers/register.js +28 -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 +2 -8
- package/lib/handlers/rules/csv.d.ts.map +1 -1
- package/lib/handlers/rules/csv.js +3 -9
- package/lib/handlers/rules/csv.js.map +1 -1
- 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 +3 -0
- package/lib/handlers/rules/svg.inline.d.ts.map +1 -0
- package/lib/handlers/rules/svg.inline.js +6 -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 +2 -8
- package/lib/handlers/rules/toml.d.ts.map +1 -1
- package/lib/handlers/rules/toml.js +3 -9
- package/lib/handlers/rules/toml.js.map +1 -1
- 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 +2 -8
- package/lib/handlers/rules/xml.d.ts.map +1 -1
- package/lib/handlers/rules/xml.js +3 -9
- package/lib/handlers/rules/xml.js.map +1 -1
- 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 +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/item/index.d.ts +2 -2
- package/lib/item/index.d.ts.map +1 -1
- package/lib/item/index.js +6 -3
- package/lib/item/index.js.map +1 -1
- package/lib/loader/index.d.ts +2 -1
- package/lib/loader/index.d.ts.map +1 -1
- package/lib/loader/index.js +2 -1
- package/lib/loader/index.js.map +1 -1
- package/lib/rule/index.d.ts +30 -21
- package/lib/rule/index.d.ts.map +1 -1
- package/lib/rule/index.js +64 -37
- package/lib/rule/index.js.map +1 -1
- package/lib/service.d.ts +9 -12
- package/lib/service.d.ts.map +1 -1
- package/lib/service.js +28 -59
- package/lib/service.js.map +1 -1
- package/lib/shared/base.d.ts +1 -1
- package/lib/shared/base.d.ts.map +1 -1
- package/lib/shared/base.js +4 -2
- package/lib/shared/base.js.map +1 -1
- package/lib/types.d.ts +8 -2
- package/lib/types.d.ts.map +1 -1
- package/package.json +35 -37
- 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 +21 -0
- package/src/config/loader.ts +4 -0
- package/src/config/mode.ts +4 -0
- package/src/config/module.ts +43 -0
- package/src/config/name.ts +4 -0
- package/src/config/node.ts +4 -0
- package/src/config/optimization.ts +19 -0
- package/src/config/output/assetModuleFilename.ts +9 -0
- package/src/config/output/chunkFilename.ts +18 -0
- package/src/config/output/filename.ts +19 -0
- package/src/config/output/index.ts +27 -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 +33 -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 +117 -0
- package/src/handlers/loaders/loaders.ts +31 -0
- package/src/handlers/register.ts +51 -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 +25 -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.ts +8 -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 +24 -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 +181 -0
- package/src/loader/index.ts +40 -0
- package/src/rule/index.test.ts +88 -0
- package/src/rule/index.ts +311 -0
- package/src/service.ts +245 -0
- package/src/shared/base.ts +37 -0
- package/src/types.ts +57 -0
- package/lib/config/builder.d.ts +0 -31
- package/lib/config/builder.d.ts.map +0 -1
- package/lib/config/builder.js +0 -32
- package/lib/config/builder.js.map +0 -1
- package/lib/config/output.d.ts +0 -4
- package/lib/config/output.d.ts.map +0 -1
- package/lib/config/output.js +0 -13
- package/lib/config/output.js.map +0 -1
- package/lib/handlers/items.d.ts +0 -69
- package/lib/handlers/items.d.ts.map +0 -1
- package/lib/handlers/items.js +0 -99
- package/lib/handlers/items.js.map +0 -1
- package/lib/handlers/loaders.d.ts +0 -57
- package/lib/handlers/loaders.d.ts.map +0 -1
- package/lib/handlers/loaders.js +0 -82
- package/lib/handlers/loaders.js.map +0 -1
- package/lib/handlers/rules/rules.d.ts +0 -63
- package/lib/handlers/rules/rules.d.ts.map +0 -1
- package/lib/handlers/rules/rules.js +0 -124
- package/lib/handlers/rules/rules.js.map +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
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-es'
|
|
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
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class Item extends Base implements Build.Item {
|
|
18
|
+
/**
|
|
19
|
+
* Identifier
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
public ident: string
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Loader
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
public loader: Loader | `${keyof Loaders & string}`
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Loader options
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
public options: Build.Item['options']
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Class constructor
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
public constructor(
|
|
44
|
+
public override _app: () => Bud,
|
|
45
|
+
constructorParams?: {
|
|
46
|
+
ident?: string
|
|
47
|
+
loader?: Loader | `${keyof Loaders & string}`
|
|
48
|
+
options?: Item['options']
|
|
49
|
+
},
|
|
50
|
+
) {
|
|
51
|
+
super(_app)
|
|
52
|
+
|
|
53
|
+
constructorParams?.ident && this.setIdent(constructorParams.ident)
|
|
54
|
+
constructorParams?.loader && this.setLoader(constructorParams.loader)
|
|
55
|
+
|
|
56
|
+
!constructorParams?.ident &&
|
|
57
|
+
constructorParams?.loader &&
|
|
58
|
+
this.setIdent(
|
|
59
|
+
isString(constructorParams.loader)
|
|
60
|
+
? constructorParams.loader
|
|
61
|
+
: basename(constructorParams.loader.getSrc()),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
constructorParams?.options &&
|
|
65
|
+
this.setOptions(constructorParams.options)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@bind
|
|
69
|
+
public getIdent(): Build.Item['ident'] {
|
|
70
|
+
return this.ident
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@bind
|
|
74
|
+
public setIdent(ident: Build.Item['ident']): this {
|
|
75
|
+
this.ident = ident
|
|
76
|
+
return this
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get rule set item loader
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
* @decorator `@bind`
|
|
84
|
+
*/
|
|
85
|
+
@bind
|
|
86
|
+
public getLoader(): Loader {
|
|
87
|
+
return this.loader instanceof Loader
|
|
88
|
+
? this.loader
|
|
89
|
+
: this.app.build.loaders[this.loader]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set rule set item loader
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
* @decorator `@bind`
|
|
97
|
+
*/
|
|
98
|
+
@bind
|
|
99
|
+
public setLoader(loader: Loader | `${keyof Loaders & string}`): this {
|
|
100
|
+
this.loader = loader
|
|
101
|
+
|
|
102
|
+
if (!this.ident)
|
|
103
|
+
this.setIdent(basename(isString(loader) ? loader : loader.getSrc()))
|
|
104
|
+
|
|
105
|
+
return this
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get rule set item options
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
* @decorator `@bind`
|
|
113
|
+
*/
|
|
114
|
+
@bind
|
|
115
|
+
public getOptions(): Item['options'] {
|
|
116
|
+
return this.unwrap(this.options)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Set rule set item options
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @decorator `@bind`
|
|
124
|
+
*/
|
|
125
|
+
@bind
|
|
126
|
+
public setOptions(options: Item['options']) {
|
|
127
|
+
this.options = options
|
|
128
|
+
return this
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Merge rule set item options
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @decorator `@bind`
|
|
136
|
+
*/
|
|
137
|
+
@bind
|
|
138
|
+
public mergeOptions(options: Build.Item.Options): this {
|
|
139
|
+
this.setOptions({
|
|
140
|
+
...(this.getOptions() ?? {}),
|
|
141
|
+
...options,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
return this
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Produce rule set item object for Webpack
|
|
149
|
+
*
|
|
150
|
+
* @public
|
|
151
|
+
* @decorator `@bind`
|
|
152
|
+
*/
|
|
153
|
+
@bind
|
|
154
|
+
public toWebpack(): Build.Item.Output {
|
|
155
|
+
const output: Build.Item.Output = {
|
|
156
|
+
loader: this.getLoader()?.getSrc(),
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (this.options) {
|
|
160
|
+
output.options = this.getOptions()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (this.ident) {
|
|
164
|
+
output.ident = this.getIdent()
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!output.loader) {
|
|
168
|
+
this.app.error(`error in ${this.ident}`, `no loader registered`)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return Object.entries(output).reduce(
|
|
172
|
+
(output, [key, value]) => ({
|
|
173
|
+
...(output ?? {}),
|
|
174
|
+
...(value ? {[key]: value} : {}),
|
|
175
|
+
}),
|
|
176
|
+
{},
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export {Item}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {Bud} from '@roots/bud-framework'
|
|
2
|
+
|
|
3
|
+
import Base from '../shared/base.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bud Loader
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
class Loader extends Base {
|
|
11
|
+
/**
|
|
12
|
+
* Factory returning the loader path
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
public src: string
|
|
17
|
+
/**
|
|
18
|
+
* Class constructor
|
|
19
|
+
*
|
|
20
|
+
* @param src - Either a factory returning a string or a literal string
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
public constructor(public override _app: () => Bud, src: string) {
|
|
25
|
+
super(_app)
|
|
26
|
+
this._app = _app
|
|
27
|
+
this.src = src
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public getSrc(): string {
|
|
31
|
+
return this.src
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public setSrc(src: string) {
|
|
35
|
+
this.src = src
|
|
36
|
+
return this
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {Loader}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {factory} from '@repo/test-kit/bud'
|
|
2
|
+
import {beforeAll, describe, expect, it} from 'vitest'
|
|
3
|
+
|
|
4
|
+
import {Rule} from './index.js'
|
|
5
|
+
|
|
6
|
+
describe(`Build Rule`, function () {
|
|
7
|
+
let bud
|
|
8
|
+
|
|
9
|
+
beforeAll(async () => {
|
|
10
|
+
bud = await factory()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it(`is constructable`, () => {
|
|
14
|
+
const rule = {test: /.foo$/}
|
|
15
|
+
expect(new Rule(() => bud, rule)).toBeInstanceOf(Rule)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it(`make`, () => {
|
|
19
|
+
const rule = {test: /.foo$/}
|
|
20
|
+
expect(new Rule(() => bud, rule).toWebpack()).toEqual({
|
|
21
|
+
test: /.foo$/,
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it(`getUse`, () => {
|
|
26
|
+
const input = [`md`]
|
|
27
|
+
const rule = new Rule(() => bud, {
|
|
28
|
+
test: /.foo$/,
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
use: input,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
expect(rule.getUse()).toEqual(input)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it(`setUse`, () => {
|
|
37
|
+
const input = [`raw`, `md`]
|
|
38
|
+
const rule = new Rule(() => bud, {test: /.foo$/})
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
rule.setUse(input)
|
|
41
|
+
|
|
42
|
+
expect(rule.use).toEqual(input)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it(`getTest`, () => {
|
|
46
|
+
const input = /.foo$/
|
|
47
|
+
const rule = new Rule(() => bud, {test: input})
|
|
48
|
+
|
|
49
|
+
expect(rule.getTest()).toEqual(input)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it(`setTest`, () => {
|
|
53
|
+
const input = () => /.js$/
|
|
54
|
+
const rule = new Rule(() => bud, {test: /.foo$/})
|
|
55
|
+
rule.setTest(input)
|
|
56
|
+
|
|
57
|
+
expect(rule.test).toEqual(input)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it(`getExclude`, () => {
|
|
61
|
+
const definition = {
|
|
62
|
+
test: /.foo$/,
|
|
63
|
+
exclude: [/.bar$/],
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const rule = new Rule(() => bud, definition)
|
|
67
|
+
|
|
68
|
+
expect(rule.exclude).toEqual(definition.exclude)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it(`setExclude from fn`, () => {
|
|
72
|
+
const rule = new Rule(() => bud, {test: /.foo$/})
|
|
73
|
+
|
|
74
|
+
const mutationFn = () => [/.js$/]
|
|
75
|
+
rule.setExclude(mutationFn)
|
|
76
|
+
|
|
77
|
+
expect(rule.getExclude()).toEqual([/.js$/])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it(`setExclude from obj`, () => {
|
|
81
|
+
const rule = new Rule(() => bud, {test: /.foo$/})
|
|
82
|
+
|
|
83
|
+
const mutation = [/.js$/]
|
|
84
|
+
rule.setExclude(mutation)
|
|
85
|
+
|
|
86
|
+
expect(rule.getExclude()).toStrictEqual(mutation)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import type {Bud, Items} from '@roots/bud-framework'
|
|
2
|
+
import type {
|
|
3
|
+
Options,
|
|
4
|
+
Output,
|
|
5
|
+
Parser,
|
|
6
|
+
Rule as Interface,
|
|
7
|
+
} from '@roots/bud-framework/services/build/rule'
|
|
8
|
+
import {bind} from '@roots/bud-support/decorators'
|
|
9
|
+
import {isFunction, isString} from '@roots/bud-support/lodash-es'
|
|
10
|
+
|
|
11
|
+
import type {Item} from '../item/index.js'
|
|
12
|
+
import Base from '../shared/base.js'
|
|
13
|
+
|
|
14
|
+
export {Interface, Options, Output, Parser}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Bud Rule
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class Rule extends Base implements Interface {
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
public test: Options['test']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
public use?: Options[`use`]
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
public include?: Options['include']
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
public exclude?: Options['exclude']
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
public type?: Interface['type']
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
public resourceQuery?: Interface['resourceQuery']
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
public parser?: Interface['parser']
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generator factory
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
public generator?: Interface['generator']
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Class constructor
|
|
66
|
+
*
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
public constructor(_app: () => Bud, options?: Options) {
|
|
70
|
+
super(_app)
|
|
71
|
+
this._app = _app
|
|
72
|
+
|
|
73
|
+
if (!options) return
|
|
74
|
+
|
|
75
|
+
this.setTest(options.test)
|
|
76
|
+
this.setUse(options.use)
|
|
77
|
+
this.setInclude(options.include)
|
|
78
|
+
this.setExclude(options.exclude)
|
|
79
|
+
this.setType(options.type)
|
|
80
|
+
this.setParser(options.parser)
|
|
81
|
+
this.setGenerator(options.generator)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Test value
|
|
86
|
+
*
|
|
87
|
+
* @param app - Bud instance
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
* @decorator `@bind`
|
|
91
|
+
*/
|
|
92
|
+
@bind
|
|
93
|
+
public getTest(): Output['test'] {
|
|
94
|
+
return this.unwrap(this.test)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set test value
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
* @decorator `@bind`
|
|
102
|
+
*/
|
|
103
|
+
@bind
|
|
104
|
+
public setTest(test: Options['test']): this {
|
|
105
|
+
this.test = test
|
|
106
|
+
return this
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get parser value
|
|
111
|
+
*
|
|
112
|
+
* @public
|
|
113
|
+
* @decorator `@bind`
|
|
114
|
+
*/
|
|
115
|
+
@bind
|
|
116
|
+
public getParser(): Output['parser'] {
|
|
117
|
+
return this.unwrap(this.parser)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Set parser value
|
|
122
|
+
*
|
|
123
|
+
* @public
|
|
124
|
+
* @decorator `@bind`
|
|
125
|
+
*/
|
|
126
|
+
@bind
|
|
127
|
+
public setParser(parser: Interface['parser']): this {
|
|
128
|
+
this.parser = this.wrap(parser)
|
|
129
|
+
return this
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Get use value
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
* @decorator `@bind`
|
|
137
|
+
*/
|
|
138
|
+
@bind
|
|
139
|
+
public getUse(): Array<`${keyof Items & string}` | Item> {
|
|
140
|
+
return this.use
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Set use value
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
* @decorator `@bind`
|
|
148
|
+
*/
|
|
149
|
+
@bind
|
|
150
|
+
public setUse(
|
|
151
|
+
use: Options[`use`] | ((use: Options[`use`]) => Options[`use`]),
|
|
152
|
+
): this {
|
|
153
|
+
this.use = isFunction(use) ? use(this.getUse()) : use
|
|
154
|
+
return this
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get include value
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
* @decorator `@bind`
|
|
162
|
+
*/
|
|
163
|
+
@bind
|
|
164
|
+
public getInclude(): Array<string | RegExp> {
|
|
165
|
+
return this.include?.map(item =>
|
|
166
|
+
isFunction(item) ? item(this.app) : item,
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Set include value
|
|
172
|
+
*
|
|
173
|
+
* @public
|
|
174
|
+
* @decorator `@bind`
|
|
175
|
+
*/
|
|
176
|
+
@bind
|
|
177
|
+
public setInclude(includes: Options['include']): this {
|
|
178
|
+
this.include = isFunction(includes) ? includes(this.include) : includes
|
|
179
|
+
return this
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Get include value
|
|
184
|
+
*
|
|
185
|
+
* @public
|
|
186
|
+
* @decorator `@bind`
|
|
187
|
+
*/
|
|
188
|
+
@bind
|
|
189
|
+
public getResourceQuery(): Output[`resourceQuery`] {
|
|
190
|
+
return this.resourceQuery
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Set include value
|
|
195
|
+
*
|
|
196
|
+
* @public
|
|
197
|
+
* @decorator `@bind`
|
|
198
|
+
*/
|
|
199
|
+
@bind
|
|
200
|
+
public setResourceQuery(query: Options['resourceQuery']): this {
|
|
201
|
+
this.resourceQuery = query
|
|
202
|
+
return this
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get exclude value
|
|
207
|
+
*
|
|
208
|
+
* @public
|
|
209
|
+
* @decorator `@bind`
|
|
210
|
+
*/
|
|
211
|
+
@bind
|
|
212
|
+
public getExclude(): Array<string | RegExp> {
|
|
213
|
+
return this.exclude?.map(this.unwrap)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Set exclude value
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
* @decorator `@bind`
|
|
221
|
+
*/
|
|
222
|
+
@bind
|
|
223
|
+
public setExclude(
|
|
224
|
+
excludes:
|
|
225
|
+
| Options['exclude']
|
|
226
|
+
| ((excludes: Options['exclude']) => Options['exclude']),
|
|
227
|
+
): this {
|
|
228
|
+
this.exclude = isFunction(excludes) ? excludes(this.exclude) : excludes
|
|
229
|
+
return this
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Get type value
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
* @decorator `@bind`
|
|
237
|
+
*/
|
|
238
|
+
@bind
|
|
239
|
+
public getType(): string {
|
|
240
|
+
return this.unwrap(this.type)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set type value
|
|
245
|
+
*
|
|
246
|
+
* @public
|
|
247
|
+
* @decorator `@bind`
|
|
248
|
+
*/
|
|
249
|
+
@bind
|
|
250
|
+
public setType(type: Options[`type`]): this {
|
|
251
|
+
this.type = type
|
|
252
|
+
return this
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Get generator value
|
|
257
|
+
*
|
|
258
|
+
* @public
|
|
259
|
+
* @decorator `@bind`
|
|
260
|
+
*/
|
|
261
|
+
@bind
|
|
262
|
+
public getGenerator() {
|
|
263
|
+
return this.unwrap(this.generator)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Set generator value
|
|
268
|
+
*
|
|
269
|
+
* @public
|
|
270
|
+
* @decorator `@bind`
|
|
271
|
+
*/
|
|
272
|
+
@bind
|
|
273
|
+
public setGenerator(generator: Interface['generator']): this {
|
|
274
|
+
this.generator = this.wrap(generator)
|
|
275
|
+
return this
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Produce final Base output
|
|
280
|
+
*
|
|
281
|
+
* @param app - {@link @roots/bud-framework#Bud}
|
|
282
|
+
* @returns finalized rule
|
|
283
|
+
*
|
|
284
|
+
* @public
|
|
285
|
+
* @decorator `@bind`
|
|
286
|
+
*/
|
|
287
|
+
@bind
|
|
288
|
+
public toWebpack(): Output {
|
|
289
|
+
const output: Output = Object.entries({
|
|
290
|
+
test: this.getTest(),
|
|
291
|
+
type: this.getType(),
|
|
292
|
+
parser: this.getParser(),
|
|
293
|
+
generator: this.getGenerator(),
|
|
294
|
+
use: this.getUse()
|
|
295
|
+
?.map(item => (isString(item) ? this.app.build.items[item] : item))
|
|
296
|
+
.map(item => item.toWebpack()),
|
|
297
|
+
resourceQuery: this.getResourceQuery(),
|
|
298
|
+
include: this.getInclude(),
|
|
299
|
+
exclude: this.getExclude(),
|
|
300
|
+
}).reduce((a, [k, v]) => {
|
|
301
|
+
if (v === undefined) return a
|
|
302
|
+
return {...a, [k]: v}
|
|
303
|
+
}, {})
|
|
304
|
+
|
|
305
|
+
this.app.info(output)
|
|
306
|
+
|
|
307
|
+
return output
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export {Rule}
|