UNPKG

typia

Version:

Superfast runtime validators with only one line

1 lines 54.1 kB
{"version":3,"file":"TypiaGenerateWizard.mjs","names":[],"sources":["../../src/executable/TypiaGenerateWizard.ts"],"sourcesContent":["import { createCommand } from \"commander\";\nimport fs from \"fs\";\nimport inquirer from \"inquirer\";\nimport { createRequire } from \"module\";\nimport os from \"os\";\nimport path from \"path\";\nimport { glob, isDynamicPattern } from \"tinyglobby\";\nimport type {\n ITtscCompilerDiagnostic,\n ITtscCompilerTransformation,\n} from \"ttsc\";\n\nimport { FileSystemIdentity } from \"./FileSystemIdentity\";\n\nexport namespace TypiaGenerateWizard {\n export async function generate(): Promise<void> {\n console.log(\"----------------------------------------\");\n console.log(\" Typia Generate Wizard\");\n console.log(\"----------------------------------------\");\n\n const options: IArguments = await parseArguments();\n await build(options);\n }\n\n async function parseArguments(): Promise<IArguments> {\n const command = createCommand(\"typia generate\");\n command.usage(\"[options] [files...]\");\n command.argument(\"[files...]\", \"input TypeScript source files or globs\");\n command.option(\"--input <path>\", \"input directory\");\n command.option(\"--output <directory>\", \"output directory\");\n command.option(\n \"--project <project>\",\n \"tsconfig.json/jsconfig.json file or directory\",\n );\n\n const questioned = { value: false };\n const prompt = inquirer.createPromptModule;\n\n const input = (name: string) => async (message: string) => {\n questioned.value = true;\n const result = await prompt()({\n type: \"input\",\n name,\n message,\n default: \"\",\n });\n return result[name] as string;\n };\n const configure = async (): Promise<string> => {\n const file: string | null = findProjectConfigFile(process.cwd());\n if (file === null) {\n throw new URIError(\n `Unable to find \"tsconfig.json\" or \"jsconfig.json\" file.`,\n );\n }\n return file;\n };\n\n return new Promise<IArguments>((resolve, reject) => {\n command.action(async (files: string[], options: Partial<IArguments>) => {\n try {\n if (files.length !== 0 && options.input !== undefined) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): file arguments cannot be combined with --input.\",\n );\n }\n if (files.length === 0) {\n options.input ??= await input(\"input\")(\"input directory\");\n }\n if (files.length !== 0 && options.output === undefined) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): output directory is required when file arguments are used.\",\n );\n }\n const output: string =\n options.output ?? (await input(\"output\")(\"output directory\"));\n const project: string = options.project ?? (await configure());\n if (questioned.value) console.log(\"\");\n resolve({\n input: options.input,\n output,\n project,\n files,\n });\n } catch (exp) {\n reject(exp);\n }\n });\n command.parseAsync(process.argv.slice(3), { from: \"user\" }).catch(reject);\n });\n }\n\n export interface IArguments {\n input?: string;\n output: string;\n project: string;\n files: string[];\n }\n\n async function build(location: IArguments): Promise<void> {\n location.output = path.resolve(location.output);\n location.project = resolveProjectConfigFile(location.project);\n\n const policy = new FileSystemIdentity.Policy();\n const outputProbe: string = await nearestExistingAncestor(location.output);\n await ensureExistingDirectoryPath({\n label: \"output parent path\",\n directory: outputProbe,\n });\n policy.observe(\n await FileSystemIdentity.probeDirectory(outputProbe),\n outputProbe,\n );\n policy.observe(\n await FileSystemIdentity.inspectDirectory(path.dirname(location.project)),\n path.dirname(location.project),\n );\n\n const entries: IInputFile[] =\n location.files.length === 0\n ? await prepareDirectoryInput(location, policy)\n : await prepareFileInputs(location, policy);\n const identity: FileSystemIdentity.IIdentity = policy.get();\n await inspectTargetDirectories({\n identity,\n output: location.output,\n targets: entries.map((entry) => entry.target),\n });\n\n const binary = resolveTsgoBinary();\n const cwd = path.dirname(location.project);\n const temporaryProject: ITemporaryProject = await createTemporaryProject({\n entries,\n project: location.project,\n });\n let transformed: Record<string, string>;\n try {\n transformed = transformProject({\n binary,\n cwd,\n projectRoot: cwd,\n tsconfig: temporaryProject.config,\n });\n } finally {\n await fs.promises.rm(temporaryProject.directory, {\n force: true,\n recursive: true,\n });\n }\n const outputByKey: Map<string, string> = indexTransformedOutputs(\n transformed,\n identity,\n );\n const outputs: IOutputFile[] = entries.map((entry) => {\n const output = getTransformedOutput({\n cwd,\n entry,\n identity,\n outputByKey,\n });\n if (output === undefined) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): no transformed output for ${entry.file}. Check that --project includes the file.`,\n );\n }\n return { entry, output };\n });\n\n await ensureOutputDirectory(location.output);\n await ensureTargetDirectories({\n identity,\n output: location.output,\n targets: outputs.map(({ entry }) => entry.target),\n });\n await ensurePhysicalTargets({\n identity,\n output: location.output,\n entries: outputs.map(({ entry }) => entry),\n });\n await ensureTargetFiles(\n outputs.map(({ entry }) => entry),\n identity,\n );\n for (const { entry, output } of outputs) {\n await fs.promises.writeFile(entry.target, formatOutput(output), \"utf8\");\n }\n }\n\n interface IInputFile {\n file: string;\n target: string;\n }\n\n interface IOutputFile {\n entry: IInputFile;\n output: string;\n }\n\n interface ITraversalEntry {\n file: string;\n name: string;\n stat: fs.Stats;\n }\n\n interface ITemporaryProject {\n config: string;\n directory: string;\n }\n\n async function createTemporaryProject(props: {\n entries: IInputFile[];\n project: string;\n }): Promise<ITemporaryProject> {\n const directory: string = await fs.promises.mkdtemp(\n path.join(os.tmpdir(), \"typia-generate-project-\"),\n );\n const config: string = path.join(directory, \"tsconfig.json\");\n try {\n await fs.promises.writeFile(\n config,\n JSON.stringify({\n extends: props.project,\n exclude: [],\n files: props.entries.map((entry) => compilerInputPath(entry.file)),\n include: [],\n }),\n \"utf8\",\n );\n return { config, directory };\n } catch (error) {\n await fs.promises.rm(directory, { force: true, recursive: true });\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to prepare the bounded input project: ${formatUnknownError(error)}`,\n );\n }\n }\n\n async function ensureOutputDirectory(output: string): Promise<void> {\n if (fs.existsSync(output) === false) {\n await ensureCreatableDirectory(output);\n await fs.promises.mkdir(output, { recursive: true });\n } else {\n await ensureExistingDirectory({\n label: \"output path\",\n directory: output,\n });\n }\n }\n\n async function ensureTargetDirectories(props: {\n identity: FileSystemIdentity.IIdentity;\n output: string;\n targets: string[];\n }): Promise<void> {\n await inspectTargetDirectories(props);\n const directories: Map<string, string> = targetDirectories(props);\n for (const directory of directories.values()) {\n try {\n await fs.promises.mkdir(directory, { recursive: true });\n } catch (exp) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to create output parent directory ${directory}: ${formatUnknownError(exp)}`,\n );\n }\n await ensureExistingDirectory({\n label: \"output parent path\",\n directory,\n });\n }\n }\n\n async function inspectTargetDirectories(props: {\n identity: FileSystemIdentity.IIdentity;\n output: string;\n targets: string[];\n }): Promise<void> {\n const directories: Map<string, string> = targetDirectories(props);\n for (const directory of directories.values()) {\n await ensureOutputAncestorDirectories({\n identity: props.identity,\n output: props.output,\n directory,\n });\n if (fs.existsSync(directory)) {\n await ensureExistingDirectory({\n label: \"output parent path\",\n directory,\n });\n }\n }\n }\n\n function targetDirectories(props: {\n identity: FileSystemIdentity.IIdentity;\n targets: string[];\n }): Map<string, string> {\n const directories: Map<string, string> = new Map();\n for (const target of props.targets) {\n const directory: string = path.dirname(target);\n directories.set(props.identity.filesystemKey(directory), directory);\n }\n return directories;\n }\n\n async function ensureCreatableDirectory(directory: string): Promise<void> {\n const parent: string = await nearestExistingAncestor(directory);\n await ensureExistingDirectoryPath({\n label: \"output parent path\",\n directory: parent,\n });\n }\n\n async function nearestExistingAncestor(directory: string): Promise<string> {\n let current: string = path.resolve(directory);\n while (fs.existsSync(current) === false) {\n const parent: string = path.dirname(current);\n if (parent === current) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to find existing output parent path: ${directory}`,\n );\n }\n current = parent;\n }\n return current;\n }\n\n async function ensureOutputAncestorDirectories(props: {\n identity: FileSystemIdentity.IIdentity;\n output: string;\n directory: string;\n }): Promise<void> {\n const output: string = path.resolve(props.output);\n const directory: string = path.resolve(props.directory);\n if (props.identity.contains(directory, output) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output parent path escapes output directory: ${props.directory}`,\n );\n }\n\n const relative: string = path.relative(output, directory);\n if (relative === \"\") {\n return;\n }\n\n let current: string = output;\n for (const segment of relative.split(path.sep)) {\n current = path.join(current, segment);\n let stat: fs.Stats;\n try {\n stat = await fs.promises.lstat(current);\n } catch (exp) {\n if (isMissingFileError(exp)) {\n return;\n }\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to inspect output parent path ${current}: ${formatUnknownError(exp)}`,\n );\n }\n if (stat.isSymbolicLink()) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output parent path contains a symbolic link: ${current}`,\n );\n }\n if (stat.isDirectory() === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output parent path is not a directory: ${current}`,\n );\n }\n }\n }\n\n async function ensureExistingDirectory(props: {\n label: string;\n directory: string;\n }): Promise<void> {\n await ensureExistingDirectoryPath(props);\n }\n\n async function ensureExistingDirectoryPath(props: {\n label: string;\n directory: string;\n }): Promise<void> {\n const directory: string = path.resolve(props.directory);\n const parsed: path.ParsedPath = path.parse(directory);\n const relative: string = path.relative(parsed.root, directory);\n let current: string = parsed.root;\n for (const segment of relative === \"\" ? [] : relative.split(path.sep)) {\n current = path.join(current, segment);\n await ensureExistingDirectorySegment({\n label:\n path.normalize(current) === path.normalize(directory)\n ? props.label\n : `${props.label} ancestor`,\n directory: current,\n });\n }\n }\n\n async function ensureExistingDirectorySegment(props: {\n label: string;\n directory: string;\n }): Promise<void> {\n const stat: fs.Stats = await fs.promises.lstat(props.directory);\n if (stat.isSymbolicLink()) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): ${props.label} is a symbolic link: ${props.directory}`,\n );\n }\n if (stat.isDirectory() === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): ${props.label} is not a directory: ${props.directory}`,\n );\n }\n }\n\n async function ensurePhysicalTargets(props: {\n identity: FileSystemIdentity.IIdentity;\n output: string;\n entries: IInputFile[];\n }): Promise<void> {\n const output: string = await fs.promises.realpath(props.output);\n const inputs: Set<string> = new Set();\n for (const entry of props.entries) {\n inputs.add(\n props.identity.filesystemKey(await fs.promises.realpath(entry.file)),\n );\n }\n\n for (const entry of props.entries) {\n const parent: string = path.dirname(entry.target);\n const directory: string = await fs.promises.realpath(parent);\n if (props.identity.contains(directory, output) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output parent path escapes output directory through a symbolic link: ${parent}`,\n );\n }\n\n const target: string = path.join(directory, path.basename(entry.target));\n if (inputs.has(props.identity.filesystemKey(target))) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output file would overwrite input file through a symbolic link: ${entry.target}`,\n );\n }\n }\n }\n\n async function ensureTargetFiles(\n entries: IInputFile[],\n identity: FileSystemIdentity.IIdentity,\n ): Promise<void> {\n const inputs: Set<string> = new Set();\n const files: Map<string, IInputFile> = new Map();\n for (const entry of entries) {\n inputs.add(\n fileIdentityKey(\n await fs.promises.stat(entry.file, { bigint: true }),\n await fs.promises.realpath(entry.file),\n ),\n );\n files.set(identity.filesystemKey(entry.target), entry);\n }\n\n for (const entry of files.values()) {\n let stat: fs.BigIntStats;\n try {\n stat = await fs.promises.lstat(entry.target, { bigint: true });\n } catch (exp) {\n if (isMissingFileError(exp)) {\n continue;\n }\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to inspect output file ${entry.target}: ${formatUnknownError(exp)}`,\n );\n }\n if (stat.isFile() === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output file path is not a regular file: ${entry.target}`,\n );\n }\n if (\n inputs.has(\n fileIdentityKey(stat, await fs.promises.realpath(entry.target)),\n )\n ) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output file would overwrite input file through a physical file alias: ${entry.target}`,\n );\n }\n if (stat.nlink > BigInt(1)) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output file has multiple hard links: ${entry.target}`,\n );\n }\n }\n }\n\n async function prepareDirectoryInput(\n location: IArguments,\n policy: FileSystemIdentity.Policy,\n ): Promise<IInputFile[]> {\n if (location.input === undefined) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): input path is required.\",\n );\n }\n const input = path.resolve(location.input);\n if (fs.existsSync(input) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input path does not exist: ${input}`,\n );\n }\n if ((await isDirectory(input)) === false) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): input path is not a directory.\",\n );\n }\n\n const inputReal: string = await fs.promises.realpath(input);\n const outputReal: string | undefined = await optionalRealPath(\n location.output,\n );\n const files: string[] = [];\n await gather({\n container: files,\n from: input,\n inputReal,\n outputReal,\n policy,\n visitedDirectories: new Set(),\n visitedFiles: new Set(),\n });\n return files.map((file) => ({\n file,\n target: path.join(location.output, path.relative(input, file)),\n }));\n }\n\n async function prepareFileInputs(\n location: IArguments,\n policy: FileSystemIdentity.Policy,\n ): Promise<IInputFile[]> {\n const targets: Set<string> = new Set();\n const output: IInputFile[] = [];\n for (const input of await expandFileInputs(\n location.files,\n location.output,\n policy,\n )) {\n const file: string = path.resolve(input);\n policy.observe(\n await FileSystemIdentity.inspectDirectory(path.dirname(file)),\n path.dirname(file),\n );\n const identity: FileSystemIdentity.IIdentity = policy.get();\n if (fs.existsSync(file) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input file does not exist: ${input}`,\n );\n } else if ((await isFile(file)) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input path is not a file: ${input}`,\n );\n } else if (identity.isDeclarationFile(file)) {\n continue;\n } else if (identity.isSupportedExtension(file) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input file is not a supported TypeScript source: ${input}`,\n );\n }\n\n const target: string = path.join(location.output, path.basename(file));\n if (identity.isSamePath(file, target)) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): output file would overwrite input file: ${input}`,\n );\n }\n const key: string = identity.filesystemKey(target);\n if (targets.has(key)) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): duplicate output filename for ${target}`,\n );\n }\n targets.add(key);\n output.push({ file, target });\n }\n if (output.length === 0) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): input files do not include any supported TypeScript source files outside the output directory.\",\n );\n }\n return output;\n }\n\n async function expandFileInputs(\n inputs: string[],\n directory: string,\n policy: FileSystemIdentity.Policy,\n ): Promise<string[]> {\n const output: string[] = [];\n for (const input of inputs) {\n const pattern: string = toGlobPattern(input);\n if (isDynamicPattern(pattern, { caseSensitiveMatch: true })) {\n const searchDirectory: string = await globSearchDirectory(input);\n const caseSensitive: boolean | undefined =\n await FileSystemIdentity.inspectDirectory(searchDirectory);\n if (caseSensitive === undefined) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to determine filesystem case behavior for input pattern base ${searchDirectory}.`,\n );\n }\n policy.observe(caseSensitive, searchDirectory);\n const identity: FileSystemIdentity.IIdentity = policy.get();\n const matches: string[] = await glob(pattern, {\n absolute: true,\n caseSensitiveMatch: identity.caseSensitive,\n cwd: process.cwd(),\n onlyFiles: true,\n });\n if (matches.length === 0) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input pattern does not match any files: ${input}`,\n );\n }\n output.push(\n ...excludeOutputFiles(matches, directory, identity).filter((file) =>\n identity.isSupportedExtension(file),\n ),\n );\n } else {\n const file: string = path.resolve(input);\n policy.observe(\n await FileSystemIdentity.inspectDirectory(path.dirname(file)),\n path.dirname(file),\n );\n if (policy.get().contains(file, directory) === false) {\n output.push(file);\n }\n }\n }\n return output;\n }\n\n function excludeOutputFiles(\n files: string[],\n directory: string,\n identity: FileSystemIdentity.IIdentity,\n ): string[] {\n return files.filter((file) => identity.contains(file, directory) === false);\n }\n\n async function globSearchDirectory(input: string): Promise<string> {\n let current: string = path.resolve(input);\n while (\n isDynamicPattern(toGlobPattern(current), { caseSensitiveMatch: true })\n ) {\n const parent: string = path.dirname(current);\n if (parent === current) break;\n current = parent;\n }\n if (fs.existsSync(current) && (await isDirectory(current))) return current;\n return nearestExistingAncestor(path.dirname(current));\n }\n\n function toGlobPattern(input: string): string {\n return input.replace(/\\\\/g, \"/\");\n }\n\n function transformProject(props: {\n binary: string;\n cwd: string;\n projectRoot: string;\n tsconfig: string;\n }): Record<string, string> {\n const TtscCompiler = loadTtscCompiler();\n const result: ITtscCompilerTransformation = new TtscCompiler({\n binary: props.binary,\n cwd: props.cwd,\n projectRoot: props.projectRoot,\n tsconfig: props.tsconfig,\n }).transform();\n if (result.type === \"success\") {\n return result.typescript;\n }\n if (result.type === \"failure\") {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): ${formatDiagnostics(result.diagnostics)}`,\n );\n }\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): ${formatUnknownError(result.error)}`,\n );\n }\n\n function resolveProjectConfigFile(project: string): string {\n const resolved: string = path.resolve(project);\n if (fs.existsSync(resolved) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): project path does not exist: ${resolved}`,\n );\n }\n\n const stat: fs.Stats = fs.statSync(resolved);\n if (stat.isDirectory()) {\n for (const filename of [\"tsconfig.json\", \"jsconfig.json\"]) {\n const candidate: string = path.join(resolved, filename);\n if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {\n return resolveRealPath(candidate);\n }\n }\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): project directory has no tsconfig.json or jsconfig.json: ${resolved}`,\n );\n }\n if (stat.isFile() === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): project path is not a file: ${resolved}`,\n );\n }\n return resolveRealPath(resolved);\n }\n\n function findProjectConfigFile(directory: string): string | null {\n let current: string = path.resolve(directory);\n while (true) {\n for (const filename of [\"tsconfig.json\", \"jsconfig.json\"]) {\n const candidate: string = path.join(current, filename);\n if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {\n return resolveRealPath(candidate);\n }\n }\n const parent: string = path.dirname(current);\n if (parent === current) {\n return null;\n }\n current = parent;\n }\n }\n\n function loadTtscCompiler(): typeof import(\"ttsc\").TtscCompiler {\n const packageRoot: string = resolveTypiaPackageRoot();\n const resolved: string | null = resolveFromRoots(\n \"ttsc\",\n resolveRuntimeRoots(packageRoot),\n );\n if (resolved === null) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to resolve ttsc from the current project, typia package, or workspace root. Run \"npm i -D ttsc typescript\" before.`,\n );\n }\n const imported = createRequire(resolved)(resolved) as typeof import(\"ttsc\");\n return imported.TtscCompiler;\n }\n\n function resolveTsgoBinary(): string {\n const explicit: string | undefined = process.env.TTSC_TSGO_BINARY;\n if (explicit !== undefined && explicit.length !== 0) {\n if (path.isAbsolute(explicit) && fs.existsSync(explicit)) {\n return explicit;\n }\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): TTSC_TSGO_BINARY must be an existing absolute path: ${explicit}`,\n );\n }\n\n const packageRoot: string = resolveTypiaPackageRoot();\n const manifest: string | null = resolveFromRoots(\n \"typescript/package.json\",\n resolveRuntimeRoots(packageRoot),\n );\n if (manifest === null) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): unable to resolve typescript from the current project, typia package, or workspace root.\",\n );\n }\n\n const platform: string = `@typescript/typescript-${process.platform}-${process.arch}`;\n const platformManifest: string = createRequire(manifest).resolve(\n `${platform}/package.json`,\n );\n const binary: string = path.join(\n path.dirname(platformManifest),\n \"lib\",\n process.platform === \"win32\" ? \"tsc.exe\" : \"tsc\",\n );\n if (fs.existsSync(binary) === false) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): TypeScript-Go executable not found: ${binary}`,\n );\n }\n return binary;\n }\n\n function resolveTypiaPackageRoot(): string {\n // The CLI entrypoint (`lib/executable/typia.js`) lives in the same\n // directory as this module, so its `process.argv[1]` path anchors the\n // walk-up identically in both the CJS and ESM builds — `__dirname` does\n // not exist in the transcoded `.mjs`.\n const current: string = path.dirname(path.resolve(process.argv[1] ?? \"\"));\n for (const directory of [\n path.resolve(current, \"..\", \"..\"),\n path.resolve(current, \"..\"),\n ]) {\n const file: string = path.join(directory, \"package.json\");\n if (fs.existsSync(file) === false) {\n continue;\n }\n try {\n const pack = JSON.parse(fs.readFileSync(file, \"utf8\")) as Partial<\n Record<\"name\", unknown>\n >;\n if (pack.name === \"typia\") {\n return directory;\n }\n } catch {\n continue;\n }\n }\n\n const resolved: string | null = resolveFromRoots(\"typia/package.json\", [\n process.cwd(),\n current,\n ]);\n if (resolved === null) {\n throw new URIError(\n \"Error on TypiaGenerateWizard.generate(): unable to resolve typia package root.\",\n );\n }\n return path.dirname(resolved);\n }\n\n function resolveRuntimeRoots(packageRoot: string): string[] {\n return [process.cwd(), packageRoot, path.resolve(packageRoot, \"..\", \"..\")];\n }\n\n function resolveFromRoots(request: string, roots: string[]): string | null {\n for (const root of roots) {\n try {\n return createRequire(path.join(root, \"package.json\")).resolve(request);\n } catch {\n continue;\n }\n }\n return null;\n }\n\n async function isDirectory(current: string): Promise<boolean> {\n const stat: fs.Stats = await fs.promises.stat(current);\n return stat.isDirectory();\n }\n\n async function isFile(current: string): Promise<boolean> {\n const stat: fs.Stats = await fs.promises.stat(current);\n return stat.isFile();\n }\n\n async function gather(props: {\n container: string[];\n from: string;\n inputReal: string;\n outputReal: string | undefined;\n policy: FileSystemIdentity.Policy;\n visitedDirectories: Set<string>;\n visitedFiles: Set<string>;\n }): Promise<void> {\n const currentReal: string = await resolveTraversalPath(props.from);\n if (\n props.outputReal !== undefined &&\n isPhysicalSameOrChildPath(currentReal, props.outputReal)\n )\n return;\n ensurePhysicalInputContainment({\n file: props.from,\n input: props.inputReal,\n real: currentReal,\n });\n\n const currentStat: fs.BigIntStats = await fs.promises.stat(props.from, {\n bigint: true,\n });\n const directoryIdentity: string = fileIdentityKey(currentStat, currentReal);\n if (props.visitedDirectories.has(directoryIdentity)) {\n const lexicalStat: fs.Stats = await fs.promises.lstat(props.from);\n if (lexicalStat.isSymbolicLink()) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input directory link revisits a physical directory: ${props.from}.`,\n );\n }\n return;\n }\n props.visitedDirectories.add(directoryIdentity);\n\n props.policy.observe(\n await FileSystemIdentity.inspectDirectory(props.from),\n props.from,\n );\n const identity: FileSystemIdentity.IIdentity = props.policy.get();\n const entries: ITraversalEntry[] = await Promise.all(\n (await fs.promises.readdir(props.from)).map(async (name) => {\n const file: string = path.join(props.from, name);\n try {\n return { file, name, stat: await fs.promises.lstat(file) };\n } catch (error) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to inspect input path ${file}: ${formatUnknownError(error)}`,\n );\n }\n }),\n );\n entries.sort((x, y) => {\n const linkOrder: number =\n Number(x.stat.isSymbolicLink()) - Number(y.stat.isSymbolicLink());\n return linkOrder !== 0\n ? linkOrder\n : Buffer.compare(Buffer.from(x.name), Buffer.from(y.name));\n });\n\n for (const entry of entries) {\n let stat: fs.BigIntStats;\n let real: string;\n try {\n stat = await fs.promises.stat(entry.file, { bigint: true });\n real = await fs.promises.realpath(entry.file);\n } catch (error) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input link target is missing or unreadable: ${entry.file}: ${formatUnknownError(error)}`,\n );\n }\n\n if (\n props.outputReal !== undefined &&\n isPhysicalSameOrChildPath(real, props.outputReal)\n )\n continue;\n ensurePhysicalInputContainment({\n file: entry.file,\n input: props.inputReal,\n real,\n });\n\n if (stat.isDirectory()) {\n await gather({ ...props, from: entry.file });\n continue;\n }\n if (\n stat.isFile() === false ||\n identity.isSupportedExtension(entry.name) === false\n )\n continue;\n\n const fileIdentity: string = fileIdentityKey(stat, real);\n if (props.visitedFiles.has(fileIdentity)) continue;\n props.visitedFiles.add(fileIdentity);\n props.container.push(entry.file);\n }\n }\n\n function formatOutput(output: string): string {\n return output.startsWith(\"// @ts-nocheck\")\n ? output\n : `// @ts-nocheck\\n${output}`;\n }\n\n function indexTransformedOutputs(\n outputs: Record<string, string>,\n identity: FileSystemIdentity.IIdentity,\n ): Map<string, string> {\n const map: Map<string, string> = new Map();\n for (const [file, output] of Object.entries(outputs)) {\n const key: string = identity.projectFileKey(file);\n if (map.has(key)) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): transformed outputs have ambiguous filesystem identities: ${file}.`,\n );\n }\n map.set(key, output);\n }\n return map;\n }\n\n function getTransformedOutput(props: {\n cwd: string;\n entry: IInputFile;\n identity: FileSystemIdentity.IIdentity;\n outputByKey: Map<string, string>;\n }): string | undefined {\n const output = props.outputByKey.get(\n props.identity.projectFileKey(projectKey(props.cwd, props.entry.file)),\n );\n if (output !== undefined) {\n return output;\n }\n\n const compilerFile: string = compilerInputPath(props.entry.file);\n if (\n props.identity.isSamePath(compilerFile, props.entry.file) === false &&\n props.identity.contains(compilerFile, props.cwd)\n ) {\n const compiled: string | undefined = props.outputByKey.get(\n props.identity.projectFileKey(projectKey(props.cwd, compilerFile)),\n );\n if (compiled !== undefined) return compiled;\n }\n\n const real: string = resolveRealPath(props.entry.file);\n if (\n props.identity.isSamePath(real, props.entry.file) ||\n props.identity.contains(real, props.cwd) === false\n ) {\n return undefined;\n }\n return props.outputByKey.get(\n props.identity.projectFileKey(projectKey(props.cwd, real)),\n );\n }\n\n function projectKey(root: string, file: string): string {\n return path.relative(root, file).replace(/\\\\/g, \"/\");\n }\n\n function resolveRealPath(file: string): string {\n try {\n return fs.realpathSync(file);\n } catch {\n return file;\n }\n }\n\n function compilerInputPath(file: string): string {\n try {\n if (fs.lstatSync(file).isSymbolicLink()) {\n return path.join(\n resolveRealPath(path.dirname(file)),\n path.basename(file),\n );\n }\n } catch {\n return file;\n }\n return resolveRealPath(file);\n }\n\n async function optionalRealPath(file: string): Promise<string | undefined> {\n try {\n return await fs.promises.realpath(file);\n } catch (error) {\n if (isMissingFileError(error)) return undefined;\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to resolve path ${file}: ${formatUnknownError(error)}`,\n );\n }\n }\n\n async function resolveTraversalPath(file: string): Promise<string> {\n try {\n return await fs.promises.realpath(file);\n } catch (error) {\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): unable to resolve input path ${file}: ${formatUnknownError(error)}`,\n );\n }\n }\n\n function ensurePhysicalInputContainment(props: {\n file: string;\n input: string;\n real: string;\n }): void {\n if (isPhysicalSameOrChildPath(props.real, props.input)) return;\n throw new URIError(\n `Error on TypiaGenerateWizard.generate(): input path resolves outside the input directory: ${props.file}.`,\n );\n }\n\n function isPhysicalSameOrChildPath(file: string, directory: string): boolean {\n const relative: string = path.relative(directory, file);\n return (\n relative === \"\" ||\n (relative !== \"..\" &&\n relative.startsWith(`..${path.sep}`) === false &&\n path.isAbsolute(relative) === false)\n );\n }\n\n function isMissingFileError(exp: unknown): boolean {\n return (\n typeof exp === \"object\" &&\n exp !== null &&\n \"code\" in exp &&\n exp.code === \"ENOENT\"\n );\n }\n\n /**\n * Delegates to {@link FileSystemIdentity.identityKey}, which owns the rule and\n * carries the reasoning for reading the identity as a `bigint`.\n */\n function fileIdentityKey(stat: fs.BigIntStats, realpath: string): string {\n return FileSystemIdentity.identityKey(stat, realpath);\n }\n\n function formatDiagnostics(diagnostics: ITtscCompilerDiagnostic[]): string {\n return diagnostics.length === 0\n ? \"transformation failed\"\n : diagnostics\n .map((diag) =>\n [\n diag.file ?? \"ttsc\",\n diag.line === undefined\n ? undefined\n : `${diag.line}:${diag.character ?? 1}`,\n diag.messageText,\n ]\n .filter((part) => part !== undefined && part !== \"\")\n .join(\": \"),\n )\n .join(\"\\n\");\n }\n\n function formatUnknownError(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n if (\n typeof error === \"object\" &&\n error !== null &&\n \"message\" in error &&\n typeof error.message === \"string\"\n ) {\n return error.message;\n }\n return String(error);\n }\n}\n"],"mappings":";;;;;;;;;AAcO,IAAA;;CACE,eAAe,WAA0B;EAC9C,QAAQ,IAAI,0CAA0C;EACtD,QAAQ,IAAI,wBAAwB;EACpC,QAAQ,IAAI,0CAA0C;EAGtD,MAAM,MAAM,MADsB,eAAe,CAC9B;CACrB;;CAEA,eAAe,iBAAsC;EACnD,MAAM,UAAU,cAAc,gBAAgB;EAC9C,QAAQ,MAAM,sBAAsB;EACpC,QAAQ,SAAS,cAAc,wCAAwC;EACvE,QAAQ,OAAO,kBAAkB,iBAAiB;EAClD,QAAQ,OAAO,wBAAwB,kBAAkB;EACzD,QAAQ,OACN,uBACA,+CACF;EA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