63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
import { writeFileSync } from 'fs';
|
|
import { format, resolveConfig } from 'prettier';
|
|
import { createImportMap } from '../importmap/index.js';
|
|
|
|
const tsconfigPath = 'tsconfig.json';
|
|
const tsconfigComment = `// Don't edit this file directly. It is generated by /devops/tsconfig/index.js\n\n`;
|
|
|
|
const tsConfigBase = {
|
|
compilerOptions: {
|
|
module: 'esnext',
|
|
target: 'ES2020',
|
|
lib: ['es2020', 'dom', 'dom.iterable'],
|
|
outDir: './types',
|
|
allowSyntheticDefaultImports: true,
|
|
experimentalDecorators: true,
|
|
forceConsistentCasingInFileNames: true,
|
|
useDefineForClassFields: false,
|
|
baseUrl: '.',
|
|
incremental: true,
|
|
skipLibCheck: true,
|
|
/* Bundler mode */
|
|
moduleResolution: 'bundler',
|
|
allowImportingTsExtensions: true,
|
|
resolveJsonModule: true,
|
|
isolatedModules: true,
|
|
noEmit: true,
|
|
/* Linting */
|
|
strict: true,
|
|
noFallthroughCasesInSwitch: true,
|
|
noImplicitReturns: true,
|
|
},
|
|
include: ['src/**/*.ts', 'apps/**/*.ts', 'e2e/**/*.ts', 'index.ts', 'storybook/stories/**/*.ts', 'examples/**/*.ts'],
|
|
references: [
|
|
{
|
|
path: './tsconfig.node.json',
|
|
},
|
|
],
|
|
};
|
|
|
|
const importmap = createImportMap({
|
|
rootDir: './src',
|
|
additionalImports: {
|
|
'@umbraco-cms/internal/test-utils': './utils/test-utils.ts',
|
|
},
|
|
replaceModuleExtensions: true,
|
|
});
|
|
|
|
const paths = {};
|
|
|
|
for (const [key, value] of Object.entries(importmap.imports)) {
|
|
const valueAsArray = [value];
|
|
paths[key] = valueAsArray;
|
|
}
|
|
|
|
tsConfigBase.compilerOptions.paths = paths;
|
|
|
|
const content = tsconfigComment + JSON.stringify(tsConfigBase, null, ' ');
|
|
|
|
const config = await resolveConfig('./.prettierrc.json');
|
|
const formattedContent = await format(content, { ...config, parser: 'json' });
|
|
|
|
writeFileSync(tsconfigPath, formattedContent);
|