@netlify/build 28.0.0-beta → 29.0.0-rc

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/src/core/main.js CHANGED
@@ -1,29 +1,12 @@
1
- /* eslint-disable max-lines, import/max-dependencies */
2
1
  import { handleBuildError } from '../error/handle.js'
3
- import { getErrorInfo } from '../error/info.js'
4
- import { startErrorMonitor } from '../error/monitor/start.js'
5
- import { getBufferLogs } from '../log/logger.js'
6
- import { logBuildStart, logTimer, logBuildSuccess } from '../log/messages/core.js'
7
- import { loadPlugins } from '../plugins/load.js'
8
- import { getPluginsOptions } from '../plugins/options.js'
9
- import { pinPlugins } from '../plugins/pinned_version.js'
10
- import { startPlugins, stopPlugins } from '../plugins/spawn.js'
11
- import { addCorePlugins } from '../plugins_core/add.js'
12
- import { reportStatuses } from '../status/report.js'
13
- import { getSteps } from '../steps/get.js'
14
- import { runSteps } from '../steps/run_steps.js'
2
+ import { logTimer, logBuildSuccess } from '../log/messages/core.js'
15
3
  import { trackBuildComplete } from '../telemetry/main.js'
16
- import { initTimers, measureDuration } from '../time/main.js'
17
4
  import { reportTimers } from '../time/report.js'
18
5
 
19
- import { getConfigOpts, loadConfig } from './config.js'
20
- import { getConstants } from './constants.js'
21
- import { doDryRun } from './dry.js'
22
- import { warnOnLingeringProcesses } from './lingering.js'
23
- import { warnOnMissingSideFiles } from './missing_side_file.js'
24
- import { normalizeFlags } from './normalize_flags.js'
6
+ import { execBuild, startBuild } from './build.js'
25
7
  import { getSeverity } from './severity.js'
26
8
 
9
+ export { startDev } from './dev.js'
27
10
  export { runCoreSteps } from '../steps/run_core_steps.js'
28
11
 
