Skip to content

Commit

Permalink
refactor: removed module ast and merge with core
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Oct 10, 2024
1 parent 8e3589d commit 83deae3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 0 additions & 15 deletions packages/unplugin-environment/src/core/ast.ts

This file was deleted.

15 changes: 12 additions & 3 deletions packages/unplugin-environment/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -286,5 +297,3 @@ export const unpluginFactory = flow(
R.map(updateFactory),
R.mapWithDefault(defaultFactory, (data) => data.factory),
);

export { printTypeDefinition } from "./ast";

0 comments on commit 83deae3

Please sign in to comment.