@roots/bud-build 6.14.2 → 6.15.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 (196) hide show
  1. package/lib/config/bail.d.ts +1 -1
  2. package/lib/config/cache.d.ts +1 -1
  3. package/lib/config/context.d.ts +1 -1
  4. package/lib/config/dependencies.d.ts +1 -1
  5. package/lib/config/devtool.d.ts +1 -1
  6. package/lib/config/entry.d.ts +1 -1
  7. package/lib/config/experiments.d.ts +1 -1
  8. package/lib/config/experiments.js +1 -0
  9. package/lib/config/externals.d.ts +1 -1
  10. package/lib/config/externalsType.d.ts +1 -1
  11. package/lib/config/index.d.ts +28 -29
  12. package/lib/config/index.js +27 -28
  13. package/lib/config/infrastructureLogging.d.ts +1 -1
  14. package/lib/config/infrastructureLogging.js +4 -4
  15. package/lib/config/loader.d.ts +1 -1
  16. package/lib/config/mode.d.ts +1 -1
  17. package/lib/config/module.d.ts +1 -1
  18. package/lib/config/name.d.ts +1 -1
  19. package/lib/config/node.d.ts +1 -1
  20. package/lib/config/optimization.d.ts +1 -1
  21. package/lib/config/optimization.js +1 -1
  22. package/lib/config/output/assetModuleFilename.js +1 -1
  23. package/lib/config/output/filename.js +1 -1
  24. package/lib/config/output/index.d.ts +1 -1
  25. package/lib/config/output/index.js +7 -2
  26. package/lib/config/parallelism.d.ts +1 -1
  27. package/lib/config/parallelism.js +8 -7
  28. package/lib/config/performance.d.ts +1 -1
  29. package/lib/config/plugins.d.ts +1 -1
  30. package/lib/config/plugins.js +4 -1
  31. package/lib/config/profile.d.ts +1 -1
  32. package/lib/config/recordsPath.d.ts +1 -1
  33. package/lib/config/resolve.d.ts +1 -1
  34. package/lib/config/resolve.js +1 -1
  35. package/lib/config/resolveLoader.d.ts +1 -1
  36. package/lib/config/resolveLoader.js +0 -3
  37. package/lib/config/snapshot.d.ts +1 -1
  38. package/lib/config/stats.d.ts +1 -1
  39. package/lib/config/stats.js +1 -19
  40. package/lib/config/target.d.ts +1 -1
  41. package/lib/helpers/isMjs.d.ts +2 -1
  42. package/lib/helpers/isMjs.js +2 -1
  43. package/lib/{shared/base.d.ts → helpers/registrable.d.ts} +2 -1
  44. package/lib/{shared/base.js → helpers/registrable.js} +7 -13
  45. package/lib/helpers/script-extension.d.ts +3 -0
  46. package/lib/helpers/script-extension.js +5 -0
  47. package/lib/index.d.ts +53 -7
  48. package/lib/index.js +5 -7
  49. package/lib/item/index.d.ts +4 -4
  50. package/lib/item/index.js +14 -38
  51. package/lib/{handlers/items/items.d.ts → items/index.d.ts} +1 -1
  52. package/lib/loader/index.d.ts +4 -4
  53. package/lib/loader/index.js +4 -4
  54. package/lib/{handlers/loaders/loaders.d.ts → loaders/index.d.ts} +1 -1
  55. package/lib/registry/index.d.ts +36 -0
  56. package/lib/{handlers/register.js → registry/index.js} +9 -5
  57. package/lib/rule/index.d.ts +3 -3
  58. package/lib/rule/index.js +22 -76
  59. package/lib/rules/css.d.ts +3 -0
  60. package/lib/{handlers/rules → rules}/css.js +2 -1
  61. package/lib/rules/css.module.d.ts +3 -0
  62. package/lib/{handlers/rules → rules}/css.module.js +2 -1
  63. package/lib/rules/csv.d.ts +3 -0
  64. package/lib/{handlers/rules → rules}/csv.js +2 -1
  65. package/lib/rules/font.d.ts +3 -0
  66. package/lib/rules/font.inline.d.ts +3 -0
  67. package/lib/{handlers/rules → rules}/font.inline.js +2 -1
  68. package/lib/{handlers/rules → rules}/font.js +2 -1
  69. package/lib/rules/html.d.ts +3 -0
  70. package/lib/{handlers/rules → rules}/html.js +2 -1
  71. package/lib/rules/image.d.ts +3 -0
  72. package/lib/rules/image.inline.d.ts +3 -0
  73. package/lib/{handlers/rules → rules}/image.inline.js +2 -1
  74. package/lib/rules/image.js +8 -0
  75. package/lib/rules/index.d.ts +15 -0
  76. package/lib/rules/index.js +15 -0
  77. package/lib/rules/js.d.ts +3 -0
  78. package/lib/{handlers/rules → rules}/js.js +2 -1
  79. package/lib/rules/json.d.ts +3 -0
  80. package/lib/{handlers/rules → rules}/json.js +2 -1
  81. package/lib/rules/svg.d.ts +3 -0
  82. package/lib/rules/svg.inline.d.ts +5 -0
  83. package/lib/{handlers/rules → rules}/svg.inline.js +3 -2
  84. package/lib/{handlers/rules → rules}/svg.js +2 -1
  85. package/lib/rules/toml.d.ts +3 -0
  86. package/lib/{handlers/rules → rules}/toml.js +2 -1
  87. package/lib/rules/webp.d.ts +3 -0
  88. package/lib/{handlers/rules → rules}/webp.js +2 -1
  89. package/lib/rules/yml.d.ts +3 -0
  90. package/lib/{handlers/rules → rules}/yml.js +2 -1
  91. package/lib/{service.d.ts → service/index.d.ts} +27 -24
  92. package/lib/{service.js → service/index.js} +45 -70
  93. package/package.json +121 -37
  94. package/src/config/bail.ts +1 -1
  95. package/src/config/cache.ts +1 -1
  96. package/src/config/context.ts +1 -1
  97. package/src/config/dependencies.ts +2 -2
  98. package/src/config/devtool.ts +1 -1
  99. package/src/config/entry.ts +1 -1
  100. package/src/config/experiments.ts +2 -1
  101. package/src/config/externals.ts +1 -1
  102. package/src/config/externalsType.ts +1 -1
  103. package/src/config/index.ts +28 -58
  104. package/src/config/infrastructureLogging.ts +6 -6
  105. package/src/config/loader.ts +1 -1
  106. package/src/config/mode.ts +1 -1
  107. package/src/config/module.ts +1 -2
  108. package/src/config/name.ts +1 -1
  109. package/src/config/node.ts +1 -1
  110. package/src/config/optimization.ts +2 -2
  111. package/src/config/output/assetModuleFilename.ts +1 -1
  112. package/src/config/output/filename.ts +1 -1
  113. package/src/config/output/index.ts +8 -6
  114. package/src/config/parallelism.ts +11 -8
  115. package/src/config/performance.ts +1 -1
  116. package/src/config/plugins.ts +5 -3
  117. package/src/config/profile.ts +1 -1
  118. package/src/config/recordsPath.ts +1 -1
  119. package/src/config/resolve.ts +3 -3
  120. package/src/config/resolveLoader.ts +1 -4
  121. package/src/config/snapshot.ts +1 -1
  122. package/src/config/stats.ts +2 -23
  123. package/src/config/target.ts +1 -1
  124. package/src/helpers/isMjs.ts +3 -1
  125. package/src/{shared/base.ts → helpers/registrable.ts} +3 -1
  126. package/src/helpers/{scriptExtension.ts → script-extension.ts} +4 -2
  127. package/src/index.ts +56 -7
  128. package/src/item/index.ts +5 -6
  129. package/src/{handlers/items/items.ts → items/index.ts} +1 -2
  130. package/src/loader/index.ts +6 -5
  131. package/src/{handlers/loaders/loaders.ts → loaders/index.ts} +1 -2
  132. package/src/{handlers/register.ts → registry/index.ts} +36 -13
  133. package/src/rule/index.ts +3 -4
  134. package/src/rules/css.module.ts +9 -0
  135. package/src/rules/css.ts +9 -0
  136. package/src/rules/csv.ts +9 -0
  137. package/src/rules/font.inline.ts +10 -0
  138. package/src/rules/font.ts +9 -0
  139. package/src/rules/html.ts +9 -0
  140. package/src/rules/image.inline.ts +10 -0
  141. package/src/rules/image.ts +12 -0
  142. package/src/rules/index.ts +15 -0
  143. package/src/{handlers/rules → rules}/js.ts +4 -2
  144. package/src/{handlers/rules → rules}/json.ts +5 -3
  145. package/src/{handlers/rules → rules}/svg.inline.ts +6 -4
  146. package/src/rules/svg.ts +9 -0
  147. package/src/{handlers/rules → rules}/toml.ts +5 -3
  148. package/src/rules/webp.ts +9 -0
  149. package/src/rules/yml.ts +9 -0
  150. package/src/{service.ts → service/index.ts} +43 -36
  151. package/lib/handlers/index.d.ts +0 -19
  152. package/lib/handlers/index.js +0 -5
  153. package/lib/handlers/register.d.ts +0 -13
  154. package/lib/handlers/rules/css.d.ts +0 -2
  155. package/lib/handlers/rules/css.module.d.ts +0 -2
  156. package/lib/handlers/rules/csv.d.ts +0 -2
  157. package/lib/handlers/rules/font.d.ts +0 -2
  158. package/lib/handlers/rules/font.inline.d.ts +0 -2
  159. package/lib/handlers/rules/html.d.ts +0 -2
  160. package/lib/handlers/rules/image.d.ts +0 -2
  161. package/lib/handlers/rules/image.inline.d.ts +0 -2
  162. package/lib/handlers/rules/image.js +0 -4
  163. package/lib/handlers/rules/index.d.ts +0 -17
  164. package/lib/handlers/rules/index.js +0 -32
  165. package/lib/handlers/rules/js.d.ts +0 -2
  166. package/lib/handlers/rules/json.d.ts +0 -2
  167. package/lib/handlers/rules/svg.d.ts +0 -2
  168. package/lib/handlers/rules/svg.inline.d.ts +0 -4
  169. package/lib/handlers/rules/toml.d.ts +0 -2
  170. package/lib/handlers/rules/webp.d.ts +0 -2
  171. package/lib/handlers/rules/yml.d.ts +0 -2
  172. package/lib/helpers/scriptExtension.d.ts +0 -2
  173. package/lib/helpers/scriptExtension.js +0 -4
  174. package/lib/types.d.ts +0 -52
  175. package/lib/types.js +0 -1
  176. package/src/config/index.test.ts +0 -125
  177. package/src/handlers/index.ts +0 -24
  178. package/src/handlers/rules/css.module.ts +0 -7
  179. package/src/handlers/rules/css.ts +0 -7
  180. package/src/handlers/rules/csv.test.ts +0 -31
  181. package/src/handlers/rules/csv.ts +0 -7
  182. package/src/handlers/rules/font.inline.ts +0 -8
  183. package/src/handlers/rules/font.ts +0 -7
  184. package/src/handlers/rules/html.ts +0 -7
  185. package/src/handlers/rules/image.inline.ts +0 -8
  186. package/src/handlers/rules/image.ts +0 -7
  187. package/src/handlers/rules/index.ts +0 -33
  188. package/src/handlers/rules/svg.inline.test.ts +0 -31
  189. package/src/handlers/rules/svg.ts +0 -7
  190. package/src/handlers/rules/toml.test.ts +0 -23
  191. package/src/handlers/rules/webp.ts +0 -7
  192. package/src/handlers/rules/yml.ts +0 -7
  193. package/src/rule/index.test.ts +0 -88
  194. package/src/types.ts +0 -57
  195. /package/lib/{handlers/items/items.js → items/index.js} +0 -0
  196. /package/lib/{handlers/loaders/loaders.js → loaders/index.js} +0 -0
