@roots/bud-build 5.0.0-next.9 → 5.3.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 (73) hide show
  1. package/README.md +8 -28
  2. package/lib/cjs/Build/config.js +176 -89
  3. package/lib/cjs/Build/index.js +140 -68
  4. package/lib/cjs/Build/items.js +55 -33
  5. package/lib/cjs/Build/loaders.js +28 -17
  6. package/lib/cjs/Build/rules.js +153 -90
  7. package/lib/cjs/Item/index.js +26 -26
  8. package/lib/cjs/Item/item.dependencies.js +0 -1
  9. package/lib/cjs/Item/item.interface.js +2 -3
  10. package/lib/cjs/Loader/index.js +34 -10
  11. package/lib/cjs/Rule/index.js +180 -82
  12. package/lib/cjs/index.js +31 -14
  13. package/lib/cjs/shared/Base.js +0 -1
  14. package/lib/tsconfig.tsbuildinfo +1 -1
  15. package/package.json +17 -37
  16. package/types/Build/config.d.ts +8 -1
  17. package/types/Build/config.d.ts.map +1 -1
  18. package/types/Build/index.d.ts +44 -7
  19. package/types/Build/index.d.ts.map +1 -1
  20. package/types/Build/items.d.ts +30 -3
  21. package/types/Build/items.d.ts.map +1 -1
  22. package/types/Build/loaders.d.ts +14 -4
  23. package/types/Build/loaders.d.ts.map +1 -1
  24. package/types/Build/rules.d.ts +61 -22
  25. package/types/Build/rules.d.ts.map +1 -1
  26. package/types/Item/index.d.ts +9 -17
  27. package/types/Item/index.d.ts.map +1 -1
  28. package/types/Item/item.interface.d.ts +1 -1
  29. package/types/Item/item.interface.d.ts.map +1 -1
  30. package/types/Loader/index.d.ts +13 -10
  31. package/types/Loader/index.d.ts.map +1 -1
  32. package/types/Rule/index.d.ts +122 -24
  33. package/types/Rule/index.d.ts.map +1 -1
  34. package/types/index.d.ts +5 -6
  35. package/types/index.d.ts.map +1 -1
  36. package/types/shared/Base.d.ts.map +1 -1
  37. package/lib/cjs/Build/config.js.map +0 -1
  38. package/lib/cjs/Build/index.js.map +0 -1
  39. package/lib/cjs/Build/items.js.map +0 -1
  40. package/lib/cjs/Build/loaders.js.map +0 -1
  41. package/lib/cjs/Build/rules.js.map +0 -1
  42. package/lib/cjs/Item/index.js.map +0 -1
  43. package/lib/cjs/Item/item.dependencies.js.map +0 -1
  44. package/lib/cjs/Item/item.interface.js.map +0 -1
  45. package/lib/cjs/Loader/index.js.map +0 -1
  46. package/lib/cjs/Rule/index.js.map +0 -1
  47. package/lib/cjs/index.js.map +0 -1
  48. package/lib/cjs/shared/Base.js.map +0 -1
  49. package/lib/esm/Build/config.js +0 -174
  50. package/lib/esm/Build/config.js.map +0 -1
  51. package/lib/esm/Build/index.js +0 -104
  52. package/lib/esm/Build/index.js.map +0 -1
  53. package/lib/esm/Build/items.js +0 -92
  54. package/lib/esm/Build/items.js.map +0 -1
  55. package/lib/esm/Build/loaders.js +0 -45
  56. package/lib/esm/Build/loaders.js.map +0 -1
  57. package/lib/esm/Build/rules.js +0 -103
  58. package/lib/esm/Build/rules.js.map +0 -1
  59. package/lib/esm/Item/index.js +0 -88
  60. package/lib/esm/Item/index.js.map +0 -1
  61. package/lib/esm/Item/item.dependencies.js +0 -4
  62. package/lib/esm/Item/item.dependencies.js.map +0 -1
  63. package/lib/esm/Item/item.interface.js +0 -2
  64. package/lib/esm/Item/item.interface.js.map +0 -1
  65. package/lib/esm/Loader/index.js +0 -49
  66. package/lib/esm/Loader/index.js.map +0 -1
  67. package/lib/esm/Rule/index.js +0 -155
  68. package/lib/esm/Rule/index.js.map +0 -1
  69. package/lib/esm/index.js +0 -27
  70. package/lib/esm/index.js.map +0 -1
  71. package/lib/esm/shared/Base.js +0 -8
  72. package/lib/esm/shared/Base.js.map +0 -1
  73. package/lib/tsconfig-esm.tsbuildinfo +0 -1
