diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3c5d487d8..7166bc439 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -281,12 +281,12 @@ jobs: source .venv/bin/activate # this doesn't publish it but only builds it - WASM_OPT=1 ghjk x build-tgraph-ts + ghjk x build-tgraph-ts # start the docker containers ghjk x dev-compose base prisma grpc subredis - WASM_OPT=1 ghjk x build-tgraph + ghjk x build-tgraph ghjk x install-ts diff --git a/src/typegraph/deno/deno.json b/src/typegraph/deno/deno.json index 1326072fc..0efa70db8 100644 --- a/src/typegraph/deno/deno.json +++ b/src/typegraph/deno/deno.json @@ -9,7 +9,6 @@ "./deps/mod.ts": "./src/deps/mod.ts", "./effects.ts": "./src/effects.ts", "./envs/cli.ts": "./src/envs/cli.ts", - "./gen/typegraph_core.d.ts": "./src/gen/typegraph_core.d.ts", "./host/host.d.ts": "./src/host/host.d.ts", "./index.ts": "./src/index.ts", "./io.ts": "./src/io.ts", diff --git a/tests/metagen/metagen_test.ts b/tests/metagen/metagen_test.ts index 12ad310f8..e5859f370 100644 --- a/tests/metagen/metagen_test.ts +++ b/tests/metagen/metagen_test.ts @@ -11,7 +11,7 @@ import { testDir } from "test-utils/dir.ts"; import $ from "@david/dax"; import { z as zod } from "zod"; import { workspaceDir } from "test-utils/dir.ts"; -import { FdkOutput } from "@typegraph/sdk/gen/typegraph_core.d.ts"; +import { FdkOutput } from "@typegraph/sdk/gen/utils.ts"; const denoJson = resolve(testDir, "./deno.jsonc"); diff --git a/tools/jsr/fix-declarations.ts b/tools/jsr/fix-declarations.ts deleted file mode 100644 index 286bb7bd4..000000000 --- a/tools/jsr/fix-declarations.ts +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. -// SPDX-License-Identifier: MPL-2.0 - -import { dirname, fromFileUrl, resolve } from "@std/path"; -import { expandGlob } from "@std/fs"; -import { join, relative } from "../deps.ts"; -import { denoSdkDir } from "./common.ts"; - -export const thisDir = dirname(fromFileUrl(import.meta.url)); - -type Replacer = { - path: string; - op: (s: string) => string; -}; - -const basePath = "../../src/typegraph/deno/src/gen"; - -const replacements = [ - // Imports should refer to the actual file - ...(await Array.fromAsync( - expandGlob(join(basePath, "/**/*.d.ts"), { - root: thisDir, - includeDirs: false, - globstar: true, - }), - )).map(({ path }) => ({ - path, - op: (s: string) => s.replace(/^(import .*)(\.js)\';$/, "$1.d.ts';"), - })), - // Remove exports aliases - { - path: resolve(thisDir, basePath, "typegraph_core.js"), - op: (s: string) => s.replaceAll(/,\s*\w+ as '[\w:\/]+'/g, ""), - }, - // Normalize native node imports - { - path: resolve(thisDir, basePath, "typegraph_core.js"), - op: (s: string) => - s.replaceAll(/["']fs\/promises["']/g, "'node:fs/promises'"), - }, -] as Array; - -console.log("Fixing declarations.."); -for (const { path, op } of replacements) { - const text = await Deno.readTextFile(path); - const rewrite = [...text.split("\n")]; - - for (let i = 0; i < rewrite.length; i += 1) { - rewrite[i] = op(rewrite[i]); - } - - const newText = rewrite.join("\n"); - if (text != newText) { - console.log(` Fixed generated code at ${relative(thisDir, path)}`); - await Deno.writeTextFile(path, newText); - } -} - -console.log("Merge types"); -// Merge everything at interfaces/* -const merged = (await Array.fromAsync( - expandGlob(join(basePath, "/interfaces/*.d.ts"), { - root: thisDir, - includeDirs: false, - globstar: true, - }), -)).reduce((curr, { path }) => { - console.log(` < ${path}`); - const next = ` -// ${relative(denoSdkDir, path)} -${ - Deno.readTextFileSync(path) - .replaceAll(/import type {.+} from ['"].+\.d\.ts['"];/g, (m) => `// ${m}`) - .replaceAll(/export {.+};/g, (m) => `// ${m}`) - } -`; - return curr + next; -}, ""); - -// Dump everything into typegraph_core.d.ts -// As of jco 1.2.4, typegraph_core.d.ts simply re-exports the types from interfaces/*.d.ts -const hintMainPath = join(thisDir, basePath, "/typegraph_core.d.ts"); -let mergedContent = ` -// interfaces begin -${merged} -// interfaces end - -// common -`; - -const dupDecl = ["export type TypeId = number;"]; -for (const dup of dupDecl) { - mergedContent = mergedContent.replaceAll(dup, ""); -} -mergedContent += `\n${dupDecl.join("\n")}`; - -await Deno.writeTextFile(hintMainPath, mergedContent); -await Deno.remove(join(thisDir, basePath, "/interfaces"), { recursive: true });