@roots/bud-compiler 6.14.3 → 6.15.1

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 './service.js';
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
@@ -6,5 +6,5 @@
6
6
  * @see https://bud.js.org
7
7
  * @see https://github.com/roots/bud
8
8
  */
9
- import { Compiler } from './service.js';
9
+ import { default as Compiler } from '@roots/bud-compiler/service';
10
10
  export { Compiler as default };
@@ -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 { type BudHandler } from '@roots/bud-support/errors';
7
- import webpack from '@roots/bud-support/webpack';
8
6
  /**
9
7
  * {@link BudCompiler} implementation
10
8
  */
11
- export declare class Compiler extends Service implements BudCompiler {
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: BudHandler | webpack.WebpackError): void;
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,24 +1,21 @@
1
- import { __decorate, __metadata } from "tslib";
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';
11
+ import isNull from '@roots/bud-support/lodash/isNull';
12
+ import isNumber from '@roots/bud-support/lodash/isNumber';
13
+ import isString from '@roots/bud-support/lodash/isString';
12
14
  import stripAnsi from '@roots/bud-support/strip-ansi';
13
- import webpack from '@roots/bud-support/webpack';
14
15
  /**
15
16
  * {@link BudCompiler} implementation
16
17
  */
17
- export class Compiler extends Service {
18
- /**
19
- * {@link BudCompiler.compilationStats}
20
- */
21
- compilationStats;
18
+ class Compiler extends Service {
22
19
  /**
23
20
  * {@link BudCompiler.config}
24
21
  */
@@ -27,24 +24,18 @@ export class Compiler extends Service {
27
24
  * {@link BudCompiler.implementation}
28
25
  */
29
26
  implementation;
30
- /**
31
- * {@link BudCompiler.instance}
32
- */
33
- instance;
34
- /**
35
- * {@link BudCompiler.stats}
36
- */
37
- stats;
38
27
  /**
39
28
  * {@link BudCompiler.compile}
40
29
  */
41
30
  async compile(bud) {
42
- this.config = !bud.hasChildren
31
+ const config = !bud.hasChildren
43
32
  ? [await bud.build.make()]
44
- : await Promise.all(Object.values(bud.children).map(async (child) => await child.build.make().catch(error => {
33
+ : await Promise.all(Object.values(bud.children).map(async (child) => child.build.make().catch(error => {
45
34
  throw error;
46
35
  })));
47
- this.config.parallelism = Math.min(cpus().length - 1, 1);
36
+ this.config = config?.filter(Boolean);
37
+ this.config.parallelism = Math.max(cpus().length - 1, 1);
38
+ this.logger.info(`parallel compilations: ${this.config.parallelism}`);
48
39
  await bud.hooks.fire(`compiler.before`, bud).catch(error => {
49
40
  throw error;
50
41
  });
@@ -54,13 +45,12 @@ export class Compiler extends Service {
54
45
  this.instance = this.implementation(this.config);
55
46
  }
56
47
  catch (error) {
57
- throw BudError.normalize(error);
48
+ const normalError = error instanceof Error ? error : BudError.normalize(error);
49
+ this.onError(normalError);
58
50
  }
59
51
  this.instance.hooks.done.tap(bud.label, (stats) => {
60
52
  this.onStats(stats);
61
- bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
62
- throw error;
63
- });
53
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(this.onError);
64
54
  });
65
55
  return this.instance;
66
56
  }
@@ -69,6 +59,8 @@ export class Compiler extends Service {
69
59
  */
70
60
  onError(error) {
71
61
  process.exitCode = 1;
62
+ if (!error)
63
+ return;
72
64
  this.app.server?.appliedMiddleware?.hot?.publish({ error });
73
65
  this.app.notifier?.notify({
74
66
  group: this.app.label,
@@ -76,10 +68,10 @@ export class Compiler extends Service {
76
68
  subtitle: error.name,
77
69
  });
78
70
  if (`isBudError` in error) {
79
- render(_jsx(Error, { error: error }));
71
+ render(_jsx(DisplayError, { error: error }));
80
72
  }
81
73
  else {
82
- render(_jsx(Error, { error: BudError.normalize(error) }));
74
+ render(_jsx(DisplayError, { error: BudError.normalize(error) }));
83
75
  }
84
76
  }
85
77
  /**
@@ -96,10 +88,12 @@ export class Compiler extends Service {
96
88
  process.exitCode = 1;
97
89
  this.compilationStats.children = this.compilationStats.children?.map(child => ({
98
90
  ...child,
99
- errors: this.sourceErrors(child.errors),
91
+ errors: child.errors && this.sourceErrors
92
+ ? this.sourceErrors(child.errors)
93
+ : child.errors ?? [],
100
94
  }));
101
95
  this.compilationStats.children
102
- ?.filter(child => child.errorsCount > 0)
96
+ ?.filter(child => isNumber(child.errorsCount) && child.errorsCount > 0)
103
97
  .forEach(child => {
104
98
  try {
105
99
  const error = child.errors?.shift();
@@ -112,7 +106,7 @@ export class Compiler extends Service {
112
106
  subtitle: error.file ? `Error in ${error.name}` : error.name,
113
107
  title: makeNoticeTitle(child),
114
108
  });
115
- this.app.notifier.openEditor(error.file);
109
+ error.file && this.app.notifier.openEditor(error.file);
116
110
  }
117
111
  catch (error) {
118
112
  this.logger.error(error);
@@ -126,13 +120,14 @@ export class Compiler extends Service {
126
120
  this.app.notifier.notify({
127
121
  group: `${this.app.label}-${child.name}`,
128
122
  message: child.modules
129
- ? `${child.modules.length} modules compiled in ${duration(child.time)}`
130
- : `Compiled in ${duration(child.time)}`,
123
+ ? `${child.modules.length} modules compiled`
124
+ : `Modules compiled successfully`,
131
125
  open: this.app.server?.publicUrl.href,
132
126
  subtitle: `Build successful`,
133
127
  title: makeNoticeTitle(child),
134
128
  });
135
- this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
129
+ this.app.server?.publicUrl.href &&
130
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href);
136
131
  }
137
132
  catch (error) {
138
133
  this.logger.error(error);
@@ -153,61 +148,79 @@ export class Compiler extends Service {
153
148
  if (!errors || !errors.length)
154
149
  return [];
155
150
  try {
156
- const parseError = (error) => {
151
+ return errors
152
+ ?.map((error) => {
157
153
  let file;
158
- const moduleIdent = error.moduleId ?? error.moduleName;
159
- const module = this.compilationStats.children
160
- .flatMap(child => child?.modules)
161
- .find(module => module?.id === moduleIdent || module?.name === moduleIdent);
154
+ let module;
155
+ const ident = error.moduleId ?? error.moduleName;
156
+ /**
157
+ * In a perfect world webpack plugins would use the
158
+ * `nameForCondition` property to identify the module.
159
+ */
160
+ if (ident && this.compilationStats?.children) {
161
+ module = this.compilationStats.children
162
+ .flatMap(child => child?.modules)
163
+ .find(module => [module?.id, module?.name].includes(ident));
164
+ }
165
+ /**
166
+ * If the module is not found, we try to parse the error message
167
+ */
168
+ if (!ident && error.message?.includes(`[stylelint]`)) {
169
+ // try to get the origin of the stylelint error,
170
+ // which is contained in the second line of the error message
171
+ const unparsedOrigin = error.message?.split(`\n`)?.[1];
172
+ // if the origin is not a string or too long, we return the error as-is
173
+ if (!isString(unparsedOrigin) || unparsedOrigin.length > 100)
174
+ return error;
175
+ // extract absolute path and context relative name of module
176
+ const styleError = unparsedOrigin.match(/file:\/\/(.*)\x07(.*)\x1B]8;;/);
177
+ if (isNull(styleError))
178
+ return error;
179
+ // get parts of matched error
180
+ const [, file, name] = styleError;
181
+ // return enriched error
182
+ return { ...error, file, name, nameForCondition: file };
183
+ }
184
+ /**
185
+ * If the module is still not found, we return the error as-is
186
+ */
162
187
  if (!module)
163
188
  return error;
189
+ /**
190
+ * We'll prefer the `nameForCondition` property if it exists,
191
+ * otherwise we'll use the `name` property.
192
+ */
164
193
  if (module.nameForCondition) {
165
194
  file = module.nameForCondition;
166
195
  }
167
196
  else if (module.name) {
168
197
  file = this.app.path(`@src`, module.name);
169
198
  }
170
- return !file
171
- ? { ...error, name: module.name ?? error.name }
172
- : { ...error, file, name: module.name ?? error.name };
173
- };
174
- return errors?.map(parseError).filter(Boolean);
199
+ const name = module.name ?? error.name ?? `error`;
200
+ return { ...error, file, name };
201
+ })
202
+ .filter(Boolean);
175
203
  }
176
204
  catch (error) {
177
- this.app.warn(`error parsing errors`, error);
178
- return [];
205
+ this.logger.warn(`Problem parsing errors. This probably won't break anything but please report it: https://github.com/roots/bud/issues/new`, error);
206
+ return errors;
179
207
  }
180
208
  }
181
209
  }
