@batijs/cli 0.0.260 → 0.0.262

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/boilerplates/@batijs/aws/files/$README.md.js +109 -0
  2. package/dist/boilerplates/@batijs/aws/files/$package.json.js +138 -0
  3. package/dist/boilerplates/@batijs/aws/files/$tsconfig.json.js +15 -0
  4. package/dist/boilerplates/@batijs/aws/files/cdk/$stack-name-suffix.json.js +19 -0
  5. package/dist/boilerplates/@batijs/aws/files/cdk/bin/infrastructure.ts +85 -0
  6. package/dist/boilerplates/@batijs/aws/files/cdk/lib/vike-stack.ts +186 -0
  7. package/dist/boilerplates/@batijs/aws/files/cdk.json +72 -0
  8. package/dist/boilerplates/@batijs/aws/files/tests/aws_handler.spec.ts +116 -0
  9. package/dist/boilerplates/@batijs/aws/files/vitest.config.ts +8 -0
  10. package/dist/boilerplates/@batijs/aws/types/cdk/bin/infrastructure.d.ts +11 -0
  11. package/dist/boilerplates/@batijs/aws/types/cdk/lib/vike-stack.d.ts +13 -0
  12. package/dist/boilerplates/@batijs/aws/types/tests/aws_handler.spec.d.ts +1 -0
  13. package/dist/boilerplates/@batijs/aws/types/vitest.config.d.ts +2 -0
  14. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +12 -1
  15. package/dist/boilerplates/@batijs/hattip/files/entry_aws_lambda.ts +37 -0
  16. package/dist/boilerplates/@batijs/hattip/types/entry_aws_lambda.d.ts +2 -0
  17. package/dist/boilerplates/@batijs/hono/files/$package.json.js +8 -1
  18. package/dist/boilerplates/@batijs/hono/files/entry_aws_lambda.ts +37 -0
  19. package/dist/boilerplates/@batijs/hono/types/entry_aws_lambda.d.ts +3 -0
  20. package/dist/boilerplates/@batijs/plain-sentry/files/$package.json.js +117 -0
  21. package/dist/boilerplates/@batijs/plain-sentry/files/pages/sentry/+Page.js +19 -0
  22. package/dist/boilerplates/@batijs/plain-sentry/files/pages/sentry/+client.js +37 -0
  23. package/dist/boilerplates/@batijs/plain-sentry/files/sentry.browser.config.ts +25 -0
  24. package/dist/boilerplates/@batijs/plain-sentry/files/vite-env.d.ts +1 -0
  25. package/dist/boilerplates/@batijs/plain-sentry/types/pages/sentry/+Page.d.ts +1 -0
  26. package/dist/boilerplates/@batijs/plain-sentry/types/pages/sentry/+client.d.ts +6 -0
  27. package/dist/boilerplates/@batijs/plain-sentry/types/sentry.browser.config.d.ts +1 -0
  28. package/dist/boilerplates/@batijs/prettier/files/.prettierignore +3 -0
  29. package/dist/boilerplates/@batijs/react-sentry/files/$package.json.js +101 -0
  30. package/dist/boilerplates/@batijs/react-sentry/files/pages/sentry/+Page.tsx +43 -0
  31. package/dist/boilerplates/@batijs/react-sentry/files/sentry.browser.config.ts +22 -0
  32. package/dist/boilerplates/@batijs/react-sentry/types/pages/sentry/+Page.d.ts +1 -0
  33. package/dist/boilerplates/@batijs/react-sentry/types/sentry.browser.config.d.ts +1 -0
  34. package/dist/boilerplates/@batijs/sentry/files/$.env.js +22 -0
  35. package/dist/boilerplates/@batijs/sentry/files/$README.md.js +31 -0
  36. package/dist/boilerplates/@batijs/sentry/files/$package.json.js +86 -0
  37. package/dist/boilerplates/@batijs/sentry/files/$vite.config.ts.js +18 -0
  38. package/dist/boilerplates/@batijs/sentry/files/.env.sentry-build-plugin +8 -0
  39. package/dist/boilerplates/@batijs/sentry/files/pages/$+client.ts.js +23 -0
  40. package/dist/boilerplates/@batijs/shared/files/.gitignore +3 -0
  41. package/dist/boilerplates/@batijs/solid-sentry/files/$package.json.js +99 -0
  42. package/dist/boilerplates/@batijs/solid-sentry/files/pages/sentry/+Page.tsx +47 -0
  43. package/dist/boilerplates/@batijs/solid-sentry/files/sentry.browser.config.ts +22 -0
  44. package/dist/boilerplates/@batijs/solid-sentry/types/pages/sentry/+Page.d.ts +1 -0
  45. package/dist/boilerplates/@batijs/solid-sentry/types/sentry.browser.config.d.ts +1 -0
  46. package/dist/boilerplates/@batijs/vue/files/layouts/LayoutDefault.vue +3 -0
  47. package/dist/boilerplates/@batijs/vue-sentry/files/$package.json.js +93 -0
  48. package/dist/boilerplates/@batijs/vue-sentry/files/pages/sentry/+Page.vue +33 -0
  49. package/dist/boilerplates/@batijs/vue-sentry/files/sentry.browser.config.ts +25 -0
  50. package/dist/boilerplates/@batijs/vue-sentry/types/sentry.browser.config.d.ts +1 -0
  51. package/dist/boilerplates/boilerplates.json +99 -0
  52. package/dist/index.js +5 -1
  53. package/package.json +5 -5
