{"version":3,"file":"build-live-commonjs.d.ts","sourceRoot":"","sources":["../../src/build-live-commonjs.ts"],"names":[],"mappings":"AAUA,OAAO,eAAe,CAAA;AAKtB,eAAO,MAAM,iBAAiB,YA2B7B,CAAA","sourcesContent":["import chalk from 'chalk'\nimport { linkSync, mkdirSync } from 'node:fs'\nimport { dirname } from 'node:path'\nimport { relative, resolve } from 'node:path/posix'\nimport config from './config.js'\nimport * as console from './console.js'\nimport ifExist from './if-exist.js'\nimport polyfills from './polyfills.js'\nimport setFolderDialect from './set-folder-dialect.js'\nimport sources from './sources.js'\nimport './tsconfig.js'\n\nconst { commonjsDialects = [] } = config\n\n// don't actually do a build, just link files into places.\nexport const buildLiveCommonJS = () => {\n  for (const d of ['commonjs', ...commonjsDialects]) {\n    const pf = polyfills.get(d === 'commonjs' ? 'cjs' : d)\n    console.debug(chalk.cyan.dim('linking ' + d))\n    for (const s of sources) {\n      const source = s.substring('./src/'.length)\n      const target = resolve(`.tshy-build/${d}/${source}`)\n      mkdirSync(dirname(target), { recursive: true })\n      linkSync(s, target)\n    }\n    setFolderDialect('.tshy-build/' + d, 'commonjs')\n    for (const [override, orig] of pf?.map.entries() ?? []) {\n      const stemFrom = resolve(\n        `.tshy-build/${d}`,\n        relative(resolve('src'), resolve(override)),\n      ).replace(/\\.cts$/, '')\n      const stemTo = resolve(\n        `.tshy-build/${d}`,\n        relative(resolve('src'), resolve(orig)),\n      ).replace(/\\.tsx?$/, '')\n      ifExist.unlink(`${stemTo}.js.map`)\n      ifExist.unlink(`${stemTo}.d.ts.map`)\n      ifExist.rename(`${stemFrom}.cjs`, `${stemTo}.js`)\n      ifExist.rename(`${stemFrom}.d.cts`, `${stemTo}.d.ts`)\n    }\n    console.error(chalk.cyan.bold('linked commonjs'))\n  }\n}\n"]}