UNPKG

@airbnb/config-typescript

Version:

Reusable TypeScript configs.

68 lines (67 loc) 2.26 kB
"use strict"; // Keep in sync with the `tsconfig.options.json` file in this package. Object.defineProperty(exports, "__esModule", { value: true }); /** * Create common compiler options. */ function getCompilerOptions({ library = false, next = false, node = false, react = false, }) { const options = { allowSyntheticDefaultImports: true, declaration: library, esModuleInterop: true, forceConsistentCasingInFileNames: true, isolatedModules: next && !library, jsx: 'preserve', lib: ['dom', 'esnext'], module: node ? 'commonjs' : 'esnext', moduleResolution: 'node', noEmitOnError: true, noImplicitReturns: true, noUnusedLocals: true, pretty: true, removeComments: false, strict: true, target: next || node ? 'es2018' : 'es2015', // Use define in development for spec accuracy, // but omit in production for smaller file sizes. useDefineForClassFields: next && process.env.NODE_ENV === 'development', }; if (react) { options.jsx = 'react'; } return options; } exports.getCompilerOptions = getCompilerOptions; /** * Create a root configuration object for a single project. */ function getConfig(options) { const config = { compilerOptions: getCompilerOptions(options), include: [`./${options.srcFolder}/**/*`, `./${options.typesFolder}/**/*`], exclude: ['**/node_modules/*'], }; if (options.includeTests) { config.include.push(`./${options.testFolder}/**/*`); } if (options.library) { config.compilerOptions.declarationDir = `./${options.buildFolder}`; } config.compilerOptions.outDir = `./${options.buildFolder}`; return config; } exports.getConfig = getConfig; /** * Create a root configuration object for a multi-project that uses project references. */ function getConfigWithProjectRefs(options) { const config = { compilerOptions: getCompilerOptions(options), files: [], references: [], }; config.compilerOptions.composite = true; config.compilerOptions.declarationMap = true; return config; } exports.getConfigWithProjectRefs = getConfigWithProjectRefs;