@@ -1,69 +1,39 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
  import type {Configuration} from '@roots/bud-framework/config'
3
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 {resolveLoader} from './resolveLoader.js'
28
- import {snapshot} from './snapshot.js'
29
- import {stats} from './stats.js'
30
- import {target} from './target.js'
31
-
32
- export {
33
- bail,
34
- cache,
35
- context,
36
- dependencies,
37
- devtool,
38
- entry,
39
- experiments,
40
- externals,
41
- externalsType,
42
- infrastructureLogging,
43
- loader,
44
- mode,
45
- module,
46
- name,
47
- node,
48
- optimization,
49
- output,
50
- parallelism,
51
- performance,
52
- plugins,
53
- profile,
54
- recordsPath,
55
- resolve,
56
- resolveLoader,
57
- snapshot,
58
- stats,
59
- target,
60
- }
4
+ export {bail} from './bail.js'
5
+ export {cache} from './cache.js'
6
+ export {context} from './context.js'
7
+ export {dependencies} from './dependencies.js'
8
+ export {devtool} from './devtool.js'
9
+ export {entry} from './entry.js'
10
+ export {experiments} from './experiments.js'
11
+ export {externals} from './externals.js'
12
+ export {externalsType} from './externalsType.js'
13
+ export {infrastructureLogging} from './infrastructureLogging.js'
14
+ export {loader} from './loader.js'
15
+ export {mode} from './mode.js'
16
+ export {module} from './module.js'
17
+ export {name} from './name.js'
18
+ export {node} from './node.js'
19
+ export {optimization} from './optimization.js'
20
+ export {output} from './output/index.js'
21
+ export {parallelism} from './parallelism.js'
22
+ export {performance} from './performance.js'
23
+ export {plugins} from './plugins.js'
24
+ export {profile} from './profile.js'
25
+ export {recordsPath} from './recordsPath.js'
26
+ export {resolve} from './resolve.js'
27
+ export {resolveLoader} from './resolveLoader.js'
28
+ export {snapshot} from './snapshot.js'
29
+ export {stats} from './stats.js'
30
+ export {target} from './target.js'
61
31
 
