@sentry/cloudflare 10.76.2 → 10.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/vite/autoInstrument.js +40 -16
- package/build/cjs/vite/autoInstrument.js.map +1 -1
- package/build/cjs/vite/instrumentFile.js +1 -2
- package/build/cjs/vite/instrumentFile.js.map +1 -1
- package/build/cjs/vite/transform.js +144 -14
- package/build/cjs/vite/transform.js.map +1 -1
- package/build/cjs/vite/wranglerConfig.js +7 -3
- package/build/cjs/vite/wranglerConfig.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/vite/autoInstrument.js +41 -17
- package/build/esm/vite/autoInstrument.js.map +1 -1
- package/build/esm/vite/instrumentFile.js +2 -3
- package/build/esm/vite/instrumentFile.js.map +1 -1
- package/build/esm/vite/transform.js +144 -14
- package/build/esm/vite/transform.js.map +1 -1
- package/build/esm/vite/wranglerConfig.js +7 -3
- package/build/esm/vite/wranglerConfig.js.map +1 -1
- package/build/types/vite/autoInstrument.d.ts +7 -6
- package/build/types/vite/autoInstrument.d.ts.map +1 -1
- package/build/types/vite/index.d.ts +1 -3
- package/build/types/vite/index.d.ts.map +1 -1
- package/build/types/vite/instrumentFile.d.ts +3 -3
- package/build/types/vite/instrumentFile.d.ts.map +1 -1
- package/build/types/vite/transform.d.ts.map +1 -1
- package/build/types/vite/wranglerConfig.d.ts +10 -6
- package/build/types/vite/wranglerConfig.d.ts.map +1 -1
- package/build/types-ts3.8/vite/autoInstrument.d.ts +7 -6
- package/build/types-ts3.8/vite/index.d.ts +1 -3
- package/build/types-ts3.8/vite/instrumentFile.d.ts +3 -3
- package/build/types-ts3.8/vite/wranglerConfig.d.ts +10 -6
- package/package.json +8 -4
|
@@ -5,6 +5,7 @@ const node_path = require('node:path');
|
|
|
5
5
|
const wrangler = require('wrangler');
|
|
6
6
|
const bindings = require('./bindings.js');
|
|
7
7
|
|
|
8
|
+
const ENTRY_FILE_REGEX = /\.(?:m?[jt]s|[jt]sx)$/;
|
|
8
9
|
function resolveWranglerConfig(root, explicitPath) {
|
|
9
10
|
const configPath = explicitPath ? node_path.resolve(root, explicitPath) : ["wrangler.json", "wrangler.jsonc", "wrangler.toml"].map((name) => node_path.resolve(root, name)).find(node_fs.existsSync);
|
|
10
11
|
if (!configPath || !node_fs.existsSync(configPath)) {
|
|
@@ -12,19 +13,22 @@ function resolveWranglerConfig(root, explicitPath) {
|
|
|
12
13
|
}
|
|
13
14
|
let raw;
|
|
14
15
|
try {
|
|
15
|
-
raw = wrangler.unstable_readConfig({ config: configPath }, { hideWarnings: true });
|
|
16
|
+
raw = wrangler.unstable_readConfig({ config: configPath }, { hideWarnings: true, preserveOriginalMain: true });
|
|
16
17
|
} catch {
|
|
17
18
|
return void 0;
|
|
18
19
|
}
|
|
20
|
+
const resolvedConfigPath = raw.configPath ?? configPath;
|
|
21
|
+
const configDir = node_path.dirname(resolvedConfigPath);
|
|
19
22
|
return {
|
|
20
23
|
config: {
|
|
21
|
-
main: raw.main,
|
|
24
|
+
main: raw.main && ENTRY_FILE_REGEX.test(raw.main) ? node_path.resolve(configDir, raw.main) : raw.main,
|
|
22
25
|
durableObjects: collectClassBindings(raw.durable_objects?.bindings),
|
|
23
26
|
workflows: collectClassBindings(raw.workflows),
|
|
24
27
|
workerEntrypoints: collectSelfBoundEntrypoints(raw),
|
|
25
28
|
sameWorkerBindings: collectSameWorkerBindings(raw)
|
|
26
29
|
},
|
|
27
|
-
|
|
30
|
+
configPath: resolvedConfigPath,
|
|
31
|
+
configDir
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
34
|
function collectSelfBoundEntrypoints(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wranglerConfig.js","sources":["../../../src/vite/wranglerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { type Unstable_Config, unstable_readConfig } from 'wrangler';\nimport { DEFAULT_EXPORT, type ExportName, type SameWorkerBinding } from './bindings';\n\nexport { DEFAULT_EXPORT, type ExportName, type SameWorkerBinding };\n\n/**\n * The slice of the wrangler configuration the auto-instrument plugin cares\n * about
|
|
1
|
+
{"version":3,"file":"wranglerConfig.js","sources":["../../../src/vite/wranglerConfig.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport { type Unstable_Config, unstable_readConfig } from 'wrangler';\nimport { DEFAULT_EXPORT, type ExportName, type SameWorkerBinding } from './bindings';\n\nexport { DEFAULT_EXPORT, type ExportName, type SameWorkerBinding };\n\n/**\n * The slice of the wrangler configuration the auto-instrument plugin cares\n * about.\n */\nexport interface WranglerConfig {\n /**\n * An absolute path when `main` names a JS or TS file, otherwise the\n * original value (a package export or virtual module) for Vite to resolve.\n */\n main?: string;\n durableObjects: Array<{ name: string; className: string }>;\n workflows: Array<{ name: string; className: string }>;\n /**\n * Named `WorkerEntrypoint` exports this worker binds to itself via a service\n * binding (`services[]` whose `service` is this worker's own `name`). Only\n * self-bindings appear here: a service binding's `entrypoint` otherwise names\n * an export on a *different* worker, which this build can't wrap.\n */\n workerEntrypoints: string[];\n /**\n * Bindings whose RPC receiver lives in this worker, so this build instruments it. Not deduped by\n * class, two bindings may point at the same class and both names have to be listed.\n */\n sameWorkerBindings: SameWorkerBinding[];\n}\n\n// Same rule as `@cloudflare/vite-plugin`: only these extensions mark `main` as a file path.\nconst ENTRY_FILE_REGEX = /\\.(?:m?[jt]s|[jt]sx)$/;\n\n/**\n * Locate and resolve the wrangler configuration via wrangler's own\n * `unstable_readConfig` — the API `@cloudflare/vite-plugin` uses.\n *\n * We only locate the file (probing `wrangler.json`, `.jsonc`, `.toml` inside\n * `root` with wrangler's own precedence, since it discovers from `cwd` rather\n * than an arbitrary root); wrangler then parses it and flattens the active\n * environment (honoring `CLOUDFLARE_ENV`). Durable Object and Workflow\n * bindings are the active environment's, matching what the deployed Worker\n * actually binds.\n *\n * Returns `undefined` when no config file is found or it can't be read/parsed\n * (the caller warns and disables auto-instrumentation rather than failing the\n * whole build).\n */\nexport function resolveWranglerConfig(\n root: string,\n explicitPath?: string,\n): { config: WranglerConfig; configPath: string; configDir: string } | undefined {\n const configPath = explicitPath\n ? resolve(root, explicitPath)\n : ['wrangler.json', 'wrangler.jsonc', 'wrangler.toml'].map(name => resolve(root, name)).find(existsSync);\n\n if (!configPath || !existsSync(configPath)) {\n return undefined;\n }\n\n let raw: Unstable_Config;\n try {\n // `hideWarnings` keeps wrangler's config diagnostics (e.g. missing DO\n // migrations) out of the Vite build output.\n raw = unstable_readConfig({ config: configPath }, { hideWarnings: true, preserveOriginalMain: true });\n } catch {\n return undefined;\n }\n\n const resolvedConfigPath = raw.configPath ?? configPath;\n const configDir = dirname(resolvedConfigPath);\n\n return {\n config: {\n main: raw.main && ENTRY_FILE_REGEX.test(raw.main) ? resolve(configDir, raw.main) : raw.main,\n durableObjects: collectClassBindings(raw.durable_objects?.bindings),\n workflows: collectClassBindings(raw.workflows),\n workerEntrypoints: collectSelfBoundEntrypoints(raw),\n sameWorkerBindings: collectSameWorkerBindings(raw),\n },\n configPath: resolvedConfigPath,\n configDir,\n };\n}\n\n/**\n * Collect named `WorkerEntrypoint` exports the worker binds to itself. A service\n * binding's `entrypoint` normally names an export on the *target* worker, so it\n * is only ours when `service` equals this worker's own `name`. Without a `name`\n * there is nothing to match against, so no entrypoints are derivable.\n */\nfunction collectSelfBoundEntrypoints(raw: Unstable_Config): string[] {\n if (!raw.name) {\n return [];\n }\n const entrypoints = new Set<string>();\n for (const binding of raw.services ?? []) {\n if (binding?.service === raw.name && typeof binding.entrypoint === 'string') {\n entrypoints.add(binding.entrypoint);\n }\n }\n return [...entrypoints];\n}\n\n/**\n * Bindings with a `script_name` or naming another worker target a class this build does not wrap,\n * so they are excluded and stay opt-in.\n */\nfunction collectSameWorkerBindings(raw: Unstable_Config): SameWorkerBinding[] {\n const bindings: SameWorkerBinding[] = [];\n\n for (const binding of raw.durable_objects?.bindings ?? []) {\n if (typeof binding?.name === 'string' && typeof binding.class_name === 'string' && !binding.script_name) {\n bindings.push({ bindingName: binding.name, className: binding.class_name });\n }\n }\n\n for (const binding of raw.services ?? []) {\n // A service binding is only ours when `service` names this worker; without a `name` none can be.\n if (raw.name && binding?.service === raw.name && typeof binding.binding === 'string') {\n bindings.push({\n bindingName: binding.binding,\n className: typeof binding.entrypoint === 'string' ? binding.entrypoint : DEFAULT_EXPORT,\n });\n }\n }\n\n return bindings;\n}\n\n/**\n * Map wrangler class bindings (Durable Objects, Workflows — same shape) to the\n * `{ name, className }` the transform needs, skipping duplicates and bindings\n * with a `script_name` (those reference a class exported by a *different*\n * worker, so there is nothing to wrap in this worker's entry file).\n */\nfunction collectClassBindings(\n bindings: ReadonlyArray<{ name: string; class_name?: string; script_name?: string }> | undefined,\n): Array<{ name: string; className: string }> {\n const result: Array<{ name: string; className: string }> = [];\n const seenClassNames = new Set<string>();\n for (const binding of bindings ?? []) {\n if (typeof binding?.class_name !== 'string' || binding.script_name || seenClassNames.has(binding.class_name)) {\n continue;\n }\n seenClassNames.add(binding.class_name);\n result.push({ name: binding.name, className: binding.class_name });\n }\n return result;\n}\n"],"names":["resolve","existsSync","unstable_readConfig","dirname","bindings","DEFAULT_EXPORT"],"mappings":";;;;;;;AAkCA,MAAM,gBAAA,GAAmB,uBAAA;AAiBlB,SAAS,qBAAA,CACd,MACA,YAAA,EAC+E;AAC/E,EAAA,MAAM,aAAa,YAAA,GACfA,iBAAA,CAAQ,MAAM,YAAY,CAAA,GAC1B,CAAC,eAAA,EAAiB,gBAAA,EAAkB,eAAe,CAAA,CAAE,GAAA,CAAI,UAAQA,iBAAA,CAAQ,IAAA,EAAM,IAAI,CAAC,CAAA,CAAE,KAAKC,kBAAU,CAAA;AAEzG,EAAA,IAAI,CAAC,UAAA,IAAc,CAACA,kBAAA,CAAW,UAAU,CAAA,EAAG;AAC1C,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,IAAI,GAAA;AAC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AACA,IAAA,cAAA,CAAe,GAAA,CAAI,QAAQ,UAAU,CAAA;AACrC,IAAA,MAAA,CAAO,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,CAAQ,MAAM,SAAA,EAAW,OAAA,CAAQ,YAAY,CAAA;AAAA,EACnE;AACA,EAAA,OAAO,MAAA;AACT;;;;;"}
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"10.
|
|
1
|
+
{"type":"module","version":"10.78.0","sideEffects":false}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { basename } from 'node:path';
|
|
1
|
+
import { basename, isAbsolute, dirname } from 'node:path';
|
|
2
|
+
import { createIdResolver } from 'vite';
|
|
2
3
|
import { collectAgentCandidates, detectAgentClasses } from './agentClass.js';
|
|
3
4
|
import { resolveInstrumentFile, buildOptionsImport, ENV_FALLBACK_OPTIONS_FN } from './instrumentFile.js';
|
|
4
5
|
import { applyAutoInstrumentTransforms } from './transform.js';
|
|
@@ -11,8 +12,29 @@ const JS_EXTENSION_REGEX = /\.[cm]?[jt]sx?$/;
|
|
|
11
12
|
function sentryCloudflareAutoInstrumentPlugin(options = {}) {
|
|
12
13
|
let wranglerConfig;
|
|
13
14
|
let entryFilePath;
|
|
14
|
-
let
|
|
15
|
-
let
|
|
15
|
+
let entrySpecifier;
|
|
16
|
+
let wranglerConfigPath;
|
|
17
|
+
let resolveId;
|
|
18
|
+
const resolvedEntries = /* @__PURE__ */ new Map();
|
|
19
|
+
let instrumentFilePath;
|
|
20
|
+
function resolveEntrySpecifier(ctx, specifier) {
|
|
21
|
+
const environment = ctx.environment;
|
|
22
|
+
if (!environment || !resolveId) return Promise.resolve(void 0);
|
|
23
|
+
let entry = resolvedEntries.get(environment.name);
|
|
24
|
+
if (!entry) {
|
|
25
|
+
entry = resolveId(environment, specifier, wranglerConfigPath).catch(() => void 0).then((id) => {
|
|
26
|
+
if (!id) {
|
|
27
|
+
ctx.warn?.(
|
|
28
|
+
`[sentry] Could not resolve the wrangler \`main\` "${specifier}". Auto-instrumentation disabled.`
|
|
29
|
+
);
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
return normalizePath(id.replace(/[?#].*$/, ""));
|
|
33
|
+
});
|
|
34
|
+
resolvedEntries.set(environment.name, entry);
|
|
35
|
+
}
|
|
36
|
+
return entry;
|
|
37
|
+
}
|
|
16
38
|
return {
|
|
17
39
|
name: "sentry-cloudflare-auto-instrument",
|
|
18
40
|
configResolved(config) {
|
|
@@ -24,25 +46,26 @@ function sentryCloudflareAutoInstrumentPlugin(options = {}) {
|
|
|
24
46
|
return;
|
|
25
47
|
}
|
|
26
48
|
wranglerConfig = result.config;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
49
|
+
const main = wranglerConfig.main;
|
|
50
|
+
if (main && isAbsolute(main)) {
|
|
51
|
+
entryFilePath = normalizePath(main);
|
|
52
|
+
instrumentFilePath = resolveInstrumentFile(dirname(main));
|
|
53
|
+
} else if (main) {
|
|
54
|
+
entrySpecifier = main;
|
|
55
|
+
wranglerConfigPath = result.configPath;
|
|
56
|
+
resolveId = createIdResolver(config);
|
|
57
|
+
instrumentFilePath = resolveInstrumentFile(result.configDir);
|
|
37
58
|
}
|
|
38
59
|
},
|
|
39
60
|
async transform(code, id) {
|
|
40
|
-
if (!wranglerConfig || !entryFilePath) return void 0;
|
|
61
|
+
if (!wranglerConfig || !entryFilePath && !entrySpecifier) return void 0;
|
|
41
62
|
if (this.environment?.name === "client") return void 0;
|
|
63
|
+
const entryPath = entrySpecifier ? await resolveEntrySpecifier(this, entrySpecifier) : entryFilePath;
|
|
64
|
+
if (!entryPath) return void 0;
|
|
42
65
|
const normalizedId = normalizePath(id.replace(/[?#].*$/, ""));
|
|
43
|
-
if (normalizedId !==
|
|
44
|
-
if (!JS_EXTENSION_REGEX.test(normalizedId) || !JS_EXTENSION_REGEX.test(
|
|
45
|
-
if (normalizedId.replace(JS_EXTENSION_REGEX, "") !==
|
|
66
|
+
if (normalizedId !== entryPath) {
|
|
67
|
+
if (!JS_EXTENSION_REGEX.test(normalizedId) || !JS_EXTENSION_REGEX.test(entryPath)) return void 0;
|
|
68
|
+
if (normalizedId.replace(JS_EXTENSION_REGEX, "") !== entryPath.replace(JS_EXTENSION_REGEX, "")) {
|
|
46
69
|
return void 0;
|
|
47
70
|
}
|
|
48
71
|
}
|
|
@@ -70,6 +93,7 @@ function sentryCloudflareAutoInstrumentPlugin(options = {}) {
|
|
|
70
93
|
parse: (code2) => this.parse(code2),
|
|
71
94
|
resolve: this.resolve ? (source, importer) => this.resolve(source, importer) : void 0
|
|
72
95
|
}) : void 0;
|
|
96
|
+
const { optionsFn, importStmt: optionsImport } = instrumentFilePath ? buildOptionsImport(entryPath, instrumentFilePath) : { optionsFn: ENV_FALLBACK_OPTIONS_FN, importStmt: void 0 };
|
|
73
97
|
const result = applyAutoInstrumentTransforms(code, ast, {
|
|
74
98
|
classWrappers,
|
|
75
99
|
agentClasses,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoInstrument.js","sources":["../../../src/vite/autoInstrument.ts"],"sourcesContent":["import { basename } from 'node:path';\nimport { collectAgentCandidates, detectAgentClasses, type ModuleResolver } from './agentClass';\nimport { buildOptionsImport, ENV_FALLBACK_OPTIONS_FN, resolveInstrumentFile } from './instrumentFile';\nimport { applyAutoInstrumentTransforms, type ClassWrapperKind, type ProgramBody } from './transform';\nimport { resolveWranglerConfig, type WranglerConfig } from './wranglerConfig';\n\n// Vite normalizes module IDs to posix separators even on Windows, while\n// `path.resolve` yields backslashes there — normalize before comparing.\nfunction normalizePath(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\n// Extensions the entry-module match may tolerate swapping (e.g. wrangler's\n// `main` says `.ts` but the served module is `.js`). Anything else — `.css`,\n// `.html`, … — sharing the entry's basename must never be treated as the entry.\nconst JS_EXTENSION_REGEX = /\\.[cm]?[jt]sx?$/;\n\nexport function sentryCloudflareAutoInstrumentPlugin(options: { wranglerConfigPath?: string } = {}) {\n let wranglerConfig: WranglerConfig | undefined;\n let entryFilePath: string | undefined;\n\n let optionsFn = ENV_FALLBACK_OPTIONS_FN;\n let optionsImport: string | undefined;\n\n return {\n name: 'sentry-cloudflare-auto-instrument',\n\n configResolved(config: { root: string; logger?: { warn(msg: string): void } }): void {\n const result = resolveWranglerConfig(config.root, options.wranglerConfigPath);\n if (!result) {\n // An explicit path that fails is a misconfiguration worth naming;\n // without one, hint at the option so custom-named configs (e.g. a\n // `configPath` handed to @cloudflare/vite-plugin) are discoverable.\n config.logger?.warn(\n options.wranglerConfigPath\n ? `[sentry] Could not find or parse the wrangler config \"${basename(options.wranglerConfigPath)}\" ` +\n '(resolved against the Vite root) — auto-instrumentation disabled.'\n : '[sentry] No parseable wrangler config found — auto-instrumentation disabled. ' +\n 'Set `wranglerConfigPath` if your config uses a custom name.',\n );\n return;\n }\n\n wranglerConfig = result.config;\n if (wranglerConfig.main) {\n // `main` is already absolute (wrangler resolves it); just normalize\n // separators so the entry-module comparison holds on Windows.\n entryFilePath = normalizePath(wranglerConfig.main);\n }\n\n if (entryFilePath) {\n const instrumentFilePath = resolveInstrumentFile(entryFilePath);\n if (instrumentFilePath) {\n const built = buildOptionsImport(entryFilePath, instrumentFilePath);\n optionsFn = built.optionsFn;\n optionsImport = built.importStmt;\n }\n }\n },\n\n async transform(\n this: ModuleResolver & { warn?(msg: string): void; environment?: { name?: string } },\n code: string,\n id: string,\n ): Promise<{ code: string; map: unknown } | undefined> {\n if (!wranglerConfig || !entryFilePath) return undefined;\n\n // The worker entry never belongs to the client (browser) environment.\n // Skipping it keeps a same-basename sibling (e.g. a `src/index.tsx`\n // client entry next to a `src/index.ts` worker) out of the browser bundle.\n if (this.environment?.name === 'client') return undefined;\n\n // Vite may append query/hash params to the module ID.\n const normalizedId = normalizePath(id.replace(/[?#].*$/, ''));\n if (normalizedId !== entryFilePath) {\n // Tolerate a differing JS-flavored extension (e.g. `.js` vs `.ts`).\n if (!JS_EXTENSION_REGEX.test(normalizedId) || !JS_EXTENSION_REGEX.test(entryFilePath)) return undefined;\n if (normalizedId.replace(JS_EXTENSION_REGEX, '') !== entryFilePath.replace(JS_EXTENSION_REGEX, '')) {\n return undefined;\n }\n }\n\n let ast: ProgramBody;\n try {\n ast = this.parse(code);\n } catch {\n // Raw TypeScript or syntax error — esbuild hasn't run yet (unlikely)\n // or the file is genuinely broken. Either way, skip silently.\n return undefined;\n }\n\n const classWrappers = new Map<string, ClassWrapperKind>();\n for (const { className } of wranglerConfig.durableObjects) {\n classWrappers.set(className, 'durableObject');\n }\n for (const { className } of wranglerConfig.workflows) {\n classWrappers.set(className, 'workflow');\n }\n for (const className of wranglerConfig.workerEntrypoints) {\n classWrappers.set(className, 'workerEntrypoint');\n }\n\n // An `agents` Agent is a Durable Object, so wrangler lists it among the DO bindings and only\n // its base-class chain tells the two apart. Detection walks the module graph (base classes\n // usually live in their own file), so it is limited to the configured DO classes.\n //\n // Only `resolve` is handed over — never `load`: awaiting `load()` from inside a transform\n // hook deadlocks the build, since the module can't finish loading while this transform is\n // still pending. `agentClass` reads sibling modules off disk instead.\n const agentCandidates = collectAgentCandidates(\n ast,\n [...classWrappers].filter(([, kind]) => kind === 'durableObject').map(([name]) => name),\n );\n const agentClasses =\n agentCandidates.size > 0\n ? await detectAgentClasses(ast, normalizedId, agentCandidates, {\n parse: code => this.parse(code),\n resolve: this.resolve ? (source, importer) => this.resolve!(source, importer) : undefined,\n })\n : undefined;\n\n // No registration import is injected here: the orchestrion plugin's\n // subscribe-injection makes each bundled package self-register its channel\n // subscriber on the global marker, so wrapping the entry with `withSentry`\n // is all this plugin needs to do.\n const result = applyAutoInstrumentTransforms(code, ast, {\n classWrappers,\n agentClasses,\n optionsFn,\n optionsImport,\n sameWorkerBindings: wranglerConfig.sameWorkerBindings,\n });\n\n const wrappedClasses = result?.wrappedClasses ?? new Set<string>();\n const missing = [...classWrappers.keys()].filter(name => !wrappedClasses.has(name));\n if (missing.length > 0) {\n this.warn?.(\n `[sentry] Could not auto-instrument ${missing.join(', ')}.` +\n 'The worker entry has no export matching them. ' +\n 'Star re-exports (`export * from \"./do\"`) are not matched. ' +\n 'Export them by name or wrap them manually with corresponding `instrument*WithSentry` helpers.',\n );\n }\n\n return result ?? undefined;\n },\n };\n}\n"],"names":["code"],"mappings":";;;;;;AAQA,SAAS,cAAc,IAAA,EAAsB;AAC3C,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA;AAChC;AAKA,MAAM,kBAAA,GAAqB,iBAAA;AAEpB,SAAS,oCAAA,CAAqC,OAAA,GAA2C,EAAC,EAAG;AAClG,EAAA,IAAI,cAAA;AACJ,EAAA,IAAI,aAAA;AAEJ,EAAA,IAAI,SAAA,GAAY,uBAAA;AAChB,EAAA,IAAI,aAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,mCAAA;AAAA,IAEN,eAAe,MAAA,EAAsE;AACnF,MAAA,MAAM,MAAA,GAAS,qBAAA,CAAsB,MAAA,CAAO,IAAA,EAAM,QAAQ,kBAAkB,CAAA;AAC5E,MAAA,IAAI,CAAC,MAAA,EAAQ;AAIX,QAAA,MAAA,CAAO,MAAA,EAAQ,IAAA;AAAA,UACb,QAAQ,kBAAA,GACJ,CAAA,sDAAA,EAAyD,SAAS,OAAA,CAAQ,kBAAkB,CAAC,CAAA,wEAAA,CAAA,GAE7F;AAAA,SAEN;AACA,QAAA;AAAA,MACF;AAEA,MAAA,cAAA,GAAiB,MAAA,CAAO,MAAA;AACxB,MAAA,IAAI,eAAe,IAAA,EAAM;AAGvB,QAAA,aAAA,GAAgB,aAAA,CAAc,eAAe,IAAI,CAAA;AAAA,MACnD;AAEA,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,MAAM,kBAAA,GAAqB,sBAAsB,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C,CAAA;AAClF,MAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,QAAA,IAAA,CAAK,IAAA;AAAA,UACH,CAAA,mCAAA,EAAsC,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,0MAAA;AAAA,SAI1D;AAAA,MACF;AAEA,MAAA,OAAO,MAAA,IAAU,MAAA;AAAA,IACnB;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"autoInstrument.js","sources":["../../../src/vite/autoInstrument.ts"],"sourcesContent":["import { basename, dirname, isAbsolute } from 'node:path';\nimport { createIdResolver, type ResolvedConfig } from 'vite';\nimport { collectAgentCandidates, detectAgentClasses, type ModuleResolver } from './agentClass';\nimport { buildOptionsImport, ENV_FALLBACK_OPTIONS_FN, resolveInstrumentFile } from './instrumentFile';\nimport { applyAutoInstrumentTransforms, type ClassWrapperKind, type ProgramBody } from './transform';\nimport { resolveWranglerConfig, type WranglerConfig } from './wranglerConfig';\n\n// Vite normalizes module IDs to posix separators even on Windows, while\n// `path.resolve` yields backslashes there — normalize before comparing.\nfunction normalizePath(path: string): string {\n return path.replace(/\\\\/g, '/');\n}\n\n// Extensions the entry-module match may tolerate swapping (e.g. wrangler's\n// `main` says `.ts` but the served module is `.js`). Anything else — `.css`,\n// `.html`, … — sharing the entry's basename must never be treated as the entry.\nconst JS_EXTENSION_REGEX = /\\.[cm]?[jt]sx?$/;\n\ntype TransformContext = ModuleResolver & {\n warn?(msg: string): void;\n environment?: Parameters<ReturnType<typeof createIdResolver>>[0];\n};\n\nexport function sentryCloudflareAutoInstrumentPlugin(options: { wranglerConfigPath?: string } = {}) {\n let wranglerConfig: WranglerConfig | undefined;\n let entryFilePath: string | undefined;\n // A `main` that is not a file path (a package export or virtual module).\n let entrySpecifier: string | undefined;\n let wranglerConfigPath: string | undefined;\n let resolveId: ReturnType<typeof createIdResolver> | undefined;\n // Each environment resolves with its own conditions, so the entry may differ between them.\n const resolvedEntries = new Map<string, Promise<string | undefined>>();\n\n let instrumentFilePath: string | undefined;\n\n function resolveEntrySpecifier(ctx: TransformContext, specifier: string): Promise<string | undefined> {\n const environment = ctx.environment;\n if (!environment || !resolveId) return Promise.resolve(undefined);\n\n let entry = resolvedEntries.get(environment.name);\n if (!entry) {\n // Resolved from the wrangler config, as wrangler does. Without an importer, Vite's resolver\n // tries the specifier as a path below the root first.\n entry = resolveId(environment, specifier, wranglerConfigPath)\n .catch(() => undefined)\n .then(id => {\n if (!id) {\n ctx.warn?.(\n `[sentry] Could not resolve the wrangler \\`main\\` \"${specifier}\". Auto-instrumentation disabled.`,\n );\n return undefined;\n }\n return normalizePath(id.replace(/[?#].*$/, ''));\n });\n resolvedEntries.set(environment.name, entry);\n }\n return entry;\n }\n\n return {\n name: 'sentry-cloudflare-auto-instrument',\n\n configResolved(config: { root: string; logger?: { warn(msg: string): void } }): void {\n const result = resolveWranglerConfig(config.root, options.wranglerConfigPath);\n if (!result) {\n // An explicit path that fails is a misconfiguration worth naming;\n // without one, hint at the option so custom-named configs (e.g. a\n // `configPath` handed to @cloudflare/vite-plugin) are discoverable.\n config.logger?.warn(\n options.wranglerConfigPath\n ? `[sentry] Could not find or parse the wrangler config \"${basename(options.wranglerConfigPath)}\" ` +\n '(resolved against the Vite root) — auto-instrumentation disabled.'\n : '[sentry] No parseable wrangler config found — auto-instrumentation disabled. ' +\n 'Set `wranglerConfigPath` if your config uses a custom name.',\n );\n return;\n }\n\n wranglerConfig = result.config;\n const main = wranglerConfig.main;\n if (main && isAbsolute(main)) {\n // Normalize separators so the entry-module comparison holds on Windows.\n entryFilePath = normalizePath(main);\n instrumentFilePath = resolveInstrumentFile(dirname(main));\n } else if (main) {\n entrySpecifier = main;\n wranglerConfigPath = result.configPath;\n // Not `this.resolve()`: Rollup's commonjs resolver loads the module it resolves, so a\n // resolve of the entry from the entry's own `transform` never finishes.\n resolveId = createIdResolver(config as ResolvedConfig);\n // A package entry has no project directory of its own.\n instrumentFilePath = resolveInstrumentFile(result.configDir);\n }\n },\n\n async transform(\n this: TransformContext,\n code: string,\n id: string,\n ): Promise<{ code: string; map: unknown } | undefined> {\n if (!wranglerConfig || (!entryFilePath && !entrySpecifier)) return undefined;\n\n // The worker entry never belongs to the client (browser) environment.\n // Skipping it keeps a same-basename sibling (e.g. a `src/index.tsx`\n // client entry next to a `src/index.ts` worker) out of the browser bundle.\n if (this.environment?.name === 'client') return undefined;\n\n const entryPath = entrySpecifier ? await resolveEntrySpecifier(this, entrySpecifier) : entryFilePath;\n if (!entryPath) return undefined;\n\n // Vite may append query/hash params to the module ID.\n const normalizedId = normalizePath(id.replace(/[?#].*$/, ''));\n if (normalizedId !== entryPath) {\n // Tolerate a differing JS-flavored extension (e.g. `.js` vs `.ts`).\n if (!JS_EXTENSION_REGEX.test(normalizedId) || !JS_EXTENSION_REGEX.test(entryPath)) return undefined;\n if (normalizedId.replace(JS_EXTENSION_REGEX, '') !== entryPath.replace(JS_EXTENSION_REGEX, '')) {\n return undefined;\n }\n }\n\n let ast: ProgramBody;\n try {\n ast = this.parse(code);\n } catch {\n // Raw TypeScript or syntax error — esbuild hasn't run yet (unlikely)\n // or the file is genuinely broken. Either way, skip silently.\n return undefined;\n }\n\n const classWrappers = new Map<string, ClassWrapperKind>();\n for (const { className } of wranglerConfig.durableObjects) {\n classWrappers.set(className, 'durableObject');\n }\n for (const { className } of wranglerConfig.workflows) {\n classWrappers.set(className, 'workflow');\n }\n for (const className of wranglerConfig.workerEntrypoints) {\n classWrappers.set(className, 'workerEntrypoint');\n }\n\n // An `agents` Agent is a Durable Object, so wrangler lists it among the DO bindings and only\n // its base-class chain tells the two apart. Detection walks the module graph (base classes\n // usually live in their own file), so it is limited to the configured DO classes.\n //\n // Only `resolve` is handed over — never `load`: awaiting `load()` from inside a transform\n // hook deadlocks the build, since the module can't finish loading while this transform is\n // still pending. `agentClass` reads sibling modules off disk instead.\n const agentCandidates = collectAgentCandidates(\n ast,\n [...classWrappers].filter(([, kind]) => kind === 'durableObject').map(([name]) => name),\n );\n const agentClasses =\n agentCandidates.size > 0\n ? await detectAgentClasses(ast, normalizedId, agentCandidates, {\n parse: code => this.parse(code),\n resolve: this.resolve ? (source, importer) => this.resolve!(source, importer) : undefined,\n })\n : undefined;\n\n const { optionsFn, importStmt: optionsImport } = instrumentFilePath\n ? buildOptionsImport(entryPath, instrumentFilePath)\n : { optionsFn: ENV_FALLBACK_OPTIONS_FN, importStmt: undefined };\n\n // No registration import is injected here: the orchestrion plugin's\n // subscribe-injection makes each bundled package self-register its channel\n // subscriber on the global marker, so wrapping the entry with `withSentry`\n // is all this plugin needs to do.\n const result = applyAutoInstrumentTransforms(code, ast, {\n classWrappers,\n agentClasses,\n optionsFn,\n optionsImport,\n sameWorkerBindings: wranglerConfig.sameWorkerBindings,\n });\n\n const wrappedClasses = result?.wrappedClasses ?? new Set<string>();\n const missing = [...classWrappers.keys()].filter(name => !wrappedClasses.has(name));\n if (missing.length > 0) {\n this.warn?.(\n `[sentry] Could not auto-instrument ${missing.join(', ')}.` +\n 'The worker entry has no export matching them. ' +\n 'Star re-exports (`export * from \"./do\"`) are not matched. ' +\n 'Export them by name or wrap them manually with corresponding `instrument*WithSentry` helpers.',\n );\n }\n\n return result ?? undefined;\n },\n };\n}\n"],"names":["code"],"mappings":";;;;;;;AASA,SAAS,cAAc,IAAA,EAAsB;AAC3C,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA;AAChC;AAKA,MAAM,kBAAA,GAAqB,iBAAA;AAOpB,SAAS,oCAAA,CAAqC,OAAA,GAA2C,EAAC,EAAG;AAClG,EAAA,IAAI,cAAA;AACJ,EAAA,IAAI,aAAA;AAEJ,EAAA,IAAI,cAAA;AACJ,EAAA,IAAI,kBAAA;AACJ,EAAA,IAAI,SAAA;AAEJ,EAAA,MAAM,eAAA,uBAAsB,GAAA,EAAyC;AAErE,EAAA,IAAI,kBAAA;AAEJ,EAAA,SAAS,qBAAA,CAAsB,KAAuB,SAAA,EA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B,kBAAA,GAC7C,kBAAA,CAAmB,SAAA,EAAW,kBAAkB,CAAA,GAChD,EAAE,SAAA,EAAW,uBAAA,EAAyB,YAAY,MAAA,EAAU;AAMhE,MAAA,MAAM,MAAA,GAAS,6BAAA,CAA8B,IAAA,EAAM,GAAA,EAAK;AAAA,QACtD,aAAA;AAAA,QACA,YAAA;AAAA,QACA,SAAA;AAAA,QACA,aAAA;AAAA,QACA,oBAAoB,cAAA,CAAe;AAAA,OACpC,CAAA;AAED,MAAA,MAAM,cAAA,GAAiB,MAAA,EAAQ,cAAA,oBAAkB,IAAI,GAAA,EAAY;AACjE,MAAA,MAAM,OAAA,GAAU,CAAC,GAAG,aAAA,CAAc,IAAA,EAAM,CAAA,CAAE,MAAA,CAAO,CAAA,IAAA,KAAQ,CAAC,cAAA,CAAe,GAAA,CAAI,IAAI,CAAC,CAAA;AAClF,MAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,QAAA,IAAA,CAAK,IAAA;AAAA,UACH,CAAA,mCAAA,EAAsC,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,0MAAA;AAAA,SAI1D;AAAA,MACF;AAEA,MAAA,OAAO,MAAA,IAAU,MAAA;AAAA,IACnB;AAAA,GACF;AACF;;;;"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { resolve, relative, dirname } from 'node:path';
|
|
3
3
|
|
|
4
4
|
const ENV_FALLBACK_OPTIONS_FN = "() => undefined";
|
|
5
5
|
const OPTIONS_IMPORT_IDENTIFIER = "__SENTRY_OPTIONS_CALLBACK__";
|
|
6
6
|
const INSTRUMENT_FILE_BASENAME = "instrument.server";
|
|
7
7
|
const INSTRUMENT_FILE_EXTENSIONS = ["ts", "mts", "js", "mjs", "cjs"];
|
|
8
|
-
function resolveInstrumentFile(
|
|
9
|
-
const dir = dirname(entryFilePath);
|
|
8
|
+
function resolveInstrumentFile(dir) {
|
|
10
9
|
for (const ext of INSTRUMENT_FILE_EXTENSIONS) {
|
|
11
10
|
const candidate = resolve(dir, `${INSTRUMENT_FILE_BASENAME}.${ext}`);
|
|
12
11
|
if (existsSync(candidate)) return candidate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentFile.js","sources":["../../../src/vite/instrumentFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\n\n// Fallback options callback used when no instrument file is present. Returning\n// `undefined` makes the SDK read all configuration (DSN, release, environment,\n// sample rate, …) from the worker's `env` at runtime.\nexport const ENV_FALLBACK_OPTIONS_FN = '() => undefined';\n\n// Identifier the generated import binds the user's options module to.\nconst OPTIONS_IMPORT_IDENTIFIER = '__SENTRY_OPTIONS_CALLBACK__';\n\n// Conventional, non-configurable name of the Sentry options module. It is\n// looked up next to the worker entry file; its default export is the options\n// callback `(env) => CloudflareOptions`.\nconst INSTRUMENT_FILE_BASENAME = 'instrument.server';\nconst INSTRUMENT_FILE_EXTENSIONS = ['ts', 'mts', 'js', 'mjs', 'cjs'];\n\n/**\n * Locate the conventional `instrument.server.*` module
|
|
1
|
+
{"version":3,"file":"instrumentFile.js","sources":["../../../src/vite/instrumentFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { dirname, relative, resolve } from 'node:path';\n\n// Fallback options callback used when no instrument file is present. Returning\n// `undefined` makes the SDK read all configuration (DSN, release, environment,\n// sample rate, …) from the worker's `env` at runtime.\nexport const ENV_FALLBACK_OPTIONS_FN = '() => undefined';\n\n// Identifier the generated import binds the user's options module to.\nconst OPTIONS_IMPORT_IDENTIFIER = '__SENTRY_OPTIONS_CALLBACK__';\n\n// Conventional, non-configurable name of the Sentry options module. It is\n// looked up next to the worker entry file, or next to the wrangler config\n// when `main` is not a file path; its default export is the options\n// callback `(env) => CloudflareOptions`.\nconst INSTRUMENT_FILE_BASENAME = 'instrument.server';\nconst INSTRUMENT_FILE_EXTENSIONS = ['ts', 'mts', 'js', 'mjs', 'cjs'];\n\n/**\n * Locate the conventional `instrument.server.*` module in `dir`. Returns its\n * absolute path, or `undefined` when absent.\n */\nexport function resolveInstrumentFile(dir: string): string | undefined {\n for (const ext of INSTRUMENT_FILE_EXTENSIONS) {\n const candidate = resolve(dir, `${INSTRUMENT_FILE_BASENAME}.${ext}`);\n if (existsSync(candidate)) return candidate;\n }\n return undefined;\n}\n\n/**\n * Build the `optionsFn` reference and `import` statement for the instrument\n * module whose **default export** is the options callback\n * `(env) => CloudflareOptions`.\n *\n * The import is emitted relative to `entryFilePath` because it is injected into\n * the entry file's source. The file extension is kept: extensionless specifiers\n * only resolve for extensions in Vite's default `resolve.extensions` (which\n * excludes `.cjs`), and keeping it makes our probe order authoritative when\n * several `instrument.server.*` files coexist.\n */\nexport function buildOptionsImport(\n entryFilePath: string,\n instrumentFilePath: string,\n): { optionsFn: string; importStmt: string } {\n let relativePath = relative(dirname(entryFilePath), instrumentFilePath).replace(/\\\\/g, '/');\n if (!relativePath.startsWith('.')) relativePath = `./${relativePath}`;\n\n return {\n optionsFn: OPTIONS_IMPORT_IDENTIFIER,\n importStmt: `import ${OPTIONS_IMPORT_IDENTIFIER} from '${relativePath}';\\n`,\n };\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,uBAAA,GAA0B;AAGvC,MAAM,yBAAA,GAA4B,6BAAA;AAMlC,MAAM,wBAAA,GAA2B,mBAAA;AACjC,MAAM,6BAA6B,CAAC,IAAA,EAAM,KAAA,EAAO,IAAA,EAAM,OAAO,KAAK,CAAA;AAM5D,SAAS,sBAAsB,GAAA,EAAiC;AACrE,EAAA,KAAA,MAAW,OAAO,0BAAA,EAA4B;AAC5C,IAAA,MAAM,YAAY,OAAA,CAAQ,GAAA,EAAK,GAAG,wBAAwB,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE,CAAA;AACnE,IAAA,IAAI,UAAA,CAAW,SAAS,CAAA,EAAG,OAAO,SAAA;AAAA,EACpC;AACA,EAAA,OAAO,MAAA;AACT;AAaO,SAAS,kBAAA,CACd,eACA,kBAAA,EAC2C;AAC3C,EAAA,IAAI,YAAA,GAAe,SAAS,OAAA,CAAQ,aAAa,GAAG,kBAAkB,CAAA,CAAE,OAAA,CAAQ,KAAA,EAAO,GAAG,CAAA;AAC1F,EAAA,IAAI,CAAC,YAAA,CAAa,UAAA,CAAW,GAAG,CAAA,EAAG,YAAA,GAAe,KAAK,YAAY,CAAA,CAAA;AAEnE,EAAA,OAAO;AAAA,IACL,SAAA,EAAW,yBAAA;AAAA,IACX,UAAA,EAAY,CAAA,OAAA,EAAU,yBAAyB,CAAA,OAAA,EAAU,YAAY,CAAA;AAAA;AAAA,GACvE;AACF;;;;"}
|
|
@@ -27,19 +27,24 @@ function applyAutoInstrumentTransforms(code, ast, ctx) {
|
|
|
27
27
|
wrappedClasses: /* @__PURE__ */ new Set(),
|
|
28
28
|
topLevelClasses,
|
|
29
29
|
renamedLocals: /* @__PURE__ */ new Set(),
|
|
30
|
+
exportedClasses: collectExportedClasses(ast),
|
|
31
|
+
aliasedLocals: /* @__PURE__ */ new Map(),
|
|
30
32
|
classWrappers: ctx.classWrappers,
|
|
31
33
|
agentClasses: ctx.agentClasses ?? /* @__PURE__ */ new Set(),
|
|
32
34
|
workerEntrypointClasses: detectWorkerEntrypointClasses(ast),
|
|
33
35
|
// The identifier must be chosen before wrapping, which bindings survive is only known after.
|
|
34
36
|
optionsFn: sameWorkerBindings.length > 0 ? MERGED_OPTIONS_IDENTIFIER : ctx.optionsFn,
|
|
35
37
|
autoWrapped: /* @__PURE__ */ new Set(),
|
|
36
|
-
manuallyWrappedLocals: collectManuallyWrappedLocals(ast)
|
|
38
|
+
manuallyWrappedLocals: collectManuallyWrappedLocals(ast),
|
|
39
|
+
declaringStatements: collectDeclaringStatements(ast)
|
|
37
40
|
};
|
|
38
41
|
const { wrappedClasses } = state;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
const namedExports = ast.body.filter((node) => node.type === "ExportNamedDeclaration");
|
|
43
|
+
for (const node of namedExports) {
|
|
44
|
+
if (node.declaration) handleNamedExport(node, ctx, state);
|
|
45
|
+
}
|
|
46
|
+
for (const node of namedExports) {
|
|
47
|
+
if (!node.declaration) handleNamedExport(node, ctx, state);
|
|
43
48
|
}
|
|
44
49
|
for (const node of ast.body) {
|
|
45
50
|
if (node.type === "ExportDefaultDeclaration") {
|
|
@@ -84,8 +89,9 @@ function collectManuallyWrappedLocals(ast) {
|
|
|
84
89
|
const wrapperMethods = Object.values(WRAPPER_METHODS);
|
|
85
90
|
const locals = /* @__PURE__ */ new Set();
|
|
86
91
|
for (const node of ast.body) {
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
const declaration = declarationOf(node);
|
|
93
|
+
if (declaration?.type !== "VariableDeclaration") continue;
|
|
94
|
+
for (const declarator of declaration.declarations ?? []) {
|
|
89
95
|
const name = declarator.id?.type === "Identifier" ? declarator.id.name : void 0;
|
|
90
96
|
const init = declarator.init;
|
|
91
97
|
if (name && init && wrapperMethods.some((method) => isCallToMethod(init, method))) {
|
|
@@ -95,15 +101,42 @@ function collectManuallyWrappedLocals(ast) {
|
|
|
95
101
|
}
|
|
96
102
|
return locals;
|
|
97
103
|
}
|
|
104
|
+
function collectDeclaringStatements(ast) {
|
|
105
|
+
const statements = /* @__PURE__ */ new Map();
|
|
106
|
+
for (const node of ast.body) {
|
|
107
|
+
const declaration = declarationOf(node);
|
|
108
|
+
if (!declaration) continue;
|
|
109
|
+
const ids = declaration.type === "VariableDeclaration" ? (declaration.declarations ?? []).map((declarator) => declarator.id) : declaration.type === "ImportDeclaration" ? (declaration.specifiers ?? []).map((specifier) => specifier.local) : [declaration.id];
|
|
110
|
+
for (const id of ids) {
|
|
111
|
+
if (id?.type === "Identifier" && id.name) statements.set(id.name, node);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return statements;
|
|
115
|
+
}
|
|
98
116
|
function collectTopLevelClasses(ast) {
|
|
99
117
|
const classes = /* @__PURE__ */ new Map();
|
|
100
118
|
for (const node of ast.body) {
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
const declaration = declarationOf(node);
|
|
120
|
+
if (declaration?.type !== "ClassDeclaration") continue;
|
|
121
|
+
const classNode = declaration;
|
|
103
122
|
if (classNode.id?.name) classes.set(classNode.id.name, classNode);
|
|
104
123
|
}
|
|
105
124
|
return classes;
|
|
106
125
|
}
|
|
126
|
+
function collectExportedClasses(ast) {
|
|
127
|
+
const names = /* @__PURE__ */ new Set();
|
|
128
|
+
for (const node of ast.body) {
|
|
129
|
+
if (node.type !== "ExportNamedDeclaration") continue;
|
|
130
|
+
const declaration = node.declaration;
|
|
131
|
+
if (declaration?.type !== "ClassDeclaration") continue;
|
|
132
|
+
const name = declaration.id?.name;
|
|
133
|
+
if (name) names.add(name);
|
|
134
|
+
}
|
|
135
|
+
return names;
|
|
136
|
+
}
|
|
137
|
+
function declarationOf(node) {
|
|
138
|
+
return node.type === "ExportNamedDeclaration" ? node.declaration : node;
|
|
139
|
+
}
|
|
107
140
|
function wrapDefaultExport(node, ctx, state) {
|
|
108
141
|
const decl = node.declaration;
|
|
109
142
|
if (isCallToMethod(decl, "withSentry")) return;
|
|
@@ -111,13 +144,53 @@ function wrapDefaultExport(node, ctx, state) {
|
|
|
111
144
|
state.autoWrapped.add(DEFAULT_EXPORT);
|
|
112
145
|
return;
|
|
113
146
|
}
|
|
114
|
-
|
|
147
|
+
const source = state.ms.original;
|
|
148
|
+
const keywordsEnd = exportDefaultKeywordsEnd(source, node.start);
|
|
149
|
+
const declaredName = decl.type === "ClassDeclaration" || decl.type === "FunctionDeclaration" ? decl.id?.name : void 0;
|
|
150
|
+
let wrapped = "__SENTRY_DEFAULT_EXPORT__";
|
|
151
|
+
if (declaredName) {
|
|
152
|
+
state.ms.remove(node.start, decl.start);
|
|
153
|
+
state.ms.appendLeft(node.end, `
|
|
154
|
+
var __SENTRY_DEFAULT_EXPORT__ = ${declaredName};`);
|
|
155
|
+
wrapped = declaredName;
|
|
156
|
+
} else if (isAnonymousFunctionOrClass(decl)) {
|
|
157
|
+
const hasSemicolon = source[node.end - 1] === ";";
|
|
158
|
+
state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ = { default:");
|
|
159
|
+
state.ms.appendLeft(hasSemicolon ? node.end - 1 : node.end, hasSemicolon ? " }.default" : " }.default;");
|
|
160
|
+
} else {
|
|
161
|
+
state.ms.overwrite(node.start, keywordsEnd, "var __SENTRY_DEFAULT_EXPORT__ =");
|
|
162
|
+
}
|
|
163
|
+
state.ms.appendLeft(node.end, "\nexport { __SENTRY_DEFAULT_EXPORT__ as default };");
|
|
115
164
|
state.ms.append(`
|
|
116
|
-
|
|
117
|
-
`);
|
|
165
|
+
__SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${wrapped});`);
|
|
118
166
|
state.needsImport = true;
|
|
119
167
|
state.autoWrapped.add(DEFAULT_EXPORT);
|
|
120
168
|
}
|
|
169
|
+
function exportDefaultKeywordsEnd(source, start) {
|
|
170
|
+
let index = start + "export".length;
|
|
171
|
+
while (index < source.length && !source.startsWith("default", index)) {
|
|
172
|
+
if (source.startsWith("//", index)) {
|
|
173
|
+
const lineEnd = source.indexOf("\n", index);
|
|
174
|
+
index = lineEnd === -1 ? source.length : lineEnd;
|
|
175
|
+
} else if (source.startsWith("/*", index)) {
|
|
176
|
+
const commentEnd = source.indexOf("*/", index + 2);
|
|
177
|
+
index = commentEnd === -1 ? source.length : commentEnd + 2;
|
|
178
|
+
} else {
|
|
179
|
+
index++;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return index + "default".length;
|
|
183
|
+
}
|
|
184
|
+
function isAnonymousFunctionOrClass(node) {
|
|
185
|
+
if (node.type === "ArrowFunctionExpression") return true;
|
|
186
|
+
const isFunctionOrClass = [
|
|
187
|
+
"FunctionExpression",
|
|
188
|
+
"FunctionDeclaration",
|
|
189
|
+
"ClassExpression",
|
|
190
|
+
"ClassDeclaration"
|
|
191
|
+
].includes(node.type);
|
|
192
|
+
return isFunctionOrClass && !node.id;
|
|
193
|
+
}
|
|
121
194
|
function handleNamedExport(node, ctx, state) {
|
|
122
195
|
const decl = node.declaration;
|
|
123
196
|
if (decl?.type === "VariableDeclaration") {
|
|
@@ -183,16 +256,56 @@ function wrapSpecifierExports(node, ctx, state) {
|
|
|
183
256
|
}
|
|
184
257
|
state.ms.overwrite(node.start, node.end, statements.join("\n"));
|
|
185
258
|
}
|
|
259
|
+
function wrapDefaultSpecifier(localName, state) {
|
|
260
|
+
if (state.manuallyWrappedLocals.has(localName)) return void 0;
|
|
261
|
+
if (state.renamedLocals.has(localName)) {
|
|
262
|
+
state.autoWrapped.add(DEFAULT_EXPORT);
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
const declaringStatement = state.declaringStatements.get(localName);
|
|
266
|
+
if (declaringStatement) {
|
|
267
|
+
state.ms.appendLeft(declaringStatement.end, `
|
|
268
|
+
var __SENTRY_DEFAULT_EXPORT__ = ${localName};`);
|
|
269
|
+
}
|
|
270
|
+
state.ms.append(
|
|
271
|
+
`
|
|
272
|
+
${declaringStatement ? "" : "var "}__SENTRY_DEFAULT_EXPORT__ = __SENTRY__.withSentry(${state.optionsFn}, ${localName});`
|
|
273
|
+
);
|
|
274
|
+
state.needsImport = true;
|
|
275
|
+
state.autoWrapped.add(DEFAULT_EXPORT);
|
|
276
|
+
return "__SENTRY_DEFAULT_EXPORT__ as default";
|
|
277
|
+
}
|
|
278
|
+
function wrapDefaultReexport(localName, sourceLiteral, state, prelude) {
|
|
279
|
+
const target = "__SENTRY_REEXPORT_default__";
|
|
280
|
+
prelude.push(
|
|
281
|
+
localName === DEFAULT_IMPORT ? `import ${target} from ${sourceLiteral};` : `import { ${localName} as ${target} } from ${sourceLiteral};`,
|
|
282
|
+
`var __SENTRY_DEFAULT_EXPORT__ = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.withSentry, ${state.optionsFn}, ${target});`
|
|
283
|
+
);
|
|
284
|
+
state.needsImport = true;
|
|
285
|
+
state.autoWrapped.add(DEFAULT_EXPORT);
|
|
286
|
+
return "__SENTRY_DEFAULT_EXPORT__ as default";
|
|
287
|
+
}
|
|
186
288
|
function wrapCrossModuleSpecifier(specifier, sourceLiteral, ctx, state, prelude) {
|
|
187
289
|
const exportedName = specifier.type === "ExportSpecifier" && specifier.exported?.type === "Identifier" ? specifier.exported.name : void 0;
|
|
188
290
|
const localName = specifier.local?.type === "Identifier" ? specifier.local.name : void 0;
|
|
189
291
|
const kind = exportedName ? resolveWrapperKind(exportedName, sourceLiteral ? void 0 : localName, state) : void 0;
|
|
190
|
-
if (!exportedName || !localName
|
|
292
|
+
if (!exportedName || !localName) return void 0;
|
|
293
|
+
if (!kind) {
|
|
294
|
+
if (exportedName !== DEFAULT_IMPORT) return void 0;
|
|
295
|
+
return sourceLiteral ? wrapDefaultReexport(localName, sourceLiteral, state, prelude) : wrapDefaultSpecifier(localName, state);
|
|
296
|
+
}
|
|
191
297
|
if (!sourceLiteral) {
|
|
192
298
|
const localClass = state.topLevelClasses.get(localName);
|
|
299
|
+
if (localClass?.id && state.exportedClasses.has(localName) && !state.renamedLocals.has(localName)) {
|
|
300
|
+
const wrappedName2 = wrapExportedClassAlias(localName, localClass, kind, state);
|
|
301
|
+
state.wrappedClasses.add(exportedName);
|
|
302
|
+
state.autoWrapped.add(toExportName(exportedName));
|
|
303
|
+
return `${wrappedName2} as ${exportedName}`;
|
|
304
|
+
}
|
|
193
305
|
if (localClass?.id) {
|
|
194
306
|
wrapLocalClassExport(localName, localClass, kind, ctx, state);
|
|
195
307
|
state.wrappedClasses.add(exportedName);
|
|
308
|
+
state.autoWrapped.add(toExportName(exportedName));
|
|
196
309
|
state.needsImport = true;
|
|
197
310
|
return void 0;
|
|
198
311
|
}
|
|
@@ -213,10 +326,27 @@ function wrapCrossModuleSpecifier(specifier, sourceLiteral, ctx, state, prelude)
|
|
|
213
326
|
`const ${wrappedName} = __SENTRY__._INTERNAL_wrapUnlessInstrumented(__SENTRY__.${WRAPPER_METHODS[kind]}, ${state.optionsFn}, ${target});`
|
|
214
327
|
);
|
|
215
328
|
state.wrappedClasses.add(exportedName);
|
|
216
|
-
state.autoWrapped.add(exportedName);
|
|
329
|
+
state.autoWrapped.add(toExportName(exportedName));
|
|
217
330
|
state.needsImport = true;
|
|
218
331
|
return `${wrappedName} as ${exportedName}`;
|
|
219
332
|
}
|
|
333
|
+
function wrapExportedClassAlias(localName, localClass, kind, state) {
|
|
334
|
+
const existing = state.aliasedLocals.get(localName);
|
|
335
|
+
if (existing) return existing;
|
|
336
|
+
const wrappedName = `__SENTRY_WRAPPED_${localName}__`;
|
|
337
|
+
state.aliasedLocals.set(localName, wrappedName);
|
|
338
|
+
state.ms.appendLeft(
|
|
339
|
+
localClass.end,
|
|
340
|
+
`
|
|
341
|
+
const ${wrappedName} = __SENTRY__.${WRAPPER_METHODS[kind]}(${state.optionsFn}, ${localName});
|
|
342
|
+
`
|
|
343
|
+
);
|
|
344
|
+
state.needsImport = true;
|
|
345
|
+
return wrappedName;
|
|
346
|
+
}
|
|
347
|
+
function toExportName(exportedName) {
|
|
348
|
+
return exportedName === DEFAULT_IMPORT ? DEFAULT_EXPORT : exportedName;
|
|
349
|
+
}
|
|
220
350
|
function wrapLocalClassExport(localName, localClass, kind, ctx, state) {
|
|
221
351
|
const classId = localClass.id;
|
|
222
352
|
if (!classId || state.renamedLocals.has(localName)) return;
|