MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / transform

Function transform

packages/remix/src/config/vite.ts:118–172  ·  view source on GitHub ↗
(code, id)

Source from the content-addressed store, hash-verified

116 },
117
118 transform(code, id) {
119 if (!routeManifestJson) {
120 return null;
121 }
122
123 const isClientEntry =
124 /entry[.-]client\.[jt]sx?$/.test(id) ||
125 // Also handle Remix's default entry.client location
126 id.includes('/entry.client.') ||
127 id.includes('/entry-client.');
128
129 const isServerEntry =
130 /entry[.-]server\.[jt]sx?$/.test(id) ||
131 // Also handle Remix's default entry.server location
132 id.includes('/entry.server.') ||
133 id.includes('/entry-server.') ||
134 // Also handle Hydrogen/Cloudflare Workers server files
135 /(^|\/)server\.[jt]sx?$/.test(id);
136
137 if (isClientEntry) {
138 // XSS Prevention: Escape HTML-dangerous sequences in addition to JSON escaping
139 const safeJsonValue = escapeJsonForHtml(JSON.stringify(routeManifestJson));
140 const injectedCode = `
141// Sentry Remix Route Manifest - Auto-injected
142if (typeof window !== 'undefined') {
143 window.${MANIFEST_GLOBAL_KEY} = window.${MANIFEST_GLOBAL_KEY} || ${safeJsonValue};
144}
145${code}`;
146
147 return {
148 code: injectedCode,
149 map: null,
150 };
151 }
152
153 if (isServerEntry) {
154 // Inject into server entry for server-side transaction naming
155 // Use globalThis for Cloudflare Workers/Hydrogen compatibility
156 // XSS Prevention: Escape HTML-dangerous sequences (important if server renders this)
157 const safeJsonValue = escapeJsonForHtml(JSON.stringify(routeManifestJson));
158 const injectedCode = `
159// Sentry Remix Route Manifest - Auto-injected
160if (typeof globalThis !== 'undefined') {
161 globalThis.${MANIFEST_GLOBAL_KEY} = globalThis.${MANIFEST_GLOBAL_KEY} || ${safeJsonValue};
162}
163${code}`;
164
165 return {
166 code: injectedCode,
167 map: null,
168 };
169 }
170
171 return null;
172 },
173 };
174}

Callers

nothing calls this directly

Calls 2

escapeJsonForHtmlFunction · 0.85
testMethod · 0.65

Tested by

no test coverage detected