@roots/bud-build 6.12.3 → 6.13.1

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 (77) hide show
  1. package/lib/config/experiments.js +3 -1
  2. package/lib/config/externalsType.js +1 -1
  3. package/lib/config/index.d.ts +1 -1
  4. package/lib/config/infrastructureLogging.js +6 -6
  5. package/lib/config/module.js +6 -2
  6. package/lib/config/optimization.js +13 -3
  7. package/lib/config/output/index.js +1 -1
  8. package/lib/config/performance.js +1 -1
  9. package/lib/config/profile.js +1 -1
  10. package/lib/config/resolve.js +19 -27
  11. package/lib/config/resolveLoader.js +2 -2
  12. package/lib/config/snapshot.js +8 -3
  13. package/lib/config/stats.js +1 -1
  14. package/lib/handlers/index.d.ts +1 -1
  15. package/lib/handlers/items/items.d.ts +1 -5
  16. package/lib/handlers/items/items.js +2 -6
  17. package/lib/handlers/loaders/loaders.d.ts +0 -1
  18. package/lib/handlers/loaders/loaders.js +0 -1
  19. package/lib/handlers/register.js +2 -2
  20. package/lib/handlers/rules/csv.js +1 -1
  21. package/lib/handlers/rules/index.d.ts +9 -10
  22. package/lib/handlers/rules/index.js +9 -11
  23. package/lib/handlers/rules/js.js +3 -1
  24. package/lib/handlers/rules/json.js +3 -1
  25. package/lib/handlers/rules/toml.js +3 -1
  26. package/lib/index.d.ts +1 -1
  27. package/lib/index.js +1 -1
  28. package/lib/item/index.d.ts +11 -11
  29. package/lib/item/index.js +45 -32
  30. package/lib/loader/index.js +5 -0
  31. package/lib/rule/index.d.ts +62 -50
  32. package/lib/rule/index.js +143 -81
  33. package/lib/service.d.ts +30 -29
  34. package/lib/service.js +96 -99
  35. package/lib/shared/base.d.ts +6 -6
  36. package/lib/shared/base.js +16 -15
  37. package/lib/types.d.ts +12 -15
  38. package/lib/types.js +0 -2
  39. package/package.json +7 -7
  40. package/src/config/experiments.ts +3 -1
  41. package/src/config/externalsType.ts +2 -1
  42. package/src/config/index.test.ts +5 -5
  43. package/src/config/index.ts +1 -1
  44. package/src/config/infrastructureLogging.ts +6 -6
  45. package/src/config/module.ts +7 -3
  46. package/src/config/optimization.ts +22 -2
  47. package/src/config/output/chunkFilename.ts +2 -2
  48. package/src/config/output/index.ts +3 -2
  49. package/src/config/performance.ts +1 -1
  50. package/src/config/profile.ts +2 -2
  51. package/src/config/resolve.ts +27 -41
  52. package/src/config/resolveLoader.ts +3 -3
  53. package/src/config/snapshot.ts +21 -4
  54. package/src/config/stats.ts +1 -1
  55. package/src/handlers/index.ts +2 -1
  56. package/src/handlers/items/items.ts +3 -8
  57. package/src/handlers/loaders/loaders.ts +1 -5
  58. package/src/handlers/register.ts +3 -2
  59. package/src/handlers/rules/csv.test.ts +1 -1
  60. package/src/handlers/rules/csv.ts +1 -1
  61. package/src/handlers/rules/index.ts +9 -11
  62. package/src/handlers/rules/js.ts +3 -1
  63. package/src/handlers/rules/json.ts +3 -1
  64. package/src/handlers/rules/svg.inline.test.ts +1 -1
  65. package/src/handlers/rules/toml.test.ts +1 -1
  66. package/src/handlers/rules/toml.ts +3 -1
  67. package/src/index.ts +1 -2
  68. package/src/item/index.ts +29 -28
  69. package/src/rule/index.test.ts +1 -1
  70. package/src/rule/index.ts +108 -79
  71. package/src/service.ts +80 -77
  72. package/src/shared/base.ts +12 -11
  73. package/src/types.ts +12 -18
  74. package/lib/handlers/rules/xml.d.ts +0 -2
  75. package/lib/handlers/rules/xml.js +0 -4
  76. package/src/handlers/rules/xml.test.ts +0 -30
  77. package/src/handlers/rules/xml.ts +0 -7