182
210
  __decorate([
183
- bind,
184
- __metadata("design:type", Function),
185
- __metadata("design:paramtypes", [Function]),
186
- __metadata("design:returntype", Promise)
211
+ bind
187
212
  ], Compiler.prototype, "compile", null);
188
213
  __decorate([
189
- bind,
190
- __metadata("design:type", Function),
191
- __metadata("design:paramtypes", [Object]),
192
- __metadata("design:returntype", void 0)
214
+ bind
193
215
  ], Compiler.prototype, "onError", null);
194
216
  __decorate([
195
- bind,
196
- __metadata("design:type", Function),
197
- __metadata("design:paramtypes", [Function]),
198
- __metadata("design:returntype", void 0)
217
+ bind
199
218
  ], Compiler.prototype, "onStats", null);
200
219
  __decorate([
201
- bind,
202
- __metadata("design:type", Function),
203
- __metadata("design:paramtypes", [Function]),
204
- __metadata("design:returntype", Promise)
220
+ bind
205
221
  ], Compiler.prototype, "register", null);
206
222
  __decorate([
207
- bind,
208
- __metadata("design:type", Function),
209
- __metadata("design:paramtypes", [Array]),
210
- __metadata("design:returntype", Array)
223
+ bind
211
224
  ], Compiler.prototype, "sourceErrors", null);
