@roots/bud-compiler 2023.7.28-1813 → 2023.8.3-210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/service.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { Compiler as BudCompiler } from '@roots/bud-framework';
2
1
  import type { Bud } from '@roots/bud-framework';
2
+ import type { Compiler as BudCompiler } from '@roots/bud-framework';
3
3
  import type { MultiCompiler, MultiStats, Stats, StatsError, Webpack } from '@roots/bud-framework/config';
4
4
  import type { ErrorWithSourceFile } from '@roots/bud-support/open';
5
5
  import { Service } from '@roots/bud-framework/service';
6
- import { BudError } from '@roots/bud-support/errors';
7
- import webpack from '@roots/bud-support/webpack';
8
6
  /**
9
7
  * {@link BudCompiler} implementation
10
8
  */
@@ -36,7 +34,7 @@ export declare class Compiler extends Service implements BudCompiler {
36
34
  /**
37
35
  * {@link BudCompiler.onError}
38
36
  */
39
- onError(error: BudError | webpack.WebpackError): void;
37
+ onError(error: Error): void;
40
38
  /**
41
39
  * {@link BudCompiler.onStats}
42
40
  */
@@ -45,5 +43,5 @@ export declare class Compiler extends Service implements BudCompiler {
45
43
  * {@link Service.register}
46
44
  */
47
45
  register?(bud: Bud): Promise<any>;
48
- sourceErrors?(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
46
+ sourceErrors?(errors: Array<StatsError> | undefined): Array<ErrorWithSourceFile | StatsError>;
49
47
  }
package/lib/service.js CHANGED
@@ -1,26 +1,21 @@
1
- import { __decorate, __metadata } from "tslib";
1
+ import { __decorate } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { cpus } from 'node:os';
4
4
  import process from 'node:process';
5
5
  import { pathToFileURL } from 'node:url';
6
- import { Error } from '@roots/bud-dashboard/components/error';
6
+ import { Error as DisplayError } from '@roots/bud-dashboard/components/error';
7
7
  import { Service } from '@roots/bud-framework/service';
8
8
  import { bind } from '@roots/bud-support/decorators/bind';
9
9
  import { BudError } from '@roots/bud-support/errors';
10
- import { duration } from '@roots/bud-support/human-readable';
11
10
  import { render } from '@roots/bud-support/ink';
12
11
  import isNull from '@roots/bud-support/lodash/isNull';
12
+ import isNumber from '@roots/bud-support/lodash/isNumber';
13
13
  import isString from '@roots/bud-support/lodash/isString';
14
14
  import stripAnsi from '@roots/bud-support/strip-ansi';
15
- import webpack from '@roots/bud-support/webpack';
16
15
  /**
17
16
  * {@link BudCompiler} implementation
18
17
  */
19
18
  export class Compiler extends Service {
20
- /**
21
- * {@link BudCompiler.compilationStats}
22
- */
23
- compilationStats;
24
19
  /**
25
20
  * {@link BudCompiler.config}
26
21
  */
@@ -29,23 +24,16 @@ export class Compiler extends Service {
29
24
  * {@link BudCompiler.implementation}
30
25
  */
31
26
  implementation;
32
- /**
33
- * {@link BudCompiler.instance}
34
- */
35
- instance;
36
- /**
37
- * {@link BudCompiler.stats}
38
- */
39
- stats;
40
27
  /**
41
28
  * {@link BudCompiler.compile}
42
29
  */
43
30
  async compile(bud) {
44
- this.config = !bud.hasChildren
31
+ const config = !bud.hasChildren
45
32
  ? [await bud.build.make()]
46
33
  : await Promise.all(Object.values(bud.children).map(async (child) => child.build.make().catch(error => {
47
34
  throw error;
48
35
  })));
36
+ this.config = config?.filter(Boolean);
49
37
  this.config.parallelism = Math.max(cpus().length - 1, 1);
50
38
  this.logger.info(`parallel compilations: ${this.config.parallelism}`);
51
39
  await bud.hooks.fire(`compiler.before`, bud).catch(error => {
@@ -57,7 +45,8 @@ export class Compiler extends Service {
57
45
  this.instance = this.implementation(this.config);
58
46
  }
59
47
  catch (error) {
60
- this.onError(error);
48
+ const normalError = error instanceof Error ? error : BudError.normalize(error);
49
+ this.onError(normalError);
61
50
  }
62
51
  this.instance.hooks.done.tap(bud.label, (stats) => {
63
52
  this.onStats(stats);
@@ -81,10 +70,10 @@ export class Compiler extends Service {
81
70
  subtitle: error.name,
82
71
  });
83
72
  if (`isBudError` in error) {
84
- render(_jsx(Error, { error: error }));
73
+ render(_jsx(DisplayError, { error: error }));
85
74
  }
86
75
  else {
87
- render(_jsx(Error, { error: BudError.normalize(error) }));
76
+ render(_jsx(DisplayError, { error: BudError.normalize(error) }));
88
77
  }
89
78
  }
90
79
  /**
@@ -101,10 +90,12 @@ export class Compiler extends Service {
101
90
  process.exitCode = 1;
102
91
  this.compilationStats.children = this.compilationStats.children?.map(child => ({
103
92
  ...child,
104
- errors: this.sourceErrors(child.errors),
93
+ errors: child.errors && this.sourceErrors
94
+ ? this.sourceErrors(child.errors)
95
+ : child.errors ?? [],
105
96
  }));
106
97
  this.compilationStats.children
107
- ?.filter(child => child.errorsCount > 0)
98
+ ?.filter(child => isNumber(child.errorsCount) && child.errorsCount > 0)
108
99
  .forEach(child => {
109
100
  try {
110
101
  const error = child.errors?.shift();
@@ -117,7 +108,7 @@ export class Compiler extends Service {
117
108
  subtitle: error.file ? `Error in ${error.name}` : error.name,
118
109
  title: makeNoticeTitle(child),
119
110
  });
120
- this.app.notifier.openEditor(error.file);
111
+ error.file && this.app.notifier.openEditor(error.file);
121
112
  }
122
113
  catch (error) {
123
114
  this.logger.error(error);
@@ -131,13 +122,14 @@ export class Compiler extends Service {
131
122
  this.app.notifier.notify({
132
123
  group: `${this.app.label}-${child.name}`,
133
124
  message: child.modules
134
- ? `${child.modules.length} modules compiled in ${duration(child.time)}`
135
- : `Compiled in ${duration(child.time)}`,
125
+ ? `${child.modules.length} modules compiled`
126
+ : `Modules compiled successfully`,
136
127
  open: this.app.server?.publicUrl.href,
137
128
  subtitle: `Build successful`,
138
129
  title: makeNoticeTitle(child),
139
130
  });
140
- this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
131
+ this.app.server?.publicUrl.href &&
132
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
141
133
  }
142
134
  catch (error) {
143
135
  this.logger.error(error);
@@ -167,7 +159,7 @@ export class Compiler extends Service {
167
159
  * In a perfect world webpack plugins would use the
168
160
  * `nameForCondition` property to identify the module.
169
161
  */
170
- if (ident) {
162
+ if (ident && this.compilationStats?.children) {
171
163
  module = this.compilationStats.children
172
164
  .flatMap(child => child?.modules)
173
165
  .find(module => [module?.id, module?.name].includes(ident));
@@ -218,34 +210,19 @@ export class Compiler extends Service {
218
210
  }
219
211
  }
220
212
  __decorate([
221
- bind,
222
- __metadata("design:type", Function),
223
- __metadata("design:paramtypes", [Function]),
224
- __metadata("design:returntype", Promise)
213
+ bind
225
214
  ], Compiler.prototype, "compile", null);
226
215
  __decorate([
227
- bind,
228
- __metadata("design:type", Function),
229
- __metadata("design:paramtypes", [Object]),
230
- __metadata("design:returntype", void 0)
216
+ bind
231
217
  ], Compiler.prototype, "onError", null);
232
218
  __decorate([
233
- bind,
234
- __metadata("design:type", Function),
235
- __metadata("design:paramtypes", [Function]),
236
- __metadata("design:returntype", void 0)
219
+ bind
237
220
  ], Compiler.prototype, "onStats", null);
238
221
  __decorate([
239
- bind,
240
- __metadata("design:type", Function),
241
- __metadata("design:paramtypes", [Function]),
242
- __metadata("design:returntype", Promise)
222
+ bind
243
223
  ], Compiler.prototype, "register", null);
244
224
  __decorate([
245
- bind,
246
- __metadata("design:type", Function),
247
- __metadata("design:paramtypes", [Array]),
248
- __metadata("design:returntype", Array)
225
+ bind
249
226
  ], Compiler.prototype, "sourceErrors", null);
250
227
  const statsOptions = {
251
228
  all: false,
@@ -256,6 +233,7 @@ const statsOptions = {
256
233
  cachedAssets: true,
257
234
  cachedModules: true,
258
235
  entrypoints: true,
236
+ errorDetails: false,
259
237
  errors: true,
260
238
  errorsCount: true,
261
239
  hash: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "2023.7.28-1813",
3
+ "version": "2023.8.3-210",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -61,15 +61,15 @@
61
61
  "types": "./lib/index.d.ts",
62
62
  "module": "./lib/index.js",
63
63
  "devDependencies": {
64
- "@roots/bud-api": "2023.7.28-1813",
64
+ "@roots/bud-api": "2023.8.3-210",
65
65
  "@skypack/package-check": "0.2.2",
66
66
  "@types/node": "18.16.19",
67
67
  "@types/react": "18.2.15"
68
68
  },
69
69
  "dependencies": {
70
- "@roots/bud-dashboard": "2023.7.28-1813",
71
- "@roots/bud-framework": "2023.7.28-1813",
72
- "@roots/bud-support": "2023.7.28-1813",
70
+ "@roots/bud-dashboard": "2023.8.3-210",
71
+ "@roots/bud-framework": "2023.8.3-210",
72
+ "@roots/bud-support": "2023.8.3-210",
73
73
  "react": "18.2.0",
74
74
  "tslib": "2.6.0"
75
75
  },
package/src/service.tsx CHANGED
@@ -1,5 +1,5 @@
1
- import type {Compiler as BudCompiler} from '@roots/bud-framework'
2
1
  import type {Bud} from '@roots/bud-framework'
2
+ import type {Compiler as BudCompiler} from '@roots/bud-framework'
3
3
  import type {
4
4
  MultiCompiler,
5
5
  MultiStats,
@@ -17,16 +17,15 @@ import {cpus} from 'node:os'
17
17
  import process from 'node:process'
18
18
  import {pathToFileURL} from 'node:url'
19
19
 
20
- import {Error} from '@roots/bud-dashboard/components/error'
20
+ import {Error as DisplayError} from '@roots/bud-dashboard/components/error'
21
21
  import {Service} from '@roots/bud-framework/service'
22
22
  import {bind} from '@roots/bud-support/decorators/bind'
23
23
  import {BudError} from '@roots/bud-support/errors'
24
- import {duration} from '@roots/bud-support/human-readable'
25
24
  import {render} from '@roots/bud-support/ink'
26
25
  import isNull from '@roots/bud-support/lodash/isNull'
26
+ import isNumber from '@roots/bud-support/lodash/isNumber'
27
27
  import isString from '@roots/bud-support/lodash/isString'
28
28
  import stripAnsi from '@roots/bud-support/strip-ansi'
29
- import webpack from '@roots/bud-support/webpack'
30
29
 
31
30
  /**
32
31
  * {@link BudCompiler} implementation
@@ -35,7 +34,7 @@ export class Compiler extends Service implements BudCompiler {
35
34
  /**
36
35
  * {@link BudCompiler.compilationStats}
37
36
  */
38
- public compilationStats: BudCompiler[`compilationStats`]
37
+ public declare compilationStats: BudCompiler[`compilationStats`]
39
38
 
40
39
  /**
41
40
  * {@link BudCompiler.config}
@@ -50,19 +49,19 @@ export class Compiler extends Service implements BudCompiler {
50
49
  /**
51
50
  * {@link BudCompiler.instance}
52
51
  */
53
- public instance: BudCompiler[`instance`]
52
+ public declare instance: BudCompiler[`instance`]
54
53
 
55
54
  /**
56
55
  * {@link BudCompiler.stats}
57
56
  */
58
- public stats: BudCompiler[`stats`]
57
+ public declare stats: BudCompiler[`stats`]
59
58
 
60
59
  /**
61
60
  * {@link BudCompiler.compile}
62
61
  */
63
62
  @bind
64
63
  public async compile(bud: Bud): Promise<MultiCompiler> {
65
- this.config = !bud.hasChildren
64
+ const config = !bud.hasChildren
66
65
  ? [await bud.build.make()]
67
66
  : await Promise.all(
68
67
  Object.values(bud.children).map(async (child: Bud) =>
@@ -72,6 +71,8 @@ export class Compiler extends Service implements BudCompiler {
72
71
  ),
73
72
  )
74
73
 
74
+ this.config = config?.filter(Boolean)
75
+
75
76
  this.config.parallelism = Math.max(cpus().length - 1, 1)
76
77
  this.logger.info(`parallel compilations: ${this.config.parallelism}`)
77
78
 
@@ -84,8 +85,9 @@ export class Compiler extends Service implements BudCompiler {
84
85
 
85
86
  try {
86
87
  this.instance = this.implementation(this.config)
87
- } catch (error) {
88
- this.onError(error)
88
+ } catch (error: unknown) {
89
+ const normalError = error instanceof Error ? error : BudError.normalize(error)
90
+ this.onError(normalError)
89
91
  }
90
92
 
91
93
  this.instance.hooks.done.tap(bud.label, (stats: any) => {
@@ -102,7 +104,7 @@ export class Compiler extends Service implements BudCompiler {
102
104
  * {@link BudCompiler.onError}
103
105
  */
104
106
  @bind
105
- public onError(error: BudError | webpack.WebpackError) {
107
+ public onError(error: Error) {
106
108
  process.exitCode = 1
107
109
  if (!error) return
108
110
 
@@ -115,9 +117,9 @@ export class Compiler extends Service implements BudCompiler {
115
117
  })
116
118
 
117
119
  if (`isBudError` in error) {
118
- render(<Error error={error} />)
120
+ render(<DisplayError error={error} />)
119
121
  } else {
120
- render(<Error error={BudError.normalize(error)} />)
122
+ render(<DisplayError error={BudError.normalize(error)} />)
121
123
  }
122
124
  }
123
125
 
@@ -143,12 +145,17 @@ export class Compiler extends Service implements BudCompiler {
143
145
  this.compilationStats.children = this.compilationStats.children?.map(
144
146
  child => ({
145
147
  ...child,
146
- errors: this.sourceErrors(child.errors),
148
+ errors:
149
+ child.errors && this.sourceErrors
150
+ ? this.sourceErrors(child.errors)
151
+ : child.errors ?? [],
147
152
  }),
148
153
  )
149
154
 
150
155
  this.compilationStats.children
151
- ?.filter(child => child.errorsCount > 0)
156
+ ?.filter(
157
+ child => isNumber(child.errorsCount) && child.errorsCount > 0,
158
+ )
152
159
  .forEach(child => {
153
160
  try {
154
161
  const error = child.errors?.shift()
@@ -162,7 +169,7 @@ export class Compiler extends Service implements BudCompiler {
162
169
  title: makeNoticeTitle(child),
163
170
  })
164
171
 
165
- this.app.notifier.openEditor(error.file)
172
+ error.file && this.app.notifier.openEditor(error.file)
166
173
  } catch (error) {
167
174
  this.logger.error(error)
168
175
  }
@@ -176,16 +183,15 @@ export class Compiler extends Service implements BudCompiler {
176
183
  this.app.notifier.notify({
177
184
  group: `${this.app.label}-${child.name}`,
178
185
  message: child.modules
179
- ? `${child.modules.length} modules compiled in ${duration(
180
- child.time,
181
- )}`
182
- : `Compiled in ${duration(child.time)}`,
186
+ ? `${child.modules.length} modules compiled`
187
+ : `Modules compiled successfully`,
183
188
  open: this.app.server?.publicUrl.href,
184
189
  subtitle: `Build successful`,
185
190
  title: makeNoticeTitle(child),
186
191
  })
187
192
 
188
- this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
193
+ this.app.server?.publicUrl.href &&
194
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
189
195
  } catch (error) {
190
196
  this.logger.error(error)
191
197
  }
@@ -206,7 +212,7 @@ export class Compiler extends Service implements BudCompiler {
206
212
 
207
213
  @bind
208
214
  public sourceErrors?(
209
- errors: Array<StatsError>,
215
+ errors: Array<StatsError> | undefined,
210
216
  ): Array<ErrorWithSourceFile | StatsError> {
211
217
  if (!errors || !errors.length) return []
212
218
 
@@ -222,7 +228,7 @@ export class Compiler extends Service implements BudCompiler {
222
228
  * In a perfect world webpack plugins would use the
223
229
  * `nameForCondition` property to identify the module.
224
230
  */
225
- if (ident) {
231
+ if (ident && this.compilationStats?.children) {
226
232
  module = this.compilationStats.children
227
233
  .flatMap(child => child?.modules)
228
234
  .find(module => [module?.id, module?.name].includes(ident))
@@ -290,6 +296,7 @@ const statsOptions = {
290
296
  cachedAssets: true,
291
297
  cachedModules: true,
292
298
  entrypoints: true,
299
+ errorDetails: false,
293
300
  errors: true,
294
301
  errorsCount: true,
295
302
  hash: true,