@roots/bud-compiler 2023.7.20-1957 → 2023.7.21-611

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.js CHANGED
@@ -9,6 +9,8 @@ import { bind } from '@roots/bud-support/decorators/bind';
9
9
  import { BudError } from '@roots/bud-support/errors';
10
10
  import { duration } from '@roots/bud-support/human-readable';
11
11
  import { render } from '@roots/bud-support/ink';
12
+ import isNull from '@roots/bud-support/lodash/isNull';
13
+ import isString from '@roots/bud-support/lodash/isString';
12
14
  import stripAnsi from '@roots/bud-support/strip-ansi';
13
15
  import webpack from '@roots/bud-support/webpack';
14
16
  /**
@@ -156,27 +158,38 @@ export class Compiler extends Service {
156
158
  if (!errors || !errors.length)
157
159
  return [];
158
160
  try {
159
- const parseError = (error) => {
161
+ return errors
162
+ ?.map((error) => {
160
163
  let file;
161
- const moduleIdent = error.moduleId ?? error.moduleName;
164
+ let module;
165
+ const ident = error.moduleId ?? error.moduleName;
162
166
  /**
163
167
  * In a perfect world webpack plugins would use the
164
168
  * `nameForCondition` property to identify the module.
165
169
  */
166
- let module = this.compilationStats.children
167
- .flatMap(child => child?.modules)
168
- .find(module => module?.id === moduleIdent || module?.name === moduleIdent);
170
+ if (ident) {
171
+ module = this.compilationStats.children
172
+ .flatMap(child => child?.modules)
173
+ .find(module => [module?.id, module?.name].includes(ident));
174
+ }
169
175
  /**
170
176
  * If the module is not found, we try to parse the error message
171
177
  */
172
- if (!moduleIdent) {
173
- const stylelintExtracted = error.message.match(/file:\/\/(.*)\x07(.*)\x1B]8;;/);
174
- if (stylelintExtracted?.[1]) {
175
- module = {
176
- name: stylelintExtracted[2] ?? stylelintExtracted[1],
177
- nameForCondition: stylelintExtracted[1],
178
- };
179
- }
178
+ if (!ident && error.message?.includes(`[stylelint]`)) {
179
+ // try to get the origin of the stylelint error,
180
+ // which is contained in the second line of the error message
181
+ const unparsedOrigin = error.message?.split(`\n`)?.[1];
182
+ // if the origin is not a string or too long, we return the error as-is
183
+ if (!isString(unparsedOrigin) || unparsedOrigin.length > 100)
184
+ return error;
185
+ // extract absolute path and context relative name of module
186
+ const styleError = unparsedOrigin.match(/file:\/\/(.*)\x07(.*)\x1B]8;;/);
187
+ if (isNull(styleError))
188
+ return error;
189
+ // get parts of matched error
190
+ const [, file, name] = styleError;
191
+ // return enriched error
192
+ return { ...error, file, name, nameForCondition: file };
180
193
  }
