mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 04:22:07 +00:00
Add type-check and unify tsconfig (#10667)
This adds a new `pnpm type-check` that leverages `turbo` to validate the TypeScript code. This can be run at the top-level or for an individual package. The `test-lint` workflow will run it after linting and doing the prettier check. As apart of this effort, each package's `tsconfig.json` has been simplified. There's a new top-level `tsconfig.base.json` file that extends the Vercel Style Guide for TypeScript. Each package's `tsconfig.json` has been audited and previously suppressed rules that no longer apply have been removed. The result is each package's `tsconfig.json` is greatly simplified and we can control common settings in the base config while keeping the flexibility of package-level overrides. Lastly, in `package/cli`, `pnpm build` calls `scripts/build.mjs` which calls `scripts/compile-templates.mjs`. The `compile-templates.mjs` file was generating invalid TypeScript code. I've fixed it and now it's happier than ever. Note: In order to run `pnpm type-check`, you must first `pnpm build` because we need the `.d.ts` definition files.
This commit is contained in:
@@ -28,36 +28,16 @@ export async function compileDevTemplates() {
|
||||
const interfaceName = def.match(/interface (\w+)/)[1];
|
||||
|
||||
const { default: fn } = await import(fnPath);
|
||||
const lines = fn.toString().split('\n');
|
||||
let errorHtmlStart = -1;
|
||||
let errorHtmlEnd = -1;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (errorHtmlStart === -1 && line.includes('encodeHTML')) {
|
||||
errorHtmlStart = i;
|
||||
} else if (errorHtmlEnd === -1 && line.includes(')();')) {
|
||||
errorHtmlEnd = i;
|
||||
}
|
||||
if (/\bvar\b/.test(line)) {
|
||||
lines[i] = line.replace(/\bvar\b/g, 'let');
|
||||
}
|
||||
}
|
||||
lines.splice(errorHtmlStart, errorHtmlEnd);
|
||||
|
||||
lines[0] = `export default ${lines[0].replace(
|
||||
'(it)',
|
||||
`(it: ${interfaceName}): string`
|
||||
)}`;
|
||||
const contents = `import encodeHTML from 'escape-html';
|
||||
|
||||
lines.unshift(
|
||||
"import encodeHTML from 'escape-html';",
|
||||
'',
|
||||
...def.split('\n')
|
||||
);
|
||||
${def}
|
||||
export default ${fn
|
||||
.toString()
|
||||
.replace(/var encodeHTML.+\(\)\);/s, '')
|
||||
.replace(/\bvar\b/g, 'let')
|
||||
.replace(/\(it\s*\)/s, `(it: ${interfaceName}): string`)}`;
|
||||
|
||||
await Promise.all([
|
||||
writeFile(new URL(tsPath), lines.join('\n')),
|
||||
unlink(fnPath),
|
||||
]);
|
||||
await Promise.all([writeFile(new URL(tsPath), contents), unlink(fnPath)]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user