212
225
  const statsOptions = {
213
226
  all: false,
@@ -221,16 +234,14 @@ const statsOptions = {
221
234
  errorDetails: false,
222
235
  errors: true,
223
236
  errorsCount: true,
224
- errorStack: false,
225
237
  hash: true,
226
238
  modules: true,
227
239
  name: true,
228
240
  outputPath: true,
229
- reasons: false,
230
- runtime: true,
231
241
  timings: true,
232
242
  warnings: true,
233
243
  warningsCount: true,
234
244
  },
235
245
  name: true,
236
246
  };
247
+ export { Compiler as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "6.14.3",
3
+ "version": "6.15.1",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -49,29 +49,33 @@
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": "6.14.3",
68
+ "@roots/bud-api": "6.15.1",
65
69
  "@skypack/package-check": "0.2.2",
66
- "@types/node": "18.16.18",
67
- "@types/react": "18.2.14"
70
+ "@types/node": "18.17.5",
71
+ "@types/react": "18.2.20"
68
72
  },
69
73
  "dependencies": {
70
- "@roots/bud-dashboard": "6.14.3",
71
- "@roots/bud-framework": "6.14.3",
72
- "@roots/bud-support": "6.14.3",
74
+ "@roots/bud-dashboard": "6.15.1",
75
+ "@roots/bud-framework": "6.15.1",
76
+ "@roots/bud-support": "6.15.1",
73
77
  "react": "18.2.0",
74
- "tslib": "2.6.0"
78
+ "tslib": "2.6.1"
75
79
  },
