main() — react Function Reference
Architecture documentation for the main() function in extract-errors.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD f504b12d_ebae_cbda_099f_98be4eb41738["main()"] abf00c13_713e_105a_9a95_bf14e262ea5f["extract-errors.js"] f504b12d_ebae_cbda_099f_98be4eb41738 -->|defined in| abf00c13_713e_105a_9a95_bf14e262ea5f style f504b12d_ebae_cbda_099f_98be4eb41738 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
scripts/error-codes/extract-errors.js lines 7–69
async function main() {
const originalJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, '../error-codes/codes.json'))
);
const existingMessages = new Set();
const codes = Object.keys(originalJSON);
let nextCode = 0;
for (let i = 0; i < codes.length; i++) {
const codeStr = codes[i];
const message = originalJSON[codeStr];
const code = parseInt(codeStr, 10);
existingMessages.add(message);
if (code >= nextCode) {
nextCode = code + 1;
}
}
console.log('Searching `build` directory for unminified errors...\n');
let out;
try {
out = execSync(
"git --no-pager grep -n --untracked --no-exclude-standard '/*! <expected-error-format>' -- build"
).toString();
} catch (e) {
if (e.status === 1 && e.stdout.toString() === '') {
// No unminified errors found.
return;
}
throw e;
}
let newJSON = null;
const regex = /\<expected-error-format\>"(.+?)"\<\/expected-error-format\>/g;
do {
const match = regex.exec(out);
if (match === null) {
break;
} else {
const message = match[1].trim();
if (existingMessages.has(message)) {
// This probably means you ran the script twice.
continue;
}
existingMessages.add(message);
// Add to json map
if (newJSON === null) {
newJSON = Object.assign({}, originalJSON);
}
console.log(`"${nextCode}": "${message}"`);
newJSON[nextCode] = message;
nextCode += 1;
}
} while (true);
if (newJSON) {
fs.writeFileSync(
path.resolve(__dirname, '../error-codes/codes.json'),
JSON.stringify(newJSON, null, 2)
);
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does main() do?
main() is a function in the react codebase, defined in scripts/error-codes/extract-errors.js.
Where is main() defined?
main() is defined in scripts/error-codes/extract-errors.js at line 7.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free