@roots/bud-compiler 2023.6.15-2014 → 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
+ }
@@ -8,11 +8,17 @@ import { duration } from '@roots/bud-support/human-readable';
8
8
  import { render } from '@roots/bud-support/ink';
9
9
  import stripAnsi from '@roots/bud-support/strip-ansi';
10
10
  import webpack from '@roots/bud-support/webpack';
11
+ import { cpus } from 'node:os';
12
+ import process from 'node:process';
11
13
  import { pathToFileURL } from 'node:url';
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,32 +31,21 @@ 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
37
- .resolve(`webpack`, import.meta.url)
38
- .catch(error => {
39
- throw BudError.normalize(error);
40
- });
41
- this.implementation = await this.app.module
42
- .import(compilerPath, import.meta.url)
43
- .catch(error => {
44
- throw BudError.normalize(error);
45
- })
46
- .finally(() => {
47
- this.logger.info(`imported webpack from ${compilerPath}`);
48
- });
42
+ async compile(bud) {
49
43
  this.config = !this.app.hasChildren
50
44
  ? [await this.app.build.make()]
51
45
  : await Promise.all(Object.values(this.app.children).map(async (child) => await child.build.make().catch(error => {
52
46
  throw error;
53
47
  })));
48
+ this.config.parallelism = Math.min(cpus().length - 1, 1);
54
49
  await this.app.hooks.fire(`compiler.before`, this.app);
55
50
  this.logger.timeEnd(`initialize`);
56
51
  try {
@@ -62,14 +57,9 @@ export class Compiler extends Service {
62
57
  this.instance.hooks.done.tap(this.app.label, async (stats) => {
63
58
  await this.onStats(stats);
64
59
  await this.app.hooks
65
- .fire(`compiler.after`, this.app)
60
+ .fire(`compiler.done`, [this.app, this.stats])
66
61
  .catch(error => {
67
- this.logger.error(error);
68
- });
69
- await this.app.hooks
70
- .fire(`compiler.close`, this.app)
71
- .catch(error => {
72
- this.logger.error(error);
62
+ throw error;
73
63
  });
74
64
  });
75
65
  return this.instance;
@@ -78,21 +68,23 @@ export class Compiler extends Service {
78
68
  * Compiler error event
79
69
  */
80
70
  async onError(error) {
81
- global.process.exitCode = 1;
71
+ process.exitCode = 1;
82
72
  this.app.isDevelopment &&
83
73
  this.app.server.appliedMiddleware?.hot?.publish({ error });
84
- // @eslint-disable-next-line no-console
85
- render(_jsx(Error, { ...new BudError(error.message, {
86
- props: {
87
- error: BudError.normalize(error),
88
- },
89
- }) }));
90
- await this.app.hooks.fire(`compiler.error`, error);
74
+ await this.app.hooks
75
+ .fire(`compiler.error`, error)
76
+ .catch(this.app.error);
91
77
  this.app.notifier.notify({
92
78
  group: this.app.label,
93
79
  message: error.message,
94
80
  subtitle: error.name,
95
81
  });
82
+ if (`isBudError` in error) {
83
+ render(_jsx(Error, { error: error }));
84
+ }
85
+ else {
86
+ render(_jsx(Error, { error: BudError.normalize(error) }));
87
+ }
96
88
  }
97
89
  /**
98
90
  * Stats handler
@@ -101,16 +93,40 @@ export class Compiler extends Service {
101
93
  const makeNoticeTitle = (child) => this.app.label !== child.name
102
94
  ? `${this.app.label} (${child.name})`
103
95
  : child.name;
104
- this.stats = stats.toJson(this.app.hooks.filter(`build.stats`));
105
- await this.app.hooks.fire(`compiler.stats`, stats);
106
- 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);
107
123
  if (stats.hasErrors()) {
108
124
  process.exitCode = 1;
109
- this.stats.children = this.stats.children?.map(child => ({
125
+ this.compilationStats.children = this.compilationStats.children?.map(child => ({
110
126
  ...child,
111
127
  errors: this.sourceErrors(child.errors),
112
128
  }));
113
- this.stats.children
129
+ this.compilationStats.children
114
130
  ?.filter(child => child.errorsCount > 0)
115
131
  .forEach(child => {
116
132
  try {
@@ -131,7 +147,7 @@ export class Compiler extends Service {
131
147
  }
132
148
  });
133
149
  }
134
- this.stats.children
150
+ this.compilationStats.children
135
151
  ?.filter(child => child.errorsCount === 0)
136
152
  .forEach(child => {
137
153
  try {
@@ -150,7 +166,16 @@ export class Compiler extends Service {
150
166
  this.logger.error(error);
151
167
  }
152
168
  });
153
- 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
+ });
154
179
  }
155
180
  /**
156
181
  * Parse errors from webpack stats
@@ -161,9 +186,10 @@ export class Compiler extends Service {
161
186
  try {
162
187
  const parseError = (error) => {
163
188
  let file;
164
- const modules = this.stats.children.flatMap(child => child.modules);
165
189
  const moduleIdent = error.moduleId ?? error.moduleName;
166
- const module = modules.find(module => module?.id === moduleIdent || module?.name === moduleIdent);
190
+ const module = this.compilationStats.children
191
+ .flatMap(child => child?.modules)
192
+ .find(module => module?.id === moduleIdent || module?.name === moduleIdent);
167
193
  if (!module)
168
194
  return error;
169
195
  if (module.nameForCondition) {
@@ -172,10 +198,9 @@ export class Compiler extends Service {
172
198
  else if (module.name) {
173
199
  file = this.app.path(`@src`, module.name);
174
200
  }
175
- if (!file) {
176
- return error;
177
- }
178
- 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 };
179
204
  };
180
205
  return errors?.map(parseError).filter(Boolean);
181
206
  }
@@ -188,13 +213,13 @@ export class Compiler extends Service {
188
213
  __decorate([
189
214
  bind,
190
215
  __metadata("design:type", Function),
191
- __metadata("design:paramtypes", []),
216
+ __metadata("design:paramtypes", [Function]),
192
217
  __metadata("design:returntype", Promise)
193
218
  ], Compiler.prototype, "compile", null);
194
219
  __decorate([
195
220
  bind,
196
221
  __metadata("design:type", Function),
197
- __metadata("design:paramtypes", [webpack.WebpackError]),
222
+ __metadata("design:paramtypes", [Object]),
198
223
  __metadata("design:returntype", Promise)
199
224
  ], Compiler.prototype, "onError", null);
200
225
  __decorate([
@@ -203,6 +228,12 @@ __decorate([
203
228
  __metadata("design:paramtypes", [Function]),
204
229
  __metadata("design:returntype", Promise)
205
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);
206
237
  __decorate([
207
238
  bind,
208
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.15-2014",
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.15-2014",
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.15-2014",
81
- "@roots/bud-framework": "2023.6.15-2014",
82
- "@roots/bud-support": "2023.6.15-2014",
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,11 +1,13 @@
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,
@@ -14,21 +16,28 @@ import type {
14
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} 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
21
  import {render} from '@roots/bud-support/ink'
20
22
  import stripAnsi from '@roots/bud-support/strip-ansi'
21
23
  import webpack from '@roots/bud-support/webpack'
24
+ import {cpus} from 'node:os'
25
+ import process from 'node:process'
22
26
  import {pathToFileURL} from 'node:url'
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,33 +47,20 @@ 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
54
- .resolve(`webpack`, import.meta.url)
55
- .catch(error => {
56
- throw BudError.normalize(error)
57
- })
58
-
59
- this.implementation = await this.app.module
60
- .import(compilerPath, import.meta.url)
61
- .catch(error => {
62
- throw BudError.normalize(error)
63
- })
64
- .finally(() => {
65
- this.logger.info(`imported webpack from ${compilerPath}`)
66
- })
67
-
63
+ public async compile(bud: Bud): Promise<MultiCompiler> {
68
64
  this.config = !this.app.hasChildren
69
65
  ? [await this.app.build.make()]
70
66
  : await Promise.all(
@@ -76,6 +72,8 @@ export class Compiler extends Service implements Contract.Service {
76
72
  ),
77
73
  )
78
74
 
75
+ this.config.parallelism = Math.min(cpus().length - 1, 1)
76
+
79
77
  await this.app.hooks.fire(`compiler.before`, this.app)
80
78
 
81
79
  this.logger.timeEnd(`initialize`)
@@ -88,16 +86,11 @@ export class Compiler extends Service implements Contract.Service {
88
86
 
89
87
  this.instance.hooks.done.tap(this.app.label, async (stats: any) => {
90
88
  await this.onStats(stats)
91
- await this.app.hooks
92
- .fire(`compiler.after`, this.app)
93
- .catch(error => {
94
- this.logger.error(error)
95
- })
96
89
 
97
90
  await this.app.hooks
98
- .fire(`compiler.close`, this.app)
91
+ .fire(`compiler.done`, [this.app, this.stats])
99
92
  .catch(error => {
100
- this.logger.error(error)
93
+ throw error
101
94
  })
102
95
  })
103
96
 
@@ -108,57 +101,80 @@ export class Compiler extends Service implements Contract.Service {
108
101
  * Compiler error event
109
102
  */
110
103
  @bind
111
- public async onError(error: webpack.WebpackError) {
112
- global.process.exitCode = 1
104
+ public async onError(error: BudHandler | webpack.WebpackError) {
105
+ process.exitCode = 1
113
106
 
114
107
  this.app.isDevelopment &&
115
108
  this.app.server.appliedMiddleware?.hot?.publish({error})
116
109
 
117
- // @eslint-disable-next-line no-console
118
- render(
119
- <Error
120
- {...new BudError(error.message, {
121
- props: {
122
- error: BudError.normalize(error),
123
- },
124
- })}
125
- />,
126
- )
127
-
128
- await this.app.hooks.fire(`compiler.error`, error)
110
+ await this.app.hooks
111
+ .fire(`compiler.error`, error)
112
+ .catch(this.app.error)
129
113
 
130
114
  this.app.notifier.notify({
131
115
  group: this.app.label,
132
116
  message: error.message,
133
117
  subtitle: error.name,
134
118
  })
119
+
120
+ if (`isBudError` in error) {
121
+ render(<Error error={error} />)
122
+ } else {
123
+ render(<Error error={BudError.normalize(error)} />)
124
+ }
135
125
  }
136
126
 
137
127
  /**
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,13 +245,14 @@ 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
257
  if (!module) return error
230
258
 
@@ -234,11 +262,9 @@ export class Compiler extends Service implements Contract.Service {
234
262
  file = this.app.path(`@src`, module.name)
235
263
  }
236
264
 
237
- if (!file) {
238
- return error
239
- }
240
-
241
- 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}
242
268
  }
243
269
 
244
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 '@roots/bud-support/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: webpack.WebpackError): 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
- */