@roots/bud-compiler 2023.11.28-7 → 2023.11.29-7
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/index.d.ts +1 -1
- package/lib/service/index.js +18 -21
- package/package.json +5 -5
- package/src/service/index.tsx +26 -26
package/lib/service/index.d.ts
CHANGED
package/lib/service/index.js
CHANGED
@@ -3,10 +3,10 @@ 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 {
|
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';
|
9
|
+
import { BudError, CompilerError } from '@roots/bud-support/errors';
|
10
10
|
import isNull from '@roots/bud-support/lodash/isNull';
|
11
11
|
import isNumber from '@roots/bud-support/lodash/isNumber';
|
12
12
|
import isString from '@roots/bud-support/lodash/isString';
|
@@ -31,17 +31,16 @@ class Compiler extends Service {
|
|
31
31
|
if (!error)
|
32
32
|
return;
|
33
33
|
this.app.server?.appliedMiddleware?.hot?.publish({ error });
|
34
|
+
const normalized = CompilerError.normalize(error, {
|
35
|
+
thrownBy: import.meta.url,
|
36
|
+
});
|
37
|
+
normalized.details = undefined;
|
34
38
|
this.app.notifier?.notify({
|
35
39
|
group: this.app.label,
|
36
|
-
message:
|
37
|
-
subtitle:
|
40
|
+
message: normalized.message,
|
41
|
+
subtitle: normalized.name,
|
38
42
|
});
|
39
|
-
|
40
|
-
this.app.context.render(_jsx(DisplayError, { error: error }));
|
41
|
-
}
|
42
|
-
else {
|
43
|
-
this.app.context.render(_jsx(DisplayError, { error: BudError.normalize(error) }));
|
44
|
-
}
|
43
|
+
this.app.context.render(_jsx(DisplayError, { error: error }));
|
45
44
|
}
|
46
45
|
/**
|
47
46
|
* {@link BudCompiler.onStats}
|
@@ -109,26 +108,24 @@ class Compiler extends Service {
|
|
109
108
|
async compile(bud) {
|
110
109
|
const config = !bud.hasChildren
|
111
110
|
? [await bud.build.make()]
|
112
|
-
: 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 => {
|
113
112
|
throw error;
|
114
113
|
})));
|
115
114
|
this.config = config?.filter(Boolean);
|
116
|
-
this.config.
|
117
|
-
|
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
|
+
}
|
118
119
|
await bud.hooks.fire(`compiler.before`, bud).catch(error => {
|
119
120
|
throw error;
|
120
121
|
});
|
121
122
|
this.logger.timeEnd(`initialize`);
|
122
|
-
|
123
|
-
this.instance = this.implementation(this.config);
|
124
|
-
}
|
125
|
-
catch (error) {
|
126
|
-
const normalError = error instanceof Error ? error : BudError.normalize(error);
|
127
|
-
this.onError(normalError);
|
128
|
-
}
|
123
|
+
this.instance = this.implementation(this.config);
|
129
124
|
this.instance.hooks.done.tap(bud.label, (stats) => {
|
130
125
|
this.onStats(stats);
|
131
|
-
bud.hooks
|
126
|
+
bud.hooks
|
127
|
+
.fire(`compiler.done`, bud, this.stats)
|
128
|
+
.catch(this.app.catch);
|
132
129
|
});
|
133
130
|
return this.instance;
|
134
131
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@roots/bud-compiler",
|
3
|
-
"version": "2023.11.
|
3
|
+
"version": "2023.11.29-7",
|
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": "2023.11.
|
68
|
+
"@roots/bud-api": "2023.11.29-7",
|
69
69
|
"@skypack/package-check": "0.2.2",
|
70
70
|
"@types/node": "20.9.0",
|
71
71
|
"@types/react": "18.2.37"
|
72
72
|
},
|
73
73
|
"dependencies": {
|
74
|
-
"@roots/bud-dashboard": "2023.11.
|
75
|
-
"@roots/bud-framework": "2023.11.
|
76
|
-
"@roots/bud-support": "2023.11.
|
74
|
+
"@roots/bud-dashboard": "2023.11.29-7",
|
75
|
+
"@roots/bud-framework": "2023.11.29-7",
|
76
|
+
"@roots/bud-support": "2023.11.29-7",
|
77
77
|
"react": "18.2.0",
|
78
78
|
"tslib": "2.6.2"
|
79
79
|
},
|
package/src/service/index.tsx
CHANGED
@@ -17,10 +17,10 @@ import {cpus} from 'node:os'
|
|
17
17
|
import process from 'node:process'
|
18
18
|
import {pathToFileURL} from 'node:url'
|
19
19
|
|
20
|
-
import {
|
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'
|
23
|
+
import {BudError, CompilerError} from '@roots/bud-support/errors'
|
24
24
|
import isNull from '@roots/bud-support/lodash/isNull'
|
25
25
|
import isNumber from '@roots/bud-support/lodash/isNumber'
|
26
26
|
import isString from '@roots/bud-support/lodash/isString'
|
@@ -54,26 +54,27 @@ class Compiler extends Service implements BudCompiler {
|
|
54
54
|
* {@link BudCompiler.onError}
|
55
55
|
*/
|
56
56
|
@bind
|
57
|
-
public onError(error: Error) {
|
57
|
+
public onError(error: Error | undefined) {
|
58
58
|
process.exitCode = 1
|
59
59
|
if (!error) return
|
60
60
|
|
61
61
|
this.app.server?.appliedMiddleware?.hot?.publish({error})
|
62
62
|
|
63
|
+
const normalized = CompilerError.normalize(error, {
|
64
|
+
thrownBy: import.meta.url,
|
65
|
+
})
|
66
|
+
|
67
|
+
normalized.details = undefined
|
68
|
+
|
63
69
|
this.app.notifier?.notify({
|
64
70
|
group: this.app.label,
|
65
|
-
message:
|
66
|
-
subtitle:
|
71
|
+
message: normalized.message,
|
72
|
+
subtitle: normalized.name,
|
67
73
|
})
|
68
74
|
|
69
|
-
|
70
|
-
this.app.context.render(<DisplayError error={error} />)
|
71
|
-
} else {
|
72
|
-
this.app.context.render(
|
73
|
-
<DisplayError error={BudError.normalize(error)} />,
|
74
|
-
)
|
75
|
-
}
|
75
|
+
this.app.context.render(<DisplayError error={error} />)
|
76
76
|
}
|
77
|
+
|
77
78
|
/**
|
78
79
|
* {@link BudCompiler.onStats}
|
79
80
|
*/
|
@@ -152,17 +153,20 @@ class Compiler extends Service implements BudCompiler {
|
|
152
153
|
const config = !bud.hasChildren
|
153
154
|
? [await bud.build.make()]
|
154
155
|
: await Promise.all(
|
155
|
-
Object.values(bud.children).map(
|
156
|
-
child
|
157
|
-
|
158
|
-
|
156
|
+
Object.values(bud.children).map(
|
157
|
+
async (child: Bud) =>
|
158
|
+
await child.build.make().catch(error => {
|
159
|
+
throw error
|
160
|
+
}),
|
159
161
|
),
|
160
162
|
)
|
161
163
|
|
162
164
|
this.config = config?.filter(Boolean)
|
163
165
|
|
164
|
-
this.config.
|
165
|
-
|
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
|
+
}
|
166
170
|
|
167
171
|
await bud.hooks.fire(`compiler.before`, bud).catch(error => {
|
168
172
|
throw error
|
@@ -170,17 +174,13 @@ class Compiler extends Service implements BudCompiler {
|
|
170
174
|
|
171
175
|
this.logger.timeEnd(`initialize`)
|
172
176
|
|
173
|
-
|
174
|
-
this.instance = this.implementation(this.config)
|
175
|
-
} catch (error: unknown) {
|
176
|
-
const normalError =
|
177
|
-
error instanceof Error ? error : BudError.normalize(error)
|
178
|
-
this.onError(normalError)
|
179
|
-
}
|
177
|
+
this.instance = this.implementation(this.config)
|
180
178
|
|
181
179
|
this.instance.hooks.done.tap(bud.label, (stats: any) => {
|
182
180
|
this.onStats(stats)
|
183
|
-
bud.hooks
|
181
|
+
bud.hooks
|
182
|
+
.fire(`compiler.done`, bud, this.stats)
|
183
|
+
.catch(this.app.catch)
|
184
184
|
})
|
185
185
|
|
186
186
|
return this.instance
|