Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feat(cloudflare): Add basic cloudflare package and tests #12861

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev-packages/e2e-tests/verdaccio-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ packages:
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/cloudflare':
access: $all
publish: $all
unpublish: $all
# proxy: npmjs # Don't proxy for E2E tests!

'@sentry/deno':
access: $all
publish: $all
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"packages/browser-utils",
"packages/bun",
"packages/core",
"packages/cloudflare",
"packages/deno",
"packages/ember",
"packages/eslint-config-sdk",
Expand Down
11 changes: 11 additions & 0 deletions packages/cloudflare/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
env: {
node: true,
},
extends: ['../../.eslintrc.js'],
rules: {
'@sentry-internal/sdk/no-optional-chaining': 'off',
'@sentry-internal/sdk/no-nullish-coalescing': 'off',
'@sentry-internal/sdk/no-class-field-initializers': 'off',
},
};
21 changes: 21 additions & 0 deletions packages/cloudflare/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Functional Software, Inc. dba Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions packages/cloudflare/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p align="center">
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
</a>
</p>

# Official Sentry SDK for Cloudflare [UNRELEASED]

[![npm version](https://img.shields.io/npm/v/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
[![npm dm](https://img.shields.io/npm/dm/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)
[![npm dt](https://img.shields.io/npm/dt/@sentry/cloudflare.svg)](https://www.npmjs.com/package/@sentry/cloudflare)

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)

**Note: This SDK is unreleased. Please follow the
[tracking GH issue](https://github.com/getsentry/sentry-javascript/issues/12620) for updates.**

## Usage

TODO: Add usage instructions here.
76 changes: 76 additions & 0 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@sentry/cloudflare",
"version": "8.17.0",
"description": "Offical Sentry SDK for Cloudflare Workers and Pages",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare",
"author": "Sentry",
"license": "MIT",
"engines": {
"node": ">=14.18"
},
"files": [
"/build"
],
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"types": "build/types/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./build/types/index.d.ts",
"default": "./build/esm/index.js"
},
"require": {
"types": "./build/types/index.d.ts",
"default": "./build/cjs/index.js"
}
}
},
"typesVersions": {
"<4.9": {
"build/types/index.d.ts": [
"build/types-ts3.8/index.d.ts"
]
}
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/core": "8.17.0",
"@sentry/types": "8.17.0",
"@sentry/utils": "8.17.0"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"miniflare": "^3.20240701.0",
"wrangler": "^3.63.2"
},
"scripts": {
"build": "run-p build:transpile build:types",
"build:dev": "yarn build",
"build:transpile": "rollup -c rollup.npm.config.mjs",
"build:types": "run-s build:types:core build:types:downlevel",
"build:types:core": "tsc -p tsconfig.types.json",
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
"build:watch": "run-p build:transpile:watch build:types:watch",
"build:dev:watch": "yarn build:watch",
"build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:tarball": "npm pack",
"circularDepCheck": "madge --circular src/index.ts",
"clean": "rimraf build coverage sentry-cloudflare-*.tgz",
"fix": "eslint . --format stylish --fix",
"lint": "eslint . --format stylish",
"test": "yarn test:unit",
"test:unit": "vitest run",
"test:watch": "vitest --watch",
"yalc:publish": "yalc publish --push --sig"
},
"volta": {
"extends": "../../package.json"
},
"sideEffects": false
}
3 changes: 3 additions & 0 deletions packages/cloudflare/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils';

export default makeNPMConfigVariants(makeBaseNPMConfig());
8 changes: 8 additions & 0 deletions packages/cloudflare/src/debug-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const __DEBUG_BUILD__: boolean;

/**
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
*
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
*/
export const DEBUG_BUILD = __DEBUG_BUILD__;
1 change: 1 addition & 0 deletions packages/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
8 changes: 8 additions & 0 deletions packages/cloudflare/test/fixtures/worker.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @type {import('@cloudflare/workers-types').ExportedHandler}
*/
export default {
async fetch(_request, _env, _ctx) {
return new Response('Hello Sentry!');
},
};
17 changes: 17 additions & 0 deletions packages/cloudflare/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, test } from 'vitest';

import { Miniflare } from 'miniflare';

describe('index', () => {
test('simple test', async () => {
const mf = new Miniflare({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea with the local simulation!

scriptPath: './test/fixtures/worker.mjs',
modules: true,
port: 8787,
});

const res = await mf.dispatchFetch('http://localhost:8787/');
expect(await res.text()).toBe('Hello Sentry!');
await mf.dispose();
});
});
3 changes: 3 additions & 0 deletions packages/cloudflare/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.test.json",
}
9 changes: 9 additions & 0 deletions packages/cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",

"include": ["src/**/*"],

"compilerOptions": {
"types": ["@cloudflare/workers-types"]
}
}
9 changes: 9 additions & 0 deletions packages/cloudflare/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",

"include": ["test/**/*"],

"compilerOptions": {
// other package-specific, test-specific options
}
}
10 changes: 10 additions & 0 deletions packages/cloudflare/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",

"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "build/types"
}
}
3 changes: 2 additions & 1 deletion scripts/node-unit-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DEFAULT_SKIP_TESTS_PACKAGES = [
const SKIP_TEST_PACKAGES: Record<NodeVersion, VersionConfig> = {
'14': {
ignoredPackages: [
'@sentry/cloudflare',
'@sentry/solidstart',
'@sentry/sveltekit',
'@sentry/vercel-edge',
Expand All @@ -40,7 +41,7 @@ const SKIP_TEST_PACKAGES: Record<NodeVersion, VersionConfig> = {
],
},
'16': {
ignoredPackages: ['@sentry/vercel-edge', '@sentry/astro'],
ignoredPackages: ['@sentry/cloudflare', '@sentry/vercel-edge', '@sentry/astro'],
},
'18': {
ignoredPackages: [],
Expand Down
Loading
Loading