-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathrenderer.ts
More file actions
160 lines (131 loc) · 6.57 KB
/
Copy pathrenderer.ts
File metadata and controls
160 lines (131 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import type {Sourcemap} from './interfaces'
import chalk from 'chalk'
import {ICONS} from '@datadog/datadog-ci-base/helpers/formatting'
import {UploadStatus} from '@datadog/datadog-ci-base/helpers/upload'
import {pluralize} from '@datadog/datadog-ci-base/helpers/utils'
type InjectionResult = {failed: number; injected: number; skipped: number}
export const renderPathNotFound = (path: string) => `Path does not exist: ${path}\n`
export const renderDiscoveryWarning = (message: string) => `WARN: ${message}\n`
export const renderNoSourcemapsFound = (basePath: string) => `No JavaScript sourcemaps found in ${basePath}.\n`
export const renderInjectionSummary = (result: InjectionResult, dryRun: boolean) =>
`${dryRun ? 'Would inject' : 'Injected'} debug IDs into ${result.injected} file(s); skipped ${result.skipped} file(s); failed ${result.failed} file(s).\n`
export const renderGitWarning = (errorMessage: string) =>
chalk.yellow(`${ICONS.WARNING} An error occurred while invoking git: ${errorMessage}
Make sure the command is running within your git repository to fully leverage Datadog's git integration.
To ignore this warning use the --disable-git flag.
You can also provide both --repository-url and --commit-sha (or DD_GIT_REPOSITORY_URL and DD_GIT_COMMIT_SHA) to use an alternative algorithm that does not require git.\n`)
export const renderGitDataNotAttachedWarning = (sourcemap: string, errorMessage: string) =>
chalk.yellow(`${ICONS.WARNING} Could not attach git data for sourcemap ${sourcemap}: ${errorMessage}\n`)
export const renderSourcesNotFoundWarning = (sourcemap: string) =>
chalk.yellow(`${ICONS.WARNING} No tracked files found for sources contained in ${sourcemap}\n`)
export const renderAbsolutePathWarning = (source: string) =>
chalk.yellow(`${ICONS.WARNING} Absolute path "${source}" is not supported and will be skipped\n`)
export const renderConfigurationError = (error: Error) => chalk.red(`${ICONS.FAILED} Configuration error: ${error}.\n`)
export const renderInvalidPrefix = chalk.red(
`${ICONS.FAILED} --minified-path-prefix should either be an URL (such as "http://example.com/static") or an absolute path starting with a / such as "/static"\n`
)
export const renderMinifiedPathPrefixMisusage = (sourcemap: Sourcemap, repeated: string) =>
chalk.yellow(
`${ICONS.WARNING} The --minified-path-prefix flag value "${sourcemap.minifiedPathPrefix}" seems to repeat "${repeated}" which is already present in the path "${sourcemap.relativePath}"\n`
)
export const renderFailedUpload = (sourcemap: Sourcemap, errorMessage: string) => {
const sourcemapPathBold = `[${chalk.bold.dim(sourcemap.sourcemapPath)}]`
return chalk.red(`${ICONS.FAILED} Failed upload sourcemap for ${sourcemapPathBold}: ${errorMessage}\n`)
}
export const renderNoDebugIdFound = () => 'No debug ID found in any minified file. Aborting upload.\n'
export const renderRetriedUpload = (payload: Sourcemap, errorMessage: string, attempt: number) => {
const sourcemapPathBold = `[${chalk.bold.dim(payload.sourcemapPath)}]`
return chalk.yellow(`[attempt ${attempt}] Retrying sourcemap upload ${sourcemapPathBold}: ${errorMessage}\n`)
}
export const renderSuccessfulCommand = (statuses: UploadStatus[], duration: number, dryRun: boolean) => {
const results = new Map<UploadStatus, number>()
statuses.forEach((status) => {
if (!results.has(status)) {
results.set(status, 0)
}
results.set(status, results.get(status)! + 1)
})
const output = ['', chalk.bold('Command summary:')]
if (results.get(UploadStatus.Failure)) {
output.push(chalk.red(`${ICONS.FAILED} Some sourcemaps have not been uploaded correctly.`))
} else if (results.get(UploadStatus.Skipped)) {
output.push(chalk.yellow(`${ICONS.WARNING} Some sourcemaps have been skipped.`))
} else if (results.get(UploadStatus.Success)) {
if (dryRun) {
output.push(
chalk.green(
`${ICONS.SUCCESS} [DRYRUN] Handled ${pluralize(
results.get(UploadStatus.Success)!,
'sourcemap',
'sourcemaps'
)} with success in ${duration} seconds.`
)
)
} else {
output.push(
chalk.green(
`${ICONS.SUCCESS} Uploaded ${pluralize(
results.get(UploadStatus.Success)!,
'sourcemap',
'sourcemaps'
)} in ${duration} seconds.`
)
)
}
} else {
output.push(chalk.yellow(`${ICONS.WARNING} No sourcemaps detected. Did you specify the correct directory?`))
}
if (results.get(UploadStatus.Failure) || results.get(UploadStatus.Skipped)) {
output.push(`Details about the ${pluralize(statuses.length, 'found sourcemap', 'found sourcemaps')}:`)
if (results.get(UploadStatus.Success)) {
output.push(
` * ${pluralize(results.get(UploadStatus.Success)!, 'sourcemap', 'sourcemaps')} successfully uploaded`
)
}
if (results.get(UploadStatus.Skipped)) {
output.push(
chalk.yellow(` * ${pluralize(results.get(UploadStatus.Skipped)!, 'sourcemap was', 'sourcemaps were')} skipped`)
)
}
if (results.get(UploadStatus.Failure)) {
output.push(
chalk.red(` * ${pluralize(results.get(UploadStatus.Failure)!, 'sourcemap', 'sourcemaps')} failed to upload`)
)
}
}
return output.join('\n') + '\n'
}
export const renderCommandInfo = (
basePath: string,
minifiedPathPrefix: string | undefined,
projectPath: string | undefined,
releaseVersion: string | undefined,
service: string | undefined,
debugId: boolean,
poolLimit: number,
dryRun: boolean
) => {
let fullStr = ''
if (dryRun) {
fullStr += chalk.yellow(`${ICONS.WARNING} DRY-RUN MODE ENABLED. WILL NOT UPLOAD SOURCEMAPS\n`)
}
fullStr += chalk.green(`Starting upload with concurrency ${poolLimit}. \n`)
fullStr += chalk.green(`Will look for sourcemaps in ${basePath}\n`)
if (minifiedPathPrefix) {
fullStr += chalk.green(`Will match JS files for errors on files starting with ${minifiedPathPrefix}\n`)
}
const metaParts = []
if (!debugId) {
metaParts.push(`${chalk.green('Version:')} ${chalk.cyan(releaseVersion)}`)
metaParts.push(`${chalk.green('Service:')} ${chalk.cyan(service)}`)
}
metaParts.push(
`${chalk.green('Project path:')} ${projectPath !== undefined ? chalk.cyan(projectPath) : chalk.dim('<empty>')}`
)
fullStr += metaParts.join(' · ') + '\n\n'
return fullStr
}
export const renderUpload = (sourcemap: Sourcemap): string => {
const debugIdSuffix = sourcemap.debugId ? ` (debug ID: ${sourcemap.debugId})` : ''
return `Uploading sourcemap ${sourcemap.sourcemapPath} for JS file available at ${sourcemap.minifiedUrl}${debugIdSuffix}\n`
}