@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.
Files changed (306) hide show
  1. package/LICENSE.md +19 -0
  2. package/README.md +120 -0
  3. package/docs/exports.md +13 -0
  4. package/docs/rules.md +32 -0
  5. package/lib/config/bail.d.ts +3 -0
  6. package/lib/config/bail.d.ts.map +1 -0
  7. package/lib/config/bail.js +2 -0
  8. package/lib/config/bail.js.map +1 -0
  9. package/lib/config/cache.d.ts +3 -0
  10. package/lib/config/cache.d.ts.map +1 -0
  11. package/lib/config/cache.js +2 -0
  12. package/lib/config/cache.js.map +1 -0
  13. package/lib/config/context.d.ts +3 -0
  14. package/lib/config/context.d.ts.map +1 -0
  15. package/lib/config/context.js +2 -0
  16. package/lib/config/context.js.map +1 -0
  17. package/lib/config/dependencies.d.ts +3 -0
  18. package/lib/config/dependencies.d.ts.map +1 -0
  19. package/lib/config/dependencies.js +5 -0
  20. package/lib/config/dependencies.js.map +1 -0
  21. package/lib/config/devtool.d.ts +3 -0
  22. package/lib/config/devtool.d.ts.map +1 -0
  23. package/lib/config/devtool.js +2 -0
  24. package/lib/config/devtool.js.map +1 -0
  25. package/lib/config/entry.d.ts +3 -0
  26. package/lib/config/entry.d.ts.map +1 -0
  27. package/lib/config/entry.js +2 -0
  28. package/lib/config/entry.js.map +1 -0
  29. package/lib/config/experiments.d.ts +3 -0
  30. package/lib/config/experiments.d.ts.map +1 -0
  31. package/lib/config/experiments.js +2 -0
  32. package/lib/config/experiments.js.map +1 -0
  33. package/lib/config/externals.d.ts +3 -0
  34. package/lib/config/externals.d.ts.map +1 -0
  35. package/lib/config/externals.js +2 -0
  36. package/lib/config/externals.js.map +1 -0
  37. package/lib/config/externalsType.d.ts +3 -0
  38. package/lib/config/externalsType.d.ts.map +1 -0
  39. package/lib/config/externalsType.js +2 -0
  40. package/lib/config/externalsType.js.map +1 -0
  41. package/lib/config/index.d.ts +35 -0
  42. package/lib/config/index.d.ts.map +1 -0
  43. package/lib/config/index.js +27 -0
  44. package/lib/config/index.js.map +1 -0
  45. package/lib/config/infrastructureLogging.d.ts +3 -0
  46. package/lib/config/infrastructureLogging.d.ts.map +1 -0
  47. package/lib/config/infrastructureLogging.js +14 -0
  48. package/lib/config/infrastructureLogging.js.map +1 -0
  49. package/lib/config/loader.d.ts +3 -0
  50. package/lib/config/loader.d.ts.map +1 -0
  51. package/lib/config/loader.js +2 -0
  52. package/lib/config/loader.js.map +1 -0
  53. package/lib/config/mode.d.ts +3 -0
  54. package/lib/config/mode.d.ts.map +1 -0
  55. package/lib/config/mode.js +2 -0
  56. package/lib/config/mode.js.map +1 -0
  57. package/lib/config/module.d.ts +3 -0
  58. package/lib/config/module.d.ts.map +1 -0
  59. package/lib/config/module.js +23 -0
  60. package/lib/config/module.js.map +1 -0
  61. package/lib/config/name.d.ts +3 -0
  62. package/lib/config/name.d.ts.map +1 -0
  63. package/lib/config/name.js +2 -0
  64. package/lib/config/name.js.map +1 -0
  65. package/lib/config/node.d.ts +3 -0
  66. package/lib/config/node.d.ts.map +1 -0
  67. package/lib/config/node.js +2 -0
  68. package/lib/config/node.js.map +1 -0
  69. package/lib/config/optimization.d.ts +3 -0
  70. package/lib/config/optimization.d.ts.map +1 -0
  71. package/lib/config/optimization.js +11 -0
  72. package/lib/config/optimization.js.map +1 -0
  73. package/lib/config/output/assetModuleFilename.d.ts +8 -0
  74. package/lib/config/output/assetModuleFilename.d.ts.map +1 -0
  75. package/lib/config/output/assetModuleFilename.js +2 -0
  76. package/lib/config/output/assetModuleFilename.js.map +1 -0
  77. package/lib/config/output/chunkFilename.d.ts +8 -0
  78. package/lib/config/output/chunkFilename.d.ts.map +1 -0
  79. package/lib/config/output/chunkFilename.js +4 -0
  80. package/lib/config/output/chunkFilename.js.map +1 -0
  81. package/lib/config/output/filename.d.ts +8 -0
  82. package/lib/config/output/filename.d.ts.map +1 -0
  83. package/lib/config/output/filename.js +3 -0
  84. package/lib/config/output/filename.js.map +1 -0
  85. package/lib/config/output/index.d.ts +3 -0
  86. package/lib/config/output/index.d.ts.map +1 -0
  87. package/lib/config/output/index.js +18 -0
  88. package/lib/config/output/index.js.map +1 -0
  89. package/lib/config/parallelism.d.ts +3 -0
  90. package/lib/config/parallelism.d.ts.map +1 -0
  91. package/lib/config/parallelism.js +3 -0
  92. package/lib/config/parallelism.js.map +1 -0
  93. package/lib/config/performance.d.ts +3 -0
  94. package/lib/config/performance.d.ts.map +1 -0
  95. package/lib/config/performance.js +2 -0
  96. package/lib/config/performance.js.map +1 -0
  97. package/lib/config/plugins.d.ts +3 -0
  98. package/lib/config/plugins.d.ts.map +1 -0
  99. package/lib/config/plugins.js +2 -0
  100. package/lib/config/plugins.js.map +1 -0
  101. package/lib/config/profile.d.ts +3 -0
  102. package/lib/config/profile.d.ts.map +1 -0
  103. package/lib/config/profile.js +2 -0
  104. package/lib/config/profile.js.map +1 -0
  105. package/lib/config/recordsPath.d.ts +3 -0
  106. package/lib/config/recordsPath.d.ts.map +1 -0
  107. package/lib/config/recordsPath.js +2 -0
  108. package/lib/config/recordsPath.js.map +1 -0
  109. package/lib/config/resolve.d.ts +3 -0
  110. package/lib/config/resolve.d.ts.map +1 -0
  111. package/lib/config/resolve.js +30 -0
  112. package/lib/config/resolve.js.map +1 -0
  113. package/lib/config/stats.d.ts +3 -0
  114. package/lib/config/stats.d.ts.map +1 -0
  115. package/lib/config/stats.js +17 -0
  116. package/lib/config/stats.js.map +1 -0
  117. package/lib/config/target.d.ts +3 -0
  118. package/lib/config/target.d.ts.map +1 -0
  119. package/lib/config/target.js +4 -0
  120. package/lib/config/target.js.map +1 -0
  121. package/lib/handlers/index.d.ts +19 -0
  122. package/lib/handlers/index.d.ts.map +1 -0
  123. package/lib/handlers/index.js +6 -0
  124. package/lib/handlers/index.js.map +1 -0
  125. package/lib/handlers/items/items.d.ts +47 -0
  126. package/lib/handlers/items/items.d.ts.map +1 -0
  127. package/lib/handlers/items/items.js +69 -0
  128. package/lib/handlers/items/items.js.map +1 -0
  129. package/lib/handlers/loaders/loaders.d.ts +12 -0
  130. package/lib/handlers/loaders/loaders.d.ts.map +1 -0
  131. package/lib/handlers/loaders/loaders.js +11 -0
  132. package/lib/handlers/loaders/loaders.js.map +1 -0
  133. package/lib/handlers/register.d.ts +14 -0
  134. package/lib/handlers/register.d.ts.map +1 -0
  135. package/lib/handlers/register.js +26 -0
  136. package/lib/handlers/register.js.map +1 -0
  137. package/lib/handlers/rules/css.d.ts +3 -0
  138. package/lib/handlers/rules/css.d.ts.map +1 -0
  139. package/lib/handlers/rules/css.js +5 -0
  140. package/lib/handlers/rules/css.js.map +1 -0
  141. package/lib/handlers/rules/css.module.d.ts +3 -0
  142. package/lib/handlers/rules/css.module.d.ts.map +1 -0
  143. package/lib/handlers/rules/css.module.js +5 -0
  144. package/lib/handlers/rules/css.module.js.map +1 -0
  145. package/lib/handlers/rules/csv.d.ts +3 -0
  146. package/lib/handlers/rules/csv.d.ts.map +1 -0
  147. package/lib/handlers/rules/csv.js +5 -0
  148. package/lib/handlers/rules/csv.js.map +1 -0
  149. package/lib/handlers/rules/font.d.ts +3 -0
  150. package/lib/handlers/rules/font.d.ts.map +1 -0
  151. package/lib/handlers/rules/font.inline.d.ts +3 -0
  152. package/lib/handlers/rules/font.inline.d.ts.map +1 -0
  153. package/lib/handlers/rules/font.inline.js +6 -0
  154. package/lib/handlers/rules/font.inline.js.map +1 -0
  155. package/lib/handlers/rules/font.js +5 -0
  156. package/lib/handlers/rules/font.js.map +1 -0
  157. package/lib/handlers/rules/html.d.ts +3 -0
  158. package/lib/handlers/rules/html.d.ts.map +1 -0
  159. package/lib/handlers/rules/html.js +5 -0
  160. package/lib/handlers/rules/html.js.map +1 -0
  161. package/lib/handlers/rules/image.d.ts +3 -0
  162. package/lib/handlers/rules/image.d.ts.map +1 -0
  163. package/lib/handlers/rules/image.inline.d.ts +3 -0
  164. package/lib/handlers/rules/image.inline.d.ts.map +1 -0
  165. package/lib/handlers/rules/image.inline.js +6 -0
  166. package/lib/handlers/rules/image.inline.js.map +1 -0
  167. package/lib/handlers/rules/image.js +5 -0
  168. package/lib/handlers/rules/image.js.map +1 -0
  169. package/lib/handlers/rules/index.d.ts +19 -0
  170. package/lib/handlers/rules/index.d.ts.map +1 -0
  171. package/lib/handlers/rules/index.js +35 -0
  172. package/lib/handlers/rules/index.js.map +1 -0
  173. package/lib/handlers/rules/js.d.ts +3 -0
  174. package/lib/handlers/rules/js.d.ts.map +1 -0
  175. package/lib/handlers/rules/js.js +5 -0
  176. package/lib/handlers/rules/js.js.map +1 -0
  177. package/lib/handlers/rules/json.d.ts +3 -0
  178. package/lib/handlers/rules/json.d.ts.map +1 -0
  179. package/lib/handlers/rules/json.js +7 -0
  180. package/lib/handlers/rules/json.js.map +1 -0
  181. package/lib/handlers/rules/svg.d.ts +3 -0
  182. package/lib/handlers/rules/svg.d.ts.map +1 -0
  183. package/lib/handlers/rules/svg.inline.d.ts +5 -0
  184. package/lib/handlers/rules/svg.inline.d.ts.map +1 -0
  185. package/lib/handlers/rules/svg.inline.js +9 -0
  186. package/lib/handlers/rules/svg.inline.js.map +1 -0
  187. package/lib/handlers/rules/svg.js +5 -0
  188. package/lib/handlers/rules/svg.js.map +1 -0
  189. package/lib/handlers/rules/toml.d.ts +3 -0
  190. package/lib/handlers/rules/toml.d.ts.map +1 -0
  191. package/lib/handlers/rules/toml.js +7 -0
  192. package/lib/handlers/rules/toml.js.map +1 -0
  193. package/lib/handlers/rules/webp.d.ts +3 -0
  194. package/lib/handlers/rules/webp.d.ts.map +1 -0
  195. package/lib/handlers/rules/webp.js +5 -0
  196. package/lib/handlers/rules/webp.js.map +1 -0
  197. package/lib/handlers/rules/xml.d.ts +3 -0
  198. package/lib/handlers/rules/xml.d.ts.map +1 -0
  199. package/lib/handlers/rules/xml.js +5 -0
  200. package/lib/handlers/rules/xml.js.map +1 -0
  201. package/lib/handlers/rules/yml.d.ts +3 -0
  202. package/lib/handlers/rules/yml.d.ts.map +1 -0
  203. package/lib/handlers/rules/yml.js +5 -0
  204. package/lib/handlers/rules/yml.js.map +1 -0
  205. package/lib/helpers/isMjs.d.ts +3 -0
  206. package/lib/helpers/isMjs.d.ts.map +1 -0
  207. package/lib/helpers/isMjs.js +2 -0
  208. package/lib/helpers/isMjs.js.map +1 -0
  209. package/lib/helpers/scriptExtension.d.ts +3 -0
  210. package/lib/helpers/scriptExtension.d.ts.map +1 -0
  211. package/lib/helpers/scriptExtension.js +5 -0
  212. package/lib/helpers/scriptExtension.js.map +1 -0
  213. package/lib/index.d.ts +12 -0
  214. package/lib/index.d.ts.map +1 -0
  215. package/lib/index.js +14 -0
  216. package/lib/index.js.map +1 -0
  217. package/lib/item/index.d.ts +84 -0
  218. package/lib/item/index.d.ts.map +1 -0
  219. package/lib/item/index.js +165 -0
  220. package/lib/item/index.js.map +1 -0
  221. package/lib/loader/index.d.ts +26 -0
  222. package/lib/loader/index.d.ts.map +1 -0
  223. package/lib/loader/index.js +28 -0
  224. package/lib/loader/index.js.map +1 -0
  225. package/lib/rule/index.d.ts +118 -0
  226. package/lib/rule/index.d.ts.map +1 -0
  227. package/lib/rule/index.js +261 -0
  228. package/lib/rule/index.js.map +1 -0
  229. package/lib/service.d.ts +84 -0
  230. package/lib/service.d.ts.map +1 -0
  231. package/lib/service.js +212 -0
  232. package/lib/service.js.map +1 -0
  233. package/lib/shared/base.d.ts +20 -0
  234. package/lib/shared/base.d.ts.map +1 -0
  235. package/lib/shared/base.js +43 -0
  236. package/lib/shared/base.js.map +1 -0
  237. package/lib/types.d.ts +52 -0
  238. package/lib/types.d.ts.map +1 -0
  239. package/lib/types.js +4 -0
  240. package/lib/types.js.map +1 -0
  241. package/package.json +97 -0
  242. package/src/config/bail.ts +4 -0
  243. package/src/config/cache.ts +4 -0
  244. package/src/config/context.ts +3 -0
  245. package/src/config/dependencies.ts +11 -0
  246. package/src/config/devtool.ts +4 -0
  247. package/src/config/entry.ts +4 -0
  248. package/src/config/experiments.ts +4 -0
  249. package/src/config/externals.ts +4 -0
  250. package/src/config/externalsType.ts +3 -0
  251. package/src/config/index.test.ts +129 -0
  252. package/src/config/index.ts +67 -0
  253. package/src/config/infrastructureLogging.ts +18 -0
  254. package/src/config/loader.ts +4 -0
  255. package/src/config/mode.ts +4 -0
  256. package/src/config/module.ts +45 -0
  257. package/src/config/name.ts +4 -0
  258. package/src/config/node.ts +4 -0
  259. package/src/config/optimization.ts +20 -0
  260. package/src/config/output/assetModuleFilename.ts +9 -0
  261. package/src/config/output/chunkFilename.ts +18 -0
  262. package/src/config/output/filename.ts +14 -0
  263. package/src/config/output/index.ts +28 -0
  264. package/src/config/parallelism.ts +6 -0
  265. package/src/config/performance.ts +4 -0
  266. package/src/config/plugins.ts +4 -0
  267. package/src/config/profile.ts +4 -0
  268. package/src/config/recordsPath.ts +7 -0
  269. package/src/config/resolve.ts +45 -0
  270. package/src/config/stats.ts +22 -0
  271. package/src/config/target.ts +9 -0
  272. package/src/handlers/index.ts +22 -0
  273. package/src/handlers/items/items.ts +93 -0
  274. package/src/handlers/loaders/loaders.ts +31 -0
  275. package/src/handlers/register.ts +47 -0
  276. package/src/handlers/rules/css.module.ts +7 -0
  277. package/src/handlers/rules/css.ts +7 -0
  278. package/src/handlers/rules/csv.test.ts +28 -0
  279. package/src/handlers/rules/csv.ts +7 -0
  280. package/src/handlers/rules/font.inline.ts +8 -0
  281. package/src/handlers/rules/font.ts +7 -0
  282. package/src/handlers/rules/html.ts +7 -0
  283. package/src/handlers/rules/image.inline.ts +8 -0
  284. package/src/handlers/rules/image.ts +7 -0
  285. package/src/handlers/rules/index.ts +35 -0
  286. package/src/handlers/rules/js.ts +7 -0
  287. package/src/handlers/rules/json.ts +10 -0
  288. package/src/handlers/rules/svg.inline.test.ts +30 -0
  289. package/src/handlers/rules/svg.inline.ts +13 -0
  290. package/src/handlers/rules/svg.ts +7 -0
  291. package/src/handlers/rules/toml.test.ts +22 -0
  292. package/src/handlers/rules/toml.ts +10 -0
  293. package/src/handlers/rules/webp.ts +7 -0
  294. package/src/handlers/rules/xml.test.ts +27 -0
  295. package/src/handlers/rules/xml.ts +7 -0
  296. package/src/handlers/rules/yml.ts +7 -0
  297. package/src/helpers/isMjs.ts +4 -0
  298. package/src/helpers/scriptExtension.ts +11 -0
  299. package/src/index.ts +17 -0
  300. package/src/item/index.ts +179 -0
  301. package/src/loader/index.ts +38 -0
  302. package/src/rule/index.test.ts +88 -0
  303. package/src/rule/index.ts +257 -0
  304. package/src/service.ts +204 -0
  305. package/src/shared/base.ts +37 -0
  306. package/src/types.ts +57 -0
