@tui-sandbox/library 3.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/browser/assets/DejaVuSansMNerdFontMono-Regular-CRJgiq0O.ttf +0 -0
  3. package/dist/browser/assets/index-BckJD5M_.js +9 -0
  4. package/dist/browser/assets/index-Bf37MeF1.css +32 -0
  5. package/dist/browser/index.html +12 -0
  6. package/dist/src/browser/neovim-client.d.ts +7 -0
  7. package/dist/src/browser/neovim-client.js +14 -0
  8. package/dist/src/client/color-utilities.d.ts +6 -0
  9. package/dist/src/client/color-utilities.js +5 -0
  10. package/dist/src/client/color-utilities.test.d.ts +1 -0
  11. package/dist/src/client/color-utilities.test.js +7 -0
  12. package/dist/src/client/index.d.ts +2 -1
  13. package/dist/src/client/index.js +2 -1
  14. package/dist/src/client/neovim-client.js +4 -4
  15. package/dist/src/client/websocket-client.js +1 -1
  16. package/dist/src/scripts/tui.d.ts +1 -0
  17. package/dist/src/scripts/tui.js +25 -0
  18. package/dist/src/server/TestServer.d.ts +6 -4
  19. package/dist/src/server/TestServer.js +35 -11
  20. package/dist/src/server/dirtree/index.js +1 -1
  21. package/dist/src/server/dirtree/index.test.js +2 -2
  22. package/dist/src/server/index.d.ts +4 -4
  23. package/dist/src/server/index.js +3 -3
  24. package/dist/src/server/neovim/NeovimApplication.d.ts +2 -2
  25. package/dist/src/server/neovim/NeovimApplication.js +3 -3
  26. package/dist/src/server/neovim/NeovimJavascriptApiClient.d.ts +1 -1
  27. package/dist/src/server/neovim/NeovimJavascriptApiClient.js +1 -1
  28. package/dist/src/server/neovim/NeovimJavascriptApiClient.test.js +1 -1
  29. package/dist/src/server/neovim/environment/createTempDir.d.ts +2 -2
  30. package/dist/src/server/neovim/environment/createTempDir.js +2 -2
  31. package/dist/src/server/neovim/environment/createTempDir.test.js +75 -11
  32. package/dist/src/server/neovim/index.d.ts +4 -4
  33. package/dist/src/server/neovim/index.js +3 -3
  34. package/dist/src/server/server.d.ts +4 -3
  35. package/dist/src/server/server.js +80 -12
  36. package/dist/src/server/server.test.js +2 -2
  37. package/dist/src/server/updateTestdirectorySchemaFile.d.ts +0 -1
  38. package/dist/src/server/updateTestdirectorySchemaFile.js +1 -2
  39. package/dist/src/server/updateTestdirectorySchemaFile.test.js +2 -2
  40. package/dist/src/server/utilities/DisposableSingleApplication.d.ts +1 -1
  41. package/dist/src/server/utilities/DisposableSingleApplication.test.js +1 -1
  42. package/dist/src/server/utilities/TerminalApplication.d.ts +1 -1
  43. package/dist/src/server/utilities/applicationAvailable.test.js +1 -1
  44. package/dist/src/server/utilities/generator.test.js +1 -1
  45. package/dist/tsconfig.tsbuildinfo +1 -1
  46. package/index.html +11 -0
  47. package/package.json +15 -5
  48. package/src/browser/neovim-client.ts +26 -0
  49. package/src/client/color-utilities.test.ts +8 -0
  50. package/src/client/color-utilities.ts +9 -0
  51. package/src/client/index.ts +2 -1
  52. package/src/client/neovim-client.ts +4 -4
  53. package/src/client/websocket-client.ts +1 -1
  54. package/src/scripts/tui.ts +29 -0
  55. package/src/server/TestServer.ts +50 -15
  56. package/src/server/dirtree/index.test.ts +2 -2
  57. package/src/server/dirtree/index.ts +1 -1
  58. package/src/server/index.ts +4 -5
  59. package/src/server/neovim/NeovimApplication.ts +5 -5
  60. package/src/server/neovim/NeovimJavascriptApiClient.test.ts +2 -2
  61. package/src/server/neovim/NeovimJavascriptApiClient.ts +1 -1
  62. package/src/server/neovim/environment/createTempDir.test.ts +2 -2
  63. package/src/server/neovim/environment/createTempDir.ts +4 -4
  64. package/src/server/neovim/index.ts +7 -7
  65. package/src/server/server.test.ts +2 -2
  66. package/src/server/server.ts +10 -7
  67. package/src/server/updateTestdirectorySchemaFile.test.ts +3 -3
  68. package/src/server/updateTestdirectorySchemaFile.ts +1 -2
  69. package/src/server/utilities/DisposableSingleApplication.test.ts +2 -2
  70. package/src/server/utilities/DisposableSingleApplication.ts +1 -1
  71. package/src/server/utilities/TerminalApplication.ts +1 -1
  72. package/src/server/utilities/applicationAvailable.test.ts +1 -1
  73. package/src/server/utilities/generator.test.ts +1 -1
  74. package/tsconfig.json +10 -4
  75. package/vite.config.js +26 -0
  76. package/dist/vitest.config.d.ts +0 -2
  77. package/dist/vitest.config.js +0 -8
  78. package/vitest.config.ts +0 -9