package/README.md CHANGED
@@ -1,41 +1,25 @@
1
1
  <p align="center">
2
- <img alt="Bud" src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" />
2
+ <img src="https://cdn.roots.io/app/uploads/logo-bud.svg" height="100" alt="Bud" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <img
7
- alt="MIT License"
8
- src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square"
9
- />
10
- <a href="https://app.fossa.com/projects/git%2Bgithub.com%2Froots%2Fbud?ref=badge_small" alt="FOSSA Status">
11
- <img src="https://app.fossa.com/api/projects/git%2Bgithub.com%2Froots%2Fbud.svg?type=small"/>
12
- </a>
13
- <a href="https://www.npmjs.com/package/@roots/bud">
14
- <img src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" />
15
- </a>
16
- <a href="https://codecov.io/gh/roots/bud">
17
- <img src="https://codecov.io/gh/roots/bud/branch/next/graph/badge.svg?token=DRJ28OD8XD"/>
18
- </a>
19
- <a href="https://twitter.com/rootswp">
20
- <img
21
- alt="Follow Roots"
22
- src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square"
23
- />
24
- </a>
6
+ <img alt="MIT License" src="https://img.shields.io/github/license/roots/bud?color=%23525ddc&style=flat-square" /> <img alt="npm" src="https://img.shields.io/npm/v/@roots/bud.svg?color=%23525ddc&style=flat-square" /> <img alt="Follow Roots" src="https://img.shields.io/twitter/follow/rootswp.svg?color=%23525ddc&style=flat-square" />
25
7
  </p>
26
8
 
27
-
28
9
  <h1 align="center">
29
10
  <strong>@roots/bud-build</strong>
30
11
  </h1>
31
12
 
32
- > Bud webpack config build controller
13
+ <p align="center">
14
+ Bud webpack config build controller
15
+ </p>
16
+
33
17
  ## Installation
34
18
 
35
19
  Install **@roots/bud-build** to your project.
36
20
 
37
21
  ```shell
38
- yarn add @roots/bud-build
22
+ yarn add @roots/bud-build --dev
39
23
  ```
40
24
 
41
25
  ## Documentation
