diff --git a/packages/unplugin-environment/src/core/ast.ts b/packages/unplugin-environment/src/core/ast.ts deleted file mode 100644 index 056f9cb..0000000 --- a/packages/unplugin-environment/src/core/ast.ts +++ /dev/null @@ -1,15 +0,0 @@ -// AST Helpers for generated typescript definition -// this module will be used fro generated /types/env.d.ts based on user schema. -import * as ts from "typescript"; - -const printer = ts.createPrinter({ - newLine: ts.NewLineKind.LineFeed, - omitTrailingSemicolon: true, -}); - -const emptySourceFile = ts.createSourceFile("", "", ts.ScriptTarget.Latest); - -export const printTypeDefinition = (node: ts.TypeNode) => - printer.printNode(ts.EmitHint.Unspecified, node, emptySourceFile); - -export { zodToTs } from "zod-to-ts"; diff --git a/packages/unplugin-environment/src/core/index.ts b/packages/unplugin-environment/src/core/index.ts index 037bc63..0027f75 100644 --- a/packages/unplugin-environment/src/core/index.ts +++ b/packages/unplugin-environment/src/core/index.ts @@ -3,9 +3,10 @@ import { fileURLToPath } from "url"; import { A, D, F, G, R, S, flow, pipe } from "@mobily/ts-belt"; import { config as dotenvConfig } from "dotenv"; import * as fs from "fs/promises"; +import * as ts from "typescript"; import { z } from "zod"; +import { zodToTs } from "zod-to-ts"; import { name as pkgName, version as pkgVersion } from "../../package.json"; -import { printTypeDefinition, zodToTs } from "./ast"; import { log } from "./logger"; import type * as CoreType from "./types"; import { dropHead, exclaim, toJsonString, toNull, toUndefined } from "./utils"; @@ -125,6 +126,16 @@ export const createModuleEnvServer = () => ({ `, }); +const printer = ts.createPrinter({ + newLine: ts.NewLineKind.LineFeed, + omitTrailingSemicolon: true, +}); + +const emptySourceFile = ts.createSourceFile("", "", ts.ScriptTarget.Latest); + +export const printTypeDefinition = (node: ts.TypeNode) => + printer.printNode(ts.EmitHint.Unspecified, node, emptySourceFile); + export const createModuleDTS: CoreType.CreateModuleDTS = (env, options) => pipe( F.ifElse(filterEnv(env, options.match), D.isEmpty, () => [], D.keys), @@ -286,5 +297,3 @@ export const unpluginFactory = flow( R.map(updateFactory), R.mapWithDefault(defaultFactory, (data) => data.factory), ); - -export { printTypeDefinition } from "./ast";