Skip to content

Commit dc696c0

Browse files
authored
ref(tracing): Re-organize exports for node/browser (#7345)
1 parent 04d551e commit dc696c0

25 files changed

+123
-48
lines changed

Diff for: packages/tracing/.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
extends: ['../../.eslintrc.js'],
33
overrides: [
44
{
5-
files: ['src/integrations/node/**'],
5+
files: ['src/node/**'],
66
rules: {
77
'@sentry-internal/sdk/no-optional-chaining': 'off',
88
},

Diff for: packages/tracing/package.json

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@sentry/tracing",
33
"version": "7.41.0",
4-
"description": "Extensions for Sentry AM",
4+
"description": "Sentry Performance Monitoring Package",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/tracing",
77
"author": "Sentry",
@@ -12,6 +12,36 @@
1212
"main": "build/npm/cjs/index.js",
1313
"module": "build/npm/esm/index.js",
1414
"types": "build/npm/types/index.d.ts",
15+
"exports": {
16+
".": {
17+
"import": "./build/npm/esm/index.js",
18+
"require": "./build/npm/cjs/index.js",
19+
"types": "./build/npm/types/index.d.ts"
20+
},
21+
"./node": {
22+
"import": "./build/npm/esm/node/index.js",
23+
"require": "./build/npm/cjs/node/index.js",
24+
"types": "./build/npm/types/node/index.d.ts"
25+
},
26+
"./browser": {
27+
"import": "./build/npm/esm/browser/index.js",
28+
"require": "./build/npm/cjs/browser/index.js",
29+
"types": "./build/npm/types/browser/index.d.ts"
30+
}
31+
},
32+
"typesVersions": {
33+
"*": {
34+
"*": [
35+
"./build/npm/types/index.d.ts"
36+
],
37+
"node": [
38+
"./build/npm/types/node/index.d.ts"
39+
],
40+
"browser": [
41+
"./build/npm/types/browser/index.d.ts"
42+
]
43+
}
44+
},
1545
"publishConfig": {
1646
"access": "public"
1747
},

Diff for: packages/tracing/rollup.npm.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'
22

33
export default makeNPMConfigVariants(
44
makeBaseNPMConfig({
5+
entrypoints: ['src/browser/index.ts', 'src/node/index.ts', 'src/index.ts'],
56
// packages with bundles have a different build directory structure
67
hasBundles: true,
78
}),

Diff for: packages/tracing/src/browser/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from '../exports';
2+
13
export type { RequestInstrumentationOptions } from './request';
24

35
export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browsertracing';

Diff for: packages/tracing/src/exports/index.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export {
2+
extractTraceparentData,
3+
getActiveTransaction,
4+
hasTracingEnabled,
5+
IdleTransaction,
6+
Span,
7+
// eslint-disable-next-line deprecation/deprecation
8+
SpanStatus,
9+
spanStatusfromHttpCode,
10+
startIdleTransaction,
11+
stripUrlQueryAndFragment,
12+
TRACEPARENT_REGEXP,
13+
Transaction,
14+
} from '@sentry/core';
15+
export type { SpanStatusType } from '@sentry/core';

Diff for: packages/tracing/src/extensions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ function _autoloadDatabaseIntegrations(): void {
1515

1616
const packageToIntegrationMapping: Record<string, () => Integration> = {
1717
mongodb() {
18-
const integration = dynamicRequire(module, './integrations/node/mongo') as {
18+
const integration = dynamicRequire(module, './node/integrations/mongo') as {
1919
Mongo: IntegrationClass<Integration>;
2020
};
2121
return new integration.Mongo();
2222
},
2323
mongoose() {
24-
const integration = dynamicRequire(module, './integrations/node/mongo') as {
24+
const integration = dynamicRequire(module, './node/integrations/mongo') as {
2525
Mongo: IntegrationClass<Integration>;
2626
};
2727
return new integration.Mongo({ mongoose: true });
2828
},
2929
mysql() {
30-
const integration = dynamicRequire(module, './integrations/node/mysql') as {
30+
const integration = dynamicRequire(module, './node/integrations/mysql') as {
3131
Mysql: IntegrationClass<Integration>;
3232
};
3333
return new integration.Mysql();
3434
},
3535
pg() {
36-
const integration = dynamicRequire(module, './integrations/node/postgres') as {
36+
const integration = dynamicRequire(module, './node/integrations/postgres') as {
3737
Postgres: IntegrationClass<Integration>;
3838
};
3939
return new integration.Postgres();

Diff for: packages/tracing/src/index.ts

+9-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
1-
export {
2-
extractTraceparentData,
3-
getActiveTransaction,
4-
hasTracingEnabled,
5-
IdleTransaction,
6-
Span,
7-
// eslint-disable-next-line deprecation/deprecation
8-
SpanStatus,
9-
spanStatusfromHttpCode,
10-
startIdleTransaction,
11-
stripUrlQueryAndFragment,
12-
TRACEPARENT_REGEXP,
13-
Transaction,
14-
} from '@sentry/core';
15-
export type { SpanStatusType } from '@sentry/core';
1+
export * from './exports';
162

173
import { addExtensionMethods } from './extensions';
18-
import * as Integrations from './integrations';
19-
20-
export type { RequestInstrumentationOptions } from './browser';
4+
import * as Integrations from './node/integrations';
215

226
export { Integrations };
237

@@ -37,9 +21,14 @@ export { Integrations };
3721
// const instance = new BrowserTracing();
3822
//
3923
// For an example of of the new usage of BrowserTracing, see @sentry/nextjs index.client.ts
40-
export { BrowserTracing, BROWSER_TRACING_INTEGRATION_ID } from './browser';
24+
export {
25+
BrowserTracing,
26+
BROWSER_TRACING_INTEGRATION_ID,
27+
instrumentOutgoingRequests,
28+
defaultRequestInstrumentationOptions,
29+
} from './browser';
4130

42-
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './browser';
31+
export type { RequestInstrumentationOptions } from './browser';
4332

4433
// Treeshakable guard to remove all code related to tracing
4534
declare const __SENTRY_TRACING__: boolean;

Diff for: packages/tracing/src/integrations/index.ts

-11
This file was deleted.

Diff for: packages/tracing/src/node/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from '../exports';
2+
3+
export * from './integrations';

Diff for: packages/tracing/src/node/integrations/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export { Express } from './express';
2+
export { Postgres } from './postgres';
3+
export { Mysql } from './mysql';
4+
export { Mongo } from './mongo';
5+
export { Prisma } from './prisma';
6+
export { GraphQL } from './graphql';
7+
export { Apollo } from './apollo';
8+
9+
// TODO(v8): Remove this export
10+
// Please see `src/index.ts` for more details.
11+
export { BrowserTracing } from '../../browser';

Diff for: packages/tracing/test/integrations/apollo-nestjs.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../src';
6-
import { Apollo } from '../../src/integrations/node/apollo';
6+
import { Apollo } from '../../src/node/integrations/apollo';
77
import { getTestClient } from '../testutils';
88

99
type ApolloResolverGroup = {

Diff for: packages/tracing/test/integrations/apollo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../src';
6-
import { Apollo } from '../../src/integrations/node/apollo';
6+
import { Apollo } from '../../src/node/integrations/apollo';
77
import { getTestClient } from '../testutils';
88

99
type ApolloResolverGroup = {

Diff for: packages/tracing/test/integrations/graphql.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../src';
6-
import { GraphQL } from '../../src/integrations/node/graphql';
6+
import { GraphQL } from '../../src/node/integrations/graphql';
77
import { getTestClient } from '../testutils';
88

99
const GQLExecute = {

Diff for: packages/tracing/test/integrations/node/mongo.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../../src';
6-
import { Mongo } from '../../../src/integrations/node/mongo';
6+
import { Mongo } from '../../../src/node/integrations/mongo';
77
import { getTestClient } from '../../testutils';
88

99
class Collection {

Diff for: packages/tracing/test/integrations/node/postgres.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../../src';
6-
import { Postgres } from '../../../src/integrations/node/postgres';
6+
import { Postgres } from '../../../src/node/integrations/postgres';
77
import { getTestClient } from '../../testutils';
88

99
class PgClient {

Diff for: packages/tracing/test/integrations/node/prisma.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33
import { logger } from '@sentry/utils';
44

55
import { Span } from '../../../src';
6-
import { Prisma } from '../../../src/integrations/node/prisma';
6+
import { Prisma } from '../../../src/node/integrations/prisma';
77
import { getTestClient } from '../../testutils';
88

99
type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise<unknown>) => Promise<unknown>;

Diff for: scripts/prepack.ts

+40-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,33 @@ const NPM_BUILD_DIR = 'build/npm';
1313
const BUILD_DIR = 'build';
1414
const NPM_IGNORE = fs.existsSync('.npmignore') ? '.npmignore' : '../../.npmignore';
1515

16-
const ASSETS = ['README.md', 'LICENSE', 'package.json', NPM_IGNORE];
17-
const ENTRY_POINTS = ['main', 'module', 'types', 'browser'];
16+
const ASSETS = ['README.md', 'LICENSE', 'package.json', NPM_IGNORE] as const;
17+
const ENTRY_POINTS = ['main', 'module', 'types', 'browser'] as const;
18+
const EXPORT_MAP_ENTRY_POINT = 'exports';
19+
const TYPES_VERSIONS_ENTRY_POINT = 'typesVersions';
1820

1921
const packageWithBundles = process.argv.includes('--bundles');
2022
const buildDir = packageWithBundles ? NPM_BUILD_DIR : BUILD_DIR;
2123

24+
type PackageJsonEntryPoints = Record<typeof ENTRY_POINTS[number], string>;
25+
26+
interface PackageJson extends Record<string, unknown>, PackageJsonEntryPoints {
27+
[EXPORT_MAP_ENTRY_POINT]: {
28+
[key: string]: {
29+
import: string;
30+
require: string;
31+
types: string;
32+
};
33+
};
34+
[TYPES_VERSIONS_ENTRY_POINT]: {
35+
[key: string]: {
36+
[key: string]: string[];
37+
};
38+
};
39+
}
40+
2241
// eslint-disable-next-line @typescript-eslint/no-var-requires
23-
const pkgJson: { [key: string]: unknown } = require(path.resolve('package.json'));
42+
const pkgJson: PackageJson = require(path.resolve('package.json'));
2443

2544
// check if build dir exists
2645
if (!fs.existsSync(path.resolve(buildDir))) {
@@ -44,13 +63,29 @@ ASSETS.forEach(asset => {
4463
// package.json modifications
4564
const newPackageJsonPath = path.resolve(buildDir, 'package.json');
4665
// eslint-disable-next-line @typescript-eslint/no-var-requires
47-
const newPkgJson: { [key: string]: unknown } = require(newPackageJsonPath);
66+
const newPkgJson: PackageJson = require(newPackageJsonPath);
4867

4968
// modify entry points to point to correct paths (i.e. strip out the build directory)
5069
ENTRY_POINTS.filter(entryPoint => newPkgJson[entryPoint]).forEach(entryPoint => {
51-
newPkgJson[entryPoint] = (newPkgJson[entryPoint] as string).replace(`${buildDir}/`, '');
70+
newPkgJson[entryPoint] = newPkgJson[entryPoint].replace(`${buildDir}/`, '');
5271
});
5372

73+
if (newPkgJson[EXPORT_MAP_ENTRY_POINT]) {
74+
Object.entries(newPkgJson[EXPORT_MAP_ENTRY_POINT]).forEach(([key, val]) => {
75+
newPkgJson[EXPORT_MAP_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
76+
return { ...acc, [key]: val.replace(`${buildDir}/`, '') };
77+
}, {} as typeof val);
78+
});
79+
}
80+
81+
if (newPkgJson[TYPES_VERSIONS_ENTRY_POINT]) {
82+
Object.entries(newPkgJson[TYPES_VERSIONS_ENTRY_POINT]).forEach(([key, val]) => {
83+
newPkgJson[TYPES_VERSIONS_ENTRY_POINT][key] = Object.entries(val).reduce((acc, [key, val]) => {
84+
return { ...acc, [key]: val.map(v => v.replace(`${buildDir}/`, '')) };
85+
}, {});
86+
});
87+
}
88+
5489
delete newPkgJson.scripts;
5590
delete newPkgJson.volta;
5691
delete newPkgJson.jest;

0 commit comments

Comments
 (0)