@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

main
ts 45 lines 1.37 KB
Raw
1 // Mirrors `@cloudflare/vite-plugin`'s `playground/child-environment`: the
2 // Worker (`parent` environment) imports a module built by its `child`
3 // environment, with the user's own `buildApp` ordering the builds.
4 import assert from "node:assert";
5 import * as path from "node:path";
6 import type { ViteBuilder } from "vite";
7
8 export default {
9 environments: {
10 child: {
11 build: {
12 rollupOptions: {
13 input: path.resolve(import.meta.dirname, "src/child-environment-module.ts"),
14 },
15 },
16 },
17 },
18 builder: {
19 async buildApp(builder: ViteBuilder) {
20 const parentEnvironment = builder.environments.parent;
21 const childEnvironment = builder.environments.child;
22
23 assert(parentEnvironment, `No "parent" environment`);
24 assert(childEnvironment, `No "child" environment`);
25
26 await builder.build(parentEnvironment);
27 await builder.build(childEnvironment);
28 },
29 },
30 plugins: [
31 {
32 name: "virtual-module-plugin",
33 resolveId(source: string) {
34 if (source === "virtual:environment-name") {
35 return "\0virtual:environment-name";
36 }
37 },
38 load(this: { environment: { name: string } }, id: string) {
39 if (id === "\0virtual:environment-name") {
40 return `export function getEnvironmentName() { return ${JSON.stringify(this.environment.name)} }`;
41 }
42 },
43 },
44 ],
45 };