@@ -0,0 +1,129 @@
1
+ import {Bud, factory} from '@repo/test-kit/bud'
2
+ import {beforeEach, describe, expect, it} from 'vitest'
3
+
4
+ import {Build} from '../service.js'
5
+
6
+ describe(`bud.build.config`, function () {
7
+ let bud: Bud
8
+ let build: Build
9
+
10
+ beforeEach(async () => {
11
+ bud = await factory()
12
+ build = new Build(() => bud)
13
+ await build.register(bud)
14
+ await build.make()
15
+ })
16
+
17
+ it(`should not include deprecated properties`, async () => {
18
+ expect(build.config.hasOwnProperty(`devServer`)).toBe(false)
19
+ expect(build.config.hasOwnProperty(`unsafeCache`)).toBe(false)
20
+ })
21
+
22
+ it(`should have expected bail default`, async () => {
23
+ expect(build.config.bail).toEqual(true)
24
+ })
25
+
26
+ it(`should have expected cache default`, async () => {
27
+ const {cache}: any = build.config
28
+
29
+ expect(cache.type).toStrictEqual(`filesystem`)
30
+
31
+ expect(cache.cacheDirectory).toStrictEqual(
32
+ expect.stringContaining(`.budfiles`),
33
+ )
34
+
35
+ expect(cache.version).toStrictEqual(expect.any(String))
36
+ })
37
+
38
+ it(`should have expected context default`, async () => {
39
+ expect(build.config.context).toEqual(bud.path(`@src`))
40
+ })
41
+
42
+ it(`should have expected devtool default`, async () => {
43
+ expect(build.config.devtool).toBe(false)
44
+ })
45
+
46
+ it(`should have expected entry default`, async () => {
47
+ expect(build.config.entry).toEqual({main: {import: [`index`]}})
48
+ })
49
+
50
+ it(`should have expected mode default`, async () => {
51
+ expect(build.config.mode).toEqual(`production`)
52
+ })
53
+
54
+ it(`should have expected name default`, async () => {
55
+ expect(build.config.name).toEqual(`@tests/project`)
56
+ })
57
+
58
+ it(`should have expected node default`, async () => {
59
+ expect(build.config.node).toEqual(false)
60
+ })
61
+
62
+ it(`should have expected optimization.minimize default`, async () => {
63
+ expect(build.config.optimization?.minimize).toEqual(true)
64
+ })
65
+
66
+ it(`should have expected optimization.emitOnErrors default`, async () => {
67
+ expect((build.config.optimization as any).emitOnErrors).toEqual(false)
68
+ })
69
+
70
+ it(`should have expected optimization.runtimeChunk default`, async () => {
71
+ expect(build.config.optimization?.runtimeChunk).toBe(false)
72
+ })
73
+
74
+ it(`should have expected profile default`, async () => {
75
+ expect(build.config.profile).toBeUndefined()
76
+ })
77
+
78
+ it(`should have expected resolve.alias default`, async () => {
79
+ expect(build.config.resolve?.alias).toEqual({
80
+ '@src': bud.path(`@src`),
81
+ })
82
+ })
83
+
84
+ it(`should have expected resolve.extensions default`, async () => {
85
+ expect(build.config.resolve?.extensions?.sort()).toEqual(
86
+ expect.arrayContaining([
87
+ `.css`,
88
+ `.js`,
89
+ `.json`,
90
+ `.jsx`,
91
+ `.mjs`,
92
+ `.wasm`,
93
+ `.yml`,
94
+ ]),
95
+ )
96
+ })
97
+
98
+ it(`should have expected target default`, async () => {
99
+ expect(build.config.target).toMatch(/browserslist.*/)
100
+ })
101
+
102
+ it(`should have expected watch default`, async () => {
103
+ expect(build.config.watch).toBeUndefined()
104
+ })
105
+
106
+ it(`should have expected watchOptions default`, async () => {
107
+ expect(build.config.watchOptions).toBeUndefined()
108
+ })
109
+
110
+ it(`should have expected plugins`, async () => {
111
+ const plugins = build.config.plugins
112
+ ?.map(plugin => plugin.constructor.name)
113
+ .sort()
114
+
115
+ expect(plugins).toContain(`CleanWebpackPlugin`)
116
+ expect(plugins).toContain(`FixStyleOnlyEntrypoints`)
117
+ })
118
+
119
+ it(`should have expected default requireEnsure rule`, async () => {
120
+ if (!build.config.module?.rules?.length) throw new Error()
121
+ expect(build.config.module.rules[0]).toEqual(
122
+ expect.objectContaining({
123
+ parser: {
124
+ requireEnsure: false,
125
+ },
126
+ }),
127
+ )
128
+ })
129
+ })
@@ -0,0 +1,67 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+ import type {Configuration} from '@roots/bud-support/webpack'
3
+
4
+ import {bail} from './bail.js'
5
+ import {cache} from './cache.js'
6
+ import {context} from './context.js'
7
+ import {dependencies} from './dependencies.js'
8
+ import {devtool} from './devtool.js'
9
+ import {entry} from './entry.js'
10
+ import {experiments} from './experiments.js'
11
+ import {externals} from './externals.js'
12
+ import {externalsType} from './externalsType.js'
13
+ import {infrastructureLogging} from './infrastructureLogging.js'
14
+ import {loader} from './loader.js'
15
+ import {mode} from './mode.js'
16
+ import {module} from './module.js'
17
+ import {name} from './name.js'
18
+ import {node} from './node.js'
19
+ import {optimization} from './optimization.js'
20
+ import {output} from './output/index.js'
21
+ import {parallelism} from './parallelism.js'
22
+ import {performance} from './performance.js'
23
+ import {plugins} from './plugins.js'
24
+ import {profile} from './profile.js'
25
+ import {recordsPath} from './recordsPath.js'
26
+ import {resolve} from './resolve.js'
27
+ import {stats} from './stats.js'
28
+ import {target} from './target.js'
29
+
30
+ export {
31
+ bail,
32
+ cache,
33
+ context,
34
+ dependencies,
35
+ devtool,
36
+ entry,
37
+ experiments,
38
+ externals,
39
+ externalsType,
40
+ infrastructureLogging,
41
+ loader,
42
+ mode,
43
+ module,
44
+ name,
45
+ node,
46
+ optimization,
47
+ output,
48
+ parallelism,
49
+ performance,
50
+ plugins,
51
+ profile,
52
+ recordsPath,
53
+ resolve,
54
+ stats,
55
+ target,
56
+ }
57
+
58
+ export interface Factory<
59
+ Key extends keyof Config,
60
+ Config = Configuration,
61
+ > {
62
+ (app: Bud): Promise<Config[Key]>
63
+ }
64
+
65
+ export type Records<Config = Configuration> = {
66
+ [Key in keyof Config as `${Key & string}`]: Factory<Key, Config>
67
+ }
@@ -0,0 +1,18 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const infrastructureLogging: Factory<
4
+ `infrastructureLogging`
5
+ > = async bud =>
6
+ bud.hooks.filter(`build.infrastructureLogging`, {
7
+ console: bud.hooks.filter(`build.infrastructureLogging.console`, {
8
+ ...console,
9
+ log: bud.context.logger.log,
10
+ info: bud.context.logger.info,
11
+ warn: bud.context.logger.warn,
12
+ error: bud.context.logger.error,
13
+ debug: bud.context.logger.debug,
14
+ time: bud.context.logger.time,
15
+ timeEnd: bud.context.logger.timeEnd,
16
+ }),
17
+ level: bud.hooks.filter(`build.infrastructureLogging.level`, `log`),
18
+ })
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const loader: Factory<`loader`> = async app =>
4
+ app.hooks.filter(`build.loader`)
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const mode: Factory<`mode`> = async bud =>
4
+ bud.hooks.filter(`build.mode`, bud.mode)
@@ -0,0 +1,45 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+
3
+ import type {Factory} from './index.js'
4
+
5
+ interface Props {
6
+ filter: Bud[`hooks`][`filter`]
7
+ rules: Bud[`build`][`rules`]
8
+ path: Bud[`path`]
9
+ }
10
+
11
+ export const module: Factory<`module`> = async ({
12
+ build: {rules},
13
+ hooks: {filter},
14
+ path,
15
+ }) =>
16
+ filter(`build.module`, {
17
+ noParse: getNoParse(filter),
18
+ rules: getRules({filter, path, rules}),
19
+ unsafeCache: getUnsafeCache(filter),
20
+ })
21
+
22
+ const getRules = ({filter, path, rules}: Props) => [
23
+ ...filter(`build.module.rules.before`, [
24
+ {
25
+ test: filter(`pattern.js`),
26
+ include: [path(`@src`)],
27
+ parser: {requireEnsure: false},
28
+ },
29
+ ]),
30
+ {
31
+ oneOf: filter(
32
+ `build.module.rules.oneOf`,
33
+ Object.values(rules)
34
+ .filter(Boolean)
35
+ .map(rule => (`toWebpack` in rule ? rule.toWebpack() : rule)),
36
+ ),
37
+ },
38
+ ...filter(`build.module.rules.after`, []),
39
+ ]
40
+
41
+ const getNoParse = (filter: Props[`filter`]) =>
42
+ filter(`build.module.noParse`, undefined)
43
+
44
+ const getUnsafeCache = (filter: Props[`filter`]) =>
45
+ filter(`build.module.unsafeCache`, false)
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const name: Factory<`name`> = async ({hooks, label}) =>
4
+ hooks.filter(`build.name`, label)
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const node: Factory<`node`> = async ({hooks}) =>
4
+ hooks.filter(`build.node`, false)
@@ -0,0 +1,20 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const optimization: Factory<`optimization`> = async ({
4
+ hooks: {filter},
5
+ isDevelopment,
6
+ isProduction,
7
+ }) =>
8
+ filter(`build.optimization`, {
9
+ emitOnErrors: filter(`build.optimization.emitOnErrors`, isDevelopment),
10
+ minimize: filter(`build.optimization.minimize`, isProduction),
11
+ minimizer: filter(`build.optimization.minimizer`, []),
12
+ moduleIds: filter(`build.optimization.moduleIds`, `named`),
13
+ removeEmptyChunks: filter(
14
+ `build.optimization.removeEmptyChunks`,
15
+ false,
16
+ ),
17
+ runtimeChunk: filter(`build.optimization.runtimeChunk`, false),
18
+ splitChunks: filter(`build.optimization.splitChunks`, false),
19
+ usedExports: filter(`build.optimization.usedExports`, isProduction),
20
+ })
@@ -0,0 +1,9 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+
3
+ interface Props {
4
+ filter: Bud['hooks'][`filter`]
5
+ relPath: Bud['relPath']
6
+ }
7
+
8
+ export const assetModuleFilename = ({filter, relPath}: Props) =>
9
+ filter(`build.output.assetModuleFilename`, relPath(`@file`))
@@ -0,0 +1,18 @@
1
+ import {join} from 'node:path'
2
+
3
+ import type {Bud} from '@roots/bud-framework'
4
+
5
+ import {scriptExtension} from '../../helpers/scriptExtension.js'
6
+
7
+ interface Props {
8
+ filter: Bud[`hooks`][`filter`]
9
+ relPath: Bud[`relPath`]
10
+ }
11
+
12
+ export const chunkFilename = ({filter, relPath}: Props) =>
13
+ filter(
14
+ `build.output.chunkFilename`,
15
+ join(`js`, `dynamic`, relPath(`@name.chunk`)).concat(
16
+ scriptExtension(filter, `.mjs`, `.js`),
17
+ ),
18
+ )
@@ -0,0 +1,14 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+
3
+ import {scriptExtension} from '../../helpers/scriptExtension.js'
4
+
5
+ interface Props {
6
+ filter: Bud['hooks'][`filter`]
7
+ relPath: Bud['relPath']
8
+ }
9
+
10
+ export const filename = ({filter, relPath}: Props) =>
11
+ filter(
12
+ `build.output.filename`,
13
+ relPath(`js`, `@name${scriptExtension(filter, `.mjs`, `.js`)}`),
14
+ )
@@ -0,0 +1,28 @@
1
+ import {isMjs} from '../../helpers/isMjs.js'
2
+ import type {Factory} from '../index.js'
3
+ import {assetModuleFilename} from './assetModuleFilename.js'
4
+ import {chunkFilename} from './chunkFilename.js'
5
+ import {filename} from './filename.js'
6
+
7
+ export const output: Factory<`output`> = async ({
8
+ hooks: {filter},
9
+ isProduction,
10
+ path,
11
+ relPath,
12
+ }) =>
13
+ filter(`build.output`, {
14
+ assetModuleFilename: assetModuleFilename({filter, relPath}),
15
+ chunkFilename: chunkFilename({filter, relPath}),
16
+ clean: filter(`build.output.clean`, isProduction),
17
+ environment: filter(`build.output.environment`, undefined),
18
+ filename: filename({filter, relPath}),
19
+ module: filter(`build.output.module`, false),
20
+ path: filter(`build.output.path`, path(`@dist`)),
21
+ pathinfo: filter(`build.output.pathinfo`),
22
+ publicPath: filter(`build.output.publicPath`, `auto`),
23
+ scriptType: filter(
24
+ `build.output.scriptType`,
25
+ isMjs(filter) ? `module` : false,
26
+ ),
27
+ uniqueName: filter(`build.output.uniqueName`, `@roots/bud`),
28
+ })
@@ -0,0 +1,6 @@
1
+ import {cpus} from 'node:os'
2
+
3
+ import type {Factory} from './index.js'
4
+
5
+ export const parallelism: Factory<`parallelism`> = async ({hooks}) =>
6
+ hooks.filter(`build.parallelism`, 10 * Math.max(cpus().length - 1, 1))
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const performance: Factory<`performance`> = async ({hooks}) =>
4
+ hooks.filter(`build.performance`, {hints: false})
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const plugins: Factory<`plugins`> = async app =>
4
+ await app.hooks.filterAsync(`build.plugins`, await app.extensions.make())
@@ -0,0 +1,4 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const profile: Factory<`profile`> = async app =>
4
+ app.hooks.filter(`build.profile`, undefined)
@@ -0,0 +1,7 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const recordsPath: Factory<`recordsPath`> = async bud =>
4
+ bud.hooks.filter(
5
+ `build.recordsPath`,
6
+ bud.path(`@storage`, bud.label, `modules.json`),
7
+ )
@@ -0,0 +1,45 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+
3
+ import type {Factory} from './index.js'
4
+
5
+ export const resolve: Factory<`resolve`> = async bud => {
6
+ const modules = await getModules(bud)
7
+ const value = {
8
+ alias: await getAlias(bud),
9
+ extensions: getExtensions(bud),
10
+ modules,
11
+ }
12
+
13
+ return await bud.hooks.filterAsync(`build.resolve`, value)
14
+ }
15
+
16
+ const getAlias = async (bud: Bud) =>
17
+ await bud.hooks.filterAsync(`build.resolve.alias`, {
18
+ '@src': bud.path(`@src`),
19
+ })
20
+
21
+ const getExtensions = (bud: Bud) =>
22
+ Array.from(
23
+ bud.hooks.filter(
24
+ `build.resolve.extensions`,
25
+ new Set([
26
+ `.mjs`,
27
+ `.js`,
28
+ `.jsx`,
29
+ `.css`,
30
+ `.json`,
31
+ `.wasm`,
32
+ `.yml`,
33
+ `.yaml`,
34
+ `.xml`,
35
+ `.toml`,
36
+ `.csv`,
37
+ ]),
38
+ ),
39
+ )
40
+
41
+ const getModules = async (bud: Bud) =>
42
+ await bud.hooks.filterAsync(`build.resolve.modules`, [
43
+ bud.hooks.filter(`location.@src`),
44
+ bud.hooks.filter(`location.@modules`),
45
+ ])
@@ -0,0 +1,22 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const stats: Factory<`stats`> = async app =>
4
+ app.hooks.filter(
5
+ `build.stats`,
6
+ app.isProduction
7
+ ? {
8
+ all: false,
9
+ assets: true,
10
+ children: false,
11
+ entrypoints: true,
12
+ errors: true,
13
+ errorsCount: true,
14
+ hash: true,
15
+ outputPath: true,
16
+ modules: true,
17
+ timings: true,
18
+ warnings: true,
19
+ warningsCount: true,
20
+ }
21
+ : {preset: `none`},
22
+ )
@@ -0,0 +1,9 @@
1
+ import type {Factory} from './index.js'
2
+
3
+ export const target: Factory<`target`> = async ({context, hooks, root}) =>
4
+ hooks.filter(
5
+ `build.target`,
6
+ context.manifest?.browserslist
7
+ ? `browserslist:${root.path(`package.json`)}`
8
+ : `web`,
9
+ )
@@ -0,0 +1,22 @@
1
+ import type {Bud} from '@roots/bud-framework'
2
+
3
+ import type {Rule} from '../rule/index.js'
4
+ import * as items from './items/items.js'
5
+ import * as loaders from './loaders/loaders.js'
6
+ import {register} from './register.js'
7
+ import {rules} from './rules/index.js'
8
+
9
+ export interface Props {
10
+ filter: Bud[`hooks`][`filter`]
11
+ makeItem: Bud[`build`][`makeItem`]
12
+ makeLoader: Bud[`build`][`makeLoader`]
13
+ makeRule: Bud[`build`][`makeRule`]
14
+ isProduction: Bud[`isProduction`]
15
+ path: Bud[`path`]
16
+ }
17
+
18
+ export interface Factory<T = Rule> {
19
+ (props: Props): T
20
+ }
21
+
22
+ export {items, loaders, register, rules}
@@ -0,0 +1,93 @@
1
+ import type {Item} from '@roots/bud-framework/services/build'
2
+ import isBoolean from '@roots/bud-support/lodash/isBoolean'
3
+
4
+ import type {Factory} from '../index.js'
5
+
6
+ /**
7
+ * CSS loader
8
+ */
9
+ export const css: Factory<Item> = ({makeItem}) =>
10
+ makeItem()
11
+ .setIdent(`css`)
12
+ .setLoader(`css`)
13
+ .setOptions(({build: {rules}, hooks: {filter}}) => ({
14
+ importLoaders: rules.css.getUse().length - 2,
15
+ modules: false,
16
+ sourceMap: isBoolean(filter(`build.devtool`, false))
17
+ ? filter(`build.devtool`, false)
18
+ : true,
19
+ }))
20
+
21
+ /**
22
+ * CSS module loader
23
+ */
24
+ export const cssModule: Factory<Item> = ({makeItem}) =>
25
+ makeItem()
26
+ .setIdent(`cssModule`)
27
+ .setLoader(`css`)
28
+ .setOptions(({build: {rules}, hooks: {filter}}) => ({
29
+ importLoaders: rules.cssModule.getUse().length - 2,
30
+ modules: true,
31
+ sourceMap: isBoolean(filter(`build.devtool`, false))
32
+ ? filter(`build.devtool`, false)
33
+ : true,
34
+ }))
35
+
36
+ /**
37
+ * CSV loader
38
+ */
39
+ export const csv: Factory<Item> = ({makeItem}) =>
40
+ makeItem().setLoader(`csv`).setIdent(`csv`)
41
+
42
+ /**
43
+ * HTML loader
44
+ */
45
+ export const html: Factory<Item> = ({makeItem}) =>
46
+ makeItem().setLoader(`html`).setIdent(`html`)
47
+
48
+ /**
49
+ * Style loader
50
+ */
51
+ export const style: Factory<Item> = ({makeItem}) =>
52
+ makeItem().setLoader(`style`).setIdent(`style`)
53
+
54
+ /**
55
+ * Markdown loader
56
+ */
57
+ export const md: Factory<Item> = ({makeItem}) =>
58
+ makeItem().setIdent(`md`).setLoader(`md`)
59
+
60
+ /**
61
+ * MiniCss loader
62
+ */
63
+ export const minicss: Factory<Item> = ({makeItem}) =>
64
+ makeItem()
65
+ .setLoader(`minicss`)
66
+ .setIdent(`minicss`)
67
+ .setOptions(app => ({
68
+ publicPath: app.hooks.filter(`build.output.publicPath`),
69
+ }))
70
+
71
+ /**
72
+ * Raw loader
73
+ */
74
+ export const raw: Factory<Item> = ({makeItem}) =>
75
+ makeItem().setLoader(`raw`).setIdent(`raw`)
76
+
77
+ /**
78
+ * File loader
79
+ */
80
+ export const file: Factory<Item> = ({makeItem}) =>
81
+ makeItem().setLoader(`file`).setIdent(`file`)
82
+
83
+ /**
84
+ * Xml loader
85
+ */
86
+ export const xml: Factory<Item> = ({makeItem}) =>
87
+ makeItem().setLoader(`xml`).setIdent(`xml`)
88
+
89
+ /**
90
+ * Yml loader
91
+ */
92
+ export const yml: Factory<Item> = ({makeItem}) =>
93
+ makeItem().setLoader(`yml`).setIdent(`yml`)
@@ -0,0 +1,31 @@
1
+ import type {Loader} from '@roots/bud-framework/services/build'
2
+ import * as MiniCss from '@roots/bud-support/mini-css-extract-plugin'
3
+
4
+ import type {Factory} from '../index.js'
5
+
6
+ export const css: Factory<Loader> = ({makeLoader}) =>
7
+ makeLoader(`@roots/bud-support/css-loader`)
8
+
9
+ export const csv: Factory<Loader> = ({makeLoader}) =>
10
+ makeLoader(`@roots/bud-support/csv-loader`)
11
+
12
+ export const file: Factory<Loader> = ({makeLoader}) =>
13
+ makeLoader(`@roots/bud-support/file-loader`)
14
+
15
+ export const html: Factory<Loader> = ({makeLoader}) =>
16
+ makeLoader(`@roots/bud-support/html-loader`)
17
+
18
+ export const remark: Factory<Loader> = ({makeLoader}) =>
19
+ makeLoader(`@roots/bud-support/remark-loader`)
20
+
21
+ export const minicss: Factory<Loader> = ({makeLoader}) =>
22
+ makeLoader(MiniCss.loader)
23
+
24
+ export const style: Factory<Loader> = ({makeLoader}) =>
25
+ makeLoader(`@roots/bud-support/style-loader`)
26
+
27
+ export const xml: Factory<Loader> = ({makeLoader}) =>
28
+ makeLoader(`@roots/bud-support/xml-loader`)
29
+
30
+ export const yml: Factory<Loader> = ({makeLoader}) =>
31
+ makeLoader(`@roots/bud-support/yml-loader`)