@@ -1,45 +1,31 @@
1
- import type {Bud} from '@roots/bud-framework'
2
-
3
1
  import type {Factory} from './index.js'
4
2
 
5
3
  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
- ]),
4
+ return await bud.hooks.filterAsync(`build.resolve`, {
5
+ alias: {
6
+ [`@src`]: bud.path(`@src`),
7
+ ...(await bud.hooks.filterAsync(`build.resolve.alias`, {})),
8
+ },
9
+ extensionAlias: await bud.hooks.filterAsync(
10
+ `build.resolve.extensionAlias`,
11
+ {
12
+ [`.js`]: [`.ts`, `.tsx`, `.js`],
13
+ [`.mjs`]: [`.mts`, `.mtx`, `.mjs`],
14
+ },
38
15
  ),
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
- ])
16
+ extensions: Array.from(
17
+ bud.hooks.filter(
18
+ `build.resolve.extensions`,
19
+ new Set([`.js`, `.mjs`, `.jsx`, `.css`]),
20
+ ),
21
+ ),
22
+ modules: await bud.hooks.filterAsync(`build.resolve.modules`, [
23
+ bud.hooks.filter(`location.@src`),
24
+ bud.hooks.filter(`location.@modules`),
25
+ ]),
26
+ /**
27
+ * Leave `undefined` to use webpack default (true in dev, false in production)
28
+ */
29
+ unsafeCache: bud.hooks.filter(`build.module.unsafeCache`, undefined),
30
+ })
31
+ }
@@ -1,6 +1,6 @@
1
1
  import type {Factory} from './index.js'
2
2
 