76
80
  "volta": {
77
81
  "extends": "../../../package.json"
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * @see https://github.com/roots/bud
9
9
  */
10
10
 
11
- import {Compiler} from './service.js'
11
+ import {default as Compiler} from '@roots/bud-compiler/service'
12
12
 
13
13
  declare module '@roots/bud-framework' {
14
14
  interface Services {
@@ -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,23 +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
- import {BudError, type BudHandler} from '@roots/bud-support/errors'
24
- import {duration} from '@roots/bud-support/human-readable'
23
+ import {BudError} from '@roots/bud-support/errors'
25
24
  import {render} from '@roots/bud-support/ink'
25
+ import isNull from '@roots/bud-support/lodash/isNull'
26
+ import isNumber from '@roots/bud-support/lodash/isNumber'
27
+ import isString from '@roots/bud-support/lodash/isString'
26
28
  import stripAnsi from '@roots/bud-support/strip-ansi'
27
- import webpack from '@roots/bud-support/webpack'
28
29
 
29
30
  /**
30
31
  * {@link BudCompiler} implementation
31
32
  */
32
- export class Compiler extends Service implements BudCompiler {
33
+ class Compiler extends Service implements BudCompiler {
33
34
  /**
34
35
  * {@link BudCompiler.compilationStats}
35
36
  */
36
- public compilationStats: BudCompiler[`compilationStats`]
37
+ public declare compilationStats: BudCompiler[`compilationStats`]
37
38
 
38
39
  /**
39
40
  * {@link BudCompiler.config}
@@ -48,29 +49,32 @@ export class Compiler extends Service implements BudCompiler {
48
49
  /**
49
50
  * {@link BudCompiler.instance}
50
51
  */
51
- public instance: BudCompiler[`instance`]
52
+ public declare instance: BudCompiler[`instance`]
52
53
 
53
54
  /**
54
55
  * {@link BudCompiler.stats}
55
56
  */
56
- public stats: BudCompiler[`stats`]
57
+ public declare stats: BudCompiler[`stats`]
57
58
 
58
59
  /**
59
60
  * {@link BudCompiler.compile}
60
61
  */
61
62
  @bind
62
63
  public async compile(bud: Bud): Promise<MultiCompiler> {
63
- this.config = !bud.hasChildren
64
+ const config = !bud.hasChildren
64
65
  ? [await bud.build.make()]
65
66
  : await Promise.all(
66
- Object.values(bud.children).map(
67
- async (child: Bud) =>
68
- await child.build.make().catch(error => {
69
- throw error
70
- }),
67
+ Object.values(bud.children).map(async (child: Bud) =>
68
+ child.build.make().catch(error => {
69
+ throw error
70
+ }),
71
71
  ),
72
72
  )
73
- this.config.parallelism = Math.min(cpus().length - 1, 1)
73
+
74
+ this.config = config?.filter(Boolean)
75
+
76
+ this.config.parallelism = Math.max(cpus().length - 1, 1)
77
+ this.logger.info(`parallel compilations: ${this.config.parallelism}`)
74
78
 
75
79
  await bud.hooks.fire(`compiler.before`, bud).catch(error => {
76
80
  throw error
@@ -81,16 +85,15 @@ export class Compiler extends Service implements BudCompiler {
81
85
 
82
86
  try {
83
87
  this.instance = this.implementation(this.config)
84
- } catch (error) {
85
- throw BudError.normalize(error)
88
+ } catch (error: unknown) {
89
+ const normalError =
90
+ error instanceof Error ? error : BudError.normalize(error)
91
+ this.onError(normalError)
86
92
  }
87
93
 
88
94
  this.instance.hooks.done.tap(bud.label, (stats: any) => {
89
95
  this.onStats(stats)
90
-
91
- bud.hooks.fire(`compiler.done`, bud, this.stats).catch(error => {
92
- throw error
93
- })
96
+ bud.hooks.fire(`compiler.done`, bud, this.stats).catch(this.onError)
94
97
  })
95
98
 
96
99
  return this.instance
@@ -100,8 +103,9 @@ export class Compiler extends Service implements BudCompiler {
100
103
  * {@link BudCompiler.onError}
101
104
  */
102
105
  @bind
103
- public onError(error: BudHandler | webpack.WebpackError) {
106
+ public onError(error: Error) {
104
107
  process.exitCode = 1
108
+ if (!error) return
105
109
 
106
110
  this.app.server?.appliedMiddleware?.hot?.publish({error})
107
111
 
@@ -112,9 +116,9 @@ export class Compiler extends Service implements BudCompiler {
112
116
  })
113
117
 
114
118
  if (`isBudError` in error) {
115
- render(<Error error={error} />)
119
+ render(<DisplayError error={error} />)
116
120
  } else {
117
- render(<Error error={BudError.normalize(error)} />)
121
+ render(<DisplayError error={BudError.normalize(error)} />)
118
122
  }
119
123
  }
120
124
 
@@ -140,12 +144,17 @@ export class Compiler extends Service implements BudCompiler {
140
144
  this.compilationStats.children = this.compilationStats.children?.map(
141
145
  child => ({
142
146
  ...child,
143
- errors: this.sourceErrors(child.errors),
147
+ errors:
148
+ child.errors && this.sourceErrors
149
+ ? this.sourceErrors(child.errors)
150
+ : child.errors ?? [],
144
151
  }),
145
152
  )
146
153
 
147
154
  this.compilationStats.children
148
- ?.filter(child => child.errorsCount > 0)
155
+ ?.filter(
156
+ child => isNumber(child.errorsCount) && child.errorsCount > 0,
157
+ )
149
158
  .forEach(child => {
150
159
  try {
151
160
  const error = child.errors?.shift()
@@ -158,7 +167,8 @@ export class Compiler extends Service implements BudCompiler {
158
167
  subtitle: error.file ? `Error in ${error.name}` : error.name,
159
168
  title: makeNoticeTitle(child),
160
169
  })
161
- this.app.notifier.openEditor(error.file)
170
+
171
+ error.file && this.app.notifier.openEditor(error.file)
162
172
  } catch (error) {
163
173
  this.logger.error(error)
164
174
  }
@@ -172,16 +182,15 @@ export class Compiler extends Service implements BudCompiler {
172
182
  this.app.notifier.notify({
173
183
  group: `${this.app.label}-${child.name}`,
174
184
  message: child.modules
175
- ? `${child.modules.length} modules compiled in ${duration(
176
- child.time,
177
- )}`
178
- : `Compiled in ${duration(child.time)}`,
185
+ ? `${child.modules.length} modules compiled`
186
+ : `Modules compiled successfully`,
179
187
  open: this.app.server?.publicUrl.href,
180
188
  subtitle: `Build successful`,
181
189
  title: makeNoticeTitle(child),
182
190
  })
183
191
 
184
- this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
192
+ this.app.server?.publicUrl.href &&
193
+ this.app.notifier.openBrowser(this.app.server?.publicUrl.href)
185
194
  } catch (error) {
186
195
  this.logger.error(error)
187
196
  }
@@ -202,42 +211,77 @@ export class Compiler extends Service implements BudCompiler {
202
211
 
203
212
  @bind
204
213
  public sourceErrors?(
205
- errors: Array<StatsError>,
214
+ errors: Array<StatsError> | undefined,
206
215
  ): Array<ErrorWithSourceFile | StatsError> {
207
216
  if (!errors || !errors.length) return []
208
217
 
209
218
  try {
210
- const parseError = (
211
- error: StatsError,
212
- ): ErrorWithSourceFile | StatsError => {
213
- let file: SourceFile[`file`] | undefined
214
-
215
- const moduleIdent = error.moduleId ?? error.moduleName
216
-
217
- const module = this.compilationStats.children
218
- .flatMap(child => child?.modules)
219
- .find(
220
- module =>
221
- module?.id === moduleIdent || module?.name === moduleIdent,
222
- )
223
-
224
- if (!module) return error
225
-
226
- if (module.nameForCondition) {
227
- file = module.nameForCondition
228
- } else if (module.name) {
229
- file = this.app.path(`@src`, module.name)
230
- }
219
+ return errors
220
+ ?.map((error: StatsError): ErrorWithSourceFile | StatsError => {
221
+ let file: SourceFile[`file`] | undefined
222
+ let module: undefined | Webpack.StatsModule
223
+
224
+ const ident = error.moduleId ?? error.moduleName
225
+
226
+ /**
227
+ * In a perfect world webpack plugins would use the
228
+ * `nameForCondition` property to identify the module.
229
+ */
230
+ if (ident && this.compilationStats?.children) {
231
+ module = this.compilationStats.children
232
+ .flatMap(child => child?.modules)
233
+ .find(module => [module?.id, module?.name].includes(ident))
234
+ }
235
+
236
+ /**
237
+ * If the module is not found, we try to parse the error message
238
+ */
239
+ if (!ident && error.message?.includes(`[stylelint]`)) {
240
+ // try to get the origin of the stylelint error,
241
+ // which is contained in the second line of the error message
242
+ const unparsedOrigin = error.message?.split(`\n`)?.[1]
243
+
244
+ // if the origin is not a string or too long, we return the error as-is
245
+ if (!isString(unparsedOrigin) || unparsedOrigin.length > 100)
246
+ return error
247
+
248
+ // extract absolute path and context relative name of module
249
+ const styleError = unparsedOrigin.match(
250
+ /file:\/\/(.*)\x07(.*)\x1B]8;;/,
251
+ )
252
+ if (isNull(styleError)) return error
253
+
254
+ // get parts of matched error
255
+ const [, file, name] = styleError
256
+ // return enriched error
257
+ return {...error, file, name, nameForCondition: file}
258
+ }
231
259
 
232
- return !file
233
- ? {...error, name: module.name ?? error.name}
234
- : {...error, file, name: module.name ?? error.name}
235
- }
260
+ /**
261
+ * If the module is still not found, we return the error as-is
262
+ */
263
+ if (!module) return error
264
+
265
+ /**
266
+ * We'll prefer the `nameForCondition` property if it exists,
267
+ * otherwise we'll use the `name` property.
268
+ */
269
+ if (module.nameForCondition) {
270
+ file = module.nameForCondition
271
+ } else if (module.name) {
272
+ file = this.app.path(`@src`, module.name)
273
+ }
236
274
 
237
- return errors?.map(parseError).filter(Boolean)
275
+ const name = module.name ?? error.name ?? `error`
276
+ return {...error, file, name}
277
+ })
278
+ .filter(Boolean)
238
279
  } catch (error) {
239
- this.app.warn(`error parsing errors`, error)
240
- return []
280
+ this.logger.warn(
281
+ `Problem parsing errors. This probably won't break anything but please report it: https://github.com/roots/bud/issues/new`,
282
+ error,
283
+ )
284
+ return errors
241
285
  }
242
286
  }
243
287
  }
@@ -254,16 +298,15 @@ const statsOptions = {
254
298
  errorDetails: false,
255
299
  errors: true,
256
300
  errorsCount: true,
257
- errorStack: false,
258
301
  hash: true,
259
302
  modules: true,
260
303
  name: true,
261
304
  outputPath: true,
262
- reasons: false,
263
- runtime: true,
264
305
  timings: true,
265
306
  warnings: true,
266
307
  warningsCount: true,
267
308
  },
268
309
  name: true,
269
310
  }
311
+
312
+ export {Compiler as default}