@roots/bud-compiler 2023.6.29-129 → 2023.7.5-318

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,45 +11,43 @@ 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`);
51
52
  try {
52
53
  this.instance = this.implementation(this.config);
@@ -54,27 +55,21 @@ export class Compiler extends Service {
54
55
  catch (error) {
55
56
  throw BudError.normalize(error);
56
57
  }
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 => {
58
+ this.instance.hooks.done.tap(bud.label, (stats) => {
59
+ this.onStats(stats);
60
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
62
61
  throw error;
63
62
  });
64
63
  });
65
64
  return this.instance;
66
65
  }
67
66
  /**
68
- * Compiler error event
67
+ * {@link BudCompiler.onError}
69
68
  */
70
- async onError(error) {
69
+ onError(error) {
71
70
  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({
71
+ this.app.server?.appliedMiddleware?.hot?.publish({ error });
72
+ this.app.notifier?.notify({
78
73
  group: this.app.label,
79
74
  message: error.message,
80
75
  subtitle: error.name,
@@ -87,38 +82,14 @@ export class Compiler extends Service {
87
82
  }
88
83
  }
89
84
  /**
90
- * Stats handler
85
+ * {@link BudCompiler.onStats}
91
86
  */
92
- async onStats(stats) {
87
+ onStats(stats) {
93
88
  const makeNoticeTitle = (child) => this.app.label !== child.name
94
89
  ? `${this.app.label} (${child.name})`
95
90
  : child.name;
96
91
  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
- });
92
+ this.compilationStats = stats.toJson(statsOptions);
122
93
  this.app.dashboard.update(this.compilationStats);
123
94
  if (stats.hasErrors()) {
124
95
  process.exitCode = 1;
@@ -171,15 +142,12 @@ export class Compiler extends Service {
171
142
  * {@link Service.register}
172
143
  */
173
144
  async register(bud) {
174
- this.implementation = await this.app.module
175
- .import(`webpack`, import.meta.url)
145
+ this.implementation = await bud.module
146
+ .import(`@roots/bud-support/webpack`, import.meta.url)
176
147
  .catch(error => {
177
148
  throw BudError.normalize(error);
178
149
  });
179
150
  }
180
- /**
181
- * Parse errors from webpack stats
182
- */
183
151
  sourceErrors(errors) {
184
152
  if (!errors || !errors.length)
185
153
  return [];
@@ -220,13 +188,13 @@ __decorate([
220
188
  bind,
221
189
  __metadata("design:type", Function),
222
190
  __metadata("design:paramtypes", [Object]),
223
- __metadata("design:returntype", Promise)
191
+ __metadata("design:returntype", void 0)
224
192
  ], Compiler.prototype, "onError", null);
225
193
  __decorate([
226
194
  bind,
227
195
  __metadata("design:type", Function),
228
196
  __metadata("design:paramtypes", [Function]),
229
- __metadata("design:returntype", Promise)
197
+ __metadata("design:returntype", void 0)
230
198
  ], Compiler.prototype, "onStats", null);
231
199
  __decorate([
232
200
  bind,
@@ -240,3 +208,28 @@ __decorate([
240
208
  __metadata("design:paramtypes", [Array]),
241
209
  __metadata("design:returntype", Array)
242
210
  ], Compiler.prototype, "sourceErrors", null);
211
+ const statsOptions = {
212
+ all: false,
213
+ children: {
214
+ all: false,
215
+ assets: true,
216
+ cached: true,
217
+ cachedAssets: true,
218
+ cachedModules: true,
219
+ entrypoints: true,
220
+ errorDetails: false,
221
+ errors: true,
222
+ errorsCount: true,
223
+ errorStack: false,
224
+ hash: true,
225
+ modules: true,
226
+ name: true,
227
+ outputPath: true,
228
+ reasons: false,
229
+ runtime: true,
230
+ timings: true,
231
+ warnings: true,
232
+ warningsCount: true,
233
+ },
234
+ name: true,
235
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "2023.6.29-129",
3
+ "version": "2023.7.5-318",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -61,17 +61,17 @@
61
61
  "types": "./lib/index.d.ts",
62
62
  "module": "./lib/index.js",
63
63
  "devDependencies": {
64
- "@roots/bud-api": "2023.6.29-129",
64
+ "@roots/bud-api": "2023.7.5-318",
65
65
  "@skypack/package-check": "0.2.2",
66
- "@types/node": "18.16.16",
67
- "@types/react": "18.2.9"
66
+ "@types/node": "18.16.18",
67
+ "@types/react": "18.2.14"
68
68
  },
69
69
  "dependencies": {
70
- "@roots/bud-dashboard": "2023.6.29-129",
71
- "@roots/bud-framework": "2023.6.29-129",
72
- "@roots/bud-support": "2023.6.29-129",
70
+ "@roots/bud-dashboard": "2023.7.5-318",
71
+ "@roots/bud-framework": "2023.7.5-318",
72
+ "@roots/bud-support": "2023.7.5-318",
73
73
  "react": "18.2.0",
74
- "tslib": "2.5.3"
74
+ "tslib": "2.6.0"
75
75
  },
76
76
  "volta": {
77
77
  "extends": "../../../package.json"
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,60 +25,56 @@ 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
80
 
@@ -84,34 +84,27 @@ export class Compiler extends Service implements BudCompiler {
84
84
  throw BudError.normalize(error)
85
85
  }
86
86
 
87
- this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
88
- await this.onStats(stats)
87
+ this.instance.hooks.done.tap(bud.label, (stats: any) => {
88
+ this.onStats(stats)
89
89
 
90
- await this.app.hooks
91
- .fire(`compiler.done`, [this.app, this.stats])
92
- .catch(error => {
93
- throw error
94
- })
90
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
91
+ throw error
92
+ })
95
93
  })
96
94
 
97
95
  return this.instance
98
96
  }
99
97
 
100
98
  /**
101
- * Compiler error event
99
+ * {@link BudCompiler.onError}
102
100
  */
103
101
  @bind
104
- public async onError(error: BudHandler | webpack.WebpackError) {
102
+ public onError(error: BudHandler | webpack.WebpackError) {
105
103
  process.exitCode = 1
106
104
 
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)
105
+ this.app.server?.appliedMiddleware?.hot?.publish({error})
113
106
 
114
- this.app.notifier.notify({
107
+ this.app.notifier?.notify({
115
108
  group: this.app.label,
116
109
  message: error.message,
117
110
  subtitle: error.name,
@@ -125,10 +118,10 @@ export class Compiler extends Service implements BudCompiler {
125
118
  }
126
119
 
127
120
  /**
128
- * Stats handler
121
+ * {@link BudCompiler.onStats}
129
122
  */
130
123
  @bind
131
- public async onStats(stats: Stats & MultiStats) {
124
+ public onStats(stats: Stats & MultiStats) {
132
125
  const makeNoticeTitle = (child: StatsCompilation) =>
133
126
  this.app.label !== child.name
134
127
  ? `${this.app.label} (${child.name})`
@@ -136,31 +129,7 @@ export class Compiler extends Service implements BudCompiler {
136
129
 
137
130
  this.stats = stats
138
131
 
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
- })
132
+ this.compilationStats = stats.toJson(statsOptions)
164
133
 
165
134
  this.app.dashboard.update(this.compilationStats)
166
135
 
@@ -222,19 +191,16 @@ export class Compiler extends Service implements BudCompiler {
222
191
  * {@link Service.register}
223
192
  */
224
193
  @bind
225
- public override async register(bud: Bud): Promise<any> {
226
- this.implementation = await this.app.module
227
- .import(`webpack`, import.meta.url)
194
+ public override async register?(bud: Bud): Promise<any> {
195
+ this.implementation = await bud.module
196
+ .import(`@roots/bud-support/webpack`, import.meta.url)
228
197
  .catch(error => {
229
198
  throw BudError.normalize(error)
230
199
  })
231
200
  }
232
201
 
233
- /**
234
- * Parse errors from webpack stats
235
- */
236
202
  @bind
237
- public sourceErrors(
203
+ public sourceErrors?(
238
204
  errors: Array<StatsError>,
239
205
  ): Array<ErrorWithSourceFile | StatsError> {
240
206
  if (!errors || !errors.length) return []
@@ -274,3 +240,29 @@ export class Compiler extends Service implements BudCompiler {
274
240
  }
275
241
  }
276
242
  }
243
+
244
+ const statsOptions = {
245
+ all: false,
246
+ children: {
247
+ all: false,
248
+ assets: true,
249
+ cached: true,
250
+ cachedAssets: true,
251
+ cachedModules: true,
252
+ entrypoints: true,
253
+ errorDetails: false,
254
+ errors: true,
255
+ errorsCount: true,
256
+ errorStack: false,
257
+ hash: true,
258
+ modules: true,
259
+ name: true,
260
+ outputPath: true,
261
+ reasons: false,
262
+ runtime: true,
263
+ timings: true,
264
+ warnings: true,
265
+ warningsCount: true,
266
+ },
267
+ name: true,
268
+ }