Skip to content

Commit cf24b75

Browse files
committed
Readd LD integration
1 parent d9c5860 commit cf24b75

19 files changed

+680
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"packages/gatsby",
6464
"packages/google-cloud-serverless",
6565
"packages/integration-shims",
66+
"packages/launchdarkly",
6667
"packages/nestjs",
6768
"packages/nextjs",
6869
"packages/node",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
build/

packages/launchdarkly/.eslintrc.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Note: All paths are relative to the directory in which eslint is being run, rather than the directory where this file
2+
// lives
3+
4+
// ESLint config docs: https://eslint.org/docs/user-guide/configuring/
5+
6+
module.exports = {
7+
extends: ['../../.eslintrc.js'],
8+
overrides: [
9+
{
10+
files: ['src/**/*.ts'],
11+
},
12+
{
13+
files: ['test.setup.ts', 'vitest.config.ts'],
14+
parserOptions: {
15+
project: ['tsconfig.test.json'],
16+
},
17+
rules: {
18+
'no-console': 'off',
19+
},
20+
},
21+
{
22+
files: ['test/**/*.ts'],
23+
24+
rules: {
25+
// most of these errors come from `new Promise(process.nextTick)`
26+
'@typescript-eslint/unbound-method': 'off',
27+
// TODO: decide if we want to enable this again after the migration
28+
// We can take the freedom to be a bit more lenient with tests
29+
'@typescript-eslint/no-floating-promises': 'off',
30+
},
31+
},
32+
{
33+
files: ['src/types/deprecated.ts'],
34+
rules: {
35+
'@typescript-eslint/naming-convention': 'off',
36+
},
37+
},
38+
],
39+
};