29
12
  /**
@@ -57,6 +40,7 @@ export default async function buildSite(flags = {}) {
57
40
  mode,
58
41
  logs,
59
42
  debug,
43
+ systemLogFile,
60
44
  testOpts,
61
45
  statsdOpts,
62
46
  dry,
@@ -80,6 +64,7 @@ export default async function buildSite(flags = {}) {
80
64
  } = await execBuild({
81
65
  ...flagsA,
82
66
  buildId,
67
+ systemLogFile,
83
68
  deployId,
84
69
  dry,
85
70
  errorMonitor,
@@ -133,517 +118,6 @@ export default async function buildSite(flags = {}) {
133
118
  }
134
119
  }
135
120
 
136
- // Performed on build start. Must be kept small and unlikely to fail since it
137
- // does not have proper error handling. Error handling relies on `errorMonitor`
138
- // being built, which relies itself on flags being normalized.
139
- const startBuild = function (flags) {
140
- const timers = initTimers()
141
-
142
- const logs = getBufferLogs(flags)
143
- logBuildStart(logs)
144
-
145
- const { bugsnagKey, ...flagsA } = normalizeFlags(flags, logs)
146
- const errorMonitor = startErrorMonitor({ flags: flagsA, logs, bugsnagKey })
147
-
148
- return { ...flagsA, errorMonitor, logs, timers }
149
- }
150
-
151
- const tExecBuild = async function ({
152
- config,
153
- defaultConfig,
154
- cachedConfig,
155
- cachedConfigPath,
156
- cwd,
157
- repositoryRoot,
158
- apiHost,
159
- token,
160
- siteId,
161
- context,
162
- branch,
163
- baseRelDir,
164
- env: envOpt,
165
- debug,
166
- verbose,
167
- nodePath,
168
- functionsDistDir,
169
- edgeFunctionsDistDir,
170
- cacheDir,
171
- dry,
172
- mode,
173
- offline,
174
- deployId,
175
- buildId,
176
- testOpts,
177
- errorMonitor,
178
- errorParams,
179
- logs,
180
- timers,
181
- buildbotServerSocket,
182
- sendStatus,
183
- saveConfig,
184
- featureFlags,
185
- }) {
186
- const configOpts = getConfigOpts({
187
- config,
188
- defaultConfig,
189
- cwd,
190
- repositoryRoot,
191
- apiHost,
192
- token,
193
- siteId,
194
- context,
195
- branch,
196
- baseRelDir,
197
- envOpt,
198
- mode,
199
- offline,
200
- deployId,
201
- buildId,
202
- testOpts,
203
- featureFlags,
204
- })
205
- const {
206
- netlifyConfig,
207
- configPath,
208
- headersPath,
209
- redirectsPath,
210
- buildDir,
211
- repositoryRoot: repositoryRootA,
212
- packageJson,
213
- userNodeVersion,
214
- childEnv,
215
- context: contextA,
216
- branch: branchA,
217
- token: tokenA,
218
- api,
219
- siteInfo,
220
- timers: timersA,
221
- } = await loadConfig({
222
- configOpts,
223
- cachedConfig,
224
- cachedConfigPath,
225
- envOpt,
226
- debug,
227
- logs,
228
- nodePath,
229
- timers,
230
- })
231
- const constants = await getConstants({
232
- configPath,
233
- buildDir,
234
- functionsDistDir,
235
- edgeFunctionsDistDir,
236
- cacheDir,
237
- netlifyConfig,
238
- siteInfo,
239
- apiHost,
240
- token: tokenA,
241
- mode,
242
- testOpts,
243
- })
244
- const pluginsOptions = addCorePlugins({ netlifyConfig, constants })
245
- // `errorParams` is purposely stateful
246
- // eslint-disable-next-line fp/no-mutating-assign
247
- Object.assign(errorParams, { netlifyConfig, pluginsOptions, siteInfo, childEnv, userNodeVersion })
248
-
249
- const {
250
- pluginsOptions: pluginsOptionsA,
251
- netlifyConfig: netlifyConfigA,
252
- stepsCount,
253
- timers: timersB,
254
- configMutations,
255
- } = await runAndReportBuild({
256
- pluginsOptions,
257
- netlifyConfig,
258
- configOpts,
259
- siteInfo,
260
- configPath,
261
- headersPath,
262
- redirectsPath,
263
- buildDir,
264
- repositoryRoot: repositoryRootA,
265
- nodePath,
266
- packageJson,
267
- userNodeVersion,
268
- childEnv,
269
- context: contextA,
270
- branch: branchA,
271
- dry,
272
- mode,
273
- api,
274
- errorMonitor,
275
- deployId,
276
- errorParams,
277
- logs,
278
- debug,
279
- verbose,
280
- timers: timersA,
281
- sendStatus,
282
- saveConfig,
283
- testOpts,
284
- buildbotServerSocket,
285
- constants,
286
- featureFlags,
287
- })
288
- return {
289
- pluginsOptions: pluginsOptionsA,
290
- netlifyConfig: netlifyConfigA,
291
- siteInfo,
292
- userNodeVersion,
293
- stepsCount,
294
- timers: timersB,
295
- configMutations,
296
- }
297
- }
298
-
299
- const execBuild = measureDuration(tExecBuild, 'total', { parentTag: 'build_site' })
300
-
301
- // Runs a build then report any plugin statuses
302
- const runAndReportBuild = async function ({
303
- pluginsOptions,
304
- netlifyConfig,
305
- configOpts,
306
- siteInfo,
307
- configPath,
308
- headersPath,
309
- redirectsPath,
310
- buildDir,
311
- repositoryRoot,
312
- nodePath,
313
- packageJson,
314
- userNodeVersion,
315
- childEnv,
316
- context,
317
- branch,
318
- buildbotServerSocket,
319
- constants,
320
- dry,
321
- mode,
322
- api,
323
- errorMonitor,
324
- deployId,
325
- errorParams,
326
- logs,
327
- debug,
328
- verbose,
329
- timers,
330
- sendStatus,
331
- saveConfig,
332
- testOpts,
333
- featureFlags,
334
- }) {
335
- try {
336
- const {
337
- stepsCount,
338
- netlifyConfig: netlifyConfigA,
339
- statuses,
340
- pluginsOptions: pluginsOptionsA,
341
- failedPlugins,
342
- timers: timersA,
343
- configMutations,
344
- } = await initAndRunBuild({
345
- pluginsOptions,
346
- netlifyConfig,
347
- configOpts,
348
- siteInfo,
349
- configPath,
350
- headersPath,
351
- redirectsPath,
352
- buildDir,
353
- repositoryRoot,
354
- nodePath,
355
- packageJson,
356
- userNodeVersion,
357
- childEnv,
358
- context,
359
- branch,
360
- dry,
361
- mode,
362
- api,
363
- errorMonitor,
364
- deployId,
365
- errorParams,
366
- logs,
367
- debug,
368
- verbose,
369
- timers,
370
- sendStatus,
371
- saveConfig,
372
- testOpts,
373
- buildbotServerSocket,
374
- constants,
375
- featureFlags,
376
- })
377
- await Promise.all([
378
- reportStatuses({
379
- statuses,
380
- childEnv,
381
- api,
382
- mode,
383
- pluginsOptions: pluginsOptionsA,
384
- netlifyConfig: netlifyConfigA,
385
- errorMonitor,
386
- deployId,
387
- logs,
388
- debug,
389
- sendStatus,
390
- testOpts,
391
- }),
392
- pinPlugins({
393
- pluginsOptions: pluginsOptionsA,
394
- failedPlugins,
395
- api,
396
- siteInfo,
397
- childEnv,
398
- mode,
399
- netlifyConfig: netlifyConfigA,
400
- errorMonitor,
401
- logs,
402
- debug,
403
- testOpts,
404
- sendStatus,
405
- }),
406
- ])
407
-
408
- return {
409
- pluginsOptions: pluginsOptionsA,
410
- netlifyConfig: netlifyConfigA,
411
- stepsCount,
412
- timers: timersA,
413
- configMutations,
414
- }
415
- } catch (error) {
416
- const [{ statuses }] = getErrorInfo(error)
417
- await reportStatuses({
418
- statuses,
419
- childEnv,
420
- api,
421
- mode,
422
- pluginsOptions,
423
- netlifyConfig,
424
- errorMonitor,
425
- deployId,
426
- logs,
427
- debug,
428
- sendStatus,
429
- testOpts,
430
- })
431
- throw error
432
- }
433
- }
434
-
435
- // Initialize plugin processes then runs a build
436
- const initAndRunBuild = async function ({
437
- pluginsOptions,
438
- netlifyConfig,
439
- configOpts,
440
- siteInfo,
441
- configPath,
442
- headersPath,
443
- redirectsPath,
444
- buildDir,
445
- repositoryRoot,
446
- nodePath,
447
- packageJson,
448
- userNodeVersion,
449
- childEnv,
450
- context,
451
- branch,
452
- dry,
453
- mode,
454
- api,
455
- errorMonitor,
456
- deployId,
457
- errorParams,
458
- logs,
459
- debug,
460
- verbose,
461
- sendStatus,
462
- saveConfig,
463
- timers,
464
- testOpts,
465
- buildbotServerSocket,
466
- constants,
467
- featureFlags,
468
- }) {
469
- const { pluginsOptions: pluginsOptionsA, timers: timersA } = await getPluginsOptions({
470
- pluginsOptions,
471
- netlifyConfig,
472
- siteInfo,
473
- buildDir,
474
- nodePath,
475
- packageJson,
476
- userNodeVersion,
477
- mode,
478
- api,
479
- logs,
480
- debug,
481
- sendStatus,
482
- timers,
483
- testOpts,
484
- featureFlags,
485
- })
486
- // eslint-disable-next-line fp/no-mutation, no-param-reassign
487
- errorParams.pluginsOptions = pluginsOptionsA
488
-
489
- const { childProcesses, timers: timersB } = await startPlugins({
490
- pluginsOptions: pluginsOptionsA,
491
- buildDir,
492
- childEnv,
493
- logs,
494
- debug,
495
- timers: timersA,
496
- })
497
-
498
- try {
499
- const {
500
- stepsCount,
501
- netlifyConfig: netlifyConfigA,
502
- statuses,
503
- failedPlugins,
504
- timers: timersC,
505
- configMutations,
506
- } = await runBuild({
507
- childProcesses,
508
- pluginsOptions: pluginsOptionsA,
509
- netlifyConfig,
510
- configOpts,
511
- packageJson,
512
- configPath,
513
- headersPath,
514
- redirectsPath,
515
- buildDir,
516
- repositoryRoot,
517
- nodePath,
518
- childEnv,
519
- context,
520
- branch,
521
- dry,
522
- buildbotServerSocket,
523
- constants,
524
- mode,
525
- api,
526
- errorMonitor,
527
- deployId,
528
- errorParams,
529
- logs,
530
- debug,
531
- verbose,
532
- saveConfig,
533
- timers: timersB,
534
- testOpts,
535
- featureFlags,
536
- })
537
-
538
- await Promise.all([
539
- warnOnMissingSideFiles({ buildDir, netlifyConfig: netlifyConfigA, logs }),
540
- warnOnLingeringProcesses({ mode, logs, testOpts }),
541
- ])
542
-
543
- return {
544
- stepsCount,
545
- netlifyConfig: netlifyConfigA,
546
- statuses,
547
- pluginsOptions: pluginsOptionsA,
548
- failedPlugins,
549
- timers: timersC,
550
- configMutations,
551
- }
552
- } finally {
553
- stopPlugins(childProcesses)
554
- }
555
- }
556
-
557
- // Load plugin main files, retrieve their event handlers then runs them,
558
- // together with the build command
559
- const runBuild = async function ({
560
- childProcesses,
561
- pluginsOptions,
562
- netlifyConfig,
563
- configOpts,
564
- packageJson,
565
- configPath,
566
- headersPath,
567
- redirectsPath,
568
- buildDir,
569
- repositoryRoot,
570
- nodePath,
571
- childEnv,
572
- context,
573
- branch,
574
- dry,
575
- buildbotServerSocket,
576
- constants,
577
- mode,
578
- api,
579
- errorMonitor,
580
- deployId,
581
- errorParams,
582
- logs,
583
- debug,
584
- verbose,
585
- saveConfig,
586
- timers,
587
- testOpts,
588
- featureFlags,
589
- }) {
590
- const { pluginsSteps, timers: timersA } = await loadPlugins({
591
- pluginsOptions,
592
- childProcesses,
593
- packageJson,
594
- timers,
595
- logs,
596
- debug,
597
- verbose,
598
- })
599
-
600
- const { steps, events } = getSteps(pluginsSteps)
601
-
602
- if (dry) {
603
- await doDryRun({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs })
604
- return { netlifyConfig }
605
- }
606
-
607
- const {
608
- stepsCount,
609
- netlifyConfig: netlifyConfigA,
610
- statuses,
611
- failedPlugins,
612
- timers: timersB,
613
- configMutations,
614
- } = await runSteps({
615
- steps,
616
- buildbotServerSocket,
617
- events,
618
- configPath,
619
- headersPath,
620
- redirectsPath,
621
- buildDir,
622
- repositoryRoot,
623
- nodePath,
624
- childEnv,
625
- context,
626
- branch,
627
- constants,
628
- mode,
629
- api,
630
- errorMonitor,
631
- deployId,
632
- errorParams,
633
- netlifyConfig,
634
- configOpts,
635
- logs,
636
- debug,
637
- verbose,
638
- saveConfig,
639
- timers: timersA,
640
- testOpts,
641
- featureFlags,
642
- })
643
-
644
- return { stepsCount, netlifyConfig: netlifyConfigA, statuses, failedPlugins, timers: timersB, configMutations }
645
- }
646
-
647
121
  // Logs and reports that a build successfully ended
648
122
  const handleBuildSuccess = async function ({ framework, dry, logs, timers, durationNs, statsdOpts }) {
649
123
  if (dry) {
@@ -689,4 +163,3 @@ const telemetryReport = async function ({
689
163
  await handleBuildError(error, errorParams)
690
164
  }
691
165
  }
692
- /* eslint-enable max-lines, import/max-dependencies */
@@ -53,6 +53,7 @@ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
53
53
  testOpts: {},
