{"version":3,"file":"transform.mjs","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type { ITtscPlugin, ITtscPluginFactoryContext } from \"ttsc\";\n\n/**\n * Describe typia's native transform to ttsc.\n *\n * Ttsc loads this file as an ES module, where `require` is unavailable, so a\n * resolver is anchored on the consuming project to find typia's own package\n * root. The returned descriptor names the plugin and the Go command under\n * `native/cmd/ttsc-typia`; the transform itself is not written in TypeScript.\n * No file is read outside the module graph. Ttsc records the package\n * resolution, so an empty hostInputHashes declaration permits safe descriptor\n * replay. The native build host supplies generation-owned input observations\n * and compiler-owned output provenance for ttsc's checked runtime reuse\n * protocol. Its only variable reads outside ttsc's own namespace go through the\n * program's recorded `Env`, so it declares `environmentInputs` and ttsc keys\n * its outputs by the variables it read instead of the whole environment. The\n * host also answers `check-serve`, so it declares `residentCheck` and a `ttsc\n * --noEmit --watch` keeps one typia process and its program across saves.\n *\n * @param context Plugin factory context of ttsc\n *\n * @returns Plugin descriptor\n *\n * @evidence contracts/common.md#principled-implementation The ttsc loader runs this file as an ES module where `require` is absent, so the function builds a CommonJS resolver anchored at the consuming project and resolves typia's own `package.json`, whose directory holds the native sources. No external file is read; ttsc records that module lookup and invalidates descriptor replay when its module graph or factory inputs change. The descriptor names the plugin and Go command under `native/cmd/ttsc-typia`.\n * @evidence contracts/common.md#clear-and-simple-design One function returns the plugin name, Go source, supported native protocols and external-input declaration; the default export repeats the same function for loaders that read it.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The package root comes from the installed typia through the supported resolver and not from path substrings, so it works for npm consumers and workspaces alike; the transform itself stays in Go.\n * @evidence contracts/common.md#meaningful-documentation A comment explains the purpose, the ESM resolution reason and the descriptor.\n */\nexport function createTtscPlugin(\n  context: ITtscPluginFactoryContext,\n): ITtscPlugin {\n  // ttsc loads this descriptor as ESM, where the ambient `require` is\n  // unavailable; anchor a CJS resolver on the consuming project to locate\n  // typia's own package root (not the project root, which has no `native/`).\n  const requireFrom = createRequire(\n    path.join(context.projectRoot, \"package.json\"),\n  );\n  const root: string = path.dirname(requireFrom.resolve(\"typia/package.json\"));\n  return {\n    name: \"typia\",\n    source: path.resolve(root, \"native\", \"cmd\", \"ttsc-typia\"),\n    hostInputHashes: {},\n    capabilities: {\n      emitObservations: true,\n      emitProvenance: true,\n      environmentInputs: true,\n      residentCheck: true,\n    },\n  };\n}\n\nexport default createTtscPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,iBACd,SACa;CAIb,MAAM,cAAc,cAClB,KAAK,KAAK,QAAQ,aAAa,cAAc,CAC/C;CACA,MAAM,OAAe,KAAK,QAAQ,YAAY,QAAQ,oBAAoB,CAAC;CAC3E,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,QAAQ,MAAM,UAAU,OAAO,YAAY;EACxD,iBAAiB,CAAC;EAClB,cAAc;GACZ,kBAAkB;GAClB,gBAAgB;GAChB,mBAAmB;GACnB,eAAe;EACjB;CACF;AACF"}