package/index.html ADDED
@@ -0,0 +1,11 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>tui-sandbox integration tests</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script type="module" src="./src/browser/neovim-client.ts"></script>
10
+ </body>
11
+ </html>
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@tui-sandbox/library",
3
- "version": "3.0.0",
3
+ "version": "4.1.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
+ "bin": {
7
+ "tui": "dist/src/scripts/tui.js"
8
+ },
6
9
  "dependencies": {
7
10
  "@catppuccin/palette": "1.7.1",
8
- "@trpc/client": "11.0.0-rc.608",
9
- "@trpc/server": "11.0.0-rc.608",
11
+ "@trpc/client": "11.0.0-rc.630",
12
+ "@trpc/server": "11.0.0-rc.630",
10
13
  "@xterm/addon-attach": "0.11.0",
11
14
  "@xterm/addon-fit": "0.10.0",
12
15
  "@xterm/xterm": "5.5.0",
@@ -14,23 +17,30 @@
14
17
  "core-js": "3.39.0",
15
18
  "cors": "2.8.5",
16
19
  "dree": "5.1.5",
20
+ "express": "4.21.1",
17
21
  "neovim": "5.3.0",
18
22
  "node-pty": "1.0.0",
19
23
  "prettier": "3.3.3",
24
+ "tsx": "4.19.2",
20
25
  "type-fest": "4.26.1",
21
- "winston": "3.16.0",
26
+ "winston": "3.17.0",
22
27
  "zod": "3.23.8"
23
28
  },
24
29
  "devDependencies": {
25
30
  "@runtyping/zod": "2.1.1",
26
31
  "@types/command-exists": "1.2.3",
27
32
  "@types/cors": "2.8.17",
33
+ "@types/express": "5.0.0",
28
34
  "@types/node": "22.9.0",
29
35
  "nodemon": "3.1.7",
36
+ "vite": "5.4.11",
30
37
  "vitest": "2.1.4"
31
38
  },
32
39
  "scripts": {
33
- "build": "tsc",
40
+ "build": "concurrently --names 'vite,tsc' 'vite build' 'tsc' --prefix-colors blue,green",
41
+ "dev": "concurrently --names 'client,server' 'pnpm dev:client' 'pnpm dev:server' --prefix-colors blue,green",
42
+ "dev:client": "vite",
43
+ "dev:server": "cd ../integration-tests/ && nodemon --watch ../library --ext '*' --exec 'tsx ../library/src/scripts/tui.ts start'",
34
44
  "test": "vitest"
35
45
  }
36
46
  }