packages/launchdarkly/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
/*.tgz
3+
.eslintcache
4+
build

packages/launchdarkly/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023-2024 Functional Software, Inc. dba Sentry
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9+
of the Software, and to permit persons to whom the Software is furnished to do
10+
so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/launchdarkly/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<p align="center">
2+
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4+
</a>
5+
</p>
6+
7+
# Sentry Integration for LaunchDarkly
8+
9+
This SDK is **considered experimental and in a beta state**. It may experience breaking changes, and may be discontinued
10+
at any time. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/issues/new/choose) if you have
11+
any feedback/concerns.
12+
13+
## Installation
14+
15+
## Configuration

packages/launchdarkly/package.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "@sentry/launchdarkly",
3+
"version": "8.35.0",
4+
"description": "Sentry SDK integration for Launch Darkly feature flagging",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/launchdarkly",
7+
"author": "Sentry",
8+
"license": "MIT",
9+
"engines": {
10+
"node": ">=14.18"
11+
},
12+
"files": [
13+
"/build/npm"
14+
],
15+
"main": "build/npm/cjs/index.js",
16+
"module": "build/npm/esm/index.js",
17+
"types": "build/npm/types/index.d.ts",
18+
"exports": {
19+
"./package.json": "./package.json",
20+
".": {
21+
"import": {
22+
"types": "./build/npm/types/index.d.ts",
23+
"default": "./build/npm/esm/index.js"
24+
},
25+
"require": {
26+
"types": "./build/npm/types/index.d.ts",
27+
"default": "./build/npm/cjs/index.js"
28+
}
29+
}
30+
},
31+
"typesVersions": {
32+
"<4.9": {
33+
"build/npm/types/index.d.ts": [
34+
"build/npm/types-ts3.8/index.d.ts"
35+
]
36+
}
37+
},
38+
"publishConfig": {
39+
"access": "public"
40+
},
41+
"dependencies": {
42+
"@sentry/browser": "^8.35.0",
43+
"@sentry/core": "8.35.0",
44+
"@sentry/types": "8.35.0",
45+
"@sentry/utils": "8.35.0",
46+
"launchdarkly-js-client-sdk": "^3.5.0"
47+
},
48+
"scripts": {
49+
"build": "run-p build:transpile build:types build:bundle",
50+
"build:transpile": "rollup -c rollup.npm.config.mjs",
51+
"build:bundle": "rollup -c rollup.bundle.config.mjs",
52+
"build:dev": "run-p build:transpile build:types",
53+
"build:types": "run-s build:types:core build:types:downlevel",
54+
"build:types:core": "tsc -p tsconfig.types.json",
55+
"build:types:downlevel": "yarn downlevel-dts build/npm/types build/npm/types-ts3.8 --to ts3.8 && yarn node ./scripts/shim-preact-export.js",
56+
"build:watch": "run-p build:transpile:watch build:bundle:watch build:types:watch",
57+
"build:dev:watch": "run-p build:transpile:watch build:types:watch",
58+
"build:transpile:watch": "yarn build:transpile --watch",
59+
"build:bundle:watch": "yarn build:bundle --watch",
60+
"build:types:watch": "tsc -p tsconfig.types.json --watch",
61+
"build:tarball": "npm pack",
62+
"circularDepCheck": "madge --circular src/index.ts",
63+
"clean": "rimraf build sentry-internal-launchdarkly-*.tgz",
64+
"fix": "eslint . --format stylish --fix",
65+
"lint": "eslint . --format stylish",
66+
"test": "jest",
67+
"test:watch": "jest --watch",
68+
"yalc:publish": "yalc publish --push --sig"
69+
},
70+
"volta": {
71+
"extends": "../../package.json"
72+
},
73+
"sideEffects": false
74+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { makeBaseBundleConfig, makeBundleConfigVariants } from '@sentry-internal/rollup-utils';
2+
3+
const baseBundleConfig = makeBaseBundleConfig({
4+
bundleType: 'addon',
5+
entrypoints: ['src/index.ts'],
6+
licenseTitle: '@sentry/launchdarkly',
7+
outputFileBase: () => 'bundles/launchdarkly',
8+
});
9+
10+
const builds = makeBundleConfigVariants(baseBundleConfig);
11+
12+
export default builds;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';
2+
3+
export default makeNPMConfigVariants(
4+
makeBaseNPMConfig({
5+
hasBundles: true,
6+
packageSpecificConfig: {
7+
output: {
8+
// set exports to 'named' or 'auto' so that rollup doesn't warn
9+
exports: 'named',
10+
// set preserveModules to false because for Replay we actually want
11+
// to bundle everything into one file.
12+
preserveModules:
13+
process.env.SENTRY_BUILD_PRESERVE_MODULES === undefined
14+
? false
15+
: Boolean(process.env.SENTRY_BUILD_PRESERVE_MODULES),
16+
},
17+
},
18+
}),
19+
);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// preact does not support more modern TypeScript versions, which breaks our users that depend on older
2+
// TypeScript versions. To fix this, we shim the types from preact to be any and remove the dependency on preact
3+
// for types directly. This script is meant to be run after the build/npm/types-ts3.8 directory is created.
4+
5+
// Path: build/npm/types-ts3.8/global.d.ts
6+
7+
const fs = require('fs');
8+
const path = require('path');
9+
10+
/**
11+
* This regex looks for preact imports we can replace and shim out.
12+
*
13+
* Example:
14+
* import { ComponentChildren, VNode } from 'preact';
15+
*/
16+
const preactImportRegex = /import\s*{\s*([\w\s,]+)\s*}\s*from\s*'preact'\s*;?/;
17+
18+
function walk(dir) {
19+
const files = fs.readdirSync(dir);
20+
files.forEach(file => {
21+
const filePath = path.join(dir, file);
22+
const stat = fs.lstatSync(filePath);
23+
if (stat.isDirectory()) {
24+
walk(filePath);
25+
} else {
26+
if (filePath.endsWith('.d.ts')) {
27+
const content = fs.readFileSync(filePath, 'utf8');
28+
const capture = preactImportRegex.exec(content);
29+
if (capture) {
30+
const groups = capture[1].split(',').map(s => s.trim());
31+
32+
// This generates a shim snippet to replace the type imports from preact
33+
// It generates a snippet based on the capture groups of preactImportRegex.
34+
//
35+
// Example:
36+
//
37+
// import type { ComponentChildren, VNode } from 'preact';
38+
// becomes
39+
// type ComponentChildren: any;
40+
// type VNode: any;
41+
const snippet = groups.reduce((acc, curr) => {
42+
const searchableValue = curr.includes(' as ') ? curr.split(' as ')[1] : curr;
43+
44+
// look to see if imported as value, then we have to use declare const
45+
if (content.includes(`typeof ${searchableValue}`)) {
46+
return `${acc}declare const ${searchableValue}: any;\n`;
47+
}
48+
49+
// look to see if generic type like Foo<T>
50+
if (content.includes(`${searchableValue}<`)) {
51+
return `${acc}type ${searchableValue}<T> = any;\n`;
52+
}
53+
54+
// otherwise we can just leave as type
55+
return `${acc}type ${searchableValue} = any;\n`;
56+
}, '');
57+
58+
// we then can remove the import from preact
59+
const newContent = content.replace(preactImportRegex, '// replaced import from preact');
60+
61+
// and write the new content to the file
62+
fs.writeFileSync(filePath, snippet + newContent, 'utf8');
63+
}
64+
}
65+
}
66+
});
67+
}
68+
69+
function run() {
70+
// recurse through build/npm/types-ts3.8 directory
71+
const dir = path.join('build', 'npm', 'types-ts3.8');
72+
walk(dir);
73+
}
74+
75+
run();

0 commit comments

Comments
 (0)