Skip to content

Commit 5af4bb0

Browse files
committed
feat(effect): Add client/server entrypoints without functionality (#19649)
That adds now the functionality to use the `Sentry.effectLayer` properly. **But** it doesn't do anything, which means right now, to keep the PRs small, it returns an empty layer. Following can be used without any Sentry functionality: ```js const MainLive = HttpLive.pipe(Layer.provide(Sentry.effectLayer({ dsn: "", tracesSampleRate: 1.0, debug: true, }))) MainLive.pipe(Layer.launch, NodeRuntime.runMain) ```
1 parent a77c5a2 commit 5af4bb0

11 files changed

Lines changed: 179 additions & 110 deletions

File tree

packages/effect/package.json

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/effect",
3-
"version": "10.42.0",
3+
"version": "10.43.0",
44
"description": "Official Sentry SDK for Effect",
55
"repository": "git://github.com/getsentry/sentry-javascript.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/effect",
@@ -12,34 +12,66 @@
1212
"files": [
1313
"/build"
1414
],
15-
"main": "build/cjs/index.js",
16-
"module": "build/esm/index.js",
17-
"types": "build/types/index.d.ts",
15+
"main": "build/cjs/index.server.js",
16+
"module": "build/esm/index.server.js",
17+
"browser": "build/esm/index.client.js",
18+
"types": "build/types/index.types.d.ts",
1819
"exports": {
1920
"./package.json": "./package.json",
2021
".": {
21-
"import": {
22-
"types": "./build/types/index.d.ts",
23-
"default": "./build/esm/index.js"
22+
"types": "./build/types/index.types.d.ts",
23+
"browser": {
24+
"import": "./build/esm/index.client.js",
25+
"require": "./build/cjs/index.client.js"
2426
},
25-
"require": {
26-
"types": "./build/types/index.d.ts",
27-
"default": "./build/cjs/index.js"
27+
"node": {
28+
"import": "./build/esm/index.server.js",
29+
"require": "./build/cjs/index.server.js"
2830
}
31+
},
32+
"./server": {
33+
"types": "./build/types/index.server.d.ts",
34+
"import": "./build/esm/index.server.js",
35+
"require": "./build/cjs/index.server.js"
36+
},
37+
"./client": {
38+
"types": "./build/types/index.client.d.ts",
39+
"import": "./build/esm/index.client.js",
40+
"require": "./build/cjs/index.client.js"
2941
}
3042
},
3143
"typesVersions": {
3244
"<5.0": {
33-
"build/types/index.d.ts": [
34-
"build/types-ts3.8/index.d.ts"
45+
"build/types/index.types.d.ts": [
46+
"build/types-ts3.8/index.types.d.ts"
47+
],
48+
"build/types/index.server.d.ts": [
49+
"build/types-ts3.8/index.server.d.ts"
50+
],
51+
"build/types/index.client.d.ts": [
52+
"build/types-ts3.8/index.client.d.ts"
3553
]
3654
}
3755
},
3856
"publishConfig": {
3957
"access": "public"
4058
},
4159
"dependencies": {
42-
"@sentry/core": "10.42.0"
60+
"@sentry/browser": "10.43.0",
61+
"@sentry/core": "10.43.0",
62+
"@sentry/node-core": "10.43.0"
63+
},
64+
"peerDependencies": {
65+
"effect": "^3.0.0"
66+
},
67+
"peerDependenciesMeta": {
68+
"effect": {
69+
"optional": false
70+
}
71+
},
72+
"devDependencies": {
73+
"@effect/vitest": "^0.23.9",
74+
"effect": "^3.19.19"
4375
},
4476
"scripts": {
4577
"build": "run-p build:transpile build:types",
@@ -52,7 +84,7 @@
5284
"build:dev:watch": "yarn build:watch",
5385
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
5486
"build:tarball": "npm pack",
55-
"circularDepCheck": "madge --circular src/index.ts",
87+
"circularDepCheck": "madge --circular src/index.client.ts && madge --circular src/index.server.ts && madge --circular src/index.types.ts",
5688
"clean": "rimraf build coverage sentry-effect-*.tgz",
5789
"fix": "eslint . --format stylish --fix",
5890
"lint": "eslint . --format stylish",
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
22

3-
export default makeNPMConfigVariants(
4-
makeBaseNPMConfig({
5-
packageSpecificConfig: {
6-
output: {
7-
preserveModulesRoot: 'src',
8-
},
3+
const baseConfig = makeBaseNPMConfig({
4+
entrypoints: ['src/index.server.ts', 'src/index.client.ts'],
5+
packageSpecificConfig: {
6+
output: {
7+
preserveModulesRoot: 'src',
98
},
10-
}),
11-
);
9+
},
10+
});
11+
12+
const defaultExternal = baseConfig.external || [];
13+
baseConfig.external = id => {
14+
if (defaultExternal.includes(id)) {
15+
return true;
16+
}
17+
18+
if (id === 'effect' || id.startsWith('effect/') || id.startsWith('@sentry/')) {
19+
return true;
20+
}
21+
22+
return false;
23+
};
24+
25+
export default makeNPMConfigVariants(baseConfig);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { BrowserOptions } from '@sentry/browser';
2+
import * as EffectLayer from 'effect/Layer';
3+
4+
/**
5+
* Options for the Sentry Effect client layer.
6+
*/
7+
export type EffectClientLayerOptions = BrowserOptions;
8+
9+
/**
10+
* Creates an empty Effect Layer
11+
*
12+
* @example
13+
* ```typescript
14+
* import * as Sentry from '@sentry/effect/client';
15+
* import { Layer, Effect } from 'effect';
16+
*
17+
* const ApiClientWithSentry = ApiClientLive.pipe(
18+
* Layer.provide(Sentry.effectLayer({
19+
* dsn: '__DSN__',
20+
* integrations: [Sentry.browserTracingIntegration()],
21+
* tracesSampleRate: 1.0,
22+
* })),
23+
* );
24+
*
25+
* Effect.runPromise(Effect.provide(myEffect, ApiClientWithSentry));
26+
* ```
27+
*/
28+
export function effectLayer(_: EffectClientLayerOptions): EffectLayer.Layer<never, never, never> {
29+
return EffectLayer.empty;
30+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from '@sentry/browser';
2+
3+
export { effectLayer } from './client/index';
4+
export type { EffectClientLayerOptions } from './client/index';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from '@sentry/node-core/light';
2+
3+
export { effectLayer } from './server/index';
4+
export type { EffectServerLayerOptions } from './server/index';

packages/effect/src/index.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.

packages/effect/src/index.types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable import/export */
2+
3+
// We export everything from both the client part of the SDK and from the server part.
4+
// Some of the exports collide, which is not allowed, unless we redefine the colliding
5+
// exports in this file - which we do below.
6+
import type { Client, Integration, Options, StackParser } from '@sentry/core';
7+
import type * as EffectLayer from 'effect/Layer';
8+
import type * as clientSdk from './index.client';
9+
import type * as serverSdk from './index.server';
10+
11+
export * from './index.client';
12+
export * from './index.server';
13+
14+
export type { EffectClientLayerOptions } from './index.client';
15+
export type { EffectServerLayerOptions } from './index.server';
16+
17+
export declare function effectLayer(
18+
options: clientSdk.EffectClientLayerOptions | serverSdk.EffectServerLayerOptions,
19+
): EffectLayer.Layer<never, never, never>;
20+
21+
export declare function init(options: Options | clientSdk.BrowserOptions | serverSdk.NodeOptions): Client | undefined;
22+
export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsIntegration;
23+
export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration;
24+
export declare const getDefaultIntegrations: (options: Options) => Integration[];
25+
export declare const defaultStackParser: StackParser;
26+
export declare const logger: typeof clientSdk.logger | typeof serverSdk.logger;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { NodeOptions } from '@sentry/node-core';
2+
import * as EffectLayer from 'effect/Layer';
3+
4+
/**
5+
* Options for the Sentry Effect server layer.
6+
*/
7+
export type EffectServerLayerOptions = NodeOptions;
8+
9+
/**
10+
* Creates an empty Effect Layer
11+
*
12+
* @example
13+
* ```typescript
14+
* import * as Sentry from '@sentry/effect/server';
15+
* import { NodeRuntime } from '@effect/platform-node';
16+
* import { Layer } from 'effect';
17+
* import { HttpLive } from './Http.js';
18+
*
19+
* const MainLive = HttpLive.pipe(
20+
* Layer.provide(Sentry.effectLayer({
21+
* dsn: '__DSN__',
22+
* enableLogs: true,
23+
* enableMetrics: true,
24+
* })),
25+
* );
26+
*
27+
* MainLive.pipe(Layer.launch, NodeRuntime.runMain);
28+
* ```
29+
*/
30+
export function effectLayer(_: EffectServerLayerOptions): EffectLayer.Layer<never, never, never> {
31+
return EffectLayer.empty;
32+
}

packages/effect/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import * as index from '../src';
2+
import * as index from '../src/index.client';
33

44
describe('effect index export', () => {
55
it('has correct exports', () => {

packages/effect/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"module": "esnext",
5+
"moduleResolution": "bundler",
56
"outDir": "build"
67
},
78
"include": ["src/**/*"]

0 commit comments

Comments
 (0)