@@ -0,0 +1,116 @@
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+
3
+ import { execSync } from "node:child_process";
4
+ import { existsSync, readdirSync, readFileSync, rmSync } from "node:fs";
5
+ import path from "node:path";
6
+ import * as which from "which";
7
+
8
+ const bunExists = which.sync("bun", { nothrow: true }) !== null;
9
+ const npmCli = bunExists ? "bun" : "pnpm";
10
+
11
+ console.log("RUN TESTS ***");
12
+
13
+ describe("AWSHandler", () => {
14
+ beforeAll(
15
+ async () => {
16
+ if (existsSync(path.join(process.cwd(), "cdk.out"))) {
17
+ rmSync(path.join(process.cwd(), "cdk.out"), { recursive: true });
18
+ }
19
+ /*
20
+ * `--build "${npmCli} run build"` is required to build the project before synth
21
+ */
22
+ const synthCommand = `${npmCli} run cdk --json --build "${npmCli} run build" synth`;
23
+ execSync(synthCommand, {
24
+ encoding: "utf8",
25
+ maxBuffer: 50 * 1024 * 1024,
26
+ env: {
27
+ BUN_LOCKFILE: "../../bun.lockb", // This is to make sure that the correct lockfile is used in a bun project
28
+ PATH: process.env.PATH,
29
+ },
30
+ });
31
+ },
32
+ 2 * 60 * 1000,
33
+ );
34
+
35
+ it("should request a page from the AWS handler", async () => {
36
+ const cdkOutPath = path.join(process.cwd(), "cdk.out");
37
+ const templateFilePath = readdirSync(cdkOutPath).find(
38
+ (file) => file.startsWith("VikeStack-") && file.endsWith(".template.json"),
39
+ );
40
+ const templateFullPath = path.join(cdkOutPath, templateFilePath!);
41
+ expect(existsSync(templateFullPath)).toBe(true);
42
+ const cloudfrontTemplateJson = readFileSync(templateFullPath, "utf8");
43
+ const requestHandlerFolder = extractRequestHandlerPath(
44
+ JSON.parse(cloudfrontTemplateJson),
45
+ "/RequestHandler/Resource",
46
+ );
47
+ const requestHandlerPath = path.join(process.cwd(), "cdk.out", requestHandlerFolder!, "index.mjs");
48
+ expect(existsSync(requestHandlerPath)).toBe(true);
49
+
50
+ const { handler } = await import(requestHandlerPath);
51
+ const event = {
52
+ version: "2.0",
53
+ routeKey: "$default",
54
+ rawPath: "/",
55
+ rawQueryString: "",
56
+ headers: {
57
+ accept: "*/*",
58
+ "content-length": "0",
59
+ host: "example.com",
60
+ "user-agent": "PostmanRuntime/7.26.8",
61
+ "x-amzn-trace-id": "Root=1-5f84c7a9-0e5b1e1e1e1e1e1e1e1e1e1e",
62
+ "x-forwarded-for": "127.0.0.1",
63
+ "x-forwarded-port": "443",
64
+ "x-forwarded-proto": "https",
65
+ },
66
+ requestContext: {
67
+ accountId: "123456789012",
68
+ apiId: "api-id",
69
+ domainName: "example.com",
70
+ domainPrefix: "example",
71
+ http: {
72
+ method: "GET",
73
+ path: "/",
74
+ protocol: "HTTP/1.1",
75
+ sourceIp: "127.0.0.1",
76
+ userAgent: "PostmanRuntime/7.26.8",
77
+ },
78
+ requestId: "id",
79
+ routeKey: "$default",
80
+ stage: "$default",
81
+ time: "12/Mar/2021:19:03:58 +0000",
82
+ timeEpoch: 1615578238000,
83
+ },
84
+ isBase64Encoded: false,
85
+ };
86
+ const response = await handler(event, {});
87
+ expect(response.statusCode).toBe(200);
88
+ const body = response.isBase64Encoded ? Buffer.from(response.body, "base64").toString("utf8") : response.body;
89
+ expect(body).toContain("My Vike App");
90
+ });
91
+ });
92
+
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ type JsonData = Record<string, any>;
95
+
96
+ function extractRequestHandlerPath(jsonData: JsonData, targetCdkPath: string): string | null {
97
+ let assetPath: string | null = null;
98
+
99
+ function traverse(obj: JsonData) {
100
+ if (typeof obj !== "object" || obj === null) return;
101
+
102
+ if (obj?.["aws:cdk:path"]?.endsWith(targetCdkPath)) {
103
+ assetPath = obj?.["aws:asset:path"];
104
+ return;
105
+ }
106
+
107
+ for (const key in obj) {
108
+ if (obj?.[key]) {
109
+ traverse(obj[key]);
110
+ }
111
+ }
112
+ }
113
+
114
+ traverse(jsonData);
115
+ return assetPath;
116
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ["tests/**/*.spec.ts"], // Adjust the pattern as needed
6
+ watch: false,
7
+ },
8
+ });
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import "source-map-support/register";
3
+ import * as cdk from "aws-cdk-lib";
4
+ import * as certificatemanager from "aws-cdk-lib/aws-certificatemanager";
5
+ import * as route53 from "aws-cdk-lib/aws-route53";
6
+ export type CustomStackProps = cdk.StackProps & {
7
+ domainName?: string;
8
+ subDomain?: string;
9
+ certificate?: string | certificatemanager.ICertificate;
10
+ hostedZone?: route53.IHostedZone;
11
+ };
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import "source-map-support/register";
3
+ import { Construct } from "constructs";
4
+ import * as cdk from "aws-cdk-lib";
5
+ import type { CustomStackProps } from "../bin/infrastructure";
6
+ type VikeStackProps = cdk.StackProps & {
7
+ customStackProps: CustomStackProps;
8
+ };
9
+ export declare class VikeStack extends cdk.Stack {
10
+ readonly distributionUrlParameterName: string;
11
+ constructor(scope: Construct, id: string, props: VikeStackProps);
12
+ }
13
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -58,6 +58,10 @@ var require_package = __commonJS({
58
58
  "@hattip/core": "^0.0.47",
59
59
  "@hattip/router": "^0.0.47",
60
60
  "@hattip/vite": "^0.0.47",
61
+ "@hattip/adapter-aws-lambda": "^0.0.47",
62
+ "@hattip/static": "^0.0.47",
63
+ "@hattip/walk": "^0.0.47",
64
+ "@types/aws-lambda": "^8.10.143",
61
65
  "@trpc/server": "^10.45.2",
62
66
  "@types/node": "^18.19.14",
63
67
  "@universal-middleware/hattip": "^0.2.4",
@@ -82,12 +86,18 @@ var require_package = __commonJS({
82
86
  exports: {
83
87
  "./hattip-entry": {
84
88
  types: "./dist/types/hattip-entry.d.ts"
89
+ },
90
+ "./entry_aws_lambda": {
91
+ types: "./dist/types/entry_aws_lambda.d.ts"
85
92
  }
86
93
  },
87
94
  typesVersions: {
88
95
  "*": {
89
96
  "hattip-entry": [
90
97
  "./dist/types/hattip-entry.d.ts"
98
+ ],
99
+ entry_aws_lambda: [
100
+ "./dist/types/entry_aws_lambda.d.ts"
91
101
  ]
92
102
  }
93
103
  }
@@ -136,7 +146,8 @@ async function getPackageJson(props) {
136
146
  "vite",
137
147
  "vike",
138
148
  "@universal-middleware/hattip",
139
- ...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : []
149
+ ...props.meta.BATI.has("vercel") ? ["@hattip/adapter-vercel-edge"] : [],
150
+ ...props.meta.BATI.has("aws") ? ["@types/aws-lambda", "@hattip/adapter-aws-lambda", "@hattip/static", "@hattip/walk"] : []
140
151
  ]
141
152
  });
142
153
  }
@@ -0,0 +1,37 @@
1
+ /*{ @if (it.BATI.has("aws")) }*/
2
+ /*
3
+ entry_aws_lambda.ts
4
+
5
+ This file is the entry point for AWS Lambda
6
+
7
+ Notes:
8
+ * The file name must not have any special characters or dots except for the extension. https://docs.aws.amazon.com/lambda/latest/api/API_CreateFunction.html#API_CreateFunction_RequestSyntax
9
+
10
+ */
11
+
12
+ import { existsSync } from "node:fs";
13
+ import awsLambdaAdapter from "@hattip/adapter-aws-lambda";
14
+ import { walk } from "@hattip/walk";
15
+ import type { FileInfo } from "@hattip/walk";
16
+ import { createStaticMiddleware } from "@hattip/static";
17
+ import { createFileReader } from "@hattip/static/fs";
18
+ import hattipHandler from "@batijs/hattip/hattip-entry";
19
+ import type { Handler, APIGatewayProxyResultV2, APIGatewayProxyEventV2 } from "aws-lambda";
20
+
21
+ const root = new URL("./dist/client", import.meta.url);
22
+ const staticRootExists = existsSync(root);
23
+ const files = staticRootExists ? walk(root) : new Map<string, FileInfo>();
24
+ const staticMiddleware = staticRootExists
25
+ ? createStaticMiddleware(files, createFileReader(root), {
26
+ urlRoot: "/",
27
+ })
28
+ : undefined;
29
+
30
+ const awsHandler = awsLambdaAdapter((ctx) => {
31
+ if (hattipHandler === undefined) throw new Error("hattipHandler is undefined");
32
+ if (staticMiddleware === undefined) return hattipHandler(ctx);
33
+ return staticMiddleware(ctx) || hattipHandler(ctx);
34
+ });
35
+
36
+ export const handler: Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2> = awsHandler;
37
+ /*{ /if }*/
@@ -0,0 +1,2 @@
1
+ import type { Handler, APIGatewayProxyResultV2, APIGatewayProxyEventV2 } from "aws-lambda";
2
+ export declare const handler: Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2>;
@@ -55,6 +55,7 @@ var require_package = __commonJS({
55
55
  "@cloudflare/workers-types": "^4.20240821.1",
56
56
  "@hono/node-server": "^1.12.2",
57
57
  "@hono/vite-dev-server": "^0.15.1",
58
+ "@types/aws-lambda": "^8.10.145",
58
59
  "@trpc/server": "^10.45.2",
59
60
  "@types/node": "^18.19.14",
60
61
  "@universal-middleware/hono": "^0.2.5",
@@ -81,6 +82,9 @@ var require_package = __commonJS({
81
82
  "./hono-entry": {
82
83
  types: "./dist/types/hono-entry.d.ts"
83
84
  },
85
+ "./entry_aws_lambda": {
86
+ types: "./dist/types/entry_aws_lambda.d.ts"
87
+ },
84
88
  "./hono-entry.node": {
85
89
  types: "./dist/types/hono-entry.node.d.ts"
86
90
  }
@@ -90,6 +94,9 @@ var require_package = __commonJS({
90
94
  "hono-entry": [
91
95
  "./dist/types/hono-entry.d.ts"
92
96
  ],
97
+ entry_aws_lambda: [
98
+ "./dist/types/entry_aws_lambda.d.ts"
99
+ ],
93
100
  "hono-entry.node": [
94
101
  "./dist/types/hono-entry.node.d.ts"
95
102
  ]
@@ -120,7 +127,7 @@ async function getPackageJson(props) {
120
127
  }
121
128
  });
122
129
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
123
- devDependencies: ["@hono/vite-dev-server", "@types/node"],
130
+ devDependencies: ["@hono/vite-dev-server", "@types/node", "@types/aws-lambda"],
124
131
  dependencies: [
125
132
  "@hono/node-server",
126
133
  "@universal-middleware/hono",
@@ -0,0 +1,37 @@
1
+ /*{ @if (it.BATI.has("aws")) }*/
2
+ /*
3
+ entry_aws_lambda.ts
4
+
5
+ This file is the entry point for AWS Lambda
6
+
7
+ Notes:
8
+ * The file name must not have any special characters or dots except for the extension. https://docs.aws.amazon.com/lambda/latest/api/API_CreateFunction.html#API_CreateFunction_RequestSyntax
9
+
10
+ */
11
+
12
+ import { Hono } from "hono";
13
+ import { serveStatic } from "@hono/node-server/serve-static";
14
+ import { handle } from "hono/aws-lambda";
15
+ import type { LambdaEvent, LambdaContext } from "hono/aws-lambda";
16
+ import app from "@batijs/hono/hono-entry"; // file is provided by hono
17
+ import type { Handler, APIGatewayProxyResult } from "aws-lambda";
18
+
19
+ type Bindings = {
20
+ event: LambdaEvent;
21
+ lambdaContext: LambdaContext;
22
+ };
23
+
24
+ const lambdaApp = new Hono<{ Bindings: Bindings }>();
25
+
26
+ lambdaApp.use(
27
+ "/*",
28
+ serveStatic({
29
+ root: `./dist/client/`,
30
+ }),
31
+ );
32
+
33
+ lambdaApp.route("/", app!);
34
+ const awsHandler = handle(lambdaApp);
35
+
36
+ export const handler: Handler<LambdaEvent, APIGatewayProxyResult> = awsHandler;
37
+ /*{ /if }*/
@@ -0,0 +1,3 @@
1
+ import type { LambdaEvent } from "hono/aws-lambda";
2
+ import type { Handler, APIGatewayProxyResult } from "aws-lambda";
3
+ export declare const handler: Handler<LambdaEvent, APIGatewayProxyResult>;
@@ -0,0 +1,117 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // package.json
28
+ var require_package = __commonJS({
29
+ "package.json"(exports, module) {
30
+ module.exports = {
31
+ name: "@batijs/plain-sentry",
32
+ private: true,
33
+ version: "0.0.1",
34
+ description: "",
35
+ type: "module",
36
+ scripts: {
37
+ "check-types": "tsc --noEmit",
38
+ build: "bati-compile-boilerplate"
39
+ },
40
+ keywords: [],
41
+ author: "",
42
+ license: "MIT",
43
+ devDependencies: {
44
+ "@batijs/compile": "workspace:*",
45
+ "@batijs/sentry": "workspace:*",
46
+ "@sentry/browser": "^8.27.0",
47
+ "@types/node": "^18.19.14",
48
+ vite: "^5.4.2"
49
+ },
50
+ dependencies: {
51
+ "@batijs/core": "workspace:*"
52
+ },
53
+ files: [
54
+ "dist/"
55
+ ],
56
+ bati: {
57
+ if: {
58
+ $and: [
59
+ {
60
+ flag: "sentry"
61
+ },
62
+ {
63
+ flag: {
64
+ $not: {
65
+ $in: [
66
+ "react",
67
+ "vue",
68
+ "solid",
69
+ "svelte",
70
+ "preact",
71
+ "angular"
72
+ ]
73
+ }
74
+ }
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ exports: {
80
+ "./sentry.browser.config": {
81
+ types: "./dist/types/sentry.browser.config.d.ts"
82
+ },
83
+ "./pages/sentry/+Page": {
84
+ types: "./dist/types/pages/sentry/+Page.d.ts"
85
+ },
86
+ "./pages/sentry/+client": {
87
+ types: "./dist/types/pages/sentry/+client.d.ts"
88
+ }
89
+ },
90
+ typesVersions: {
91
+ "*": {
92
+ "sentry.browser.config": [
93
+ "./dist/types/sentry.browser.config.d.ts"
94
+ ],
95
+ "pages/sentry/+Page": [
96
+ "./dist/types/pages/sentry/+Page.d.ts"
97
+ ],
98
+ "pages/sentry/+client": [
99
+ "./dist/types/pages/sentry/+client.d.ts"
100
+ ]
101
+ }
102
+ }
103
+ };
104
+ }
105
+ });
106
+
107
+ // files/$package.json.ts
108
+ import { addDependency, loadAsJson } from "@batijs/core";
109
+ async function getPackageJson(props) {
110
+ const packageJson = await loadAsJson(props);
111
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
112
+ dependencies: ["@sentry/browser"]
113
+ });
114
+ }
115
+ export {
116
+ getPackageJson as default
117
+ };
@@ -0,0 +1,19 @@
1
+ export { Page };
2
+
3
+ function Page() {
4
+ // language=HTML
5
+ return `
6
+ <h1>Sentry Test Page</h1>
7
+ <p id="sentry_state" style="color:red">
8
+ Sentry Client is not initialized! Vite Mode: ${import.meta.env.PROD ? "PROD" : "DEV"}
9
+ </p>
10
+ <p id="sentry_dsn" style="color:red">
11
+ Sentry Client DSN is missing! Vite Mode: ${import.meta.env.PROD ? "PROD" : "DEV"}
12
+ </p>
13
+ <div>
14
+ <button id="errorButton">
15
+ Throw JavaScript Error
16
+ </button>
17
+ </div>
18
+ `;
19
+ }
@@ -0,0 +1,37 @@
1
+ import "../+client";
2
+ /**
3
+ * @typedef {Object} SentryClient
4
+ * @property {function(): SentryOptions} getOptions
5
+ */
6
+
7
+ /**
8
+ * @typedef {Object} SentryOptions
9
+ * @property {string} dsn
10
+ */
11
+
12
+ /**
13
+ * @type {Window & { Sentry?: { getClient: () => SentryClient } }}
14
+ */
15
+ const globalWindow = globalThis?.window;
16
+
17
+ if (typeof window !== "undefined") {
18
+ const window = globalThis?.window;
19
+
20
+ window.onload = function () {
21
+ const options = globalWindow?.Sentry?.getClient()?.getOptions();
22
+ if (options) {
23
+ const elmSentryState = document?.getElementById("sentry_state");
24
+ if (elmSentryState) elmSentryState.hidden = true;
25
+ if (options?.dsn?.length > 1) {
26
+ const elmSentryDSN = document?.getElementById("sentry_dsn");
27
+ if (elmSentryDSN) elmSentryDSN.hidden = true;
28
+ }
29
+ }
30
+
31
+ const elmSentryButton = document?.getElementById("errorButton");
32
+ if (elmSentryButton)
33
+ elmSentryButton.addEventListener("click", function () {
34
+ throw new Error("This is a SENTRY Browser Test!");
35
+ });
36
+ };
37
+ }
@@ -0,0 +1,25 @@
1
+ import * as Sentry from "@sentry/browser";
2
+
3
+ export const sentryBrowserConfig = () => {
4
+ // eslint-disable-next-line
5
+ import.meta.env.PROD === true &&
6
+ Sentry.init({
7
+ dsn: import.meta.env.PUBLIC_ENV__SENTRY_DSN,
8
+ environment: "production-frontend",
9
+ //enabled: import.meta.env.DEV ? false : true,
10
+ integrations: [Sentry.replayIntegration()],
11
+ autoSessionTracking: globalThis?.window?.document ? true : false, // disable autoSessionTracking in SSR
12
+ // Set tracesSampleRate to 1.0 to capture 100%
13
+ // of transactions for tracing.
14
+ tracesSampleRate: 1.0,
15
+ // Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
16
+ tracePropagationTargets: [/^\//, /^https:\/\/yourserver\.io\/api/],
17
+ // Capture Replay for 10% of all sessions,
18
+ // plus for 100% of sessions with an error
19
+ replaysSessionSampleRate: 0.1,
20
+ replaysOnErrorSampleRate: 1.0,
21
+ });
22
+
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ (window as any).Sentry = Sentry;
25
+ };
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1 @@
1
+ export function Page(): string;
@@ -0,0 +1,6 @@
1
+ export type SentryClient = {
2
+ getOptions: () => SentryOptions;
3
+ };
4
+ export type SentryOptions = {
5
+ dsn: string;
6
+ };
@@ -0,0 +1 @@
1
+ export declare const sentryBrowserConfig: () => void;
@@ -133,3 +133,6 @@ dist
133
133
 
134
134
  # Cloudflare
135
135
  .wrangler/
136
+
137
+ # Sentry Vite Plugin
138
+ .env.sentry-build-plugin
@@ -0,0 +1,101 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // package.json
28
+ var require_package = __commonJS({
29
+ "package.json"(exports, module) {
30
+ module.exports = {
31
+ name: "@batijs/react-sentry",
32
+ private: true,
33
+ version: "0.0.1",
34
+ description: "",
35
+ type: "module",
36
+ scripts: {
37
+ "check-types": "tsc --noEmit",
38
+ build: "bati-compile-boilerplate"
39
+ },
40
+ keywords: [],
41
+ author: "",
42
+ license: "MIT",
43
+ devDependencies: {
44
+ "@batijs/compile": "workspace:*",
45
+ "@sentry/react": "^8.27.0",
46
+ "@types/node": "^18.19.14",
47
+ "@types/react": "^18.3.4",
48
+ "@types/react-dom": "^18.3.0",
49
+ react: "^18.3.1",
50
+ "react-dom": "^18.3.1",
51
+ vite: "^5.4.2"
52
+ },
53
+ dependencies: {
54
+ "@batijs/core": "workspace:*"
55
+ },
56
+ files: [
57
+ "dist/"
58
+ ],
59
+ bati: {
60
+ if: {
61
+ flag: {
62
+ $all: [
63
+ "react",
64
+ "sentry"
65
+ ]
66
+ }
67
+ }
68
+ },
69
+ exports: {
70
+ "./sentry.browser.config": {
71
+ types: "./dist/types/sentry.browser.config.d.ts"
72
+ },
73
+ "./pages/sentry/+Page": {
74
+ types: "./dist/types/pages/sentry/+Page.d.ts"
75
+ }
76
+ },
77
+ typesVersions: {
78
+ "*": {
79
+ "sentry.browser.config": [
80
+ "./dist/types/sentry.browser.config.d.ts"
81
+ ],
82
+ "pages/sentry/+Page": [
83
+ "./dist/types/pages/sentry/+Page.d.ts"
84
+ ]
85
+ }
86
+ }
87
+ };
88
+ }
89
+ });
90
+
91
+ // files/$package.json.ts
92
+ import { addDependency, loadAsJson } from "@batijs/core";
93
+ async function getPackageJson(props) {
94
+ const packageJson = await loadAsJson(props);
95
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
96
+ dependencies: ["@sentry/react"]
97
+ });
98
+ }
99
+ export {
100
+ getPackageJson as default
101
+ };