Skip to content

Commit 5140e73

Browse files
timfishlforst
andauthored
feat: Deno SDK (#9206)
Co-authored-by: Luca Forstner <[email protected]>
1 parent 49572bd commit 5140e73

36 files changed

+1687
-7
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ jobs:
379379
- name: Set up Node
380380
uses: actions/setup-node@v3
381381
with:
382-
node-version: ${{ env.DEFAULT_NODE_VERSION }}
382+
node-version-file: 'package.json'
383383
- name: Restore caches
384384
uses: ./.github/actions/restore-cache
385385
env:
@@ -406,7 +406,7 @@ jobs:
406406
- name: Set up Node
407407
uses: actions/setup-node@v3
408408
with:
409-
node-version: ${{ matrix.node }}
409+
node-version-file: 'package.json'
410410
- name: Set up Bun
411411
uses: oven-sh/setup-bun@v1
412412
- name: Restore caches
@@ -419,6 +419,38 @@ jobs:
419419
- name: Compute test coverage
420420
uses: codecov/codecov-action@v3
421421

422+
job_deno_unit_tests:
423+
name: Deno Unit Tests
424+
needs: [job_get_metadata, job_build]
425+
timeout-minutes: 10
426+
runs-on: ubuntu-20.04
427+
strategy:
428+
fail-fast: false
429+
steps:
430+
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
431+
uses: actions/checkout@v4
432+
with:
433+
ref: ${{ env.HEAD_COMMIT }}
434+
- name: Set up Node
435+
uses: actions/setup-node@v3
436+
with:
437+
node-version-file: 'package.json'
438+
- name: Set up Deno
439+
uses: denoland/[email protected]
440+
with:
441+
deno-version: v1.37.1
442+
- name: Restore caches
443+
uses: ./.github/actions/restore-cache
444+
env:
445+
DEPENDENCY_CACHE_KEY: ${{ needs.job_build.outputs.dependency_cache_key }}
446+
- name: Run tests
447+
run: |
448+
cd packages/deno
449+
yarn build
450+
yarn test
451+
- name: Compute test coverage
452+
uses: codecov/codecov-action@v3
453+
422454
job_node_unit_tests:
423455
name: Node (${{ matrix.node }}) Unit Tests
424456
needs: [job_get_metadata, job_build]
@@ -895,6 +927,7 @@ jobs:
895927
job_browser_build_tests,
896928
job_browser_unit_tests,
897929
job_bun_unit_tests,
930+
job_deno_unit_tests,
898931
job_node_unit_tests,
899932
job_nextjs_integration_test,
900933
job_node_integration_tests,

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jest/transformers/*.js
2121
# node tarballs
2222
packages/*/sentry-*.tgz
2323
.nxcache
24+
# The Deno types are downloaded before building
25+
packages/deno/lib.deno.d.ts
2426

2527
# logs
2628
yarn-error.log

.vscode/extensions.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"recommendations": [
55
"esbenp.prettier-vscode",
66
"dbaeumer.vscode-eslint",
7-
"augustocdias.tasks-shell-input"
8-
],
7+
"augustocdias.tasks-shell-input",
8+
"denoland.vscode-deno"
9+
]
910
}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
{
2929
"mode": "auto"
3030
}
31-
]
31+
],
32+
"deno.enablePaths": ["packages/deno/test"]
3233
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"postpublish": "lerna run --stream --concurrency 1 postpublish",
2828
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test",
2929
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\" test:unit",
30-
"test-ci-browser": "lerna run test --ignore \"@sentry/{bun,node,node-experimental,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
30+
"test-ci-browser": "lerna run test --ignore \"@sentry/{bun,deno,node,node-experimental,opentelemetry-node,serverless,nextjs,remix,gatsby,sveltekit,vercel-edge}\" --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests,overhead-metrics}\"",
3131
"test-ci-node": "ts-node ./scripts/node-unit-tests.ts",
3232
"test-ci-bun": "lerna run test --scope @sentry/bun",
3333
"test:update-snapshots": "lerna run test:update-snapshots",
@@ -45,6 +45,7 @@
4545
"packages/browser-integration-tests",
4646
"packages/bun",
4747
"packages/core",
48+
"packages/deno",
4849
"packages/e2e-tests",
4950
"packages/ember",
5051
"packages/eslint-config-sdk",