181
194
  /**
182
195
  * If the module is still not found, we return the error as-is
@@ -193,14 +206,13 @@ export class Compiler extends Service {
193
206
  else if (module.name) {
194
207
  file = this.app.path(`@src`, module.name);
195
208
  }
196
- return !file
197
- ? { ...error, name: module.name ?? error.name }
198
- : { ...error, file, name: module.name ?? error.name };
199
- };
200
- return errors?.map(parseError).filter(Boolean);
209
+ const name = module.name ?? error.name ?? `error`;
210
+ return { ...error, file, name };
211
+ })
212
+ .filter(Boolean);
201
213
  }
202
214
  catch (error) {
203
- this.logger.warn(`error parsing errors`, error);
215
+ this.logger.warn(`Problem parsing errors. This probably won't break anything but please report it: https://github.com/roots/bud/issues/new`, error);
204
216
  return errors;
205
217
  }
206
218
  }
@@ -244,16 +256,12 @@ const statsOptions = {
244
256
  cachedAssets: true,
245
257
  cachedModules: true,
246
258
  entrypoints: true,
247
- errorDetails: false,
248
259
  errors: true,
249
260
  errorsCount: true,
250
- errorStack: false,
251
261
  hash: true,
252
262
  modules: true,
253
263
  name: true,
254
264
  outputPath: true,
255
- reasons: false,
256
- runtime: true,
257
265
  timings: true,
258
266
  warnings: true,
259
267
  warningsCount: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-compiler",
3
- "version": "2023.7.20-1957",
3
+ "version": "2023.7.21-611",
4
4
  "description": "Compilation handler",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -61,15 +61,15 @@
61
61
  "types": "./lib/index.d.ts",
62
62
  "module": "./lib/index.js",
63
63
  "devDependencies": {
64
- "@roots/bud-api": "2023.7.20-1957",
64
+ "@roots/bud-api": "2023.7.21-611",
65
65
  "@skypack/package-check": "0.2.2",
66
66
  "@types/node": "18.16.19",
67
67
  "@types/react": "18.2.15"
68
68
  },
69
69
  "dependencies": {
70
- "@roots/bud-dashboard": "2023.7.20-1957",
71
- "@roots/bud-framework": "2023.7.20-1957",
72
- "@roots/bud-support": "2023.7.20-1957",
70
+ "@roots/bud-dashboard": "2023.7.21-611",
71
+ "@roots/bud-framework": "2023.7.21-611",
72
+ "@roots/bud-support": "2023.7.21-611",
73
73
  "react": "18.2.0",
74
74
  "tslib": "2.6.0"
75
75
  },
package/src/service.tsx CHANGED
@@ -23,6 +23,8 @@ import {bind} from '@roots/bud-support/decorators/bind'
23
23
  import {BudError, type BudErrorClass} from '@roots/bud-support/errors'
24
24
  import {duration} from '@roots/bud-support/human-readable'
25
25
  import {render} from '@roots/bud-support/ink'
26
+ import isNull from '@roots/bud-support/lodash/isNull'
27
+ import isString from '@roots/bud-support/lodash/isString'
26
28
  import stripAnsi from '@roots/bud-support/strip-ansi'
27
29
  import webpack from '@roots/bud-support/webpack'
28
30
 
@@ -210,63 +212,71 @@ export class Compiler extends Service implements BudCompiler {
210
212
  if (!errors || !errors.length) return []
211
213
 
212
214
  try {
213
- const parseError = (
214
- error: StatsError,
215
- ): ErrorWithSourceFile | StatsError => {
216
- let file: SourceFile[`file`] | undefined
217
-
218
- const moduleIdent = error.moduleId ?? error.moduleName
219
-
220
- /**
221
- * In a perfect world webpack plugins would use the
222
- * `nameForCondition` property to identify the module.
223
- */
224
- let module = this.compilationStats.children
225
- .flatMap(child => child?.modules)
226
- .find(
227
- module =>
228
- module?.id === moduleIdent || module?.name === moduleIdent,
229
- )
230
-
231
- /**
232
- * If the module is not found, we try to parse the error message
233
- */
234
- if (!moduleIdent) {
235
- const stylelintExtracted = error.message.match(
236
- /file:\/\/(.*)\x07(.*)\x1B]8;;/,
237
- )
238
-
239
- if (stylelintExtracted?.[1]) {
240
- module = {
241
- name: stylelintExtracted[2] ?? stylelintExtracted[1],
242
- nameForCondition: stylelintExtracted[1],
243
- }
215
+ return errors
216
+ ?.map((error: StatsError): ErrorWithSourceFile | StatsError => {
217
+ let file: SourceFile[`file`] | undefined
218
+ let module: undefined | Webpack.StatsModule
219
+
220
+ const ident = error.moduleId ?? error.moduleName
221
+
222
+ /**
223
+ * In a perfect world webpack plugins would use the
224
+ * `nameForCondition` property to identify the module.
225
+ */
226
+ if (ident) {
227
+ module = this.compilationStats.children
228
+ .flatMap(child => child?.modules)
229
+ .find(module => [module?.id, module?.name].includes(ident))
244
230
  }
245
- }
246
231
 
247
- /**
248
- * If the module is still not found, we return the error as-is
249
- */
250
- if (!module) return error
251
-
252
- /**
253
- * We'll prefer the `nameForCondition` property if it exists,
254
- * otherwise we'll use the `name` property.
255
- */
256
- if (module.nameForCondition) {
257
- file = module.nameForCondition
258
- } else if (module.name) {
259
- file = this.app.path(`@src`, module.name)
260
- }
232
+ /**
233
+ * If the module is not found, we try to parse the error message
234
+ */
235
+ if (!ident && error.message?.includes(`[stylelint]`)) {
236
+ // try to get the origin of the stylelint error,
237
+ // which is contained in the second line of the error message
238
+ const unparsedOrigin = error.message?.split(`\n`)?.[1]
239
+
240
+ // if the origin is not a string or too long, we return the error as-is
241
+ if (!isString(unparsedOrigin) || unparsedOrigin.length > 100)
242
+ return error
243
+
244
+ // extract absolute path and context relative name of module
245
+ const styleError = unparsedOrigin.match(
246
+ /file:\/\/(.*)\x07(.*)\x1B]8;;/,
247
+ )
248
+ if (isNull(styleError)) return error
249
+
250
+ // get parts of matched error
251
+ const [, file, name] = styleError
252
+ // return enriched error
253
+ return {...error, file, name, nameForCondition: file}
254
+ }
261
255
 
262
- return !file
263
- ? {...error, name: module.name ?? error.name}
264
- : {...error, file, name: module.name ?? error.name}
265
- }
256
+ /**
257
+ * If the module is still not found, we return the error as-is
258
+ */
259
+ if (!module) return error
260
+
261
+ /**
262
+ * We'll prefer the `nameForCondition` property if it exists,
263
+ * otherwise we'll use the `name` property.
264
+ */
265
+ if (module.nameForCondition) {
266
+ file = module.nameForCondition
267
+ } else if (module.name) {
268
+ file = this.app.path(`@src`, module.name)
269
+ }
266
270
 
267
- return errors?.map(parseError).filter(Boolean)
271
+ const name = module.name ?? error.name ?? `error`
272
+ return {...error, file, name}
273
+ })
274
+ .filter(Boolean)
268
275
  } catch (error) {
269
- this.logger.warn(`error parsing errors`, error)
276
+ this.logger.warn(
277
+ `Problem parsing errors. This probably won't break anything but please report it: https://github.com/roots/bud/issues/new`,
278
+ error,
279
+ )
270
280
  return errors
271
281
  }
272
282
  }
@@ -281,16 +291,12 @@ const statsOptions = {
281
291
  cachedAssets: true,
282
292
  cachedModules: true,
283
293
  entrypoints: true,
284
- errorDetails: false,
285
294
  errors: true,
286
295
  errorsCount: true,
287
- errorStack: false,
288
296
  hash: true,
289
297
  modules: true,
290
298
  name: true,
291
299
  outputPath: true,
292
- reasons: false,
293
- runtime: true,
294
300
  timings: true,
295
301
  warnings: true,
296
302
  warningsCount: true,