@roots/bud-compiler 2023.7.28-1813 → 2023.8.6-752
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/index.d.ts
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
* @see https://bud.js.org
|
5
5
|
* @see https://github.com/roots/bud
|
6
6
|
*/
|
7
|
-
import { Compiler } from '
|
7
|
+
import { default as Compiler } from '@roots/bud-compiler/service';
|
8
8
|
declare module '@roots/bud-framework' {
|
9
9
|
interface Services {
|
10
10
|
compiler: Compiler;
|
package/lib/index.js
CHANGED
@@ -1,14 +1,12 @@
|
|
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
|
*/
|
11
|
-
|
9
|
+
declare class Compiler extends Service implements BudCompiler {
|
12
10
|
/**
|
13
11
|
* {@link BudCompiler.compilationStats}
|
14
12
|
*/
|
@@ -36,7 +34,7 @@ export declare class Compiler extends Service implements BudCompiler {
|
|
36
34
|
/**
|
37
35
|
* {@link BudCompiler.onError}
|
38
36
|
*/
|
39
|
-
onError(error:
|
37
|
+
onError(error: Error): void;
|
40
38
|
/**
|
41
39
|
* {@link BudCompiler.onStats}
|
42
40
|
*/
|
@@ -45,5 +43,6 @@ 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
|
}
|
48
|
+
export { Compiler as default };
|
@@ -1,26 +1,21 @@
|
|
1
|
-
import { __decorate
|
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
|
-
|
20
|
-
/**
|
21
|
-
* {@link BudCompiler.compilationStats}
|
22
|
-
*/
|
23
|
-
compilationStats;
|
18
|
+
class Compiler extends Service {
|
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
|
-
|
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
|
-
|
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(
|
73
|
+
render(_jsx(DisplayError, { error: error }));
|
85
74
|
}
|
86
75
|
else {
|
87
|
-
render(_jsx(
|
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
|
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
|
135
|
-
: `
|
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.
|
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,
|
@@ -268,3 +246,4 @@ const statsOptions = {
|
|
268
246
|
},
|
269
247
|
name: true,
|
270
248
|
};
|
249
|
+
export { Compiler as default };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@roots/bud-compiler",
|
3
|
-
"version": "2023.
|
3
|
+
"version": "2023.8.6-752",
|
4
4
|
"description": "Compilation handler",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=16"
|
@@ -49,27 +49,31 @@
|
|
49
49
|
],
|
50
50
|
"type": "module",
|
51
51
|
"exports": {
|
52
|
-
".": "./lib/index.js"
|
52
|
+
".": "./lib/index.js",
|
53
|
+
"./service": "./lib/service/index.js"
|
53
54
|
},
|
54
55
|
"typesVersions": {
|
55
56
|
"*": {
|
56
57
|
".": [
|
57
58
|
"./lib/index.d.ts"
|
59
|
+
],
|
60
|
+
"service": [
|
61
|
+
"./lib/service/index.d.ts"
|
58
62
|
]
|
59
63
|
}
|
60
64
|
},
|
61
65
|
"types": "./lib/index.d.ts",
|
62
66
|
"module": "./lib/index.js",
|
63
67
|
"devDependencies": {
|
64
|
-
"@roots/bud-api": "2023.
|
68
|
+
"@roots/bud-api": "2023.8.6-752",
|
65
69
|
"@skypack/package-check": "0.2.2",
|
66
70
|
"@types/node": "18.16.19",
|
67
71
|
"@types/react": "18.2.15"
|
68
72
|
},
|
69
73
|
"dependencies": {
|
70
|
-
"@roots/bud-dashboard": "2023.
|
71
|
-
"@roots/bud-framework": "2023.
|
72
|
-
"@roots/bud-support": "2023.
|
74
|
+
"@roots/bud-dashboard": "2023.8.6-752",
|
75
|
+
"@roots/bud-framework": "2023.8.6-752",
|
76
|
+
"@roots/bud-support": "2023.8.6-752",
|
73
77
|
"react": "18.2.0",
|
74
78
|
"tslib": "2.6.0"
|
75
79
|
},
|
package/src/index.ts
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,25 +17,24 @@ 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
|
33
32
|
*/
|
34
|
-
|
33
|
+
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
|
-
|
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,10 @@ export class Compiler extends Service implements BudCompiler {
|
|
84
85
|
|
85
86
|
try {
|
86
87
|
this.instance = this.implementation(this.config)
|
87
|
-
} catch (error) {
|
88
|
-
|
88
|
+
} catch (error: unknown) {
|
89
|
+
const normalError =
|
90
|
+
error instanceof Error ? error : BudError.normalize(error)
|
91
|
+
this.onError(normalError)
|
89
92
|
}
|
90
93
|
|
91
94
|
this.instance.hooks.done.tap(bud.label, (stats: any) => {
|
@@ -102,7 +105,7 @@ export class Compiler extends Service implements BudCompiler {
|
|
102
105
|
* {@link BudCompiler.onError}
|
103
106
|
*/
|
104
107
|
@bind
|
105
|
-
public onError(error:
|
108
|
+
public onError(error: Error) {
|
106
109
|
process.exitCode = 1
|
107
110
|
if (!error) return
|
108
111
|
|
@@ -115,9 +118,9 @@ export class Compiler extends Service implements BudCompiler {
|
|
115
118
|
})
|
116
119
|
|
117
120
|
if (`isBudError` in error) {
|
118
|
-
render(<
|
121
|
+
render(<DisplayError error={error} />)
|
119
122
|
} else {
|
120
|
-
render(<
|
123
|
+
render(<DisplayError error={BudError.normalize(error)} />)
|
121
124
|
}
|
122
125
|
}
|
123
126
|
|
@@ -143,12 +146,17 @@ export class Compiler extends Service implements BudCompiler {
|
|
143
146
|
this.compilationStats.children = this.compilationStats.children?.map(
|
144
147
|
child => ({
|
145
148
|
...child,
|
146
|
-
errors:
|
149
|
+
errors:
|
150
|
+
child.errors && this.sourceErrors
|
151
|
+
? this.sourceErrors(child.errors)
|
152
|
+
: child.errors ?? [],
|
147
153
|
}),
|
148
154
|
)
|
149
155
|
|
150
156
|
this.compilationStats.children
|
151
|
-
?.filter(
|
157
|
+
?.filter(
|
158
|
+
child => isNumber(child.errorsCount) && child.errorsCount > 0,
|
159
|
+
)
|
152
160
|
.forEach(child => {
|
153
161
|
try {
|
154
162
|
const error = child.errors?.shift()
|
@@ -162,7 +170,7 @@ export class Compiler extends Service implements BudCompiler {
|
|
162
170
|
title: makeNoticeTitle(child),
|
163
171
|
})
|
164
172
|
|
165
|
-
this.app.notifier.openEditor(error.file)
|
173
|
+
error.file && this.app.notifier.openEditor(error.file)
|
166
174
|
} catch (error) {
|
167
175
|
this.logger.error(error)
|
168
176
|
}
|
@@ -176,16 +184,15 @@ export class Compiler extends Service implements BudCompiler {
|
|
176
184
|
this.app.notifier.notify({
|
177
185
|
group: `${this.app.label}-${child.name}`,
|
178
186
|
message: child.modules
|
179
|
-
? `${child.modules.length} modules compiled
|
180
|
-
|
181
|
-
)}`
|
182
|
-
: `Compiled in ${duration(child.time)}`,
|
187
|
+
? `${child.modules.length} modules compiled`
|
188
|
+
: `Modules compiled successfully`,
|
183
189
|
open: this.app.server?.publicUrl.href,
|
184
190
|
subtitle: `Build successful`,
|
185
191
|
title: makeNoticeTitle(child),
|
186
192
|
})
|
187
193
|
|
188
|
-
this.app.
|
194
|
+
this.app.server?.publicUrl.href &&
|
195
|
+
this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
|
189
196
|
} catch (error) {
|
190
197
|
this.logger.error(error)
|
191
198
|
}
|
@@ -206,7 +213,7 @@ export class Compiler extends Service implements BudCompiler {
|
|
206
213
|
|
207
214
|
@bind
|
208
215
|
public sourceErrors?(
|
209
|
-
errors: Array<StatsError
|
216
|
+
errors: Array<StatsError> | undefined,
|
210
217
|
): Array<ErrorWithSourceFile | StatsError> {
|
211
218
|
if (!errors || !errors.length) return []
|
212
219
|
|
@@ -222,7 +229,7 @@ export class Compiler extends Service implements BudCompiler {
|
|
222
229
|
* In a perfect world webpack plugins would use the
|
223
230
|
* `nameForCondition` property to identify the module.
|
224
231
|
*/
|
225
|
-
if (ident) {
|
232
|
+
if (ident && this.compilationStats?.children) {
|
226
233
|
module = this.compilationStats.children
|
227
234
|
.flatMap(child => child?.modules)
|
228
235
|
.find(module => [module?.id, module?.name].includes(ident))
|
@@ -290,6 +297,7 @@ const statsOptions = {
|
|
290
297
|
cachedAssets: true,
|
291
298
|
cachedModules: true,
|
292
299
|
entrypoints: true,
|
300
|
+
errorDetails: false,
|
293
301
|
errors: true,
|
294
302
|
errorsCount: true,
|
295
303
|
hash: true,
|
@@ -302,3 +310,5 @@ const statsOptions = {
|
|
302
310
|
},
|
303
311
|
name: true,
|
304
312
|
}
|
313
|
+
|
314
|
+
export {Compiler as default}
|