Skip to content
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
7 changes: 6 additions & 1 deletion packages/playground/build-esbuild.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const { sentryEsbuildPlugin } = require("@sentry/unplugin");
const { build } = require("esbuild");
const placeHolderOptions = require("./config.json");

build({
entryPoints: ["./src/entrypoint1.js"],
outdir: "./out/esbuild",
plugins: [sentryEsbuildPlugin()],
plugins: [
sentryEsbuildPlugin({
...placeHolderOptions,
}),
],
minify: true,
bundle: true,
format: "cjs",
Expand Down
13 changes: 12 additions & 1 deletion packages/playground/build-webpack4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require("path");
const webpack4 = require("webpack4");
const { sentryWebpackPlugin } = require("@sentry/unplugin");

const placeHolderOptions = require("./config.json");

webpack4(
{
mode: "production",
Expand All @@ -14,7 +16,16 @@ webpack4(
library: "ExampleBundle",
libraryTarget: "commonjs",
},
plugins: [sentryWebpackPlugin()],
plugins: [
sentryWebpackPlugin({
org: "sentry-sdks",
project: "someProj",
authToken: "1234",
include: "*",
debugLogging: true,
debug: true,
}),
],
devtool: "source-map",
},
(err) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/playground/build-webpack5.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const path = require("path");
const webpack5 = require("webpack");
const { sentryWebpackPlugin } = require("@sentry/unplugin");

const placeHolderOptions = require("./config.json");

webpack5(
{
cache: false,
Expand All @@ -16,7 +18,7 @@ webpack5(
},
},
mode: "production",
plugins: [sentryWebpackPlugin()],
plugins: [sentryWebpackPlugin({ ...placeHolderOptions })],
devtool: "source-map",
},
(err) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/playground/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"release": "0.0.1",
"org": "some-org",
"project": "some-proj",
"authToken": "some-auth-token",
"include": "/dist",
"debugLogging": true,
"debug": true
}
9 changes: 8 additions & 1 deletion packages/playground/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import { sentryRollupPlugin } from "@sentry/unplugin";
import placeHolderOptions from "./config.json";

const input = ["src/entrypoint1.js"];

const extensions = [".js"];

export default {
input,
plugins: [resolve({ extensions }), commonjs(), sentryRollupPlugin()],
plugins: [
resolve({ extensions }),
commonjs(),
sentryRollupPlugin({
...placeHolderOptions,
}),
],
output: {
dir: "./out/rollup",
format: "cjs",
Expand Down
7 changes: 6 additions & 1 deletion packages/playground/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { sentryVitePlugin } from "@sentry/unplugin";
import { defineConfig } from "vite";
import * as path from "path";
import placeHolderOptions from "./config.json";

export default defineConfig({
build: {
Expand All @@ -14,5 +15,9 @@ export default defineConfig({
},
sourcemap: true,
},
plugins: [sentryVitePlugin()],
plugins: [
sentryVitePlugin({
...placeHolderOptions,
}),
],
});
4 changes: 3 additions & 1 deletion packages/unplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"check:types:src": "tsc --project ./src/tsconfig.json --noEmit",
"check:types:test": "tsc --project ./test/tsconfig.json --noEmit",
"test": "jest",
"lint": "eslint ./src ./test --max-warnings=0"
"lint": "eslint ./src ./test"
},
"dependencies": {
"@sentry/cli": "1.74.5",
"magic-string": "0.26.2",
"unplugin": "0.9.4"
},
Expand All @@ -29,6 +30,7 @@
"@babel/preset-typescript": "7.17.12",
"@rollup/plugin-babel": "5.3.1",
"@rollup/plugin-commonjs": "22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
"@swc/core": "^1.2.205",
"@swc/jest": "^0.2.21",
Expand Down
2 changes: 2 additions & 0 deletions packages/unplugin/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import packageJson from "./package.json";
import json from "@rollup/plugin-json";

const input = ["src/index.ts"];

Expand All @@ -14,6 +15,7 @@ export default {
plugins: [
resolve({ extensions, preferBuiltins: true }),
commonjs(),
json(),
babel({
extensions,
babelHelpers: "bundled",
Expand Down
52 changes: 52 additions & 0 deletions packages/unplugin/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import SentryCli from "@sentry/cli";
import { Options } from "./types";

/** Creates a new Sentry CLI instance. */
export function makeSentryCli(options: Options) {
//TODO: pass config file instead of null
const cli = new SentryCli(undefined, {
silent: false, //TODO read from options
org: options.org,
project: options.project,
authToken: options.authToken,
url: options.url,
vcsRemote: "origin", //TODO set from options,
});

// Let's not worry about dry run for now
// if (this.isDryRun()) {
// this.outputDebug("DRY Run Mode");

// return {
// releases: {
// proposeVersion: () =>
// cli.releases.proposeVersion().then((version) => {
// this.outputDebug("Proposed version:\n", version);
// return version;
// }),
// new: (release) => {
// this.outputDebug("Creating new release:\n", release);
// return Promise.resolve(release);
// },
// uploadSourceMaps: (release, config) => {
// this.outputDebug("Calling upload-sourcemaps with:\n", config);
// return Promise.resolve(release, config);
// },
// finalize: (release) => {
// this.outputDebug("Finalizing release:\n", release);
// return Promise.resolve(release);
// },
// setCommits: (release, config) => {
// this.outputDebug("Calling set-commits with:\n", config);
// return Promise.resolve(release, config);
// },
// newDeploy: (release, config) => {
// this.outputDebug("Calling deploy with:\n", config);
// return Promise.resolve(release, config);
// },
// },
// };
// }

return cli;
}
68 changes: 68 additions & 0 deletions packages/unplugin/src/facade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
//TODO: remove eslint rules

// Build a facade that exposes necessary sentry functionality
// Idea: We start out with Sentry-CLI and replace the cli-commands one by one afterwards.
// Goal: eventually replace everything sentry-cli does with "native" code here
// Reason: We don't want to depend on a binary that gets downloaded in a postinstall hook
// - no fixed version
// - huge download
// - unnecessary functionality

import { makeSentryCli } from "./cli";
import { Options } from "./types";

export type SentryFacade = {
createNewRelease: () => any;
cleanArtifacts: () => any;
uploadSourceMaps: () => any;
setCommits: () => any;
finalizeRelease: () => any;
addDeploy: () => any;
};

/**
* Factory function that provides all necessary Sentry functionality for creating
* a release on Sentry. This includes uploading source maps and finalizing the release
*/
export function makeSentryFacade(version: string, options: Options): SentryFacade {
makeSentryCli(options);
//TODO: remove
// void cli.execute(["--version"], true);

return {
createNewRelease: () => createNewRelease(version),
cleanArtifacts: () => cleanArtifacts(),
uploadSourceMaps: () => uploadSourceMaps(version),
setCommits: () => setCommits(version),
finalizeRelease: () => finalizeRelease(version),
addDeploy: () => addDeploy(version),
};
}

function createNewRelease(version: string) {
//TODO(must have): implement release creation logic here
}

function uploadSourceMaps(version: string) {
//TODO(must have): implement source maps upload logic here
}

function finalizeRelease(version: string) {
//TODO(must have): implement release finalization logic here
}

// TODO: Stuff we worry about later:

function cleanArtifacts() {
// NOOP for now
}

function setCommits(version: string) {
// NOOP for now
}

function addDeploy(version: string) {
// NOOP for now
}
22 changes: 15 additions & 7 deletions packages/unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { createUnplugin } from "unplugin";
import MagicString from "magic-string";
import { getReleaseName } from "./getReleaseName";
import * as path from "path";
import { Options } from "./types";
import { makeSentryFacade } from "./facade";

function generateGlobalInjectorCode({ release }: { release: string }) {
return `
Expand All @@ -17,15 +19,12 @@ function generateGlobalInjectorCode({ release }: { release: string }) {
_global.SENTRY_RELEASE={id:"${release}"};`;
}

export interface Options {
debugLogging?: boolean;
}

const unplugin = createUnplugin<Options>((options) => {
function debugLog(message: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function debugLog(...args: any) {
if (options?.debugLogging) {
// eslint-disable-next-line no-console
console.log(`[Sentry-plugin] ${message}`);
console.log("[Sentry-plugin]}", args);
}
}

Expand Down Expand Up @@ -88,7 +87,9 @@ const unplugin = createUnplugin<Options>((options) => {
transform(code, id) {
if (entrypoints.has(path.normalize(id))) {
const ms = new MagicString(code);
ms.prepend(generateGlobalInjectorCode({ release: getReleaseName() }));
ms.prepend(
generateGlobalInjectorCode({ release: getReleaseName(options.release || "0.0.1") })
);
return {
code: ms.toString(),
map: ms.generateMap(),
Expand All @@ -98,6 +99,11 @@ const unplugin = createUnplugin<Options>((options) => {
return undefined;
}
},
buildEnd() {
const sentryFacade = makeSentryFacade(getReleaseName(options.release || "0.0.1"), options);
//TODO: do stuff with the facade here lol
debugLog("this is my facade:", sentryFacade);
},
};
});

Expand All @@ -109,3 +115,5 @@ export const sentryRollupPlugin: (options: Options) => any = unplugin.rollup;
export const sentryWebpackPlugin: (options: Options) => any = unplugin.webpack;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sentryEsbuildPlugin: (options: Options) => any = unplugin.esbuild;

export type { Options } from "./types";
63 changes: 63 additions & 0 deletions packages/unplugin/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//TODO: JsDoc for all properties
export type Options = {
debugLogging?: boolean;

/* --- authentication/identification: */
org?: string;
project?: string;
authToken?: string;
url?: string;
// configFile: string

/* --- release properties: */
release?: string;
// dist: string,
// entries: string[] | RegExp | ((key: string) => boolean);

/* --- source maps properties: */
//TODO: make this required
include?: string; //| string[] | IncludeEntry[];
// ignoreFile: string
// ignore: string | string[]
// ext: string[]
// urlPrefix: string,
// urlSuffix: string,
// validate: boolean
// stripPrefix?: boolean,
// stripCommonPrefix?: boolean,
// sourceMapReference?: boolean,
// rewrite?: boolean,

/* --- other unimportant (for now) stuff- properties: */
// vcsRemote: string,
// customHeader: string,

// finalize?: boolean,
// dryRun?: boolean,
debug?: boolean;
// silent?: boolean,
// cleanArtifacts?: boolean,
// errorHandler?: (err: Error, invokeErr: function(): void, compilation: unknown) => void,
// setCommits?: {
// repo?: string,
// commit?: string,
// previousCommit?: string,
// auto?: boolean,
// ignoreMissing?: boolean
// },
// deploy?: {
// env: string,
// started?: number,
// finished?: number,
// time?: number,
// name?: string,
// url?: string,
// }
};

/*
type IncludeEntry = {
paths: string[];
//TODO: what about the other entries??
};
*/
Loading