Skip to content

Commit 2c01bd1

Browse files
committed
fix(misc): trim comments
1 parent 1a3f34b commit 2c01bd1

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

packages/shared/tracing/src/extract.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
11
import type { TraceContext } from './types'
22

3-
// Cache the dynamic import across all calls. Resolved (or failed) once per
4-
// process; subsequent calls hit the resolved promise as a synchronous microtask
5-
// instead of re-entering the module resolver.
6-
//
7-
// `any` here intentionally avoids referencing @opentelemetry/api types at
8-
// compile time, since it's an optional peer dep that may not be installed.
93
let otelModulePromise: Promise<any | null> | null = null
104

11-
// Indirect the specifier through a variable so static bundlers
12-
// (webpack, turbopack, rollup, vite, esbuild) do not attempt to resolve
13-
// @opentelemetry/api at build time. It's an optional peer dep that may not
14-
// be installed in the consumer app; we look it up purely at runtime.
5+
// Variable specifier + single magic-comment block: required to keep this
6+
// import optional through webpack / turbopack / vite / rolldown. See PR #2381.
157
const OTEL_PKG = '@opentelemetry/api'
168

179
function loadOtel(): Promise<any | null> {
1810
if (otelModulePromise === null) {
19-
// Magic comments tell each major SSR/Edge bundler to skip static
20-
// resolution of this dynamic import — `@opentelemetry/api` is an
21-
// optional peer dep, so it may not be installed in the consumer app.
22-
// Without these, Turbopack (Next.js Edge), webpack, and Vite each
23-
// error with `Module not found: Can't resolve '@opentelemetry/api'`
24-
// when the peer dep is absent. The variable specifier (OTEL_PKG)
25-
// also helps for bundlers that don't honor the comments.
26-
//
27-
// All three directives live in one block because rolldown's printer
28-
// only preserves block comments containing `@__PURE__`,
29-
// `@__NO_SIDE_EFFECTS__`, or `@vite-ignore`; standalone
30-
// `/* webpackIgnore */` / `/* turbopackIgnore */` blocks get stripped
31-
// from dist/index.mjs. Webpack and Turbopack both scan for their
32-
// keyword anywhere in adjacent comments, so a shared block is honored.
3311
otelModulePromise = (
3412
import(/* @vite-ignore webpackIgnore: true turbopackIgnore: true */ OTEL_PKG) as Promise<any>
3513
).catch(() => null)

0 commit comments

Comments
 (0)