Skip to content

Commit 8606b58

Browse files
committed
symbol fix
1 parent b77cde9 commit 8606b58

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/zero/tool/build.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,26 @@ async function getViteConfig(): Promise<InlineConfig> {
171171
};
172172
}
173173

174+
// Modules that should be kept external in the testing build to share
175+
// symbol instances with the main bundle
176+
const testingExternalModules = ['query-internals'];
177+
174178
async function getTestingViteConfig(): Promise<InlineConfig> {
175179
return {
176180
...baseConfig,
177181
define: testingDefine,
178182
build: {
179183
...baseConfig.build,
180184
rollupOptions: {
181-
external,
185+
external: (id: string) => {
186+
// Check standard externals
187+
if (external.some(ext => id === ext || id.startsWith(ext + '/'))) {
188+
return true;
189+
}
190+
// Keep certain modules external so testing bundle shares symbols
191+
// with the main bundle (e.g., queryInternalsTag)
192+
return testingExternalModules.some(mod => id.includes(mod));
193+
},
182194
input: await getTestingEntryPoints(),
183195
output: {
184196
format: 'es',
@@ -187,6 +199,24 @@ async function getTestingViteConfig(): Promise<InlineConfig> {
187199
// Don't preserve modules for testing - bundle dependencies so they
188200
// get the TESTING=true define
189201
preserveModules: false,
202+
// Rewrite external module paths to point to the built output
203+
paths: (id: string) => {
204+
for (const mod of testingExternalModules) {
205+
if (id.includes(mod)) {
206+
// Convert absolute path to relative path from testing.js output
207+
// testing.js is at out/zero/src/testing.js
208+
// query-internals.js is at out/zql/src/query/query-internals.js
209+
// Correct relative path: ../../zql/src/query/query-internals.js
210+
// Vite prepends ../../ for output at zero/src/, so we just return
211+
// the package-relative path
212+
const match = id.match(/packages\/([^/]+\/src\/.+)\.ts$/);
213+
if (match) {
214+
return `${match[1]}.js`;
215+
}
216+
}
217+
}
218+
return id;
219+
},
190220
},
191221
},
192222
},

0 commit comments

Comments
 (0)