54
54
  featureFlags: DEFAULT_FEATURE_FLAGS,
55
55
  statsd: { port: DEFAULT_STATSD_PORT },
56
+ timeline: 'build',
56
57
  }
57
58
  }
58
59
 
@@ -3,7 +3,15 @@
3
3
  // them consistent
4
4
  export const normalizeGroupingMessage = function (message, type) {
5
5
  const messageA = removeDependenciesLogs(message, type)
6
- return NORMALIZE_REGEXPS.reduce(normalizeMessage, messageA)
6
+ const messageB = NORMALIZE_REGEXPS.reduce(normalizeMessage, messageA)
7
+
8
+ // If this is a functions bundling error, we'll use additional normalization
9
+ // rules to group errors more aggressively.
10
+ if (type === 'functionsBundling') {
11
+ return FUNCTIONS_BUNDLING_REGEXPS.reduce(normalizeMessage, messageB)
12
+ }
13
+
14
+ return messageB
7
15
  }
8
16
 
9
17
  // Discard debug/info installation information
@@ -32,9 +40,9 @@ const normalizeMessage = function (message, [regExp, replacement]) {
32
40
 
33
41
  const NORMALIZE_REGEXPS = [
34
42
  // Base64 URL
35
- [/(data:[^;]+;base64),[\w+/-]+/g, 'dataURI'],
43
+ [/(data:[^;]+;base64),[\w+/-=]+/g, 'dataURI'],
36
44
  // File paths
37
- [/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(["'`, ]|$)/gm, '$1/file/path$3'],
45
+ [/(["'`, ]|^)([^"'`, \n]*[/\\][^"'`, \n]*)(?=["'`, ]|$)/gm, '$1/file/path'],
38
46
  // Semantic versions
39
47
  [/\d+\.\d+\.\d+(-\d+)?/g, '1.0.0'],
40
48
  [/version "[^"]+"/g, 'version "1.0.0"'],
@@ -45,7 +53,7 @@ const NORMALIZE_REGEXPS = [
45
53
  // Numbers, e.g. number of issues/problems
46
54
  [/\d+/g, '0'],
47
55
  // Hexadecimal strings
48
- [/[\da-fA-F]{6,}/g, 'hex'],
56
+ [/[\da-fA-F-]{6,}/g, 'hex'],
49
57
  // On unknown inputs, we print the inputs
50
58
  [/(does not accept any inputs but you specified: ).*/, '$1'],
51
59
  [/(Unknown inputs for plugin).*/, '$1'],
@@ -75,3 +83,14 @@ const NORMALIZE_REGEXPS = [
75
83
  // Multiple empty lines
76
84
  [/^\s*$/gm, ''],
77
85
  ]
86
+
87
+ const FUNCTIONS_BUNDLING_REGEXPS = [
88
+ // String literals and identifiers
89
+ [/"([^"]+)"/g, '""'],
90
+ [/'([^']+)'/g, "''"],
91
+ [/`([^`]+)`/g, '``'],
92
+
93
+ // Rust crates
94
+ [/(?:Downloaded \S+ v[\d.]+\s*)+/gm, 'Downloaded crates'],
95
+ [/(?:Compiling \S+ v[\d.]+\s*)+/gm, 'Compiled crates'],
96
+ ]
@@ -21,7 +21,7 @@ export const reportBuildError = async function ({ error, errorMonitor, childEnv,
21
21
  const { errorInfo, type, severity, title, group = title } = parseErrorInfo(error)
22
22
  const severityA = getSeverity(severity, errorInfo)
23
23
  const groupA = getGroup(group, errorInfo)
24
- const groupingHash = getGroupingHash(groupA, error, type)
24
+ const groupingHash = getGroupingHash(groupA, error, type, errorInfo)
25
25
  const metadata = getMetadata(errorInfo, childEnv, groupingHash)
26
26
  const app = getApp()
27
27
  const eventProps = getEventProps({ severity: severityA, group: groupA, groupingHash, metadata, app })
@@ -52,7 +52,12 @@ const getGroup = function (group, errorInfo) {
52
52
  return group(errorInfo)
53
53
  }
54
54
 
55
- const getGroupingHash = function (group, error, type) {
55
+ const getGroupingHash = function (group, error, type, errorInfo = {}) {
56
+ // If the error has a `normalizedMessage`, we use it as the grouping hash.
57
+ if (errorInfo.normalizedMessage) {
58
+ return errorInfo.normalizedMessage
59
+ }
60
+
56
61
  const message = error instanceof Error && typeof error.message === 'string' ? error.message : String(error)
57
62
  const messageA = normalizeGroupingMessage(message, type)
58
63
  return `${group}\n${messageA}`
@@ -23,8 +23,12 @@ const getBuildCommandLocation = function ({ buildCommand, buildCommandOrigin })
23
23
  ${buildCommand}`
24
24
  }
25
25
 
26
- const getFunctionsBundlingLocation = function ({ functionName }) {
27
- return `While bundling Function "${functionName}"`
26
+ const getFunctionsBundlingLocation = function ({ functionName, functionType }) {
27
+ if (functionType === 'edge') {
28
+ return 'While bundling edge function'
29
+ }
30
+
31
+ return `While bundling function "${functionName}"`
28
32
  }
29
33
 
30
34
  const getCoreStepLocation = function ({ coreStepName }) {
package/src/error/type.js CHANGED
@@ -81,7 +81,14 @@ const TYPES = {
81
81
 
82
82
  // User error during Functions bundling
83
83
  functionsBundling: {
84
- title: ({ location: { functionName } }) => `Bundling of Function "${functionName}" failed`,
84
+ title: ({ location: { functionName, functionType } }) => {
85
+ if (functionType === 'edge') {
86
+ return 'Bundling of edge function failed'
87
+ }
88
+
89
+ return `Bundling of function "${functionName}" failed`
90
+ },
91
+ group: ({ location: { functionType = 'serverless' } }) => `Bundling of ${functionType} function failed`,
85
92
  stackType: 'none',
86
93
  locationType: 'functionsBundling',
87
94
  severity: 'info',