forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.js
More file actions
145 lines (136 loc) · 4.32 KB
/
Copy pathvite.config.js
File metadata and controls
145 lines (136 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import tailwindcss from "@tailwindcss/vite";
import viteReact from "@vitejs/plugin-react";
import { createRequire } from "module";
import path from "path";
import { fileURLToPath } from "url";
import { defineConfig, loadEnv } from "vite";
import { BugsnagSourceMapUploaderPlugin } from "vite-plugin-bugsnag";
import { REACT_COMPILER_ENABLED_DIRS } from "./react-compiler.config.js";
// Create __dirname equivalent for ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const require = createRequire(import.meta.url);
// `@openai/agents-core` only exposes `.` and `./_shims` in its
// `exports` map — the raw `dist/shims/shims-browser.mjs` subpath is
// not exported, so `require.resolve` on it fails. Resolve the public
// root entry and walk to the sibling browser shim file inside the
// package.
const agentsCoreBrowserShim = path.resolve(
path.dirname(require.resolve("@openai/agents-core")),
"shims/shims-browser.mjs",
);
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const apiKey = env.VITE_BUGSNAG_API_KEY;
const appVersion = env.VITE_GIT_COMMIT ?? "dev";
const appUrl = process.env.APP_URL;
const sourceMapEndpoint = process.env.BUGSNAG_SOURCE_MAP_ENDPOINT;
const uploadSourcemaps = Boolean(apiKey && appUrl && sourceMapEndpoint);
const bugsnagConfig = {
apiKey,
appVersion,
endpoint: sourceMapEndpoint,
};
return {
plugins: [
viteReact({
babel: {
plugins: [
["@babel/plugin-proposal-decorators", { version: "2023-11" }],
[
"babel-plugin-react-compiler",
{
sources: (filename) => {
return REACT_COMPILER_ENABLED_DIRS.some((dir) =>
filename.includes(dir),
);
},
},
],
],
},
}),
tailwindcss(),
...(uploadSourcemaps
? [
BugsnagSourceMapUploaderPlugin({
...bugsnagConfig,
base: appUrl,
overwrite: true,
}),
]
: []),
],
base: "/",
build: {
manifest: "assets-registry.json",
sourcemap: "hidden",
rollupOptions: {
input: {
index: path.resolve(__dirname, "index.html"),
main: path.resolve(__dirname, "src/index.tsx"),
},
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
assetsInclude: ["**/*.yaml", "**/*.py"],
// The agent runs in a Web Worker. `@openai/agents-core/_shims`
// exposes a `browser` export condition, but Vite's worker bundle
// does not reliably apply it — the catch-all condition falls
// through to the Node shim that imports `node:process`. We force
// the browser variant via a scoped `resolveId`, kept here so the
// main bundle (which already resolves correctly via export
// conditions) is not affected.
//
// The runtime side of "no Node in the worker" — specifically the
// unguarded `process.env.X` read in `@openai/agents-core` — is
// handled by the `globalThis.process` stub at the top of
// `src/agent/worker.ts`, not here, so the fix applies in both
// `vite build` and `vite serve` (dev) modes.
//
// `debug` (transitive of `@openai/agents-core`) is handled
// automatically by its package.json `browser` field, which Vite
// does honor for the worker bundle.
worker: {
format: "es",
plugins: () => [
{
name: "tangle-agent-worker-shims",
enforce: "pre",
resolveId(id) {
if (id === "@openai/agents-core/_shims") {
return agentsCoreBrowserShim;
}
return null;
},
},
],
},
test: {
globals: true,
environment: "jsdom",
setupFiles: ["./vitest-setup.js"],
include: ["src/**/*.{test,spec}.?(c|m)[jt]s?(x)"],
coverage: {
provider: "v8",
reporter: ["text", "json", "html"],
exclude: [
"node_modules/",
"test/",
"tests/",
"tests/e2e/",
"*.test.tsx",
"*.test.ts",
"*.d.ts",
],
},
},
optimizeDeps: {
exclude: ["lucide-react"],
},
};
});