@roots/bud-compiler 2023.7.1-57 → 2023.7.5-148

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,55 +1,49 @@
1
- import type { Bud } from '@roots/bud-framework';
2
1
  import type { Compiler as BudCompiler } from '@roots/bud-framework';
3
- import type { Configuration, MultiCompiler, MultiStats, Stats, StatsCompilation, StatsError } from '@roots/bud-framework/config';
2
+ import type { Bud } from '@roots/bud-framework';
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
6
  import { type BudHandler } from '@roots/bud-support/errors';
7
7
  import webpack from '@roots/bud-support/webpack';
8
8
  /**
9
- * Wepback compilation controller class
9
+ * {@link BudCompiler} implementation
10
10
  */
11
11
  export declare class Compiler extends Service implements BudCompiler {
12
12
  /**
13
- * Compilation stats
13
+ * {@link BudCompiler.compilationStats}
14
14
  */
15
- compilationStats: StatsCompilation;
15
+ compilationStats: BudCompiler[`compilationStats`];
16
16
  /**
17
- * Configuration
17
+ * {@link BudCompiler.config}
18
18
  */
19
- config: Array<Configuration> & {
20
- parallelism?: number;
21
- };
19
+ config: BudCompiler[`config`];
22
20
  /**
23
- * Compiler implementation
21
+ * {@link BudCompiler.implementation}
24
22
  */
25
- implementation: typeof webpack;
23
+ implementation: BudCompiler[`implementation`] & typeof Webpack;
26
24
  /**
27
- * Compiler instance
25
+ * {@link BudCompiler.instance}
28
26
  */
29
27
  instance: BudCompiler[`instance`];
30
- label: string;
31
28
  /**
32
- * Raw stats
29
+ * {@link BudCompiler.stats}
33
30
  */
34
31
  stats: BudCompiler[`stats`];
35
32
  /**
36
- * Initiates compilation
33
+ * {@link BudCompiler.compile}
37
34
  */
38
35
  compile(bud: Bud): Promise<MultiCompiler>;
39
36
  /**
40
- * Compiler error event
37
+ * {@link BudCompiler.onError}
41
38
  */
42
- onError(error: BudHandler | webpack.WebpackError): Promise<void>;
39
+ onError(error: BudHandler | webpack.WebpackError): void;
43
40
  /**
44
- * Stats handler
41
+ * {@link BudCompiler.onStats}
45
42
  */
46
- onStats(stats: Stats & MultiStats): Promise<void>;
43
+ onStats(stats: Stats & MultiStats): void;
47
44
  /**
48
45
  * {@link Service.register}
49
46
  */
50
- register(bud: Bud): Promise<any>;
51
- /**
52
- * Parse errors from webpack stats
53
- */
54
- sourceErrors(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
47
+ register?(bud: Bud): Promise<any>;
48
+ sourceErrors?(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
55
49
  }
package/lib/service.js CHANGED
@@ -1,6 +1,9 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { Error } from '@roots/bud-dashboard/app';
3
+ import { cpus } from 'node:os';
4
+ import process from 'node:process';
5
+ import { pathToFileURL } from 'node:url';
6
+ import { Error } from '@roots/bud-dashboard/components/error';
4
7
  import { Service } from '@roots/bud-framework/service';
5
8
  import { bind } from '@roots/bud-support/decorators/bind';
6
9
  import { BudError } from '@roots/bud-support/errors';
@@ -8,73 +11,66 @@ import { duration } from '@roots/bud-support/human-readable';
8
11
  import { render } from '@roots/bud-support/ink';
9
12
  import stripAnsi from '@roots/bud-support/strip-ansi';
10
13
  import webpack from '@roots/bud-support/webpack';
11
- import { cpus } from 'node:os';
12
- import process from 'node:process';
13
- import { pathToFileURL } from 'node:url';
14
14
  /**
15
- * Wepback compilation controller class
15
+ * {@link BudCompiler} implementation
16
16
  */
17
17
  export class Compiler extends Service {
18
18
  /**
19
- * Compilation stats
19
+ * {@link BudCompiler.compilationStats}
20
20
  */
21
21
  compilationStats;
22
22
  /**
23
- * Configuration
23
+ * {@link BudCompiler.config}
24
24
  */
25
25
  config = [];
26
26
  /**
27
- * Compiler implementation
27
+ * {@link BudCompiler.implementation}
28
28
  */
29
29
  implementation;
30
30
  /**
31
- * Compiler instance
31
+ * {@link BudCompiler.instance}
32
32
  */
33
33
  instance;
34
- label = `compiler`;
35
34
  /**
36
- * Raw stats
35
+ * {@link BudCompiler.stats}
37
36
  */
38
37
  stats;
39
38
  /**
40
- * Initiates compilation
39
+ * {@link BudCompiler.compile}
41
40
  */
42
41
  async compile(bud) {
43
- this.config = !this.app.hasChildren
44
- ? [await this.app.build.make()]
45
- : await Promise.all(Object.values(this.app.children).map(async (child) => await child.build.make().catch(error => {
42
+ this.config = !bud.hasChildren
43
+ ? [await bud.build.make()]
44
+ : await Promise.all(Object.values(bud.children).map(async (child) => await child.build.make().catch(error => {
46
45
  throw error;
47
46
  })));
48
47
  this.config.parallelism = Math.min(cpus().length - 1, 1);
49
- await this.app.hooks.fire(`compiler.before`, this.app);
48
+ await bud.hooks.fire(`compiler.before`, bud).catch(error => {
49
+ throw error;
50
+ });
50
51
  this.logger.timeEnd(`initialize`);
52
+ this.app.dashboard.updateStatus(`compiling`);
51
53
  try {
52
54
  this.instance = this.implementation(this.config);
53
55
  }
54
56
  catch (error) {
55
57
  throw BudError.normalize(error);
56
58
  }
57
- this.instance.hooks.done.tap(this.app.label, async (stats) => {
58
- await this.onStats(stats);
59
- await this.app.hooks
60
- .fire(`compiler.done`, this.app, this.stats)
61
- .catch(error => {
59
+ this.instance.hooks.done.tap(bud.label, (stats) => {
60
+ this.onStats(stats);
61
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
62
62
  throw error;
63
63
  });
64
64
  });
65
65
  return this.instance;
66
66
  }
67
67
  /**
68
- * Compiler error event
68
+ * {@link BudCompiler.onError}
69
69
  */
70
- async onError(error) {
70
+ onError(error) {
71
71
  process.exitCode = 1;
72
- this.app.isDevelopment &&
73
- this.app.server.appliedMiddleware?.hot?.publish({ error });
74
- await this.app.hooks
75
- .fire(`compiler.error`, error)
76
- .catch(this.app.error);
77
- this.app.notifier.notify({
72
+ this.app.server?.appliedMiddleware?.hot?.publish({ error });
73
+ this.app.notifier?.notify({
78
74
  group: this.app.label,
79
75
  message: error.message,
80
76
  subtitle: error.name,
@@ -87,39 +83,15 @@ export class Compiler extends Service {
87
83
  }
88
84
  }
89
85
  /**
90
- * Stats handler
86
+ * {@link BudCompiler.onStats}
91
87
  */
92
- async onStats(stats) {
88
+ onStats(stats) {
93
89
  const makeNoticeTitle = (child) => this.app.label !== child.name
94
90
  ? `${this.app.label} (${child.name})`
95
91
  : child.name;
96
92
  this.stats = stats;
97
- this.compilationStats = stats.toJson({
98
- all: false,
99
- children: {
100
- all: false,
101
- assets: true,
102
- cached: true,
103
- cachedAssets: true,
104
- cachedModules: true,
105
- entrypoints: true,
106
- errorDetails: false,
107
- errors: true,
108
- errorsCount: true,
109
- errorStack: false,
110
- hash: true,
111
- modules: true,
112
- name: true,
113
- outputPath: true,
114
- reasons: this.app.context.debug ? true : false,
115
- runtime: true,
116
- timings: true,
117
- warnings: true,
118
- warningsCount: true,
119
- },
120
- name: true,
121
- });
122
- this.app.dashboard.update(this.compilationStats);
93
+ this.compilationStats = stats.toJson(statsOptions);
94
+ this.app.dashboard.updateStats(this.compilationStats);
123
95
  if (stats.hasErrors()) {
124
96
  process.exitCode = 1;
125
97
  this.compilationStats.children = this.compilationStats.children?.map(child => ({
@@ -171,15 +143,12 @@ export class Compiler extends Service {
171
143
  * {@link Service.register}
172
144
  */
173
145
  async register(bud) {
174
- this.implementation = await this.app.module
175
- .import(`webpack`, import.meta.url)
146
+ this.implementation = await bud.module
147
+ .import(`@roots/bud-support/webpack`, import.meta.url)
176
148
  .catch(error => {
177
149
  throw BudError.normalize(error);
178
150
  });
179
151
  }
180
- /**
181
- * Parse errors from webpack stats
182
- */
183
152
  sourceErrors(errors) {
184
153
  if (!errors || !errors.length)
185
154
  return [];
@@ -220,13 +189,13 @@ __decorate([
220
189
  bind,
221
190
  __metadata("design:type", Function),
222
191
  __metadata("design:paramtypes", [Object]),
223
- __metadata("design:returntype", Promise)
192
+ __metadata("design:returntype", void 0)
224
193
  ], Compiler.prototype, "onError", null);
225
194
  __decorate([
226
195
  bind,
227
196
  __metadata("design:type", Function),
228
197
  __metadata("design:paramtypes", [Function]),
229
- __metadata("design:returntype", Promise)
198
+ __metadata("design:returntype", void 0)
230
199
  ], Compiler.prototype, "onStats", null);
231
200
  __decorate([
232
201
  bind,
@@ -240,3 +209,28 @@ __decorate([
240
209
  __metadata("design:paramtypes", [Array]),
241
210
  __metadata("design:returntype", Array)
242
211
  ], Compiler.prototype, "sourceErrors", null);
212
+ const statsOptions = {
213
+ all: false,
214
+ children: {
215
+ all: false,
216
+ assets: true,
217
+ cached: true,
218
+ cachedAssets: true,
219
+ cachedModules: true,
220
+ entrypoints: true,
221
+ errorDetails: false,
222
+ errors: true,
223
+ errorsCount: true,
224
+ errorStack: false,
225
+ hash: true,
226
+ modules: true,
227
+ name: true,
228
+ outputPath: true,
229
+ reasons: false,
230
+ runtime: true,
231
+ timings: true,
232
+ warnings: true,
233
+ warningsCount: true,
234
+ },
235
+ name: true,
236
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "2023.7.1-57",
3
+ "version": "2023.7.5-148",
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.1-57",
64
+ "@roots/bud-api": "2023.7.5-148",
65
65
  "@skypack/package-check": "0.2.2",
66
66
  "@types/node": "18.16.18",
67
67
  "@types/react": "18.2.14"
68
68
  },
69
69
  "dependencies": {
70
- "@roots/bud-dashboard": "2023.7.1-57",
71
- "@roots/bud-framework": "2023.7.1-57",
72
- "@roots/bud-support": "2023.7.1-57",
70
+ "@roots/bud-dashboard": "2023.7.5-148",
71
+ "@roots/bud-framework": "2023.7.5-148",
72
+ "@roots/bud-support": "2023.7.5-148",
73
73
  "react": "18.2.0",
74
74
  "tslib": "2.6.0"
75
75
  },
package/src/service.tsx CHANGED
@@ -1,19 +1,23 @@
1
- import type {Bud} from '@roots/bud-framework'
2
1
  import type {Compiler as BudCompiler} from '@roots/bud-framework'
2
+ import type {Bud} from '@roots/bud-framework'
3
3
  import type {
4
- Configuration,
5
4
  MultiCompiler,
6
5
  MultiStats,
7
6
  Stats,
8
7
  StatsCompilation,
9
8
  StatsError,
9
+ Webpack,
10
10
  } from '@roots/bud-framework/config'
11
11
  import type {
12
12
  ErrorWithSourceFile,
13
13
  SourceFile,
14
14
  } from '@roots/bud-support/open'
15
15
 
16
- import {Error} from '@roots/bud-dashboard/app'
16
+ import {cpus} from 'node:os'
17
+ import process from 'node:process'
18
+ import {pathToFileURL} from 'node:url'
19
+
20
+ import {Error} from '@roots/bud-dashboard/components/error'
17
21
  import {Service} from '@roots/bud-framework/service'
18
22
  import {bind} from '@roots/bud-support/decorators/bind'
19
23
  import {BudError, type BudHandler} from '@roots/bud-support/errors'
@@ -21,62 +25,59 @@ import {duration} from '@roots/bud-support/human-readable'
21
25
  import {render} from '@roots/bud-support/ink'
22
26
  import stripAnsi from '@roots/bud-support/strip-ansi'
23
27
  import webpack from '@roots/bud-support/webpack'
24
- import {cpus} from 'node:os'
25
- import process from 'node:process'
26
- import {pathToFileURL} from 'node:url'
27
28
 
28
29
  /**
29
- * Wepback compilation controller class
30
+ * {@link BudCompiler} implementation
30
31
  */
31
32
  export class Compiler extends Service implements BudCompiler {
32
33
  /**
33
- * Compilation stats
34
+ * {@link BudCompiler.compilationStats}
34
35
  */
35
- public compilationStats: StatsCompilation
36
+ public compilationStats: BudCompiler[`compilationStats`]
36
37
 
37
38
  /**
38
- * Configuration
39
+ * {@link BudCompiler.config}
39
40
  */
40
- public config: Array<Configuration> & {parallelism?: number} = []
41
+ public config: BudCompiler[`config`] = []
41
42
 
42
43
  /**
43
- * Compiler implementation
44
+ * {@link BudCompiler.implementation}
44
45
  */
45
- public implementation: typeof webpack
46
+ public implementation: BudCompiler[`implementation`] & typeof Webpack
46
47
 
47
48
  /**
48
- * Compiler instance
49
+ * {@link BudCompiler.instance}
49
50
  */
50
51
  public instance: BudCompiler[`instance`]
51
52
 
52
- public label = `compiler`
53
-
54
53
  /**
55
- * Raw stats
54
+ * {@link BudCompiler.stats}
56
55
  */
57
56
  public stats: BudCompiler[`stats`]
58
57
 
59
58
  /**
60
- * Initiates compilation
59
+ * {@link BudCompiler.compile}
61
60
  */
62
61
  @bind
63
62
  public async compile(bud: Bud): Promise<MultiCompiler> {
64
- this.config = !this.app.hasChildren
65
- ? [await this.app.build.make()]
63
+ this.config = !bud.hasChildren
64
+ ? [await bud.build.make()]
66
65
  : await Promise.all(
67
- Object.values(this.app.children).map(
66
+ Object.values(bud.children).map(
68
67
  async (child: Bud) =>
69
68
  await child.build.make().catch(error => {
70
69
  throw error
71
70
  }),
72
71
  ),
73
72
  )
74
-
75
73
  this.config.parallelism = Math.min(cpus().length - 1, 1)
76
74
 
77
- await this.app.hooks.fire(`compiler.before`, this.app)
75
+ await bud.hooks.fire(`compiler.before`, bud).catch(error => {
76
+ throw error
77
+ })
78
78
 
79
79
  this.logger.timeEnd(`initialize`)
80
+ this.app.dashboard.updateStatus(`compiling`)
80
81
 
81
82
  try {
82
83
  this.instance = this.implementation(this.config)
@@ -84,34 +85,27 @@ export class Compiler extends Service implements BudCompiler {
84
85
  throw BudError.normalize(error)
85
86
  }
86
87
 
87
- this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
88
- await this.onStats(stats)
88
+ this.instance.hooks.done.tap(bud.label, (stats: any) => {
89
+ this.onStats(stats)
89
90
 
90
- await this.app.hooks
91
- .fire(`compiler.done`, this.app, this.stats)
92
- .catch(error => {
93
- throw error
94
- })
91
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
92
+ throw error
93
+ })
95
94
  })
96
95
 
97
96
  return this.instance
98
97
  }
99
98
 
100
99
  /**
101
- * Compiler error event
100
+ * {@link BudCompiler.onError}
102
101
  */
103
102
  @bind
104
- public async onError(error: BudHandler | webpack.WebpackError) {
103
+ public onError(error: BudHandler | webpack.WebpackError) {
105
104
  process.exitCode = 1
106
105
 
107
- this.app.isDevelopment &&
108
- this.app.server.appliedMiddleware?.hot?.publish({error})
109
-
110
- await this.app.hooks
111
- .fire(`compiler.error`, error)
112
- .catch(this.app.error)
106
+ this.app.server?.appliedMiddleware?.hot?.publish({error})
113
107
 
114
- this.app.notifier.notify({
108
+ this.app.notifier?.notify({
115
109
  group: this.app.label,
116
110
  message: error.message,
117
111
  subtitle: error.name,
@@ -125,10 +119,10 @@ export class Compiler extends Service implements BudCompiler {
125
119
  }
126
120
 
127
121
  /**
128
- * Stats handler
122
+ * {@link BudCompiler.onStats}
129
123
  */
130
124
  @bind
131
- public async onStats(stats: Stats & MultiStats) {
125
+ public onStats(stats: Stats & MultiStats) {
132
126
  const makeNoticeTitle = (child: StatsCompilation) =>
133
127
  this.app.label !== child.name
134
128
  ? `${this.app.label} (${child.name})`
@@ -136,33 +130,9 @@ export class Compiler extends Service implements BudCompiler {
136
130
 
137
131
  this.stats = stats
138
132
 
139
- this.compilationStats = stats.toJson({
140
- all: false,
141
- children: {
142
- all: false,
143
- assets: true,
144
- cached: true,
145
- cachedAssets: true,
146
- cachedModules: true,
147
- entrypoints: true,
148
- errorDetails: false,
149
- errors: true,
150
- errorsCount: true,
151
- errorStack: false,
152
- hash: true,
153
- modules: true,
154
- name: true,
155
- outputPath: true,
156
- reasons: this.app.context.debug ? true : false,
157
- runtime: true,
158
- timings: true,
159
- warnings: true,
160
- warningsCount: true,
161
- },
162
- name: true,
163
- })
133
+ this.compilationStats = stats.toJson(statsOptions)
164
134
 
165
- this.app.dashboard.update(this.compilationStats)
135
+ this.app.dashboard.updateStats(this.compilationStats)
166
136
 
167
137
  if (stats.hasErrors()) {
168
138
  process.exitCode = 1
@@ -222,19 +192,16 @@ export class Compiler extends Service implements BudCompiler {
222
192
  * {@link Service.register}
223
193
  */
224
194
  @bind
225
- public override async register(bud: Bud): Promise<any> {
226
- this.implementation = await this.app.module
227
- .import(`webpack`, import.meta.url)
195
+ public override async register?(bud: Bud): Promise<any> {
196
+ this.implementation = await bud.module
197
+ .import(`@roots/bud-support/webpack`, import.meta.url)
228
198
  .catch(error => {
229
199
  throw BudError.normalize(error)
230
200
  })
231
201
  }
232
202
 
233
- /**
234
- * Parse errors from webpack stats
235
- */
236
203
  @bind
237
- public sourceErrors(
204
+ public sourceErrors?(
238
205
  errors: Array<StatsError>,
239
206
  ): Array<ErrorWithSourceFile | StatsError> {
240
207
  if (!errors || !errors.length) return []
@@ -274,3 +241,29 @@ export class Compiler extends Service implements BudCompiler {
274
241
  }
275
242
  }
276
243
  }
244
+
245
+ const statsOptions = {
246
+ all: false,
247
+ children: {
248
+ all: false,
249
+ assets: true,
250
+ cached: true,
251
+ cachedAssets: true,
252
+ cachedModules: true,
253
+ entrypoints: true,
254
+ errorDetails: false,
255
+ errors: true,
256
+ errorsCount: true,
257
+ errorStack: false,
258
+ hash: true,
259
+ modules: true,
260
+ name: true,
261
+ outputPath: true,
262
+ reasons: false,
263
+ runtime: true,
264
+ timings: true,
265
+ warnings: true,
266
+ warningsCount: true,
267
+ },
268
+ name: true,
269
+ }