MCPcopy Create free account
hub / github.com/vercel/vercel / fixConfig

Function fixConfig

packages/node/src/typescript.ts:470–516  ·  view source on GitHub ↗
(
  config: { compilerOptions: any },
  nodeVersionMajor = 12
)

Source from the content-addressed store, hash-verified

468 * Do post-processing on config options to support `ts-node`.
469 */
470export function fixConfig(
471 config: { compilerOptions: any },
472 nodeVersionMajor = 12
473) {
474 if (!config.compilerOptions) {
475 config.compilerOptions = {};
476 }
477 // Delete options that *should not* be passed through.
478 delete config.compilerOptions.out;
479 delete config.compilerOptions.outFile;
480 delete config.compilerOptions.composite;
481 delete config.compilerOptions.declarationDir;
482 delete config.compilerOptions.declarationMap;
483 delete config.compilerOptions.emitDeclarationOnly;
484 delete config.compilerOptions.tsBuildInfoFile;
485 delete config.compilerOptions.incremental;
486
487 // This will prevent TS from polyfill/downlevel emit.
488 if (config.compilerOptions.target === undefined) {
489 // See https://github.com/tsconfig/bases/tree/main/bases
490 let target: string;
491 if (nodeVersionMajor >= 16) {
492 target = 'ES2021';
493 } else if (nodeVersionMajor >= 14) {
494 target = 'ES2020';
495 } else {
496 target = 'ES2019';
497 }
498 config.compilerOptions.target = target;
499 }
500
501 // When mixing TS with JS, its best to enable this flag.
502 // This is useful when no `tsconfig.json` is supplied.
503 if (config.compilerOptions.esModuleInterop === undefined) {
504 config.compilerOptions.esModuleInterop = true;
505 }
506
507 // nodenext will defer to the package.json#type field
508 // but still respect .mts and .cts files
509 if (config.compilerOptions.module === undefined) {
510 config.compilerOptions.module = 'NodeNext';
511 config.compilerOptions.moduleResolution = 'NodeNext';
512 config.compilerOptions.strict = false;
513 }
514
515 return config;
516}
517
518/**
519 * Internal source output.

Callers 2

startDevServerFunction · 0.90
readConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected