@roots/bud-compiler 6.17.0 → 6.19.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.
package/README.md CHANGED
@@ -66,9 +66,6 @@ However, the amount of effort needed to maintain and develop new features and pr
66
66
  <a href="https://wordpress.com/">
67
67
  <img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/>
68
68
  </a>
69
- <a href="https://pantheon.io/">
70
- <img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/>
71
- </a>
72
69
  <a href="https://worksitesafety.ca/careers/">
73
70
  <img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="200" height="150"/>
74
71
  </a>
@@ -7,10 +7,6 @@ import { Service } from '@roots/bud-framework/service';
7
7
  * {@link BudCompiler} implementation
8
8
  */
9
9
  declare class Compiler extends Service implements BudCompiler {
10
- /**
11
- * {@link BudCompiler.compilationStats}
12
- */
13
- compilationStats: BudCompiler[`compilationStats`];
14
10
  /**
15
11
  * {@link BudCompiler.config}
16
12
  */
@@ -30,7 +26,7 @@ declare class Compiler extends Service implements BudCompiler {
30
26
  /**
31
27
  * {@link BudCompiler.onError}
32
28
  */
33
- onError(error: Error): void;
29
+ onError(error: Error | undefined): void;
34
30
  /**
35
31
  * {@link BudCompiler.onStats}
36
32
  */
@@ -3,14 +3,13 @@ import { jsx as _jsx } from "@roots/bud-support/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 as DisplayError } from '@roots/bud-dashboard/components/error';
6
+ import { Display 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
- import { BudError } from '@roots/bud-support/errors';
10
- import { render } from '@roots/bud-support/ink';
11
- import isNull from '@roots/bud-support/lodash/isNull';
12
- import isNumber from '@roots/bud-support/lodash/isNumber';
13
- import isString from '@roots/bud-support/lodash/isString';
9
+ import { BudError, CompilerError } from '@roots/bud-support/errors';
10
+ import isNull from '@roots/bud-support/isNull';
11
+ import isNumber from '@roots/bud-support/isNumber';
12
+ import isString from '@roots/bud-support/isString';
14
13
  import stripAnsi from '@roots/bud-support/strip-ansi';
15
14
  /**
16
15
  * {@link BudCompiler} implementation
@@ -32,17 +31,16 @@ class Compiler extends Service {
32
31
  if (!error)
33
32
  return;
34
33
  this.app.server?.appliedMiddleware?.hot?.publish({ error });
34
+ const normalized = CompilerError.normalize(error, {
35
+ thrownBy: import.meta.url,
36
+ });
37
+ normalized.details = undefined;
35
38
  this.app.notifier?.notify({
36
39
  group: this.app.label,
37
- message: error.message,
38
- subtitle: error.name,
40
+ message: normalized.message,
41
+ subtitle: normalized.name,
39
42
  });
40
- if (`isBudError` in error) {
41
- render(_jsx(DisplayError, { error: error }));
42
- }
43
- else {
44
- render(_jsx(DisplayError, { error: BudError.normalize(error) }));
45
- }
43
+ this.app.context.render(_jsx(DisplayError, { error: error }));
46
44
  }
47
45
  /**
48
46
  * {@link BudCompiler.onStats}
@@ -51,18 +49,17 @@ class Compiler extends Service {
51
49
  const makeNoticeTitle = (child) => this.app.label !== child.name
52
50
  ? `${this.app.label} (${child.name})`
53
51
  : child.name;
54
- this.stats = stats;
55
- this.compilationStats = stats.toJson(statsOptions);
56
- this.app.dashboard.updateStats(this.compilationStats);
52
+ this.stats = stats.toJson(statsOptions);
53
+ this.app.context.render(this.app.dashboard.render(stats));
57
54
  if (stats.hasErrors()) {
58
55
  process.exitCode = 1;
59
- this.compilationStats.children = this.compilationStats.children?.map(child => ({
56
+ this.stats.children = this.stats.children?.map(child => ({
60
57
  ...child,
61
58
  errors: child.errors && this.sourceErrors
62
59
  ? this.sourceErrors(child.errors)
63
60
  : child.errors ?? [],
64
61
  }));
65
- this.compilationStats.children
62
+ this.stats.children
66
63
  ?.filter(child => isNumber(child.errorsCount) && child.errorsCount > 0)
67
64
  .forEach(child => {
68
65
  try {
@@ -83,7 +80,7 @@ class Compiler extends Service {
83
80
  }
84
81
  });
85
82
  }
86
- this.compilationStats.children
83
+ this.stats.children
87
84
  ?.filter(child => child.errorsCount === 0)
88
85
  .forEach(child => {
89
86
  try {
@@ -97,6 +94,7 @@ class Compiler extends Service {
97
94
  title: makeNoticeTitle(child),
98
95
  });
99
96
  this.app.server?.publicUrl.href &&
97
+ this.app.context.browser &&
100
98
  this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
101
99
  }
102
100
  catch (error) {
@@ -110,27 +108,24 @@ class Compiler extends Service {
110
108
  async compile(bud) {
111
109
  const config = !bud.hasChildren
112
110
  ? [await bud.build.make()]
113
- : await Promise.all(Object.values(bud.children).map(async (child) => child.build.make().catch(error => {
111
+ : await Promise.all(Object.values(bud.children).map(async (child) => await child.build.make().catch(error => {
114
112
  throw error;
115
113
  })));
116
114
  this.config = config?.filter(Boolean);
117
- this.config.parallelism = Math.max(cpus().length - 1, 1);
118
- this.logger.info(`parallel compilations: ${this.config.parallelism}`);
115
+ if (this.config.length > 1) {
116
+ this.config.parallelism = Math.max(cpus().length - 1, 1);
117
+ this.logger.info(`parallel compilations: ${this.config.parallelism}`);
118
+ }
119
119
  await bud.hooks.fire(`compiler.before`, bud).catch(error => {
120
120
  throw error;
121
121
  });
122
122
  this.logger.timeEnd(`initialize`);
123
- this.app.dashboard.updateStatus(`compiling`);
124
- try {
125
- this.instance = this.implementation(this.config);
126
- }
127
- catch (error) {
128
- const normalError = error instanceof Error ? error : BudError.normalize(error);
129
- this.onError(normalError);
130
- }
123
+ this.instance = this.implementation(this.config);
131
124
  this.instance.hooks.done.tap(bud.label, (stats) => {
132
125
  this.onStats(stats);
133
- bud.hooks.fire(`compiler.done`, bud, this.stats).catch(this.onError);
126
+ bud.hooks
127
+ .fire(`compiler.done`, bud, this.stats)
128
+ .catch(this.app.catch);
134
129
  });
135
130
  return this.instance;
136
131
  }
@@ -157,8 +152,8 @@ class Compiler extends Service {
157
152
  * In a perfect world webpack plugins would use the
158
153
  * `nameForCondition` property to identify the module.
159
154
  */
160
- if (ident && this.compilationStats?.children) {
161
- module = this.compilationStats.children
155
+ if (ident && this.stats?.children) {
156
+ module = this.stats.children
162
157
  .flatMap(child => child?.modules)
163
158
  .find(module => [module?.id, module?.name].includes(ident));
164
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "6.17.0",
3
+ "version": "6.19.0",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -65,15 +65,15 @@
65
65
  "types": "./lib/index.d.ts",
66
66
  "module": "./lib/index.js",
67
67
  "devDependencies": {
68
- "@roots/bud-api": "6.17.0",
68
+ "@roots/bud-api": "6.19.0",
69
69
  "@skypack/package-check": "0.2.2",
70
- "@types/node": "18.17.19",
71
- "@types/react": "18.2.22"
70
+ "@types/node": "20.10.4",
71
+ "@types/react": "18.2.43"
72
72
  },
73
73
  "dependencies": {
74
- "@roots/bud-dashboard": "6.17.0",
75
- "@roots/bud-framework": "6.17.0",
76
- "@roots/bud-support": "6.17.0",
74
+ "@roots/bud-dashboard": "6.19.0",
75
+ "@roots/bud-framework": "6.19.0",
76
+ "@roots/bud-support": "6.19.0",
77
77
  "react": "18.2.0",
78
78
  "tslib": "2.6.2"
79
79
  },
@@ -17,25 +17,19 @@ import {cpus} from 'node:os'
17
17
  import process from 'node:process'
18
18
  import {pathToFileURL} from 'node:url'
19
19
 
20
- import {Error as DisplayError} from '@roots/bud-dashboard/components/error'
20
+ import {Display 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
- import {BudError} from '@roots/bud-support/errors'
24
- import {render} from '@roots/bud-support/ink'
25
- import isNull from '@roots/bud-support/lodash/isNull'
26
- import isNumber from '@roots/bud-support/lodash/isNumber'
27
- import isString from '@roots/bud-support/lodash/isString'
23
+ import {BudError, CompilerError} from '@roots/bud-support/errors'
24
+ import isNull from '@roots/bud-support/isNull'
25
+ import isNumber from '@roots/bud-support/isNumber'
26
+ import isString from '@roots/bud-support/isString'
28
27
  import stripAnsi from '@roots/bud-support/strip-ansi'
29
28
 
30
29
  /**
31
30
  * {@link BudCompiler} implementation
32
31
  */
33
32
  class Compiler extends Service implements BudCompiler {
34
- /**
35
- * {@link BudCompiler.compilationStats}
36
- */
37
- public declare compilationStats: BudCompiler[`compilationStats`]
38
-
39
33
  /**
40
34
  * {@link BudCompiler.config}
41
35
  */
@@ -60,24 +54,27 @@ class Compiler extends Service implements BudCompiler {
60
54
  * {@link BudCompiler.onError}
61
55
  */
62
56
  @bind
63
- public onError(error: Error) {
57
+ public onError(error: Error | undefined) {
64
58
  process.exitCode = 1
65
59
  if (!error) return
66
60
 
67
61
  this.app.server?.appliedMiddleware?.hot?.publish({error})
68
62
 
63
+ const normalized = CompilerError.normalize(error, {
64
+ thrownBy: import.meta.url,
65
+ })
66
+
67
+ normalized.details = undefined
68
+
69
69
  this.app.notifier?.notify({
70
70
  group: this.app.label,
71
- message: error.message,
72
- subtitle: error.name,
71
+ message: normalized.message,
72
+ subtitle: normalized.name,
73
73
  })
74
74
 
75
- if (`isBudError` in error) {
76
- render(<DisplayError error={error} />)
77
- } else {
78
- render(<DisplayError error={BudError.normalize(error)} />)
79
- }
75
+ this.app.context.render(<DisplayError error={error} />)
80
76
  }
77
+
81
78
  /**
82
79
  * {@link BudCompiler.onStats}
83
80
  */
@@ -88,26 +85,21 @@ class Compiler extends Service implements BudCompiler {
88
85
  ? `${this.app.label} (${child.name})`
89
86
  : child.name
90
87
 
91
- this.stats = stats
92
-
93
- this.compilationStats = stats.toJson(statsOptions)
94
-
95
- this.app.dashboard.updateStats(this.compilationStats)
88
+ this.stats = stats.toJson(statsOptions)
89
+ this.app.context.render(this.app.dashboard.render(stats))
96
90
 
97
91
  if (stats.hasErrors()) {
98
92
  process.exitCode = 1
99
93
 
100
- this.compilationStats.children = this.compilationStats.children?.map(
101
- child => ({
102
- ...child,
103
- errors:
104
- child.errors && this.sourceErrors
105
- ? this.sourceErrors(child.errors)
106
- : child.errors ?? [],
107
- }),
108
- )
94
+ this.stats.children = this.stats.children?.map(child => ({
95
+ ...child,
96
+ errors:
97
+ child.errors && this.sourceErrors
98
+ ? this.sourceErrors(child.errors)
99
+ : child.errors ?? [],
100
+ }))
109
101
 
110
- this.compilationStats.children
102
+ this.stats.children
111
103
  ?.filter(
112
104
  child => isNumber(child.errorsCount) && child.errorsCount > 0,
113
105
  )
@@ -131,7 +123,7 @@ class Compiler extends Service implements BudCompiler {
131
123
  })
132
124
  }
133
125
 
134
- this.compilationStats.children
126
+ this.stats.children
135
127
  ?.filter(child => child.errorsCount === 0)
136
128
  .forEach(child => {
137
129
  try {
@@ -146,6 +138,7 @@ class Compiler extends Service implements BudCompiler {
146
138
  })
147
139
 
148
140
  this.app.server?.publicUrl.href &&
141
+ this.app.context.browser &&
149
142
  this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
150
143
  } catch (error) {
151
144
  this.logger.error(error)
@@ -160,36 +153,34 @@ class Compiler extends Service implements BudCompiler {
160
153
  const config = !bud.hasChildren
161
154
  ? [await bud.build.make()]
162
155
  : await Promise.all(
163
- Object.values(bud.children).map(async (child: Bud) =>
164
- child.build.make().catch(error => {
165
- throw error
166
- }),
156
+ Object.values(bud.children).map(
157
+ async (child: Bud) =>
158
+ await child.build.make().catch(error => {
159
+ throw error
160
+ }),
167
161
  ),
168
162
  )
169
163
 
170
164
  this.config = config?.filter(Boolean)
171
165
 
172
- this.config.parallelism = Math.max(cpus().length - 1, 1)
173
- this.logger.info(`parallel compilations: ${this.config.parallelism}`)
166
+ if (this.config.length > 1) {
167
+ this.config.parallelism = Math.max(cpus().length - 1, 1)
168
+ this.logger.info(`parallel compilations: ${this.config.parallelism}`)
169
+ }
174
170
 
175
171
  await bud.hooks.fire(`compiler.before`, bud).catch(error => {
176
172
  throw error
177
173
  })
178
174
 
179
175
  this.logger.timeEnd(`initialize`)
180
- this.app.dashboard.updateStatus(`compiling`)
181
176
 
182
- try {
183
- this.instance = this.implementation(this.config)
184
- } catch (error: unknown) {
185
- const normalError =
186
- error instanceof Error ? error : BudError.normalize(error)
187
- this.onError(normalError)
188
- }
177
+ this.instance = this.implementation(this.config)
189
178
 
190
179
  this.instance.hooks.done.tap(bud.label, (stats: any) => {
191
180
  this.onStats(stats)
192
- bud.hooks.fire(`compiler.done`, bud, this.stats).catch(this.onError)
181
+ bud.hooks
182
+ .fire(`compiler.done`, bud, this.stats)
183
+ .catch(this.app.catch)
193
184
  })
194
185
 
195
186
  return this.instance
@@ -225,8 +216,8 @@ class Compiler extends Service implements BudCompiler {
225
216
  * In a perfect world webpack plugins would use the
226
217
  * `nameForCondition` property to identify the module.
227
218
  */
228
- if (ident && this.compilationStats?.children) {
229
- module = this.compilationStats.children
219
+ if (ident && this.stats?.children) {
220
+ module = this.stats.children
230
221
  .flatMap(child => child?.modules)
231
222
  .find(module => [module?.id, module?.name].includes(ident))
232
223
  }