@@ -0,0 +1,26 @@
1
+ import { NeovimClient } from "../client/index.js"
2
+ import type { StartNeovimGenericArguments } from "../server/neovim/NeovimApplication.js"
3
+ import type { TestDirectory } from "../server/types.js"
4
+
5
+ const app = document.querySelector<HTMLElement>("#app")
6
+ if (!app) {
7
+ throw new Error("No app element found")
8
+ }
9
+
10
+ const client = new NeovimClient(app)
11
+
12
+ /** Entrypoint for the test runner (cypress) */
13
+ window.startNeovim = async function (startArgs?: StartNeovimGenericArguments): Promise<TestDirectory> {
14
+ const testDirectory = await client.startNeovim({
15
+ filename: startArgs?.filename ?? "initial-file.txt",
16
+ startupScriptModifications: startArgs?.startupScriptModifications ?? [],
17
+ })
18
+
19
+ return testDirectory
20
+ }
21
+
22
+ declare global {
23
+ interface Window {
24
+ startNeovim(startArguments?: StartNeovimGenericArguments): Promise<TestDirectory>
25
+ }
26
+ }
@@ -0,0 +1,8 @@
1
+ import { rgbify } from "./color-utilities.js"
2
+
3
+ describe("rgbify", () => {
4
+ it("converts a catppuccin RGB color to a CSS color string", () => {
5
+ const color = { r: 1, g: 2, b: 3 }
6
+ expect(rgbify(color)).toEqual("rgb(1, 2, 3)")
7
+ })
8
+ })
@@ -0,0 +1,9 @@
1
+ import type { flavors } from "@catppuccin/palette"
2
+
3
+ type RgbColor = (typeof flavors.macchiato.colors)["surface0"]["rgb"]
4
+
5
+ /** Convert a catppuccin RGB color to a CSS color string. This way you can
6
+ * assert that text that's visible on the screen has a specific color. */
7
+ export function rgbify(color: RgbColor): string {
8
+ return `rgb(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()})`
9
+ }
@@ -1,3 +1,4 @@
1
1
  // This is the public client api. Semantic versioning will be applied to this.
2
2
 
3
- export { NeovimClient } from "./neovim-client"
3
+ export { rgbify } from "./color-utilities.js"
4
+ export { NeovimClient } from "./neovim-client.js"
@@ -20,10 +20,10 @@ export class NeovimClient {
20
20
  splitLink({
21
21
  condition: operation => operation.type === "subscription",
22
22
  true: unstable_httpSubscriptionLink({
23
- url: "http://localhost:3000",
23
+ url: "/trpc",
24
24
  }),
25
25
  false: httpBatchLink({
26
- url: "http://localhost:3000",
26
+ url: "/trpc",
27
27
  }),
28
28
  }),
29
29
  ],
