{"version":3,"file":"tsconfig.d.ts","sourceRoot":"","sources":["../../src/tsconfig.ts"],"names":[],"mappings":"","sourcesContent":["import chalk from 'chalk'\nimport { mkdirpSync } from 'mkdirp'\nimport {\n  existsSync,\n  readdirSync,\n  unlinkSync,\n  writeFileSync,\n} from 'node:fs'\nimport { resolve } from 'node:path'\nimport { join } from 'node:path/posix'\nimport * as console from './console.js'\n\n// the commonjs build needs to exclude anything that will be polyfilled\nimport config from './config.js'\nimport polyfills from './polyfills.js'\nimport preventVerbatimModuleSyntax from './prevent-verbatim-module-syntax.js'\nimport readTypescriptConfig from './read-typescript-config.js'\n\nconst {\n  dialects = ['esm', 'commonjs'],\n  esmDialects = [],\n  commonjsDialects = [],\n  exclude = [],\n} = config\n\nconst relativeExclude = exclude.map(e => `../${e.replace(/^\\.\\//, '')}`)\n\nconst recommended: Record<string, any> = {\n  compilerOptions: {\n    declaration: true,\n    declarationMap: true,\n    esModuleInterop: true,\n    forceConsistentCasingInFileNames: true,\n    inlineSources: true,\n    jsx: 'react',\n    module: 'nodenext',\n    moduleResolution: 'nodenext',\n    noUncheckedIndexedAccess: true,\n    resolveJsonModule: true,\n    skipLibCheck: true,\n    sourceMap: true,\n    strict: true,\n    target: 'es2022',\n  },\n}\n\nconst build = (): Record<string, any> => ({\n  extends:\n    config.project === undefined ?\n      '../tsconfig.json'\n    : join('..', config.project),\n  compilerOptions: {\n    target:\n      readTypescriptConfig().compilerOptions.target === undefined ?\n        'es2022'\n      : undefined,\n    rootDir: '../src',\n    module: 'nodenext',\n    moduleResolution: 'nodenext',\n  },\n})\n\nconst commonjs = (dialect: string): Record<string, any> => {\n  const exclude = [\n    ...relativeExclude,\n    '../src/**/*.mts',\n    '../src/package.json',\n  ]\n  for (const [d, pf] of polyfills) {\n    if (d === dialect) continue\n    for (const f of pf.map.keys()) {\n      exclude.push(`../${join(f)}`)\n    }\n  }\n  return {\n    extends: './build.json',\n    include: [\n      '../src/**/*.ts',\n      '../src/**/*.cts',\n      '../src/**/*.tsx',\n      '../src/**/*.json',\n    ],\n    exclude,\n    compilerOptions: {\n      outDir:\n        '../.tshy-build/' + (dialect === 'cjs' ? 'commonjs' : dialect),\n    },\n  }\n}\n\nconst esm = (dialect: string): Record<string, any> => {\n  const exclude: string[] = [...relativeExclude, '../src/package.json']\n  for (const [d, pf] of polyfills) {\n    if (d === dialect) continue\n    for (const f of pf.map.keys()) {\n      exclude.push(`../${f.replace(/^\\.\\//, '')}`)\n    }\n  }\n  return {\n    extends: './build.json',\n    include: [\n      '../src/**/*.ts',\n      '../src/**/*.mts',\n      '../src/**/*.tsx',\n      '../src/**/*.json',\n    ],\n    exclude,\n    compilerOptions: {\n      outDir: '../.tshy-build/' + dialect,\n    },\n  }\n}\n\nmkdirpSync('.tshy')\nconst writeConfig = (name: string, data: Record<string, any>) =>\n  writeFileSync(`.tshy/${name}.json`, JSON.stringify(data, null, 2) + '\\n')\n\nconsole.debug(chalk.cyan.dim('writing tsconfig files...'))\nif (config.project === undefined && !existsSync('tsconfig.json')) {\n  console.debug('using recommended tsconfig.json')\n  writeConfig('../tsconfig', recommended)\n} else {\n  if (dialects.length > 1) preventVerbatimModuleSyntax()\n  console.debug('using existing tsconfig.json')\n}\nfor (const f of readdirSync('.tshy')) {\n  unlinkSync(resolve('.tshy', f))\n}\nwriteConfig('build', build())\nif (dialects.includes('commonjs')) {\n  writeConfig('commonjs', commonjs('cjs'))\n  for (const d of commonjsDialects) {\n    writeConfig(d, commonjs(d))\n  }\n}\nif (dialects.includes('esm')) {\n  writeConfig('esm', esm('esm'))\n  for (const d of esmDialects) {\n    writeConfig(d, esm(d))\n  }\n}\n"]}