Skip to content

Commit c0dfebc

Browse files
committed
fixup! feat(server-utils): Register orchestrion channel integrations via the global marker
1 parent bcc924c commit c0dfebc

3 files changed

Lines changed: 6 additions & 18 deletions

File tree

packages/server-utils/src/orchestrion/bundler/vite.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ function serverEnvironmentOnly(plugin: UnknownPlugin): UnknownPlugin {
126126
* Returns the cleaned module id when the module is eligible for injection,
127127
* `null` otherwise. Caller is responsible for recording the injection.
128128
*/
129-
function eligibleDevEntry(
130-
injectedServeModules: Map<string, string>,
131-
id: string,
132-
environment: string,
133-
): string | null {
129+
function eligibleDevEntry(injectedServeModules: Map<string, string>, id: string, environment: string): string | null {
134130
const cleanId = id.split('?')[0] ?? id;
135131
const injectedModule = injectedServeModules.get(environment);
136132

@@ -171,9 +167,6 @@ const RESOLVED_REGISTER_MODULE_ID = `\0${REGISTER_MODULE_ID}`;
171167
* eligible source module transformed in each server environment.
172168
*/
173169
function registerIntegrationsPlugin(): UnknownPlugin {
174-
// `createRequire().resolve(REGISTER_MODULE)` would select the package's CJS
175-
// export. Resolve the package root instead and explicitly target the ESM
176-
// export which is bundled alongside the ESM-only Vite plugin.
177170
const require = createRequire(import.meta.url);
178171
const packageRoot = dirname(require.resolve('@sentry/server-utils/package.json'));
179172
const resolvedRegisterModule = resolve(packageRoot, 'build/esm/orchestrion/index.js');
@@ -197,7 +190,7 @@ function registerIntegrationsPlugin(): UnknownPlugin {
197190
if (code.includes(REGISTER_MODULE_ID)) return null;
198191

199192
const ms = new MagicString(code);
200-
const injection = `import ${JSON.stringify(REGISTER_MODULE_ID)};\n`;
193+
const injection = `import '${REGISTER_MODULE_ID}';\n`;
201194
ms.prepend(injection);
202195

203196
return { code: ms.toString(), map: ms.generateMap({ hires: true }) };
@@ -218,7 +211,7 @@ function registerIntegrationsPlugin(): UnknownPlugin {
218211
// imports here and let Rollup tree-shake the rest of the ESM module.
219212
return {
220213
code: [
221-
`import { registerChannelIntegrations } from ${JSON.stringify(resolvedRegisterModule)};`,
214+
`import { registerChannelIntegrations } from '${resolvedRegisterModule}';`,
222215
'registerChannelIntegrations();',
223216
'',
224217
].join('\n'),
@@ -251,11 +244,7 @@ function registerIntegrationsPlugin(): UnknownPlugin {
251244
};
252245
}
253246

254-
function bundlerMarkerPlugin({
255-
hasRegistrationPlugin,
256-
}: {
257-
hasRegistrationPlugin: boolean;
258-
}): UnknownPlugin {
247+
function bundlerMarkerPlugin({ hasRegistrationPlugin }: { hasRegistrationPlugin: boolean }): UnknownPlugin {
259248
const banner = [
260249
'globalThis.__SENTRY_ORCHESTRION__ = (globalThis.__SENTRY_ORCHESTRION__ || {});',
261250
'globalThis.__SENTRY_ORCHESTRION__.bundler = true;',

packages/server-utils/test/orchestrion/register-integrations.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ describe('channel-integration registry', () => {
4040
expect(first).not.toBe(second);
4141
expect(first?.name).toBe(second?.name);
4242
});
43-
4443
});
4544

4645
describe('registerChannelIntegrations', () => {

packages/server-utils/test/orchestrion/vite-register-integrations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('sentryOrchestrionPlugin — registerIntegrations', () => {
8686
it('injects the virtual registration import into the entry module', () => {
8787
const result = runTransform(plugin, 'export default {};\n', ctx({ isEntry: true }));
8888

89-
expect(result?.code).toContain(`import "${REGISTER_MODULE_ID}";`);
89+
expect(result?.code).toContain(`import '${REGISTER_MODULE_ID}';`);
9090
expect(result?.map).toBeTruthy();
9191
});
9292

@@ -138,7 +138,7 @@ describe('sentryOrchestrionPlugin — registerIntegrations', () => {
138138
const plugin = makeServePlugin();
139139
const result = runTransform(plugin, 'export default {};\n', serveCtx(), '/app/src/index.ts');
140140

141-
expect(result?.code).toContain(`import "${REGISTER_MODULE_ID}";`);
141+
expect(result?.code).toContain(`import '${REGISTER_MODULE_ID}';`);
142142
});
143143

144144
it('injects only once per environment', () => {

0 commit comments

Comments
 (0)