@@ -69,7 +69,7 @@ export class NeovimClient {
69
69
  public async startNeovim(args: Except<StartNeovimGenericArguments, "terminalDimensions">): Promise<TestDirectory> {
70
70
  await this.ready
71
71
 
72
- const neovim = await this.trpc.neovim.start.mutate({
72
+ const testDirectory = await this.trpc.neovim.start.mutate({
73
73
  startNeovimArguments: {
74
74
  ...args,
75
75
  terminalDimensions: {
@@ -80,6 +80,6 @@ export class NeovimClient {
80
80
  tabId: this.tabId,
81
81
  })
82
82
 
83
- return neovim
83
+ return testDirectory
84
84
  }
85
85
  }
@@ -5,7 +5,7 @@ import "@xterm/xterm/css/xterm.css"
5
5
  import z from "zod"
6
6
  import type { TabId } from "../server/utilities/tabId.ts"
7
7
  import "./style.css"
8
- import { validateMouseEvent } from "./validateMouseEvent"
8
+ import { validateMouseEvent } from "./validateMouseEvent.js"
9
9
 
10
10
  export type StartTerminalOptions = {
11
11
  onMouseEvent: (data: string) => void
@@ -0,0 +1,29 @@
1
+ import { stat } from "node:fs/promises"
2
+ import path from "node:path"
3
+ import { startTestServer } from "../server/index.js"
4
+
5
+ //
6
+ // This is the main entrypoint to tui-sandbox
7
+ //
8
+
9
+ // the arguments passed to this script start at index 2
10
+ const args = process.argv.slice(2)
11
+
12
+ if (args[0] !== "start") {
13
+ throw new Error(`Usage: tui start`)
14
+ }
15
+
16
+ /** The cwd in the user's directory when they are running this script. Not the
17
+ * cwd of the script itself. */
18
+ const cwd = process.cwd()
19
+ console.log(`🚀 Starting test server in ${cwd}`)
20
+ await stat(path.join(cwd, "MyTestDirectory.ts"))
21
+
22
+ try {
23
+ await startTestServer({
24
+ testEnvironmentPath: path.join(cwd, "test-environment/"),
25
+ outputFilePath: path.join(cwd, "MyTestDirectory.ts"),
26
+ })
27
+ } catch (e) {
28
+ console.error(e)
29
+ }
@@ -1,36 +1,71 @@
1
1
  import type { AnyTRPCRouter } from "@trpc/server"
2
- import { createHTTPServer } from "@trpc/server/adapters/standalone"
3
- import "core-js/proposals/async-explicit-resource-management"
2
+ import * as trpcExpress from "@trpc/server/adapters/express"
4
3
  import cors from "cors"
5
4
  import { once } from "events"
6
- import type { TestServerConfig } from "./updateTestdirectorySchemaFile"
7
- import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile"
5
+ import express from "express"
6
+ import { accessSync } from "fs"
7
+ import path from "path"
8
+ import { fileURLToPath } from "url"
9
+ import type { TestServerConfig } from "./updateTestdirectorySchemaFile.js"
10
+ import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js"
11
+
12
+ export type TestServerSettings = {
13
+ port: number
14
+ }
15
+
16
+ const __filename = fileURLToPath(import.meta.url)
17
+ const __dirname = path.dirname(__filename)
8
18
 
9
19
  export class TestServer {
10
- public constructor(private readonly port: number) {}
20
+ public constructor(private readonly settings: TestServerSettings) {}
11
21
 
12
22
  public async startAndRun(appRouter: AnyTRPCRouter, config: TestServerConfig): Promise<void> {
13
23
  console.log("🚀 Server starting")
14
24
 
15
25
  await updateTestdirectorySchemaFile(config)
16
26
 
17
- const server = createHTTPServer({
18
- router: appRouter,
19
- createContext: () => ({}),
20
- middleware: cors({
21
- origin: "*",
22
- }),
27
+ const app = express()
28
+ app.use(
29
+ "/trpc",
30
+ trpcExpress.createExpressMiddleware({
31
+ router: appRouter,
32
+ createContext: () => ({}),
33
+ middleware: cors({
34
+ origin: "*",
35
+ }),
36
+ })
37
+ )
38
+
39
+ {
40
+ const publicPath = path.resolve(__dirname, "..", "..", "browser")
41
+ try {
42
+ accessSync(publicPath)
43
+ } catch (e) {
44
+ // This is normal when developing the tui-sandbox library locally. It
45
+ // should always exist when using it as an npm package, however.
46
+ console.log(`⚠️ Warning: the tui-sandbox root contents directory is not accessible at: ${publicPath}`)
47
+ }
48
+
49
+ // eslint-disable-next-line import-x/no-named-as-default-member
50
+ app.use(express.static(publicPath))
51
+ }
52
+
53
+ app.use("/ping", (_, res) => {
54
+ console.log("🏓 received /ping")
55
+ res.send("pong")
23
56
  })
24
57
 
25
- server.listen(this.port)
58
+ const server = app.listen(this.settings.port, "0.0.0.0")
59
+
26
60
  server.on("connection", socket => {
27
- console.log(`➕➕ Connection`)
61
+ const connectionInfo = `${socket.remoteAddress}:${socket.remotePort}`
62
+ console.log(`➕➕ Connection from ${connectionInfo}`)
28
63
  socket.once("close", () => {
29
- console.log(`➖➖ Connection`)
64
+ console.log(`➖➖ Connection from ${connectionInfo}`)
30
65
  })
31
66
  })
32
67
 
33
- console.log(`✅ Server listening on ws://localhost:${this.port}`)
68
+ console.log(`✅ Server listening on port ${this.settings.port}`)
34
69
 
35
70
  await Promise.race([once(process, "SIGTERM"), once(process, "SIGINT")])
36
71
  console.log("Shutting down...")
@@ -1,8 +1,8 @@
1
1
  import assert from "assert"
2
2
  import path from "path"
3
3
  import { describe, expect, it } from "vitest"
4
- import { buildSchemaForDirectoryTree, getDirectoryTree } from "."
5
- import { Lazy } from "../utilities/Lazy"
4
+ import { Lazy } from "../utilities/Lazy.js"
5
+ import { buildSchemaForDirectoryTree, getDirectoryTree } from "./index.js"
6
6
 
7
7
  describe("dirtree", () => {
8
8
  const output = new Lazy(() =>
@@ -3,7 +3,7 @@ import type { Dree } from "dree"
3
3
  import { scan, Type } from "dree"
4
4
  import { format, resolveConfig } from "prettier"
5
5
  import { fileURLToPath } from "url"
6
- import { jsonToZod } from "./json-to-zod"
6
+ import { jsonToZod } from "./json-to-zod.js"
7
7
 
8
8
  type TreeResult = { dree: Dree; allFiles: Dree[] }
9
9
 
@@ -1,7 +1,6 @@
1
- import "core-js/proposals/async-explicit-resource-management"
2
-
3
1
  // This is the public server api. Semantic versioning will be applied to this.
4
2
 
5
- export { startTestServer } from "./server"
6
- export { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile"
7
- export type { TestServerConfig } from "./updateTestdirectorySchemaFile"
3
+ export { startTestServer } from "./server.js"
4
+ export { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js"
5
+ export type { TestServerConfig } from "./updateTestdirectorySchemaFile.js"
6
+ import "core-js/proposals/async-explicit-resource-management.js"
@@ -5,11 +5,11 @@ import { access } from "fs/promises"
5
5
  import type { NeovimClient as NeovimApiClient } from "neovim"
6
6
  import { tmpdir } from "os"
7
7
  import path from "path"
8
- import type { TestDirectory } from "../types"
9
- import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication"
10
- import type { Lazy } from "../utilities/Lazy"
11
- import { TerminalApplication } from "../utilities/TerminalApplication"
12
- import { connectNeovimApi } from "./NeovimJavascriptApiClient"
8
+ import type { TestDirectory } from "../types.js"
9
+ import { DisposableSingleApplication } from "../utilities/DisposableSingleApplication.js"
10
+ import type { Lazy } from "../utilities/Lazy.js"
11
+ import { TerminalApplication } from "../utilities/TerminalApplication.js"
12
+ import { connectNeovimApi } from "./NeovimJavascriptApiClient.js"
13
13
 
14
14
  /*
15
15
 
@@ -1,7 +1,7 @@
1
1
  import { access } from "fs/promises"
2
2
  import { attach } from "neovim"
3
- import type { PollingInterval } from "./NeovimJavascriptApiClient"
4
- import { connectNeovimApi } from "./NeovimJavascriptApiClient"
3
+ import type { PollingInterval } from "./NeovimJavascriptApiClient.js"
4
+ import { connectNeovimApi } from "./NeovimJavascriptApiClient.js"
5
5
 
6
6
  vi.mock("neovim")
7
7
  vi.mock("fs/promises")
@@ -1,7 +1,7 @@
1
1
  import { access } from "fs/promises"
2
2
  import type { NeovimClient as NeovimApiClient } from "neovim"
3
3
  import { attach } from "neovim"
4
- import { Lazy } from "../utilities/Lazy"
4
+ import { Lazy } from "../utilities/Lazy.js"
5
5
 
6
6
  export type NeovimJavascriptApiClient = NeovimApiClient
7
7
 
@@ -1,8 +1,8 @@
1
1
  import fs, { rmdirSync } from "fs"
2
2
  import nodePath from "path"
3
3
  import { expect, it } from "vitest"
4
- import type { TestDirsPath } from "./createTempDir"
5
- import { createTempDir } from "./createTempDir"
4
+ import type { TestDirsPath } from "./createTempDir.js"
5
+ import { createTempDir } from "./createTempDir.js"
6
6
 
7
7
  vi.spyOn(console, "log").mockImplementation(vi.fn())
8
8
 
@@ -4,10 +4,10 @@ import { Type } from "dree"
4
4
  import { constants, readdirSync } from "fs"
5
5
  import { access, mkdir, mkdtemp } from "fs/promises"
6
6
  import path from "path"
7
- import { convertDree, getDirectoryTree } from "../../dirtree"
8
- import type { TestDirectory } from "../../types"
9
- import type { TestServerConfig } from "../../updateTestdirectorySchemaFile"
10
- import { updateTestdirectorySchemaFile } from "../../updateTestdirectorySchemaFile"
7
+ import { convertDree, getDirectoryTree } from "../../dirtree/index.js"
8
+ import type { TestDirectory } from "../../types.js"
9
+ import type { TestServerConfig } from "../../updateTestdirectorySchemaFile.js"
10
+ import { updateTestdirectorySchemaFile } from "../../updateTestdirectorySchemaFile.js"
11
11
 
12
12
  export async function createTempDir(config: TestServerConfig): Promise<TestDirectory> {
13
13
  try {
@@ -1,11 +1,11 @@
1
1
  import assert from "assert"
2
- import type { TestDirectory } from "../types"
3
- import type { TestServerConfig } from "../updateTestdirectorySchemaFile"
4
- import { convertEventEmitterToAsyncGenerator } from "../utilities/generator"
5
- import type { TabId } from "../utilities/tabId"
6
- import { createTempDir } from "./environment/createTempDir"
7
- import type { StartNeovimGenericArguments } from "./NeovimApplication"
8
- import { NeovimApplication } from "./NeovimApplication"
2
+ import type { TestDirectory } from "../types.js"
3
+ import type { TestServerConfig } from "../updateTestdirectorySchemaFile.js"
4
+ import { convertEventEmitterToAsyncGenerator } from "../utilities/generator.js"
5
+ import type { TabId } from "../utilities/tabId.js"
6
+ import { createTempDir } from "./environment/createTempDir.js"
7
+ import type { StartNeovimGenericArguments } from "./NeovimApplication.js"
8
+ import { NeovimApplication } from "./NeovimApplication.js"
9
9
 
10
10
  const neovims = new Map<TabId["tabId"], NeovimApplication>()
11
11
 
@@ -1,5 +1,5 @@
1
- import { createAppRouter } from "./server"
2
- import { applicationAvailable } from "./utilities/applicationAvailable"
1
+ import { createAppRouter } from "./server.js"
2
+ import { applicationAvailable } from "./utilities/applicationAvailable.js"
3
3
 
4
4
  vi.mock("./utilities/applicationAvailable")
5
5
 
@@ -1,11 +1,12 @@
1
1
  import type { inferRouterInputs } from "@trpc/server"
2
+ import "core-js/proposals/async-explicit-resource-management.js"
2
3
  import { z } from "zod"
3
- import { trpc } from "./connection/trpc"
4
- import * as neovim from "./neovim"
5
- import { TestServer } from "./TestServer"
6
- import type { TestServerConfig } from "./updateTestdirectorySchemaFile"
7
- import { applicationAvailable } from "./utilities/applicationAvailable"
8
- import { tabIdSchema } from "./utilities/tabId"
4
+ import { trpc } from "./connection/trpc.js"
5
+ import * as neovim from "./neovim/index.js"
6
+ import { TestServer } from "./TestServer.js"
7
+ import type { TestServerConfig } from "./updateTestdirectorySchemaFile.js"
8
+ import { applicationAvailable } from "./utilities/applicationAvailable.js"
9
+ import { tabIdSchema } from "./utilities/tabId.js"
9
10
 
10
11
  /** Stack for managing resources that need to be disposed of when the server
11
12
  * shuts down */
@@ -62,7 +63,9 @@ export type AppRouter = Awaited<ReturnType<typeof createAppRouter>>
62
63
  export type RouterInput = inferRouterInputs<AppRouter>
63
64
 
64
65
  export async function startTestServer(config: TestServerConfig): Promise<TestServer> {
65
- const testServer = new TestServer(3000)
66
+ const testServer = new TestServer({
67
+ port: 3000,
68
+ })
66
69
  const appRouter = await createAppRouter(config)
67
70
  await testServer.startAndRun(appRouter, config)
68
71
 
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, writeFileSync } from "fs"
2
- import { buildTestDirectorySchema } from "./dirtree"
3
- import type { UpdateTestdirectorySchemaFileResult } from "./updateTestdirectorySchemaFile"
4
- import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile"
2
+ import { buildTestDirectorySchema } from "./dirtree/index.js"
3
+ import type { UpdateTestdirectorySchemaFileResult } from "./updateTestdirectorySchemaFile.js"
4
+ import { updateTestdirectorySchemaFile } from "./updateTestdirectorySchemaFile.js"
5
5
 
6
6
  vi.mock("fs")
7
7
  vi.mock("./dirtree")
@@ -1,6 +1,5 @@
1
- import "core-js/proposals/async-explicit-resource-management"
2
1
  import { readFileSync, writeFileSync } from "fs"
3
- import { buildTestDirectorySchema } from "./dirtree"
2
+ import { buildTestDirectorySchema } from "./dirtree/index.js"
4
3
 
5
4
  export type TestServerConfig = {
6
5
  testEnvironmentPath: string
@@ -1,5 +1,5 @@
1
- import type { StartableApplication } from "./DisposableSingleApplication"
2
- import { DisposableSingleApplication } from "./DisposableSingleApplication"
1
+ import type { StartableApplication } from "./DisposableSingleApplication.js"
2
+ import { DisposableSingleApplication } from "./DisposableSingleApplication.js"
3
3
 
4
4
  vi.spyOn(console, "log").mockImplementation(vi.fn())
5
5
 
@@ -1,5 +1,5 @@
1
1
  import assert from "assert"
2
- import type { TerminalApplication } from "./TerminalApplication"
2
+ import type { TerminalApplication } from "./TerminalApplication.js"
3
3
 
4
4
  export type StartableApplication = Pick<TerminalApplication, "write" | "processId" | "killAndWait">
5
5
 
@@ -4,7 +4,7 @@ import { createLogger, format, transports } from "winston"
4
4
  import type { ITerminalDimensions } from "@xterm/addon-fit"
5
5
  import type { IPty } from "node-pty"
6
6
  import pty from "node-pty"
7
- import type { StartableApplication } from "./DisposableSingleApplication"
7
+ import type { StartableApplication } from "./DisposableSingleApplication.js"
8
8
 
9
9
  // NOTE separating stdout and stderr is not supported by node-pty
10
10
  // https://github.com/microsoft/node-pty/issues/71
@@ -1,4 +1,4 @@
1
- import { applicationAvailable } from "./applicationAvailable"
1
+ import { applicationAvailable } from "./applicationAvailable.js"
2
2
 
3
3
  describe("sanity checks for mocking", () => {
4
4
  // because it makes no sense to mock the actual implementation if we don't
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from "stream"
2
- import { convertEventEmitterToAsyncGenerator } from "./generator"
2
+ import { convertEventEmitterToAsyncGenerator } from "./generator.js"
3
3
 
4
4
  describe("when a listener is attached", () => {
5
5
  it("forwards events from an EventEmitter to an async generator", async () => {
package/tsconfig.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "skipLibCheck": true,
4
- "module": "ESNext",
4
+ "module": "NodeNext",
5
5
  "noImplicitOverride": true,
6
6
  "noPropertyAccessFromIndexSignature": true,
7
7
  "noUncheckedIndexedAccess": true,
8
- "moduleResolution": "Bundler",
9
- "target": "ESNext",
8
+ "moduleResolution": "NodeNext",
9
+ "target": "ES2022",
10
10
  "isolatedModules": true,
11
11
  "esModuleInterop": true,
12
+ "allowJs": true,
12
13
  "outDir": "dist",
13
14
  "lib": ["ES2023", "ESNext.Disposable"],
14
15
  "types": ["node", "vitest/globals"],
@@ -21,5 +22,10 @@
21
22
  "noFallthroughCasesInSwitch": true
22
23
  },
23
24
 
24
- "include": ["./src/", "./vitest.config.ts"]
25
+ "include": [
26
+ //
27
+ "./src/",
28
+ "src/scripts/tui.ts",
29
+ "./src/scripts/server.ts"
30
+ ]
25
31
  }
package/vite.config.js ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from "vite"
2
+
3
+ // https://vitejs.dev/config/
4
+ export default defineConfig({
5
+ server: {
6
+ host: "127.0.0.1",
7
+ https: false,
8
+ strictPort: true,
9
+ proxy: {
10
+ // inside @tui-sandbox/library, a vite development server can be used. It
11
+ // will proxy requests to the backend.
12
+ //
13
+ // When running in production, the backend starts its own static file
14
+ // server that is used (in development, it's just ignored).
15
+ "/trpc": "http://localhost:3000",
16
+ },
17
+ },
18
+ build: {
19
+ outDir: "./dist/browser/",
20
+ },
21
+ test: {
22
+ globals: true, // This will make describe, it, etc. available globally
23
+ environment: "node",
24
+ mockReset: true,
25
+ },
26
+ })
@@ -1,2 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;
@@ -1,8 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
- export default defineConfig({
3
- test: {
4
- globals: true, // This will make describe, it, etc. available globally
5
- environment: "node",
6
- mockReset: true,
7
- },
8
- });
package/vitest.config.ts DELETED
@@ -1,9 +0,0 @@
1
- import { defineConfig } from "vitest/config"
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true, // This will make describe, it, etc. available globally
6
- environment: "node",
7
- mockReset: true,
8
- },
9
- })