3
- export const resolveLoader: Factory<`resolveLoader`> = async bud =>
4
- bud.hooks.filter(`build.resolveLoader`, {
5
- alias: {},
3
+ export const resolveLoader: Factory<`resolveLoader`> = async ({hooks}) =>
4
+ hooks.filter(`build.resolveLoader`, {
5
+ alias: hooks.filter(`build.resolveLoader.alias`, {}),
6
6
  })
@@ -1,8 +1,25 @@
1
1
  import type {Factory} from './index.js'
2
2
 
3
- export const snapshot: Factory<`snapshot`> = async app =>
4
- app.hooks.filter(`build.snapshot`, {
5
- managedPaths: app.hooks.filter(`build.snapshot.managedPaths`, [
6
- ...new Set([app.path(`@modules`)]),
3
+ export const snapshot: Factory<`snapshot`> = async ({env, hooks, path}) =>
4
+ hooks.filter(`build.snapshot`, {
5
+ buildDependencies: hooks.filter(
6
+ `build.snapshot.buildDependencies`,
7
+ env.isTrue(`CI`) ? {hash: true} : {timestamp: true},
8
+ ),
9
+ immutablePaths: hooks.filter(`build.snapshot.immutablePaths`, []),
10
+ managedPaths: hooks.filter(`build.snapshot.managedPaths`, [
11
+ ...new Set([path(`@modules`)]),
7
12
  ]),
13
+ module: hooks.filter(
14
+ `build.snapshot.module`,
15
+ env.isTrue(`CI`) ? {hash: true} : {timestamp: true},
16
+ ),
17
+ resolve: hooks.filter(
18
+ `build.snapshot.resolve`,
19
+ env.isTrue(`CI`) ? {hash: true} : {timestamp: true},
20
+ ),
21
+ resolveBuildDependencies: hooks.filter(
22
+ `build.snapshot.resolveBuildDependencies`,
23
+ env.isTrue(`CI`) ? {hash: true} : {timestamp: true},
24
+ ),
8
25
  })
@@ -12,8 +12,8 @@ export const stats: Factory<`stats`> = async app =>
12
12
  errors: true,
13
13
  errorsCount: true,
14
14
  hash: true,
15
- outputPath: true,
16
15
  modules: true,
16
+ outputPath: true,
17
17
  timings: true,
18
18
  warnings: true,
19
19
  warningsCount: true,
@@ -1,6 +1,7 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
3
  import type {Rule} from '../rule/index.js'
4
+
4
5
  import * as items from './items/items.js'
5
6
  import * as loaders from './loaders/loaders.js'
6
7
  import {register} from './register.js'
@@ -8,10 +9,10 @@ import {rules} from './rules/index.js'
8
9
 
9
10
  export interface Props {
10
11
  filter: Bud[`hooks`][`filter`]
12
+ isProduction: Bud[`isProduction`]
11
13
  makeItem: Bud[`build`][`makeItem`]
12
14
  makeLoader: Bud[`build`][`makeLoader`]
13
15
  makeRule: Bud[`build`][`makeRule`]
14
- isProduction: Bud[`isProduction`]
15
16
  path: Bud[`path`]
16
17
  resolve: Bud[`module`][`resolve`]
17
18
  }
@@ -1,4 +1,5 @@
1
1
  import type {Item} from '@roots/bud-framework/services/build'
2
+
2
3
  import isBoolean from '@roots/bud-support/lodash/isBoolean'
3
4
 
4
5
  import type {Factory} from '../index.js'
@@ -65,7 +66,7 @@ export const minicss: Factory<Item> = async ({makeItem}) =>
65
66
  .setLoader(`minicss`)
66
67
  .setIdent(`minicss`)
67
68
  .setOptions(app => ({
68
- publicPath: app.hooks.filter(`build.output.publicPath`),
69
+ publicPath: app.publicPath(),
69
70
  }))
70
71
 
71
72
  /**
@@ -75,17 +76,11 @@ export const raw: Factory<Item> = async ({makeItem}) =>
75
76
  makeItem().setLoader(`raw`).setIdent(`raw`)
76
77
 
77
78
  /**
78
- * File loader
79
+ * file-loader
79
80
  */
80
81
  export const file: Factory<Item> = async ({makeItem}) =>
81
82
  makeItem().setLoader(`file`).setIdent(`file`)
82
83
 
83
- /**
84
- * Xml loader
85
- */
86
- export const xml: Factory<Item> = async ({makeItem}) =>
87
- makeItem().setLoader(`xml`).setIdent(`xml`)
88
-
89
84
  /**
90
85
  * Yml loader
91
86
  */
@@ -1,4 +1,5 @@
1
1
  import type {Loader} from '@roots/bud-framework/services/build'
2
+
2
3
  import * as MiniCss from '@roots/bud-support/mini-css-extract-plugin'
3
4
 
4
5
  import type {Factory} from '../index.js'
@@ -36,11 +37,6 @@ export const style: Factory<Loader> = async ({makeLoader, resolve}) =>
36
37
  await resolve(`@roots/bud-support/style-loader`, import.meta.url),
37
38
  )
38
39
 
39
- export const xml: Factory<Loader> = async ({makeLoader, resolve}) =>
40
- makeLoader(
41
- await resolve(`@roots/bud-support/xml-loader`, import.meta.url),
42
- )
43
-
44
40
  export const yml: Factory<Loader> = async ({makeLoader, resolve}) =>
45
41
  makeLoader(
46
42
  await resolve(`@roots/bud-support/yml-loader`, import.meta.url),
@@ -1,6 +1,7 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
2
 
3
3
  import type {Factory} from './index.js'
4
+
4
5
  import * as items from './items/items.js'
5
6
  import * as loaders from './loaders/loaders.js'
6
7
  import {rules} from './rules/index.js'
@@ -34,16 +35,16 @@ export async function register(bud: Bud) {
34
35
  }
35
36
 
36
37
  export const makeRegister: makeRegister =
37
- ({build, hooks, isProduction, path, module: {resolve}}, setRule) =>
38
+ ({build, hooks, isProduction, module: {resolve}, path}, setRule) =>
38
39
  async ([key, factory]) =>
39
40
  setRule(
40
41
  key,
41
42
  await factory({
42
43
  filter: hooks.filter,
44
+ isProduction,
43
45
  makeItem: build.makeItem,
44
46
  makeLoader: build.makeLoader,
45
47
  makeRule: build.makeRule,
46
- isProduction,
47
48
  path,
48
49
  resolve,
49
50
  }),
@@ -1,4 +1,4 @@
1
- import {factory} from '@repo/test-kit/bud'
1
+ import {factory} from '@repo/test-kit'
2
2
  import {describe, expect, it} from 'vitest'
3
3
 
4
4
  import {csv} from './csv.js'
@@ -1,6 +1,6 @@
1
1
  import type {Factory} from '../index.js'
2
2
 
3
- export const csv: Factory = async ({makeRule, path, filter}) =>
3
+ export const csv: Factory = async ({filter, makeRule, path}) =>
4
4
  makeRule()
5
5
  .setInclude([path()])
6
6
  .setTest(() => filter(`pattern.csv`))
@@ -12,24 +12,22 @@ import {inlineSvg} from './svg.inline.js'
12
12
  import {svg} from './svg.js'
13
13
  import {toml} from './toml.js'
14
14
  import {webp} from './webp.js'
15
- import {xml} from './xml.js'
16
15
  import {yml} from './yml.js'
17
16
 
18
17
  export const rules = {
19
- toml,
20
- xml,
18
+ css,
19
+ cssModule,
21
20
  csv,
22
- yml,
23
- html,
24
- json,
25
21
  font,
26
- svg,
27
- webp,
22
+ html,
28
23
  image,
29
24
  inlineFont,
30
- inlineSvg,
31
25
  inlineImage,
32
- cssModule,
33
- css,
26
+ inlineSvg,
34
27
  js,
28
+ json,
29
+ svg,
30
+ toml,
31
+ webp,
32
+ yml,
35
33
  }
@@ -4,4 +4,6 @@ export const js: Factory = async ({filter, makeRule, path}) =>
4
4
  makeRule()
5
5
  .setTest(filter(`pattern.js`))
6
6
  .setInclude([() => path(`@src`)])
7
- .setUse([])
7
+ .setResolve({
8
+ fullySpecified: false,
9
+ })
@@ -7,4 +7,6 @@ export const json: Factory = async ({filter, makeRule, path}) =>
7
7
  .setType(`json`)
8
8
  .setInclude([() => path()])
9
9
  .setTest(filter(`pattern.json`))
10
- .setParser({parse: json5.parse})
10
+ .setParser({
11
+ parse: json5.parse,
12
+ })
@@ -4,7 +4,7 @@ import {inlineSvg, dataUrl} from './svg.inline.js'
4
4
 
5
5
  describe(`svg-inline`, () => {
6
6
  it(`should return a rule`, async () => {
7
- const bud = await import(`@repo/test-kit/bud`).then(
7
+ const bud = await import(`@repo/test-kit`).then(
8
8
  async ({factory}) => await factory(),
9
9
  )
10
10
  const result = await inlineSvg({
@@ -1,4 +1,4 @@
1
- import {factory} from '@repo/test-kit/bud'
1
+ import {factory} from '@repo/test-kit'
2
2
  import {describe, expect, it} from 'vitest'
3
3
 
4
4
  import {toml} from './toml'
@@ -7,4 +7,6 @@ export const toml: Factory = async ({filter, makeRule, path}) =>
7
7
  .setType(`json`)
8
8
  .setInclude([() => path()])
9
9
  .setTest(() => filter(`pattern.toml`))
10
- .setParser({parse: tomlParser.parse})
10
+ .setParser({
11
+ parse: tomlParser.parse,
12
+ })
package/src/index.ts CHANGED
@@ -8,12 +8,11 @@
8
8
  * @see https://github.com/roots/bud
9
9
  */
10
10
 
11
- import './types.js'
12
-
13
11
  import {Item} from './item/index.js'
14
12
  import {Loader} from './loader/index.js'
15
13
  import {Rule} from './rule/index.js'
16
14
  import {Build} from './service.js'
15
+ import './types.js'
17
16
 
18
17
  export default Build
19
18
 
package/src/item/index.ts CHANGED
@@ -1,5 +1,6 @@
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 {bind} from '@roots/bud-support/decorators/bind'
4
5
  import isString from '@roots/bud-support/lodash/isString'
5
6
  import {basename} from 'path'
@@ -21,7 +22,7 @@ class Item extends Base implements Build.Item {
21
22
  /**
22
23
  * Loader
23
24
  */
24
- public loader: Loader | `${keyof Loaders & string}`
25
+ public loader: `${keyof Loaders & string}` | Loader
25
26
 
26
27
  /**
27
28
  * Loader options
@@ -35,7 +36,7 @@ class Item extends Base implements Build.Item {
35
36
  public override _app: () => Bud,
36
37
  constructorParams?: {
37
38
  ident?: string
38
- loader?: Loader | `${keyof Loaders & string}`
39
+ loader?: `${keyof Loaders & string}` | Loader
39
40
  options?: Item['options']
40
41
  },
41
42
  ) {
@@ -61,12 +62,6 @@ class Item extends Base implements Build.Item {
61
62
  return this.ident
62
63
  }
63
64
 
64
- @bind
65
- public setIdent(ident: Build.Item['ident']): this {
66
- this.ident = ident
67
- return this
68
- }
69
-
70
65
  /**
71
66
  * Get rule set item loader
72
67
  */
@@ -78,45 +73,51 @@ class Item extends Base implements Build.Item {
78
73
  }
79
74
 
80
75
  /**
81
- * Set rule set item loader
76
+ * Get rule set item options
82
77
  */
83
78
  @bind
84
- public setLoader(loader: Loader | `${keyof Loaders & string}`): this {
85
- this.loader = loader
79
+ public getOptions(): Item['options'] {
80
+ return this.unwrap(this.options)
81
+ }
86
82
 
87
- if (!this.ident)
88
- this.setIdent(basename(isString(loader) ? loader : loader.getSrc()))
83
+ /**
84
+ * Merge rule set item options
85
+ */
86
+ @bind
87
+ public mergeOptions(options: Build.Item.Options): this {
88
+ this.setOptions({
89
+ ...(this.getOptions() ?? {}),
90
+ ...options,
91
+ })
89
92
 
90
93
  return this
91
94
  }
92
95
 
93
- /**
94
- * Get rule set item options
95
- */
96
96
  @bind
97
- public getOptions(): Item['options'] {
98
- return this.unwrap(this.options)
97
+ public setIdent(ident: Build.Item['ident']): this {
98
+ this.ident = ident
99
+ return this
99
100
  }
100
101
 
101
102
  /**
102
- * Set rule set item options
103
+ * Set rule set item loader
103
104
  */
104
105
  @bind
105
- public setOptions(options: Item['options']) {
106
- this.options = options
106
+ public setLoader(loader: `${keyof Loaders & string}` | Loader): this {
107
+ this.loader = loader
108
+
109
+ if (!this.ident)
110
+ this.setIdent(basename(isString(loader) ? loader : loader.getSrc()))
111
+
107
112
  return this
108
113
  }
109
114
 
110
115
  /**
111
- * Merge rule set item options
116
+ * Set rule set item options
112
117
  */
113
118
  @bind
114
- public mergeOptions(options: Build.Item.Options): this {
115
- this.setOptions({
116
- ...(this.getOptions() ?? {}),
117
- ...options,
118
- })
119
-
119
+ public setOptions(options: Item['options']) {
120
+ this.options = options
120
121
  return this
121
122
  }
122
123
 
@@ -1,4 +1,4 @@
1
- import {factory} from '@repo/test-kit/bud'
1
+ import {factory} from '@repo/test-kit'
2
2
  import {beforeAll, describe, expect, it} from 'vitest'
3
3
 
4
4
  import {Rule} from './index.js'