{"version":3,"file":"clean-build-tmp.d.ts","sourceRoot":"","sources":["../../src/clean-build-tmp.ts"],"names":[],"mappings":";AA4DA,wBAsBC","sourcesContent":["// Remove the .tshy-build folder, but ONLY if\n// the \"incremental\" config value is not set, or if\n// it does not contain any tsbuildinfo files.\n// If we are in incremental mode, and have tsbuildinfo files,\n// then find and remove any files here that do not have a matching\n// source file in ./src\n\nimport { readdirSync } from 'fs'\nimport { parse } from 'path'\nimport { rimraf } from 'rimraf'\nimport * as console from './console.js'\nimport readTypescriptConfig from './read-typescript-config.js'\n\nconst cleanRemovedOutputs = async (path: string, root: string) => {\n  const entries = readdirSync(`${root}/${path}`, {\n    withFileTypes: true,\n  })\n  let sources: Set<string> | undefined = undefined\n  try {\n    sources = new Set(readdirSync(`src/${path}`))\n  } catch {}\n  // directory was removed\n  if (!sources) {\n    return await rimraf(`${root}/${path}`)\n  }\n  for (const e of entries) {\n    const outputFile = `${path}/${e.name}`\n    if (e.isDirectory()) {\n      await cleanRemovedOutputs(outputFile, root)\n      continue\n    }\n    let { ext, name } = parse(outputFile)\n    if (ext === '.map') {\n      continue\n    }\n    if (name.endsWith('.d') && ext.endsWith('ts')) {\n      ext = '.d' + ext\n      name = name.substring(0, name.length - '.d'.length)\n    }\n\n    const inputSearch =\n      ext === '.js' || ext === '.d.ts' ? ['.tsx', '.ts']\n      : ext === '.mjs' || ext === '.d.mts' ? ['.mts']\n      : ext === '.cjs' || ext === '.d.cts' ? ['.cts']\n      : []\n    inputSearch.push(ext)\n    let del = true\n    for (const ext of inputSearch) {\n      if (sources.has(`${name}${ext}`)) {\n        del = false\n        break\n      }\n    }\n    if (del) {\n      console.debug('removing output file', outputFile)\n      await rimraf([`${root}/${outputFile}`, `${root}/${outputFile}.map`])\n    }\n  }\n}\n\nexport default async () => {\n  const config = readTypescriptConfig()\n  if (\n    config.compilerOptions.incremental !== true &&\n    config.compilerOptions.composite !== true\n  ) {\n    return await rimraf('.tshy-build')\n  }\n\n  let buildInfos: string[] | undefined = undefined\n  try {\n    buildInfos = readdirSync('.tshy-build/.tshy')\n  } catch {}\n  if (!buildInfos?.length) {\n    return await rimraf('.tshy-build')\n  }\n\n  // delete anything that has been removed from src.\n  for (const dialect of readdirSync('.tshy-build')) {\n    if (dialect === '.tshy') continue\n    await cleanRemovedOutputs('.', `.tshy-build/${dialect}`)\n  }\n}\n"]}