@roots/bud-compiler 2023.6.14-43 → 2023.6.23-427

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
@@ -1,11 +1,13 @@
1
1
  /**
2
- * The bud compiler interface
2
+ * @roots/bud-compiler
3
3
  *
4
4
  * @see https://bud.js.org
5
5
  * @see https://github.com/roots/bud
6
- *
7
- * @packageDocumentation
8
6
  */
9
- import { Compiler } from './compiler.service.js';
10
- import './types.js';
11
- export default Compiler;
7
+ import { Compiler } from './service.js';
8
+ declare module '@roots/bud-framework' {
9
+ interface Services {
10
+ compiler: Compiler;
11
+ }
12
+ }
13
+ export { Compiler as default };
package/lib/index.js CHANGED
@@ -1,13 +1,10 @@
1
1
  // Copyright © Roots Software Foundation LLC
2
2
  // Licensed under the MIT license.
3
3
  /**
4
- * The bud compiler interface
4
+ * @roots/bud-compiler
5
5
  *
6
6
  * @see https://bud.js.org
7
7
  * @see https://github.com/roots/bud
8
- *
9
- * @packageDocumentation
10
8
  */
11
- import { Compiler } from './compiler.service.js';
12
- import './types.js';
13
- export default Compiler;
9
+ import { Compiler } from './service.js';
10
+ export { Compiler as default };
@@ -0,0 +1,55 @@
1
+ import type { Bud } from '@roots/bud-framework';
2
+ import type { Compiler as BudCompiler } from '@roots/bud-framework';
3
+ import type { Configuration, MultiCompiler, MultiStats, Stats, StatsCompilation, StatsError } from '@roots/bud-framework/config';
4
+ import type { ErrorWithSourceFile } from '@roots/bud-support/open';
5
+ import { Service } from '@roots/bud-framework/service';
6
+ import { type BudHandler } from '@roots/bud-support/errors';
7
+ import webpack from '@roots/bud-support/webpack';
8
+ /**
9
+ * Wepback compilation controller class
10
+ */
11
+ export declare class Compiler extends Service implements BudCompiler {
12
+ /**
13
+ * Compilation stats
14
+ */
15
+ compilationStats: StatsCompilation;
16
+ /**
17
+ * Configuration
18
+ */
19
+ config: Array<Configuration> & {
20
+ parallelism?: number;
21
+ };
22
+ /**
23
+ * Compiler implementation
24
+ */
25
+ implementation: typeof webpack;
26
+ /**
27
+ * Compiler instance
28
+ */
29
+ instance: BudCompiler[`instance`];
30
+ label: string;
31
+ /**
32
+ * Raw stats
33
+ */
34
+ stats: BudCompiler[`stats`];
35
+ /**
36
+ * Initiates compilation
37
+ */
38
+ compile(bud: Bud): Promise<MultiCompiler>;
39
+ /**
40
+ * Compiler error event
41
+ */
42
+ onError(error: BudHandler | webpack.WebpackError): Promise<void>;
43
+ /**
44
+ * Stats handler
45
+ */
46
+ onStats(stats: Stats & MultiStats): Promise<void>;
47
+ /**
48
+ * {@link Service.register}
49
+ */
50
+ register(bud: Bud): Promise<any>;
51
+ /**
52
+ * Parse errors from webpack stats
53
+ */
54
+ sourceErrors(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
55
+ }
@@ -1,18 +1,24 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import * as App from '@roots/bud-dashboard/app';
3
+ import { Error } from '@roots/bud-dashboard/app';
4
4
  import { Service } from '@roots/bud-framework/service';
5
5
  import { bind } from '@roots/bud-support/decorators/bind';
6
- import { BudError, CompilerError } from '@roots/bud-support/errors';
6
+ import { BudError } from '@roots/bud-support/errors';
7
7
  import { duration } from '@roots/bud-support/human-readable';
8
- import * as Ink from '@roots/bud-support/ink';
8
+ import { render } from '@roots/bud-support/ink';
9
9
  import stripAnsi from '@roots/bud-support/strip-ansi';
10
+ import webpack from '@roots/bud-support/webpack';
11
+ import { cpus } from 'node:os';
12
+ import process from 'node:process';
10
13
  import { pathToFileURL } from 'node:url';
11
- import webpack from 'webpack';
12
14
  /**
13
15
  * Wepback compilation controller class
14
16
  */
15
17
  export class Compiler extends Service {
18
+ /**
19
+ * Compilation stats
20
+ */
21
+ compilationStats;
16
22
  /**
17
23
  * Configuration
18
24
  */
@@ -25,36 +31,37 @@ export class Compiler extends Service {
25
31
  * Compiler instance
26
32
  */
27
33
  instance;
34
+ label = `compiler`;
28
35
  /**
29
- * Compilation stats
36
+ * Raw stats
30
37
  */
31
38
  stats;
32
39
  /**
33
40
  * Initiates compilation
34
41
  */
35
- async compile() {
36
- const compilerPath = await this.app.module.resolve(`webpack`, import.meta.url);
37
- this.implementation = await this.app.module.import(compilerPath, import.meta.url);
38
- this.logger.log(`imported webpack`, this.implementation.version);
42
+ async compile(bud) {
39
43
  this.config = !this.app.hasChildren
40
44
  ? [await this.app.build.make()]
41
- : await Promise.all(Object.values(this.app.children).map(async (child) => {
42
- try {
43
- return await child.build.make();
44
- }
45
- catch (error) {
46
- throw error;
47
- }
48
- }));
45
+ : await Promise.all(Object.values(this.app.children).map(async (child) => await child.build.make().catch(error => {
46
+ throw error;
47
+ })));
48
+ this.config.parallelism = Math.min(cpus().length - 1, 1);
49
49
  await this.app.hooks.fire(`compiler.before`, this.app);
50
50
  this.logger.timeEnd(`initialize`);
51
- this.logger.await(`compilation`);
52
- this.instance = this.implementation(this.config);
51
+ try {
52
+ this.instance = this.implementation(this.config);
53
+ }
54
+ catch (error) {
55
+ throw BudError.normalize(error);
56
+ }
53
57
  this.instance.hooks.done.tap(this.app.label, async (stats) => {
54
58
  await this.onStats(stats);
55
- await this.app.hooks.fire(`compiler.close`, this.app);
59
+ await this.app.hooks
60
+ .fire(`compiler.done`, [this.app, this.stats])
61
+ .catch(error => {
62
+ throw error;
63
+ });
56
64
  });
57
- await this.app.hooks.fire(`compiler.after`, this.app);
58
65
  return this.instance;
59
66
  }
60
67
  /**
@@ -62,32 +69,21 @@ export class Compiler extends Service {
62
69
  */
63
70
  async onError(error) {
64
71
  process.exitCode = 1;
65
- await this.app.hooks.fire(`compiler.error`, error);
66
72
  this.app.isDevelopment &&
67
73
  this.app.server.appliedMiddleware?.hot?.publish({ error });
68
- try {
69
- this.app.notifier.notify({
70
- group: this.app.label,
71
- message: error.message,
72
- subtitle: error.name,
73
- });
74
- }
75
- catch (error) {
76
- this.logger.error(error);
77
- }
78
- try {
79
- Ink.render(_jsx(App.Error, { error: new CompilerError(error.message, {
80
- props: {
81
- details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
82
- docs: new URL(`https://bud.js.org/`),
83
- issues: new URL(`https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`),
84
- stack: error.stack,
85
- thrownBy: `webpack`,
86
- },
87
- }) }));
74
+ await this.app.hooks
75
+ .fire(`compiler.error`, error)
76
+ .catch(this.app.error);
77
+ this.app.notifier.notify({
78
+ group: this.app.label,
79
+ message: error.message,
80
+ subtitle: error.name,
81
+ });
82
+ if (`isBudError` in error) {
83
+ render(_jsx(Error, { error: error }));
88
84
  }
89
- catch (error) {
90
- throw BudError.normalize(error);
85
+ else {
86
+ render(_jsx(Error, { error: BudError.normalize(error) }));
91
87
  }
92
88
  }
93
89
  /**
@@ -97,16 +93,40 @@ export class Compiler extends Service {
97
93
  const makeNoticeTitle = (child) => this.app.label !== child.name
98
94
  ? `${this.app.label} (${child.name})`
99
95
  : child.name;
100
- this.stats = stats.toJson(this.app.hooks.filter(`build.stats`));
101
- await this.app.hooks.fire(`compiler.stats`, stats);
102
- const statsUpdate = this.app.dashboard.update(stats);
96
+ 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);
103
123
  if (stats.hasErrors()) {
104
124
  process.exitCode = 1;
105
- this.stats.children = this.stats.children?.map(child => ({
125
+ this.compilationStats.children = this.compilationStats.children?.map(child => ({
106
126
  ...child,
107
127
  errors: this.sourceErrors(child.errors),
108
128
  }));
109
- this.stats.children
129
+ this.compilationStats.children
110
130
  ?.filter(child => child.errorsCount > 0)
111
131
  .forEach(child => {
112
132
  try {
@@ -127,7 +147,7 @@ export class Compiler extends Service {
127
147
  }
128
148
  });
129
149
  }
130
- this.stats.children
150
+ this.compilationStats.children
131
151
  ?.filter(child => child.errorsCount === 0)
132
152
  .forEach(child => {
133
153
  try {
@@ -146,7 +166,16 @@ export class Compiler extends Service {
146
166
  this.logger.error(error);
147
167
  }
148
168
  });
149
- await statsUpdate;
169
+ }
170
+ /**
171
+ * {@link Service.register}
172
+ */
173
+ async register(bud) {
174
+ this.implementation = await this.app.module
175
+ .import(`webpack`, import.meta.url)
176
+ .catch(error => {
177
+ throw BudError.normalize(error);
178
+ });
150
179
  }
151
180
  /**
152
181
  * Parse errors from webpack stats
@@ -157,22 +186,21 @@ export class Compiler extends Service {
157
186
  try {
158
187
  const parseError = (error) => {
159
188
  let file;
160
- const modules = this.stats.children.flatMap(child => child.modules);
161
189
  const moduleIdent = error.moduleId ?? error.moduleName;
162
- const module = modules.find(module => module?.id === moduleIdent || module?.name === moduleIdent);
163
- if (!module) {
190
+ const module = this.compilationStats.children
191
+ .flatMap(child => child?.modules)
192
+ .find(module => module?.id === moduleIdent || module?.name === moduleIdent);
193
+ if (!module)
164
194
  return error;
165
- }
166
195
  if (module.nameForCondition) {
167
196
  file = module.nameForCondition;
168
197
  }
169
198
  else if (module.name) {
170
199
  file = this.app.path(`@src`, module.name);
171
200
  }
172
- if (!file) {
173
- return error;
174
- }
175
- return { ...error, file, name: module.name ?? error.name };
201
+ return !file
202
+ ? { ...error, name: module.name ?? error.name }
203
+ : { ...error, file, name: module.name ?? error.name };
176
204
  };
177
205
  return errors?.map(parseError).filter(Boolean);
178
206
  }
@@ -185,13 +213,13 @@ export class Compiler extends Service {
185
213
  __decorate([
186
214
  bind,
187
215
  __metadata("design:type", Function),
188
- __metadata("design:paramtypes", []),
216
+ __metadata("design:paramtypes", [Function]),
189
217
  __metadata("design:returntype", Promise)
190
218
  ], Compiler.prototype, "compile", null);
191
219
  __decorate([
192
220
  bind,
193
221
  __metadata("design:type", Function),
194
- __metadata("design:paramtypes", [Error]),
222
+ __metadata("design:paramtypes", [Object]),
195
223
  __metadata("design:returntype", Promise)
196
224
  ], Compiler.prototype, "onError", null);
197
225
  __decorate([
@@ -200,6 +228,12 @@ __decorate([
200
228
  __metadata("design:paramtypes", [Function]),
201
229
  __metadata("design:returntype", Promise)
202
230
  ], Compiler.prototype, "onStats", null);
231
+ __decorate([
232
+ bind,
233
+ __metadata("design:type", Function),
234
+ __metadata("design:paramtypes", [Function]),
235
+ __metadata("design:returntype", Promise)
236
+ ], Compiler.prototype, "register", null);
203
237
  __decorate([
204
238
  bind,
205
239
  __metadata("design:type", Function),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "2023.6.14-43",
3
+ "version": "2023.6.23-427",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -49,40 +49,29 @@
49
49
  ],
50
50
  "type": "module",
51
51
  "exports": {
52
- ".": {
53
- "import": "./lib/index.js",
54
- "default": "./lib/index.js"
55
- },
56
- "./types": {
57
- "import": "./lib/types.js",
58
- "default": "./lib/types.js"
59
- }
52
+ ".": "./lib/index.js"
60
53
  },
61
54
  "typesVersions": {
62
55
  "*": {
63
56
  ".": [
64
57
  "./lib/index.d.ts"
65
- ],
66
- "types": [
67
- "./lib/types.d.ts"
68
58
  ]
69
59
  }
70
60
  },
71
61
  "types": "./lib/index.d.ts",
72
62
  "module": "./lib/index.js",
73
63
  "devDependencies": {
74
- "@roots/bud-api": "2023.6.14-43",
64
+ "@roots/bud-api": "2023.6.23-427",
75
65
  "@skypack/package-check": "0.2.2",
76
66
  "@types/node": "18.16.16",
77
67
  "@types/react": "18.2.9"
78
68
  },
79
69
  "dependencies": {
80
- "@roots/bud-dashboard": "2023.6.14-43",
81
- "@roots/bud-framework": "2023.6.14-43",
82
- "@roots/bud-support": "2023.6.14-43",
70
+ "@roots/bud-dashboard": "2023.6.23-427",
71
+ "@roots/bud-framework": "2023.6.23-427",
72
+ "@roots/bud-support": "2023.6.23-427",
83
73
  "react": "18.2.0",
84
- "tslib": "2.5.3",
85
- "webpack": "5.86.0"
74
+ "tslib": "2.5.3"
86
75
  },
87
76
  "volta": {
88
77
  "extends": "../../../package.json"
package/src/index.ts CHANGED
@@ -2,15 +2,18 @@
2
2
  // Licensed under the MIT license.
3
3
 
4
4
  /**
5
- * The bud compiler interface
5
+ * @roots/bud-compiler
6
6
  *
7
7
  * @see https://bud.js.org
8
8
  * @see https://github.com/roots/bud
9
- *
10
- * @packageDocumentation
11
9
  */
12
10
 
13
- import {Compiler} from './compiler.service.js'
14
- import './types.js'
11
+ import {Compiler} from './service.js'
12
+
13
+ declare module '@roots/bud-framework' {
14
+ interface Services {
15
+ compiler: Compiler
16
+ }
17
+ }
15
18
 
16
- export default Compiler
19
+ export {Compiler as default}
@@ -1,34 +1,43 @@
1
1
  import type {Bud} from '@roots/bud-framework'
2
+ import type {Compiler as BudCompiler} from '@roots/bud-framework'
2
3
  import type {
4
+ Configuration,
3
5
  MultiCompiler,
4
6
  MultiStats,
7
+ Stats,
5
8
  StatsCompilation,
6
9
  StatsError,
7
10
  } from '@roots/bud-framework/config'
8
- import type {Compiler as Contract} from '@roots/bud-framework/services'
9
11
  import type {
10
12
  ErrorWithSourceFile,
11
13
  SourceFile,
12
14
  } from '@roots/bud-support/open'
13
15
 
14
- import * as App from '@roots/bud-dashboard/app'
16
+ import {Error} from '@roots/bud-dashboard/app'
15
17
  import {Service} from '@roots/bud-framework/service'
16
18
  import {bind} from '@roots/bud-support/decorators/bind'
17
- import {BudError, CompilerError} from '@roots/bud-support/errors'
19
+ import {BudError, type BudHandler} from '@roots/bud-support/errors'
18
20
  import {duration} from '@roots/bud-support/human-readable'
19
- import * as Ink from '@roots/bud-support/ink'
21
+ import {render} from '@roots/bud-support/ink'
20
22
  import stripAnsi from '@roots/bud-support/strip-ansi'
23
+ import webpack from '@roots/bud-support/webpack'
24
+ import {cpus} from 'node:os'
25
+ import process from 'node:process'
21
26
  import {pathToFileURL} from 'node:url'
22
- import webpack from 'webpack'
23
27
 
24
28
  /**
25
29
  * Wepback compilation controller class
26
30
  */
27
- export class Compiler extends Service implements Contract.Service {
31
+ export class Compiler extends Service implements BudCompiler {
32
+ /**
33
+ * Compilation stats
34
+ */
35
+ public compilationStats: StatsCompilation
36
+
28
37
  /**
29
38
  * Configuration
30
39
  */
31
- public config: Contract.Service[`config`] = []
40
+ public config: Array<Configuration> & {parallelism?: number} = []
32
41
 
33
42
  /**
34
43
  * Compiler implementation
@@ -38,53 +47,52 @@ export class Compiler extends Service implements Contract.Service {
38
47
  /**
39
48
  * Compiler instance
40
49
  */
41
- public instance: Contract.Service[`instance`]
50
+ public instance: BudCompiler[`instance`]
51
+
52
+ public label = `compiler`
42
53
 
43
54
  /**
44
- * Compilation stats
55
+ * Raw stats
45
56
  */
46
- public stats: Contract.Service[`stats`]
57
+ public stats: BudCompiler[`stats`]
47
58
 
48
59
  /**
49
60
  * Initiates compilation
50
61
  */
51
62
  @bind
52
- public async compile(): Promise<MultiCompiler> {
53
- const compilerPath = await this.app.module.resolve(
54
- `webpack`,
55
- import.meta.url,
56
- )
57
- this.implementation = await this.app.module.import(
58
- compilerPath,
59
- import.meta.url,
60
- )
61
- this.logger.log(`imported webpack`, this.implementation.version)
62
-
63
+ public async compile(bud: Bud): Promise<MultiCompiler> {
63
64
  this.config = !this.app.hasChildren
64
65
  ? [await this.app.build.make()]
65
66
  : await Promise.all(
66
- Object.values(this.app.children).map(async (child: Bud) => {
67
- try {
68
- return await child.build.make()
69
- } catch (error) {
70
- throw error
71
- }
72
- }),
67
+ Object.values(this.app.children).map(
68
+ async (child: Bud) =>
69
+ await child.build.make().catch(error => {
70
+ throw error
71
+ }),
72
+ ),
73
73
  )
74
74
 
75
+ this.config.parallelism = Math.min(cpus().length - 1, 1)
76
+
75
77
  await this.app.hooks.fire(`compiler.before`, this.app)
76
78
 
77
79
  this.logger.timeEnd(`initialize`)
78
80
 
79
- this.logger.await(`compilation`)
81
+ try {
82
+ this.instance = this.implementation(this.config)
83
+ } catch (error) {
84
+ throw BudError.normalize(error)
85
+ }
80
86
 
81
- this.instance = this.implementation(this.config)
82
87
  this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
83
88
  await this.onStats(stats)
84
- await this.app.hooks.fire(`compiler.close`, this.app)
85
- })
86
89
 
87
- await this.app.hooks.fire(`compiler.after`, this.app)
90
+ await this.app.hooks
91
+ .fire(`compiler.done`, [this.app, this.stats])
92
+ .catch(error => {
93
+ throw error
94
+ })
95
+ })
88
96
 
89
97
  return this.instance
90
98
  }
@@ -93,44 +101,26 @@ export class Compiler extends Service implements Contract.Service {
93
101
  * Compiler error event
94
102
  */
95
103
  @bind
96
- public async onError(error: Error) {
104
+ public async onError(error: BudHandler | webpack.WebpackError) {
97
105
  process.exitCode = 1
98
106
 
99
- await this.app.hooks.fire(`compiler.error`, error)
100
-
101
107
  this.app.isDevelopment &&
102
108
  this.app.server.appliedMiddleware?.hot?.publish({error})
103
109
 
104
- try {
105
- this.app.notifier.notify({
106
- group: this.app.label,
107
- message: error.message,
108
- subtitle: error.name,
109
- })
110
- } catch (error) {
111
- this.logger.error(error)
112
- }
110
+ await this.app.hooks
111
+ .fire(`compiler.error`, error)
112
+ .catch(this.app.error)
113
113
 
114
- try {
115
- Ink.render(
116
- <App.Error
117
- error={
118
- new CompilerError(error.message, {
119
- props: {
120
- details: `This error was thrown by the webpack compiler itself. It is not the same as a syntax error. It is likely a missing or unresolvable build dependency.`,
121
- docs: new URL(`https://bud.js.org/`),
122
- issues: new URL(
123
- `https://github.com/roots/bud/search?q=is:issue+"compiler" in:title`,
124
- ),
125
- stack: error.stack,
126
- thrownBy: `webpack`,
127
- },
128
- })
129
- }
130
- />,
131
- )
132
- } catch (error) {
133
- throw BudError.normalize(error)
114
+ this.app.notifier.notify({
115
+ group: this.app.label,
116
+ message: error.message,
117
+ subtitle: error.name,
118
+ })
119
+
120
+ if (`isBudError` in error) {
121
+ render(<Error error={error} />)
122
+ } else {
123
+ render(<Error error={BudError.normalize(error)} />)
134
124
  }
135
125
  }
136
126
 
@@ -138,27 +128,53 @@ export class Compiler extends Service implements Contract.Service {
138
128
  * Stats handler
139
129
  */
140
130
  @bind
141
- public async onStats(stats: MultiStats) {
131
+ public async onStats(stats: Stats & MultiStats) {
142
132
  const makeNoticeTitle = (child: StatsCompilation) =>
143
133
  this.app.label !== child.name
144
134
  ? `${this.app.label} (${child.name})`
145
135
  : child.name
146
136
 
147
- this.stats = stats.toJson(this.app.hooks.filter(`build.stats`))
148
-
149
- await this.app.hooks.fire(`compiler.stats`, stats)
137
+ this.stats = stats
138
+
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
+ })
150
164
 
151
- const statsUpdate = this.app.dashboard.update(stats)
165
+ this.app.dashboard.update(this.compilationStats)
152
166
 
153
167
  if (stats.hasErrors()) {
154
168
  process.exitCode = 1
155
169
 
156
- this.stats.children = this.stats.children?.map(child => ({
157
- ...child,
158
- errors: this.sourceErrors(child.errors),
159
- }))
170
+ this.compilationStats.children = this.compilationStats.children?.map(
171
+ child => ({
172
+ ...child,
173
+ errors: this.sourceErrors(child.errors),
174
+ }),
175
+ )
160
176
 
161
- this.stats.children
177
+ this.compilationStats.children
162
178
  ?.filter(child => child.errorsCount > 0)
163
179
  .forEach(child => {
164
180
  try {
@@ -179,7 +195,7 @@ export class Compiler extends Service implements Contract.Service {
179
195
  })
180
196
  }
181
197
 
182
- this.stats.children
198
+ this.compilationStats.children
183
199
  ?.filter(child => child.errorsCount === 0)
184
200
  .forEach(child => {
185
201
  try {
@@ -194,13 +210,24 @@ export class Compiler extends Service implements Contract.Service {
194
210
  subtitle: `Build successful`,
195
211
  title: makeNoticeTitle(child),
196
212
  })
213
+
197
214
  this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
198
215
  } catch (error) {
199
216
  this.logger.error(error)
200
217
  }
201
218
  })
219
+ }
202
220
 
203
- await statsUpdate
221
+ /**
222
+ * {@link Service.register}
223
+ */
224
+ @bind
225
+ public override async register(bud: Bud): Promise<any> {
226
+ this.implementation = await this.app.module
227
+ .import(`webpack`, import.meta.url)
228
+ .catch(error => {
229
+ throw BudError.normalize(error)
230
+ })
204
231
  }
205
232
 
206
233
  /**
@@ -218,17 +245,16 @@ export class Compiler extends Service implements Contract.Service {
218
245
  ): ErrorWithSourceFile | StatsError => {
219
246
  let file: SourceFile[`file`] | undefined
220
247
 
221
- const modules = this.stats.children.flatMap(child => child.modules)
222
248
  const moduleIdent = error.moduleId ?? error.moduleName
223
249
 
224
- const module = modules.find(
225
- module =>
226
- module?.id === moduleIdent || module?.name === moduleIdent,
227
- )
250
+ const module = this.compilationStats.children
251
+ .flatMap(child => child?.modules)
252
+ .find(
253
+ module =>
254
+ module?.id === moduleIdent || module?.name === moduleIdent,
255
+ )
228
256
 
229
- if (!module) {
230
- return error
231
- }
257
+ if (!module) return error
232
258
 
233
259
  if (module.nameForCondition) {
234
260
  file = module.nameForCondition
@@ -236,11 +262,9 @@ export class Compiler extends Service implements Contract.Service {
236
262
  file = this.app.path(`@src`, module.name)
237
263
  }
238
264
 
239
- if (!file) {
240
- return error
241
- }
242
-
243
- return {...error, file, name: module.name ?? error.name}
265
+ return !file
266
+ ? {...error, name: module.name ?? error.name}
267
+ : {...error, file, name: module.name ?? error.name}
244
268
  }
245
269
 
246
270
  return errors?.map(parseError).filter(Boolean)
@@ -1,42 +0,0 @@
1
- import type { MultiCompiler, MultiStats, StatsError } from '@roots/bud-framework/config';
2
- import type { Compiler as Contract } from '@roots/bud-framework/services';
3
- import type { ErrorWithSourceFile } from '@roots/bud-support/open';
4
- import { Service } from '@roots/bud-framework/service';
5
- import webpack from 'webpack';
6
- /**
7
- * Wepback compilation controller class
8
- */
9
- export declare class Compiler extends Service implements Contract.Service {
10
- /**
11
- * Configuration
12
- */
13
- config: Contract.Service[`config`];
14
- /**
15
- * Compiler implementation
16
- */
17
- implementation: typeof webpack;
18
- /**
19
- * Compiler instance
20
- */
21
- instance: Contract.Service[`instance`];
22
- /**
23
- * Compilation stats
24
- */
25
- stats: Contract.Service[`stats`];
26
- /**
27
- * Initiates compilation
28
- */
29
- compile(): Promise<MultiCompiler>;
30
- /**
31
- * Compiler error event
32
- */
33
- onError(error: Error): Promise<void>;
34
- /**
35
- * Stats handler
36
- */
37
- onStats(stats: MultiStats): Promise<void>;
38
- /**
39
- * Parse errors from webpack stats
40
- */
41
- sourceErrors(errors: Array<StatsError>): Array<ErrorWithSourceFile | StatsError>;
42
- }
package/lib/types.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export {};
2
- /**
3
- * @package @roots/bud-compiler
4
- */
package/lib/types.js DELETED
@@ -1,4 +0,0 @@
1
- export {};
2
- /**
3
- * @package @roots/bud-compiler
4
- */
@@ -1,67 +0,0 @@
1
- import {Bud, factory} from '@repo/test-kit'
2
- import {beforeEach, describe, expect, it, vi} from 'vitest'
3
-
4
- import Compiler from './index.js'
5
-
6
- describe(`@roots/bud-compiler`, function () {
7
- let bud: Bud
8
- let compiler: Compiler
9
-
10
- beforeEach(async () => {
11
- vi.clearAllMocks()
12
-
13
- bud = await factory({mode: `development`})
14
- compiler = new Compiler(() => bud)
15
- })
16
-
17
- it(`has compile fn`, () => {
18
- expect(compiler.compile).toBeInstanceOf(Function)
19
- })
20
-
21
- it(`should call logger.log`, async () => {
22
- const logSpy = vi.spyOn(compiler.logger, `log`)
23
- await compiler.compile()
24
- expect(logSpy).toHaveBeenCalled()
25
- })
26
-
27
- it(`should have config with array length 1`, async () => {
28
- await compiler.compile()
29
- expect(compiler.config).toHaveLength(1)
30
- })
31
-
32
- it(`should have config with array length 2 when hasChildren is true`, async () => {
33
- // @ts-ignore
34
- await bud.make(`foo`)
35
- await bud.make(`bar`)
36
-
37
- compiler.app.children = {
38
- foo: compiler.app,
39
- bar: compiler.app,
40
- }
41
-
42
- await compiler.compile()
43
- expect(compiler.config).toHaveLength(2)
44
- })
45
-
46
- it(`should set done tap`, async () => {
47
- try {
48
- await compiler.compile()
49
- expect(compiler.instance.hooks.done.tap).toHaveBeenCalledWith(
50
- `MOCK-dev-handle`,
51
- compiler.onStats,
52
- )
53
- } catch (e) {}
54
- })
55
-
56
- it(`has onStats fn`, () => {
57
- expect(compiler.onStats).toBeInstanceOf(Function)
58
- })
59
-
60
- it(`has error handler`, () => {
61
- expect(compiler.onError).toBeInstanceOf(Function)
62
- })
63
-
64
- it(`has close handler`, () => {
65
- expect(compiler.onError).toBeInstanceOf(Function)
66
- })
67
- })
package/src/types.ts DELETED
@@ -1,3 +0,0 @@
1
- /**
2
- * @package @roots/bud-compiler
3
- */