@@ -67,8 +51,4 @@ Help support our open-source development efforts by [becoming a patron](https://
67
51
  <a href="https://carrot.com/"><img src="https://cdn.roots.io/app/uploads/carrot.svg" alt="Carrot" width="200" height="150"/></a>
68
52
  <a href="https://www.c21redwood.com/"><img src="https://cdn.roots.io/app/uploads/c21redwood.svg" alt="C21 Redwood Realty" width="200" height="150"/></a>
69
53
  <a href="https://wordpress.com/"><img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/></a>
70
- <a href="https://icons8.com/"><img src="https://cdn.roots.io/app/uploads/icons8.svg" alt="Icons8" width="200" height="150"/></a>
71
- <a href="https://www.harnessup.com/"><img src="https://cdn.roots.io/app/uploads/harness-software.svg" alt="Harness Software" width="200" height="150"/></a>
72
- <a href="https://www.codersclan.com/"><img src="https://cdn.roots.io/app/uploads/coders-clan.svg" alt="Coders Clan" width="200" height="150"/></a>
73
- <a href="https://generodigital.com/"><img src="https://cdn.roots.io/app/uploads/genero.svg" alt="Genero" width="200" height="150"/></a>
74
- <a href="https://motto.ca/roots"><img src="https://cdn.roots.io/app/uploads/motto.svg" alt="Motto" width="200" height="150"/></a>
54
+ <a href="https://pantheon.io/"><img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/></a>
@@ -1,68 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
- function config(app) {
4
+ const bud_support_1 = require("@roots/bud-support");
5
+ const path_1 = require("path");
6
+ const { dirname } = path_1.posix;
7
+ /**
8
+ * Filters framework values and returns a webpack configuration
9
+ *
10
+ * @param app - the Framework instance
11
+ *
12
+ * @public
13
+ */
14
+ async function config(app) {
5
15
  app.hooks
6
- .on('build', () => ({
7
- bail: app.hooks.filter('build.bail'),
8
- cache: app.hooks.filter('build.cache'),
9
- context: app.hooks.filter('build.context'),
10
- devtool: app.hooks.filter('build.devtool'),
11
- entry: app.hooks.filter('build.entry'),
12
- experiments: app.hooks.filter('build.experiments'),
13
- externals: app.hooks.filter('build.externals'),
14
- infrastructureLogging: app.hooks.filter('build.infrastructureLogging'),
15
- mode: app.hooks.filter('build.mode'),
16
- module: app.hooks.filter('build.module'),
17
- name: app.hooks.filter('build.name'),
18
- node: app.hooks.filter('build.node'),
19
- output: app.hooks.filter('build.output'),
20
- optimization: app.hooks.filter('build.optimization'),
21
- parallelism: app.hooks.filter('build.parallelism'),
22
- performance: app.hooks.filter('build.performance'),
23
- plugins: app.hooks.filter('build.plugins'),
24
- profile: app.hooks.filter('build.profile'),
25
- recordsPath: app.hooks.filter('build.recordsPath'),
26
- resolve: app.hooks.filter('build.resolve'),
27
- stats: app.hooks.filter('build.stats'),
28
- target: app.hooks.filter('build.target'),
29
- watch: app.hooks.filter('build.watch'),
30
- watchOptions: app.hooks.filter('build.watchOptions'),
31
- }))
16
+ .async('build', async () => {
17
+ const entry = await app.hooks.filterAsync('build.entry');
18
+ const plugins = await app.hooks.filterAsync('build.plugins');
19
+ const resolve = await app.hooks.filterAsync('build.resolve');
20
+ return {
21
+ entry,
22
+ plugins,
23
+ resolve,
24
+ bail: app.hooks.filter('build.bail'),
25
+ cache: app.hooks.filter('build.cache'),
26
+ context: app.hooks.filter('build.context'),
27
+ devtool: app.hooks.filter('build.devtool'),
28
+ experiments: app.hooks.filter('build.experiments'),
29
+ externals: app.hooks.filter('build.externals'),
30
+ infrastructureLogging: app.hooks.filter('build.infrastructureLogging'),
31
+ mode: app.hooks.filter('build.mode'),
32
+ module: app.hooks.filter('build.module'),
33
+ name: app.hooks.filter('build.name'),
34
+ node: app.hooks.filter('build.node'),
35
+ output: app.hooks.filter('build.output'),
36
+ optimization: app.hooks.filter('build.optimization'),
37
+ parallelism: app.hooks.filter('build.parallelism'),
38
+ performance: app.hooks.filter('build.performance'),
39
+ profile: app.hooks.filter('build.profile'),
40
+ recordsPath: app.hooks.filter('build.recordsPath'),
41
+ stats: app.hooks.filter('build.stats'),
42
+ target: app.hooks.filter('build.target'),
43
+ watch: app.hooks.filter('build.watch'),
44
+ watchOptions: app.hooks.filter('build.watchOptions'),
45
+ };
46
+ })
32
47
  /**
33
- * Bail
48
+ * build.bail
34
49
  */
35
50
  .hooks.on('build.bail', () => app.store.get('build.bail'))
36
51
  /**
37
- * Cache
38
- */
39
- .hooks.on('build.cache', () => undefined)
40
- /**
41
- * Context
52
+ * build.context
42
53
  */
43
54
  .hooks.on('build.context', () => app.path('project'))
44
55
  /**
45
- * Devtool
56
+ * build.devtool
46
57
  */
47
58
  .hooks.on('build.devtool', () => app.store.get('build.devtool'))
48
59
  /**
49
- * Experiments
60
+ * build.infrastructureLogging
50
61
  */
51
- .hooks.on('build.experiments', () => undefined)
62
+ .hooks.on('build.infrastructureLogging', () => app.store.get('build.infrastructureLogging'))
52
63
  /**
53
- * InfrastructureLogging
54
- */
55
- .hooks.on('build.infrastructureLogging', () => (Object.assign({}, app.store.get('build.infrastructureLogging'))))
56
- /**
57
- * Mode
64
+ * build.mode
58
65
  */
59
66
  .hooks.on('build.mode', () => app.mode)
60
67
  /**
61
- * Module
68
+ * build.module
62
69
  */
63
70
  .hooks.on('build.module', () => ({
64
71
  rules: app.hooks.filter('build.module.rules'),
65
72
  }))
73
+ /**
74
+ * build.module.rules
75
+ */
66
76
  .hooks.on('build.module.rules', () => [
67
77
  ...app.hooks.filter('build.module.rules.before'),
68
78
  {
@@ -70,38 +80,33 @@ function config(app) {
70
80
  },
71
81
  ...app.hooks.filter('build.module.rules.after'),
72
82
  ])
73
- .hooks.on('build.module.rules.oneOf', () => Object.values(app.build.rules).map(rule => rule.make(app)))
83
+ /**
84
+ * build.module.rules[1].oneOf
85
+ */
86
+ .hooks.on('build.module.rules.oneOf', () => Object.values(app.build.rules).map(rule => rule.make()))
87
+ /**
88
+ * build.module.rules[0]
89
+ */
74
90
  .hooks.on('build.module.rules.before', () => [
75
91
  {
76
92
  test: /\.[cm]?(jsx?|tsx?)$/,
77
93
  parser: { requireEnsure: false },
78
94
  },
79
95
  ])
80
- .hooks.on('build.module.rules.after', () => [])
81
96
  /**
82
- * Name
97
+ * build.module.rules[2]
83
98
  */
84
- .hooks.on('build.name', () => app.name)
99
+ .hooks.on('build.module.rules.after', () => [])
85
100
  /**
86
- * Node
101
+ * build.name
87
102
  */
88
- .hooks.on('build.node', false)
103
+ .hooks.on('build.name', () => app.name)
89
104
  /**
90
- * Output
105
+ * build.node
91
106
  */
92
- .hooks.on('build.output', () => ({
93
- path: app.hooks.filter('build.output.path'),
94
- publicPath: app.hooks.filter('build.output.publicPath'),
95
- filename: app.hooks.filter('build.output.filename'),
96
- }))
97
- .hooks.on('build.output.filename', () => `${app.store.get('features.hash')
98
- ? app.store.get('hashFormat')
99
- : app.store.get('fileFormat')}.js`)
100
- .hooks.on('build.output.path', () => app.path('dist'))
101
- .hooks.on('build.output.pathinfo', () => app.store.get('build.output.pathinfo'))
102
- .hooks.on('build.output.publicPath', () => app.store.get('location.publicPath'))
107
+ .hooks.on('build.node', () => false)
103
108
  /**
104
- * Optimization
109
+ * build.optimization
105
110
  */
106
111
  .hooks.on('build.optimization', () => ({
107
112
  emitOnErrors: app.hooks.filter('build.optimization.emitOnErrors'),
@@ -111,68 +116,150 @@ function config(app) {
111
116
  runtimeChunk: app.hooks.filter('build.optimization.runtimeChunk'),
112
117
  splitChunks: app.hooks.filter('build.optimization.splitChunks'),
113
118
  }))
119
+ /**
120
+ * build.optimization.emitOnErrors
121
+ */
114
122
  .hooks.on('build.optimization.emitOnErrors', () => app.store.get('build.optimization.emitOnErrors'))
115
- .hooks.on('build.optimization.minimize', () => false)
123
+ /**
124
+ * build.optimization.minimize
125
+ */
126
+ .hooks.on('build.optimization.minimize', () => app.store.is('features.minimize', true))
127
+ /**
128
+ * build.optimization.minimizer
129
+ */
116
130
  .hooks.on('build.optimization.minimizer', () => ['...'])
131
+ /**
132
+ * build.optimization.moduleIds
133
+ */
117
134
  .hooks.on('build.optimization.moduleIds', () => app.store.get('build.optimization.moduleIds'))
135
+ /**
136
+ * build.optimization.removeEmptyChunks
137
+ */
118
138
  .hooks.on('build.optimization.removeEmptyChunks', () => app.store.get('build.optimization.removeEmptyChunks'))
119
- .hooks.on('build.optimization.runtimeChunk', () => undefined)
120
- .hooks.on('build.optimization.splitChunks', () => app.store.is('features.splitChunks', true)
121
- ? app.store.get('build.optimization.splitChunks')
122
- : false)
139
+ /**
140
+ * build.optimization.runtimeChunk
141
+ */
142
+ .hooks.on('build.optimization.runtimeChunk', () => app.store.is('features.runtimeChunk', true))
143
+ /**
144
+ * build.optimization.splitChunks
145
+ */
146
+ .hooks.on('build.optimization.splitChunks', () => app.store.is('features.splitChunks', true))
147
+ /**
148
+ * build.output
149
+ */
150
+ .hooks.on('build.output', () => ({
151
+ assetModuleFilename: app.hooks.filter('build.output.assetModuleFilename'),
152
+ chunkFilename: app.hooks.filter('build.output.chunkFilename'),
153
+ clean: app.hooks.filter('build.output.clean'),
154
+ filename: app.hooks.filter('build.output.filename'),
155
+ path: app.hooks.filter('build.output.path'),
156
+ pathinfo: app.hooks.filter('build.output.pathinfo'),
157
+ publicPath: app.hooks.filter('build.output.publicPath'),
158
+ }))
159
+ /**
160
+ * build.output.assetModuleFilename
161
+ */
162
+ .hooks.on('build.output.assetModuleFilename', () => app.store.is('features.hash', true)
163
+ ? app.store.get('hashFormat').concat('[ext]')
164
+ : app.store.get('fileFormat').concat('[ext]'))
165
+ .hooks.on('build.output.clean', () => app.store.get('build.output.clean'))
166
+ /**
167
+ * build.output.filename
168
+ */
169
+ .hooks.on('build.output.filename', () => app.store.is('features.hash', true)
170
+ ? app.store.get('hashFormat').concat('.js')
171
+ : app.store.get('fileFormat').concat('.js'))
172
+ /**
173
+ * build.output.path
174
+ */
175
+ .hooks.on('build.output.path', () => app.path('dist'))
176
+ /**
177
+ * build.output.pathinfo
178
+ */
179
+ .hooks.on('build.output.pathinfo', () => app.store.get('build.output.pathinfo'))
180
+ /**
181
+ * build.output.publicPath
182
+ */
183
+ .hooks.on('build.output.publicPath', () => app.store.get('build.output.publicPath'))
123
184
  /**
124
185
  * Parallelism
125
186
  */
126
187
  .hooks.on('build.parallelism', () => app.store.get('build.parallelism'))
127
188
  /**
128
- * Performance
189
+ * build.performance
129
190
  */
130
191
  .hooks.on('build.performance', () => app.store.get('build.performance'))
192
+ .hooks.async('build.plugins', async () => {
193
+ const newExtensions = await app.extensions.make();
194
+ return newExtensions;
195
+ })
131
196
  /**
132
- * Plugins
133
- */
134
- .hooks.on('build.plugins', () => app.extensions.make())
135
- /**
136
- * Profile
197
+ * build.profile
137
198
  */
138
199
  .hooks.on('build.profile', () => app.store.get('build.profile'))
139
200
  /**
140
- * RecordsPath
201
+ * build.recordsPath
141
202
  */
142
203
  .hooks.on('build.recordsPath', () => app.path('storage', app.name, `modules.json`))
204
+ .hooks.async('build.resolve', async () => {
205
+ const modules = await app.hooks.filterAsync('build.resolve.modules');
206
+ const alias = await app.hooks.filter('build.resolve.alias');
207
+ const extensions = app.hooks.filter('build.resolve.extensions');
208
+ return { modules, alias, extensions };
209
+ })
143
210
  /**
144
- * Resolve
211
+ * build.resolve.alias
145
212
  */
146
- .hooks.on('build.resolve', () => ({
147
- alias: app.hooks.filter('build.resolve.alias'),
148
- extensions: app.hooks.filter('build.resolve.extensions', app.store.get('build.resolve.extensions')),
149
- modules: app.hooks.filter('build.resolve.modules'),
150
- }))
151
- .hooks.on('build.resolve.alias', {})
152
- .hooks.on('build.resolve.modules', () => {
153
- var _a, _b, _c, _d;
213
+ .hooks.on('build.resolve.alias', () => ({}))
214
+ /**
215
+ * build.resolve.modules
216
+ */
217
+ .hooks.async('build.resolve.modules', async (value) => {
218
+ const budPkg = await (0, bud_support_1.pkgUp)({
219
+ cwd: require.resolve('@roots/bud'),
220
+ });
221
+ const bud = dirname(budPkg);
222
+ const roots = bud
223
+ .split('/')
224
+ .splice(0, bud.split('/').length - 1)
225
+ .join('/');
226
+ const peers = roots
227
+ .split('/')
228
+ .splice(0, roots.split('/').length - 1)
229
+ .join('/');
154
230
  return [
155
231
  ...new Set([
232
+ ...(value ?? []),
156
233
  app.hooks.filter('location.src'),
157
234
  app.hooks.filter('location.modules'),
158
- ...((_b = (_a = app.project) === null || _a === void 0 ? void 0 : _a.get('resolve')) !== null && _b !== void 0 ? _b : []),
159
- ...((_d = (_c = app.root) === null || _c === void 0 ? void 0 : _c.project.get('resolve')) !== null && _d !== void 0 ? _d : []),
235
+ peers,
236
+ ...(app.project?.get('resolve') ?? []),
237
+ ...(app.root?.project.get('resolve') ?? []),
160
238
  ]),
161
239
  ];
162
240
  })
163
241
  /**
164
- * Stats
242
+ * build.resolve.extensions
243
+ */
244
+ .hooks.on('build.resolve.extensions', () => app.store.get('build.resolve.extensions'))
245
+ /**
246
+ * build.stats
165
247
  */
166
248
  .hooks.on('build.stats', () => app.store.get('build.stats'))
167
249
  /**
168
- * Target
250
+ * build.target
169
251
  */
170
- .hooks.on('build.target', () => `browserslist:${app.path('project', 'package.json')}`)
252
+ .hooks.on('build.target', () => app.project.has('manifest.browserslist') &&
253
+ app.project.isArray('manifest.browserslist')
254
+ ? `browserslist:${app.path('project', 'package.json')}`
255
+ : undefined)
171
256
  /**
172
- * Watch
257
+ * build.watch
173
258
  */
174
259
  .hooks.on('build.watch', () => app.store.get('build.watch'))
260
+ /**
261
+ * build.watchOptions
262
+ */
175
263
  .hooks.on('build.watchOptions', () => app.store.get('build.watchOptions'));
176
264
  }
177
265
  exports.config = config;
178
- //# sourceMappingURL=config.js.map
@@ -1,108 +1,180 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ };
20
+ var __importStar = (this && this.__importStar) || function (mod) {
21
+ if (mod && mod.__esModule) return mod;
22
+ var result = {};
23
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
+ __setModuleDefault(result, mod);
25
+ return result;
26
+ };
27
+ var __importDefault = (this && this.__importDefault) || function (mod) {
28
+ return (mod && mod.__esModule) ? mod : { "default": mod };
29
+ };
2
30
  Object.defineProperty(exports, "__esModule", { value: true });
3
31
  exports.Build = void 0;
4
- const tslib_1 = require("tslib");
5
32
  const bud_framework_1 = require("@roots/bud-framework");
6
33
  const bud_support_1 = require("@roots/bud-support");
7
- const fs_extra_1 = require("fs-extra");
34
+ const Rule_1 = require("../Rule");
8
35
  const config_1 = require("./config");
9
- const items_1 = (0, tslib_1.__importDefault)(require("./items"));
10
- const loaders_1 = (0, tslib_1.__importDefault)(require("./loaders"));
11
- const rules = (0, tslib_1.__importStar)(require("./rules"));
36
+ const items_1 = __importDefault(require("./items"));
37
+ const loaders_1 = __importDefault(require("./loaders"));
38
+ const rules = __importStar(require("./rules"));
39
+ const { isNull, isUndefined } = bud_support_1.lodash;
40
+ const { ensureFile, writeFile } = bud_support_1.fs;
12
41
  /**
13
- * Framework configuration builder class
42
+ * Webpack configuration builder class
14
43
  *
15
44
  * @public
16
45
  */
17
46
  class Build extends bud_framework_1.Service {
18
47
  /**
19
- * Make build
48
+ * Service booted event
49
+ *
20
50
  * @public
21
51
  * @decorator `@bind`
22
52
  */
23
- make() {
24
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
25
- this.log('time', 'running build.before hooks');
26
- this.app.hooks.filter('build.before');
27
- this.log('timeEnd', 'running build.before hooks');
28
- this.log('time', 'build.make');
29
- this.config = Object.entries(this.app.hooks.filter('build')).reduce((all, [key, value]) => {
30
- if (typeof value === 'undefined') {
31
- this.log(`warn`, {
32
- prefix: 'bud.build.config',
33
- message: `excluding ${key}`,
34
- suffix: `value is undefined`,
35
- });
36
- return all;
37
- }
38
- return Object.assign(Object.assign({}, all), { [key]: value });
39
- }, {});
40
- this.log('timeEnd', 'build.make');
41
- this.log('time', { prefix: 'hook', message: 'build.after' });
42
- this.app.hooks.filter('build.after', this.app);
43
- this.log('timeEnd', { prefix: 'hook', message: 'build.after' });
44
- yield this.writeFinalConfig(this.config);
45
- return this.config;
46
- });
53
+ async registered() {
54
+ this.app.hooks.on('event.build.make.after', this.writeFinalConfig);
47
55
  }
48
56
  /**
49
- * {@inheritDoc @roots/bud-framework#Build.Interface.bootstrap}
57
+ * Make webpack configuration
50
58
  *
51
59
  * @public
52
60
  * @decorator `@bind`
53
61
  */
54
- register() {
55
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
56
- /**
57
- * Reduces components to their normalized form
58
- *
59
- * @returns normalized loaders
60
- *
61
- * @internal
62
- */
63
- function componentReducer(a, [k, v]) {
64
- return Object.assign(Object.assign({}, a), { [k]: v() });
62
+ async make() {
63
+ await this.app.hooks.filterAsync('event.build.make.before', this.app);
64
+ const build = await this.app.hooks.filterAsync('build');
65
+ if (!build) {
66
+ throw new Error('Configuration could not be processed');
67
+ }
68
+ this.config = await this.app.hooks.filterAsync('event.build.override', Object.entries(build).reduce((all, [key, value]) => {
69
+ if (isUndefined(value) || isNull(value)) {
70
+ this.log(`warn`, {
71
+ message: `build.make: excluding ${key}`,
72
+ suffix: `value is undefined`,
73
+ });
74
+ return all;
65
75
  }
66
- // Reduce loaders
67
- this.loaders = this.app
76
+ this.app.dump(value, {
77
+ prefix: `${bud_support_1.chalk.bgBlue(this.app.name)} config.${key}`,
78
+ maxDepth: 2,
79
+ });
80
+ return { ...all, [key]: value };
81
+ }, {}));
82
+ await this.app.hooks.filterAsync('event.build.make.after', async () => null);
83
+ return this.config;
84
+ }
85
+ /**
86
+ * Service register event
87
+ *
88
+ * @public
89
+ * @decorator `@bind`
90
+ */
91
+ async register() {
92
+ const reducer = (a, [k, v]) => ({
93
+ ...a,
94
+ [k]: v(this.app),
95
+ });
96
+ Object.assign(this, {
97
+ loaders: this.app
68
98
  .container(loaders_1.default)
69
99
  .getEntries()
70
- .reduce(componentReducer, this.loaders);
71
- // Reduce rules
72
- this.rules = this.app
100
+ .reduce(reducer, this.loaders),
101
+ rules: this.app
73
102
  .container(rules)
74
103
  .getEntries()
75
- .reduce(componentReducer, this.rules);
76
- // Reduce items
77
- this.items = this.app
104
+ .reduce(reducer, this.rules),
105
+ items: this.app
78
106
  .container(items_1.default)
79
107
  .getEntries()
80
- .reduce(componentReducer, this.items);
81
- (0, config_1.config)(this.app);
108
+ .reduce(reducer, this.items),
82
109
  });
110
+ await (0, config_1.config)(this.app);
83
111
  }
84
- writeFinalConfig(config) {
85
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
86
- try {
87
- const filePath = this.app.path('storage', config.name, 'webpack.config.js');
88
- yield (0, fs_extra_1.ensureFile)(filePath);
89
- yield (0, fs_extra_1.writeFile)(filePath, `module.exports = (${JSON.stringify(config, null, 2)})`);
90
- }
91
- catch (error) {
92
- this.log('error', `failed to write webpack.config.json`);
93
- this.log(`error`, error);
94
- }
112
+ /**
113
+ * Set a rule
114
+ *
115
+ * @param name - rule key
116
+ * @param constructorProperties - rule constructor properties
117
+ * @returns the rule
118
+ *
119
+ * @public
120
+ * @decorator `@bind`
121
+ */
122
+ setRule(name, constructorProperties) {
123
+ Object.assign(this.rules, {
124
+ [name]: this.makeRule(constructorProperties),
95
125
  });
126
+ return this.rules[name];
127
+ }
128
+ /**
129
+ * Make a rule
130
+ *
131
+ * @param constructorProperties - rule constructor properties
132
+ * @returns the rule
133
+ *
134
+ * @public
135
+ * @decorator `@bind`
136
+ */
137
+ makeRule(constructorProperties) {
138
+ return new Rule_1.Rule(this.app, constructorProperties);
139
+ }
140
+ /**
141
+ * Write final configuration to storage directory
142
+ *
143
+ * @public
144
+ * @decorator `@bind`
145
+ */
146
+ async writeFinalConfig() {
147
+ try {
148
+ const filePath = this.app.path('storage', this.config.name, 'webpack.config.js');
149
+ this.log('log', {
150
+ message: `writing webpack dump to disk`,
151
+ suffix: filePath,
152
+ });
153
+ await ensureFile(filePath);
154
+ await writeFile(filePath, `module.exports = (${(0, bud_support_1.prettyFormat)(this.config)})`);
155
+ }
156
+ catch (error) {
157
+ this.log('error', `failed to write webpack.config.json`);
158
+ this.log(`error`, error);
159
+ }
96
160
  }
97
161
  }
98
- (0, tslib_1.__decorate)([
162
+ __decorate([
163
+ bud_support_1.bind
164
+ ], Build.prototype, "registered", null);
165
+ __decorate([
99
166
  bud_support_1.bind
100
167
  ], Build.prototype, "make", null);
101
- (0, tslib_1.__decorate)([
168
+ __decorate([
102
169
  bud_support_1.bind
103
170
  ], Build.prototype, "register", null);
104
- (0, tslib_1.__decorate)([
171
+ __decorate([
172
+ bud_support_1.bind
173
+ ], Build.prototype, "setRule", null);
174
+ __decorate([
175
+ bud_support_1.bind
176
+ ], Build.prototype, "makeRule", null);
177
+ __decorate([
105
178
  bud_support_1.bind
106
179
  ], Build.prototype, "writeFinalConfig", null);
107
180
  exports.Build = Build;
108
- //# sourceMappingURL=index.js.map