@vercel/build-utils
Advanced tools
Comparing version 2.4.0 to 2.4.1-canary.0
@@ -34,2 +34,7 @@ /** | ||
} | ||
export declare function getPrettyError(obj: { | ||
dataPath?: string; | ||
message?: string; | ||
params: any; | ||
}): NowBuildError; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NowBuildError = void 0; | ||
exports.getPrettyError = exports.NowBuildError = void 0; | ||
/** | ||
@@ -19,1 +19,69 @@ * This error should be thrown from a Builder in | ||
exports.NowBuildError = NowBuildError; | ||
function getPrettyError(obj) { | ||
const docsUrl = 'https://vercel.com/docs/configuration'; | ||
try { | ||
const { dataPath, params, message: ajvMessage } = obj; | ||
const prop = getTopLevelPropertyName(dataPath); | ||
let message = dataPath && dataPath.startsWith('.') ? `\`${dataPath.slice(1)}\` ` : ''; | ||
if (params && typeof params.additionalProperty === 'string') { | ||
const suggestion = getSuggestion(prop, params.additionalProperty); | ||
message += `should NOT have additional property \`${params.additionalProperty}\`. ${suggestion}`; | ||
} | ||
else if (params && typeof params.missingProperty === 'string') { | ||
message += `missing required property \`${params.missingProperty}\`.`; | ||
} | ||
else { | ||
message += `${ajvMessage}.`; | ||
} | ||
return new NowBuildError({ | ||
code: 'DEV_VALIDATE_CONFIG', | ||
message: message, | ||
link: prop ? `${docsUrl}#project/${prop.toLowerCase()}` : docsUrl, | ||
action: 'View Documentation', | ||
}); | ||
} | ||
catch (e) { | ||
return new NowBuildError({ | ||
code: 'DEV_VALIDATE_CONFIG', | ||
message: `Failed to validate configuration.`, | ||
link: docsUrl, | ||
action: 'View Documentation', | ||
}); | ||
} | ||
} | ||
exports.getPrettyError = getPrettyError; | ||
/** | ||
* Get the top level property from the dataPath. | ||
* `.cleanUrls` => `cleanUrls` | ||
* `.headers[0].source` => `headers` | ||
* `.headers[0].headers[0]` => `headers` | ||
* `` => `` | ||
*/ | ||
function getTopLevelPropertyName(dataPath) { | ||
if (dataPath && dataPath.startsWith('.')) { | ||
const lastIndex = dataPath.indexOf('['); | ||
return lastIndex > -1 ? dataPath.slice(1, lastIndex) : dataPath.slice(1); | ||
} | ||
return ''; | ||
} | ||
const mapTypoToSuggestion = { | ||
'': { | ||
builder: 'builds', | ||
'build.env': '{ "build": { "env": {"name": "value"} } }', | ||
'builds.env': '{ "build": { "env": {"name": "value"} } }', | ||
}, | ||
rewrites: { src: 'source', dest: 'destination' }, | ||
redirects: { src: 'source', dest: 'destination', status: 'statusCode' }, | ||
headers: { src: 'source', header: 'headers' }, | ||
routes: { | ||
source: 'src', | ||
destination: 'dest', | ||
header: 'headers', | ||
method: 'methods', | ||
}, | ||
}; | ||
function getSuggestion(topLevelProp, additionalProperty) { | ||
const choices = mapTypoToSuggestion[topLevelProp]; | ||
const choice = choices ? choices[additionalProperty] : undefined; | ||
return choice ? `Did you mean \`${choice}\`?` : 'Please remove it.'; | ||
} |
{ | ||
"name": "@vercel/build-utils", | ||
"version": "2.4.0", | ||
"version": "2.4.1-canary.0", | ||
"license": "MIT", | ||
@@ -51,3 +51,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "63cc9009c893612dcfb95f4d8c450523eab270fb" | ||
"gitHead": "49e2274d81c46a97449eb1c4b50ce30a632681e1" | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1244974
30585
1