62
32
  export interface Factory<
63
33
  Key extends keyof Config,
64
34
  Config = Configuration,
65
35
  > {
66
- (app: Bud): Promise<Config[Key]>
36
+ (app: Bud): Promise<Config[Key] | undefined>
67
37
  }
68
38
 
69
39
  export type Records<Config = Configuration> = {
@@ -1,6 +1,6 @@
1
- import logger from '@roots/bud-support/logger'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
- import type {Factory} from './index.js'
3
+ import logger from '@roots/bud-support/logger'
4
4
 
5
5
  export const infrastructureLogging: Factory<
6
6
  `infrastructureLogging`
@@ -9,16 +9,16 @@ export const infrastructureLogging: Factory<
9
9
  console: bud.hooks.filter(`build.infrastructureLogging.console`, {
10
10
  ...console,
11
11
  error: (...args: any[]) => {
12
- logger.scope(`webpack`).error(...args)
12
+ logger.scope(bud.label, `webpack`).error(...args)
13
13
  },
14
14
  info: (...args: any[]) => {
15
- logger.scope(`webpack`).info(...args)
15
+ logger.scope(bud.label, `webpack`).info(...args)
16
16
  },
17
17
  log: (...args: any[]) => {
18
- logger.scope(`webpack`).log(...args)
18
+ logger.scope(bud.label, `webpack`).log(...args)
19
19
  },
20
20
  warn: (...args: any[]) => {
21
- logger.scope(`webpack`).info(...args)
21
+ logger.scope(bud.label, `webpack`).info(...args)
22
22
  },
23
23
  }),
24
24
  level: bud.hooks.filter(`build.infrastructureLogging.level`, `log`),
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const loader: Factory<`loader`> = async app =>
4
4
  app.hooks.filter(`build.loader`)
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const mode: Factory<`mode`> = async bud =>
4
4
  bud.hooks.filter(`build.mode`, bud.mode)
@@ -1,7 +1,6 @@
1
+ import type {Factory} from '@roots/bud-build/config'
1
2
  import type {Bud} from '@roots/bud-framework'
2
3
 
3
- import type {Factory} from './index.js'
4
-
5
4
  interface Props {
6
5
  filter: Bud[`hooks`][`filter`]
7
6
  path: Bud[`path`]
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const name: Factory<`name`> = async ({hooks, label}) =>
4
4
  hooks.filter(`build.name`, label)
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const node: Factory<`node`> = async ({hooks}) =>
4
4
  hooks.filter(`build.node`, false)
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const optimization: Factory<`optimization`> = async ({
4
4
  hooks: {filter},
@@ -31,7 +31,7 @@ export const optimization: Factory<`optimization`> = async ({
31
31
  ),
32
32
  removeEmptyChunks: filter(
33
33
  `build.optimization.removeEmptyChunks`,
34
- isProduction,
34
+ false,
35
35
  ),
36
36
  runtimeChunk: filter(`build.optimization.runtimeChunk`, `single`),
37
37
  sideEffects: filter(`build.optimization.sideEffects`, isProduction),
@@ -6,4 +6,4 @@ interface Props {
6
6
  }
7
7
 
8
8
  export const assetModuleFilename = ({filter, relPath}: Props) =>
9
- filter(`build.output.assetModuleFilename`, relPath(`@file`))
9
+ filter(`build.output.assetModuleFilename`, relPath(`@file[query]`))
@@ -1,6 +1,6 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
- import {scriptExtension} from '../../helpers/scriptExtension.js'
3
+ import scriptExtension from '@roots/bud-build/helpers/script-extension'
4
4
 
5
5
  interface Props {
6
6
  filter: Bud['hooks'][`filter`]
@@ -1,6 +1,5 @@
1
- import type {Factory} from '../index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
- import {isMjs} from '../../helpers/isMjs.js'
4
3
  import {assetModuleFilename} from './assetModuleFilename.js'
5
4
  import {filename} from './filename.js'
6
5
 
@@ -24,11 +23,14 @@ export const output: Factory<`output`> = async ({
24
23
  iife: filter(`build.output.iife`, undefined),
25
24
  module: filter(`build.output.module`, false),
26
25
  path: filter(`build.output.path`, path(`@dist`)),
26
+ /**
27
+ * Path info is not necessary unless the user
28
+ * really knows what's going on.
29
+ *
30
+ * @see {@link https://medium.com/@kenneth_chau/speeding-up-webpack-typescript-incremental-builds-by-7x-3912ba4c1d15}
31
+ */
27
32
  pathinfo: filter(`build.output.pathinfo`, false),
28
33
  publicPath: filter(`build.output.publicPath`, `auto`),
29
- scriptType: filter(
30
- `build.output.scriptType`,
31
- isMjs(filter) ? `module` : `text/javascript`,
32
- ),
34
+ scriptType: filter(`build.output.scriptType`, undefined),
33
35
  uniqueName: filter(`build.output.uniqueName`, `@roots/bud`),
34
36
  })
@@ -1,16 +1,19 @@
1
- import {cpus} from 'node:os'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
- import type {Factory} from './index.js'
3
+ import {cpus} from 'node:os'
4
4
 
5
5
  export const parallelism: Factory<`parallelism`> = async ({
6
+ build,
6
7
  hooks,
7
8
  root,
8
9
  }) => {
9
- const factor = 10
10
- const procs = Math.min(cpus().length - 1, 1)
11
- const comps = root.hasChildren
12
- ? Math.min(Object.keys(root.children).length)
13
- : 1
10
+ const concurrency = 100
11
+ const cores = Math.max(cpus().length, 1)
12
+
13
+ const available = cores * concurrency
14
+ const compilations = Math.max(Object.keys(root.children ?? []).length, 1)
15
+ const parallelism = Math.max(Math.floor(available / compilations), 1)
14
16
 
15
- return hooks.filter(`build.parallelism`, (procs * factor) / comps)
17
+ build.logger.info(`parallelism set to`, parallelism)
18
+ return hooks.filter(`build.parallelism`, parallelism)
16
19
  }
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const performance: Factory<`performance`> = async ({hooks}) =>
4
4
  hooks.filter(`build.performance`, false)
@@ -1,4 +1,6 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
- export const plugins: Factory<`plugins`> = async app =>
4
- await app.hooks.filterAsync(`build.plugins`, await app.extensions.make())
3
+ export const plugins: Factory<`plugins`> = async app => {
4
+ const plugins = await app.extensions.make()
5
+ return await app.hooks.filterAsync(`build.plugins`, plugins)
6
+ }
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const profile: Factory<`profile`> = async bud =>
4
4
  bud.hooks.filter(`build.profile`, bud.context.debug)
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const recordsPath: Factory<`recordsPath`> = async bud =>
4
4
  bud.hooks.filter(
@@ -1,6 +1,6 @@
1
- import isString from '@roots/bud-support/lodash/isString'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
- import type {Factory} from './index.js'
3
+ import isString from '@roots/bud-support/lodash/isString'
4
4
 
5
5
  export const resolve: Factory<`resolve`> = async bud => {
6
6
  return await bud.hooks.filterAsync(`build.resolve`, {
@@ -20,7 +20,7 @@ export const resolve: Factory<`resolve`> = async bud => {
20
20
  extensions: Array.from(
21
21
  bud.hooks.filter(
22
22
  `build.resolve.extensions`,
23
- new Set([`.js`, `.mjs`, `.jsx`, `.css`]),
23
+ new Set([`.js`, `.mjs`, `.css`]),
24
24
  ),
25
25
  ),
26
26
 
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const resolveLoader: Factory<`resolveLoader`> = async ({
4
4
  hooks,
@@ -13,11 +13,8 @@ export const resolveLoader: Factory<`resolveLoader`> = async ({
13
13
  'html-loader': await module.resolve(
14
14
  `@roots/bud-support/html-loader`,
15
15
  ),
16
- json5: await module.resolve(`@roots/bud-support/json5`),
17
- 'mini-svg-data-uri': await module.resolve(`mini-svg-data-uri`),
18
16
  'style-loader': await module.resolve(
19
17
  `@roots/bud-support/style-loader`,
20
18
  ),
21
- toml: await module.resolve(`@roots/bud-support/toml`),
22
19
  }),
23
20
  })
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const snapshot: Factory<`snapshot`> = async ({env, hooks, path}) =>
4
4
  hooks.filter(`build.snapshot`, {
@@ -1,25 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
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
- assetsSort: `size`,
11
- builtAt: false,
12
- children: false,
13
- chunks: false,
14
- entrypoints: true,
15
- errors: true,
16
- errorsCount: true,
17
- hash: true,
18
- modules: true,
19
- outputPath: true,
20
- timings: true,
21
- warnings: true,
22
- warningsCount: true,
23
- }
24
- : {preset: `none`},
25
- )
4
+ app.hooks.filter(`build.stats`, {preset: `none`})
@@ -1,4 +1,4 @@
1
- import type {Factory} from './index.js'
1
+ import type {Factory} from '@roots/bud-build/config'
2
2
 
3
3
  export const target: Factory<`target`> = async ({context, hooks, root}) =>
4
4
  hooks.filter(
@@ -1,4 +1,6 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
- export const isMjs = (filter: Bud[`hooks`][`filter`]) =>
3
+ const isMjs = (filter: Bud[`hooks`][`filter`]) =>
4
4
  filter(`build.experiments`)?.outputModule === true
5
+
6
+ export {isMjs as default}
@@ -4,7 +4,7 @@ import type {Base as BuildBase} from '@roots/bud-framework/services/build'
4
4
  import {bind} from '@roots/bud-support/decorators/bind'
5
5
  import isFunction from '@roots/bud-support/lodash/isFunction'
6
6
 
7
- export default class Base implements BuildBase {
7
+ class Registrable implements BuildBase {
8
8
  /**
9
9
  * Constructor
10
10
  */
@@ -34,3 +34,5 @@ export default class Base implements BuildBase {
34
34
  return isFunction(input) ? input : () => input
35
35
  }
36
36
  }
37
+
38
+ export {Registrable as default}
@@ -1,11 +1,13 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
- import {isMjs} from './isMjs.js'
3
+ import isMjs from '@roots/bud-build/helpers/isMjs'
4
4
 
5
- export const scriptExtension = (
5
+ const scriptExtension = (
6
6
  filter: Bud[`hooks`][`filter`],
7
7
  mjs: `.${string}` = `.mjs`,
8
8
  js: `.${string}` = `.js`,
9
9
  ): `.${string}` => {
10
10
  return isMjs(filter) ? mjs : js
11
11
  }
12
+
13
+ export {scriptExtension as default}
package/src/index.ts CHANGED
@@ -8,12 +8,61 @@
8
8
  * @see https://github.com/roots/bud
9
9
  */
10
10
 
11
- import {Item} from './item/index.js'
12
- import {Loader} from './loader/index.js'
13
- import {Rule} from './rule/index.js'
14
- import {Build} from './service.js'
15
- import './types.js'
11
+ import {default as Item} from '@roots/bud-build/item'
12
+ import {default as Loader} from '@roots/bud-build/loader'
13
+ import {default as Rule} from '@roots/bud-build/rule'
14
+ import {default as Build} from '@roots/bud-build/service'
16
15
 
17
- export default Build
16
+ declare module '@roots/bud-framework' {
17
+ interface Services {
18
+ build: Build
19
+ }
18
20
 
19
- export {Item, Loader, Rule}
21
+ interface Loaders {
22
+ css: Loader
23
+ csv: Loader
24
+ file: Loader
25
+ html: Loader
26
+ md: Loader
27
+ minicss: Loader
28
+ raw: Loader
29
+ style: Loader
30
+ url: Loader
31
+ yml: Loader
32
+ }
33
+
34
+ interface Items {
35
+ css: Item
36
+ cssModule: Item
37
+ csv: Item
38
+ file: Item
39
+ font: Item
40
+ html: Item
41
+ image: Item
42
+ md: Item
43
+ minicss: Item
44
+ precss: Item
45
+ raw: Item
46
+ style: Item
47
+ yml: Item
48
+ }
49
+
50
+ interface Rules {
51
+ css: Rule
52
+ cssModule: Rule
53
+ csv: Rule
54
+ font: Rule
55
+ html: Rule
56
+ image: Rule
57
+ inlineFont: Rule
58
+ inlineImage: Rule
59
+ inlineSvg: Rule
60
+ js: Rule
61
+ json: Rule
62
+ svg: Rule
63
+ toml: Rule
64
+ yml: Rule
65
+ }
66
+ }
67
+
68
+ export {Build as default, Item, Loader, Rule}
package/src/item/index.ts CHANGED
@@ -1,20 +1,19 @@
1
1
  import type {Bud, Loaders} from '@roots/bud-framework'
2
2
  import type * as Build from '@roots/bud-framework/services/build'
3
3
 
4
- import {basename} from 'path'
4
+ import {basename} from 'node:path'
5
5
 
6
+ import Registrable from '@roots/bud-build/helpers/registrable'
7
+ import Loader from '@roots/bud-build/loader'
6
8
  import {bind} from '@roots/bud-support/decorators/bind'
7
9
  import isString from '@roots/bud-support/lodash/isString'
8
10
 
9
- import {Loader} from '../loader/index.js'
10
- import Base from '../shared/base.js'
11
-
12
11
  export type ConstructorOptions = Build.Item.ConstructorOptions
13
12
 
14
13
  /**
15
14
  * Item class
16
15
  */
17
- class Item extends Base implements Build.Item {
16
+ class Item extends Registrable implements Build.Item {
18
17
  /**
19
18
  * Identifier
20
19
  */
@@ -153,4 +152,4 @@ class Item extends Base implements Build.Item {
153
152
  }
154
153
  }
155
154
 
156
- export {Item}
155
+ export {Item as default}
@@ -1,9 +1,8 @@
1
+ import type {Factory} from '@roots/bud-build/registry'
1
2
  import type {Item} from '@roots/bud-framework/services/build'
2
3
 
3
4
  import isBoolean from '@roots/bud-support/lodash/isBoolean'
4
5
 
5
- import type {Factory} from '../index.js'
6
-
7
6
  /**
8
7
  * CSS loader
9
8
  */
@@ -1,15 +1,16 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
- import Base from '../shared/base.js'
3
+ import Registrable from '@roots/bud-build/helpers/registrable'
4
4
 
5
5
  /**
6
6
  * Bud Loader
7
7
  */
8
- class Loader extends Base {
8
+ class Loader extends Registrable {
9
9
  /**
10
10
  * Factory returning the loader path
11
11
  */
12
12
  public src: string
13
+
13
14
  /**
14
15
  * Class constructor
15
16
  *
@@ -17,12 +18,12 @@ class Loader extends Base {
17
18
  */
18
19
  public constructor(
19
20
  public override _app: () => Bud,
20
- src: string,
21
+ src?: string,
21
22
  definition?: string,
22
23
  ) {
23
24
  super(_app)
24
25
  this._app = _app
25
- this.src = definition ?? src
26
+ this.src = definition ?? src ?? ``
26
27
  }
27
28
 
28
29
  public getSrc(): string {
@@ -35,4 +36,4 @@ class Loader extends Base {
35
36
  }
36
37
  }
37
38
 
38
- export {Loader}
39
+ export {Loader as default}
@@ -1,9 +1,8 @@
1
+ import type {Factory} from '@roots/bud-build/registry'
1
2
  import type {Loader} from '@roots/bud-framework/services/build'
2
3
 
3
4
  import * as MiniCss from '@roots/bud-support/mini-css-extract-plugin'
4
5
 
5
- import type {Factory} from '../index.js'
6
-
7
6
  export const css: Factory<Loader> = async ({makeLoader, resolve}) =>
8
7
  makeLoader(
9
8
  await resolve(`@roots/bud-support/css-loader`, import.meta.url),
@@ -1,24 +1,28 @@
1
+ import type Rule from '@roots/bud-build/rule'
1
2
  import type {Bud} from '@roots/bud-framework'
2
3
 
3
- import type {Factory} from './index.js'
4
+ import * as items from '@roots/bud-build/items'
5
+ import * as loaders from '@roots/bud-build/loaders'
6
+ import * as rules from '@roots/bud-build/rules'
4
7
 
5
- import * as items from './items/items.js'
6
- import * as loaders from './loaders/loaders.js'
7
- import {rules} from './rules/index.js'
8
+ interface Props {
9
+ filter: Bud[`hooks`][`filter`]
10
+ isProduction: Bud[`isProduction`]
11
+ makeItem: Bud[`build`][`makeItem`]
12
+ makeLoader: Bud[`build`][`makeLoader`]
13
+ makeRule: Bud[`build`][`makeRule`]
14
+ path: Bud[`path`]
15
+ resolve: Bud[`module`][`resolve`]
16
+ }
8
17
 
9
- /**
10
- * Registry factory curry function
11
- */
12
- export interface makeRegister {
13
- <T, F extends CallableFunction>(props: Partial<Bud>, setRule: F): <
14
- K extends keyof T & string,
15
- >([key, factory]: [K, Factory<T[K]>]) => void
18
+ interface Factory<T = Rule> {
19
+ (props: Props): Promise<T>
16
20
  }
17
21
 
18
22
  /**
19
23
  * Register built-in {@link loaders}, {@link items} and {@link rules}
20
24
  */
21
- export async function register(bud: Bud) {
25
+ async function register(bud: Bud) {
22
26
  await Promise.all([
23
27
  ...Object.entries(loaders).map(makeRegister(bud, bud.build.setLoader)),
24
28
  ...Object.entries(items).map(makeRegister(bud, bud.build.setItem)),
@@ -34,7 +38,23 @@ export async function register(bud: Bud) {
34
38
  Object.entries(rules).map(makeRegister(bud, bud.build.setRule))
35
39
  }
36
40
 
37
- export const makeRegister: makeRegister =
41
+ /**
42
+ * Registry factory curry function
43
+ */
44
+ interface makeRegister {
45
+ <T, F extends CallableFunction>(
46
+ props: Partial<Bud>,
47
+ setRule: F,
48
+ ): <K extends keyof T & string>([key, factory]: [
49
+ K,
50
+ Factory<T[K]>,
51
+ ]) => void
52
+ }
53
+
54
+ /**
55
+ * Registry factory
56
+ */
57
+ const makeRegister: makeRegister =
38
58
  ({build, hooks, isProduction, module: {resolve}, path}, setRule) =>
39
59
  async ([key, factory]) =>
40
60
  setRule(
@@ -49,3 +69,6 @@ export const makeRegister: makeRegister =
49
69
  resolve,
50
70
  }),
51
71
  )
72
+
73
+ export {items, loaders, makeRegister, register, rules}
74
+ export type {Factory, Props}