packages/deno/.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
extends: ['../../.eslintrc.js'],
3+
ignorePatterns: ['lib.deno.d.ts', 'scripts/*.mjs'],
4+
rules: {
5+
'@sentry-internal/sdk/no-optional-chaining': 'off',
6+
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
7+
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
8+
'@sentry-internal/sdk/no-class-field-initializers': 'off',
9+
},
10+
overrides: [
11+
{
12+
files: ['./test/*.ts'],
13+
rules: {
14+
'import/no-unresolved': 'off',
15+
},
16+
},
17+
],
18+
};

packages/deno/LICENSE

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

packages/deno/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
# Official Sentry SDK for Deno (Beta)
8+
9+
[![npm version](https://img.shields.io/npm/v/@sentry/deno.svg)](https://www.npmjs.com/package/@sentry/deno)
10+
[![npm dm](https://img.shields.io/npm/dm/@sentry/deno.svg)](https://www.npmjs.com/package/@sentry/deno)
11+
[![npm dt](https://img.shields.io/npm/dt/@sentry/deno.svg)](https://www.npmjs.com/package/@sentry/deno)
12+
13+
## Links
14+
15+
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
16+
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
17+
18+
The Sentry Deno SDK is in beta. Please help us improve the SDK by [reporting any issues or giving us feedback](https://github.com/getsentry/sentry-javascript/issues).
19+
20+
## Usage
21+
22+
To use this SDK, call `Sentry.init(options)` as early as possible in the main entry module. This will initialize the SDK and
23+
hook into the environment. Note that you can turn off almost all side effects using the respective options.
24+
25+
```javascript
26+
import * as Sentry from 'npm:@sentry/deno';
27+
28+
Sentry.init({
29+
dsn: '__DSN__',
30+
// ...
31+
});
32+
```
33+
34+
To set context information or send manual events, use the exported functions of `@sentry/deno`. Note that these
35+
functions will not perform any action before you have called `init()`:
36+
37+
```javascript
38+
// Set user information, as well as tags and further extras
39+
Sentry.configureScope(scope => {
40+
scope.setExtra('battery', 0.7);
41+
scope.setTag('user_mode', 'admin');
42+
scope.setUser({ id: '4711' });
43+
// scope.clear();
44+
});
45+
46+
// Add a breadcrumb for future events
47+
Sentry.addBreadcrumb({
48+
message: 'My Breadcrumb',
49+
// ...
50+
});
51+
52+
// Capture exceptions, messages or manual events
53+
Sentry.captureMessage('Hello, world!');
54+
Sentry.captureException(new Error('Good bye'));
55+
Sentry.captureEvent({
56+
message: 'Manual',
57+
stacktrace: [
58+
// ...
59+
],
60+
});
61+
```
62+
63+
64+

packages/deno/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../jest/jest.config.js');

packages/deno/package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@sentry/deno",
3+
"version": "7.73.0",
4+
"description": "Official Sentry SDK for Deno",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/deno",
7+
"author": "Sentry",
8+
"license": "MIT",
9+
"main": "build/index.js",
10+
"module": "build/index.js",
11+
"types": "build/index.d.ts",
12+
"private": true,
13+
"dependencies": {
14+
"@sentry/core": "7.73.0",
15+
"@sentry/browser": "7.73.0",
16+
"@sentry/types": "7.73.0",
17+
"@sentry/utils": "7.73.0",
18+
"lru_map": "^0.3.3"
19+
},
20+
"devDependencies": {
21+
"@types/node": "20.8.2",
22+
"@rollup/plugin-commonjs": "^25.0.5",
23+
"@rollup/plugin-typescript": "^11.1.5",
24+
"rollup-plugin-dts": "^6.1.0"
25+
},
26+
"scripts": {
27+
"deno-types": "node ./scripts/download-deno-types.mjs",
28+
"build": "run-s build:transpile build:types",
29+
"build:dev": "yarn build",
30+
"build:transpile": "yarn deno-types && rollup -c rollup.config.js",
31+
"build:types": "run-s deno-types build:types:tsc build:types:bundle",
32+
"build:types:tsc": "tsc -p tsconfig.types.json",
33+
"build:types:bundle": "rollup -c rollup.types.config.js",
34+
"circularDepCheck": "madge --circular src/index.ts",
35+
"clean": "rimraf build coverage",
36+
"prefix": "yarn deno-types",
37+
"fix": "run-s fix:eslint fix:prettier",
38+
"fix:eslint": "eslint . --format stylish --fix",
39+
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"",
40+
"prelint": "yarn deno-types",
41+
"lint": "run-s lint:prettier lint:eslint",
42+
"lint:eslint": "eslint . --format stylish",
43+
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"",
44+
"install:deno": "node ./scripts/install-deno.mjs",
45+
"test": "run-s deno-types install:deno test:types test:unit",
46+
"test:types": "deno check ./build/index.js",
47+
"test:unit": "deno test --allow-read --allow-run",
48+
"test:unit:update": "deno test --allow-read --allow-write --allow-run -- --update"
49+
},
50+
"volta": {
51+
"extends": "../../package.json"
52+
},
53+
"sideEffects": false,
54+
"madge": {
55+
"detectiveOptions": {
56+
"ts": {
57+
"skipTypeImports": true
58+
}
59+
}
60+
}
61+
}

packages/deno/rollup.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import nodeResolve from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import sucrase from '@rollup/plugin-sucrase';
4+
5+
export default {
6+
input: ['src/index.ts'],
7+
output: {
8+
dir: 'build',
9+
sourcemap: true,
10+
preserveModules: false,
11+
strict: false,
12+
freeze: false,
13+
interop: 'auto',
14+
format: 'esm',
15+
banner: '/// <reference types="./index.d.ts" />',
16+
},
17+
plugins: [
18+
nodeResolve({
19+
extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx'],
20+
}),
21+
commonjs(),
22+
sucrase({ transforms: ['typescript'] }),
23+
],
24+
};

packages/deno/rollup.types.config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import dts from 'rollup-plugin-dts';
2+
3+
export default {
4+
input: './build/index.d.ts',
5+
output: [{ file: 'build/index.d.ts', format: 'es' }],
6+
plugins: [
7+
dts({ respectExternal: true }),
8+
// The bundled types contain a declaration for the __DEBUG_BUILD__ global
9+
// This can result in errors about duplicate global declarations so we strip it out!
10+
{
11+
name: 'strip-global',
12+
renderChunk(code) {
13+
return { code: code.replace(/declare global \{\s*const __DEBUG_BUILD__: boolean;\s*\}/g, '') };
14+
},
15+
},
16+
],
17+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { writeFileSync, existsSync } from 'fs';
2+
import { download } from './download.mjs';
3+
4+
if (!existsSync('lib.deno.d.ts')) {
5+
const code = await download('https://github.com/denoland/deno/releases/download/v1.37.1/lib.deno.d.ts');
6+
writeFileSync('lib.deno.d.ts', code);
7+
}

packages/deno/scripts/download.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** Download a url to a string */
2+
export async function download(url) {
3+
try {
4+
return await fetch(url).then(res => res.text());
5+
} catch (e) {
6+
// eslint-disable-next-line no-console
7+
console.error('Failed to download', url, e);
8+
process.exit(1);
9+
}
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { execSync } from 'child_process';
2+
3+
import { download } from './download.mjs';
4+
5+
try {
6+
execSync('deno --version', { stdio: 'inherit' });
7+
} catch (_) {
8+
// eslint-disable-next-line no-console
9+
console.error('Deno is not installed. Installing...');
10+
if (process.platform === 'win32') {
11+
// TODO
12+
// eslint-disable-next-line no-console
13+
console.error('Please install Deno manually: https://docs.deno.com/runtime/manual/getting_started/installation');
14+
process.exit(1);
15+
} else {
16+
const script = await download('https://deno.land/x/install/install.sh');
17+
18+
try {
19+
execSync(script, { stdio: 'inherit' });
20+
} catch (e) {
21+
// eslint-disable-next-line no-console
22+
console.error('Failed to install Deno', e);
23+
process.exit(1);
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)