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: 1 addition & 6 deletions packages/playground/build-webpack4.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ webpack4(
},
plugins: [
sentryWebpackPlugin({
org: "sentry-sdks",
project: "someProj",
authToken: "1234",
include: "*",
debugLogging: true,
debug: true,
...placeHolderOptions,
}),
],
devtool: "source-map",
Expand Down
8 changes: 6 additions & 2 deletions packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
"build:vite": "vite build --config vite.config.js",
"build:webpack4": "node build-webpack4.js",
"build:webpack5": "node build-webpack5.js",
"build:esbuild": "node build-esbuild.js"
"build:esbuild": "node build-esbuild.js",
"build:smallNodeApp": "vite build --config vite.config.smallNodeApp.js"
},
"dependencies": {
"@sentry/unplugin": "*",
"@sentry/node": "^7.11.1",
"@sentry/integrations": "^7.11.1",
"esbuild": "0.14.49",
"rollup": "2.77.0",
"vite": "3.0.0",
"webpack4": "npm:webpack@4.46.0",
"webpack": "5.74.0",
"npm-run-all": "4.1.5"
"npm-run-all": "4.1.5",
"@sentry/cli": "1.74.5"
}
}
24 changes: 24 additions & 0 deletions packages/playground/src/smallNodeApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Sentry = require("@sentry/node");
const { RewriteFrames } = require("@sentry/integrations");

Sentry.init({
dsn: "https://8fa8ac58d94740a69f74934665aa0770@o1151230.ingest.sentry.io/6680403",
debug: true,
enabled: true,
sampleRate: 1.0,
integrations: [new RewriteFrames()],
});

const fibonacci = (n) => {
if (n === 3) {
Sentry.captureException(new Error("Test error"));
}
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
};

console.log("Hi, I'm a small sample node app");

fibonacci(10);
30 changes: 30 additions & 0 deletions packages/playground/vite.config.smallNodeApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @ts-check
import { sentryVitePlugin } from "@sentry/unplugin";
import { defineConfig } from "vite";
import * as path from "path";

export default defineConfig({
build: {
outDir: "./out/vite-smallNodeApp",
lib: {
entry: path.resolve(__dirname, "./src/smallNodeApp.js"),
name: "ExampleBundle",
fileName: "index",
formats: ["cjs"],
},
sourcemap: true,
minify: true,
},
plugins: [
sentryVitePlugin({
authToken: process.env.SENTRY_AUTH_TOKEN,
org: "lms-testorg-9m",
project: "hackweek-node-sample-app",
debug: true,
debugLogging: true,
release: "0.0.1",
include: "out/vite-smallNodeApp",
cleanArtifacts: true,
}),
],
});
2 changes: 1 addition & 1 deletion packages/unplugin/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const extensions = [".js", ".ts"];
export default {
input,
// external: [...Object.keys(packageJson.dependencies)],
external: ["path", "unplugin"],
external: ["path", "unplugin", "@sentry/cli"],
plugins: [
resolve({ extensions, preferBuiltins: true }),
commonjs(),
Expand Down
2 changes: 1 addition & 1 deletion packages/unplugin/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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, {
const cli = new SentryCli(options.configFile, {
silent: false, //TODO read from options
org: options.org,
project: options.project,
Expand Down
97 changes: 63 additions & 34 deletions packages/unplugin/src/facade.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* 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
Expand All @@ -12,57 +8,90 @@

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

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

/**
* 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);
export function makeSentryFacade(release: string, options: Options): SentryFacade {
const cli = makeSentryCli(options);

return {
createNewRelease: () => createNewRelease(version),
cleanArtifacts: () => cleanArtifacts(),
uploadSourceMaps: () => uploadSourceMaps(version),
setCommits: () => setCommits(version),
finalizeRelease: () => finalizeRelease(version),
addDeploy: () => addDeploy(version),
createNewRelease: () => createNewRelease(cli, release),
cleanArtifacts: () => cleanArtifacts(cli, release, options),
uploadSourceMaps: () => uploadSourceMaps(cli, release, options),
setCommits: () => setCommits(/* release */),
finalizeRelease: () => finalizeRelease(cli, release, options),
addDeploy: () => addDeploy(/* release */),
};
}

function createNewRelease(version: string) {
//TODO(must have): implement release creation logic here
async function createNewRelease(cli: SentryCli, release: string): Promise<string> {
return cli.releases.new(release);
}

function uploadSourceMaps(version: string) {
//TODO(must have): implement source maps upload logic here
}
async function uploadSourceMaps(
cli: SentryCli,
release: string,
options: Options
): Promise<string> {
/**
* One or more paths to ignore during upload. Overrides entries in ignoreFile file.
*/

const {
include,
// ignore,
// ignoreFile,
// rewrite,
// sourceMapReference,
// stripPrefix,
// stripCommonPrefix,
// validate,
// urlPrefix,
// urlSuffix,
// ext,
} = options;

//TODO: sort out mess between Sentry CLI options and WebPack plugin options (ideally,
// we normalize everything before and don't diverge with options between our
// own CLI implementation and the plugin.
// I don't want to do too much for this right now b/c we'll eventually get rid of the CLI anyway
const uploadSourceMapsOptions = { include: typeof include === "string" ? [include] : include };

function finalizeRelease(version: string) {
//TODO(must have): implement release finalization logic here
return cli.releases.uploadSourceMaps(release, uploadSourceMapsOptions);
}

// TODO: Stuff we worry about later:
async function finalizeRelease(cli: SentryCli, release: string, options: Options): Promise<string> {
if (options.finalize) {
return cli.releases.finalize(release);
}
return Promise.resolve("nothing to do here");
}

function cleanArtifacts() {
// NOOP for now
async function cleanArtifacts(cli: SentryCli, release: string, options: Options): Promise<string> {
if (options.cleanArtifacts) {
return cli.releases.execute(["releases", "files", release, "delete", "--all"], true);
}
return Promise.resolve("nothing to do here");
}

function setCommits(version: string) {
// NOOP for now
// TODO: Stuff we worry about later:

async function setCommits(/* version: string */): Promise<string> {
return Promise.resolve("Noop");
}

function addDeploy(version: string) {
// NOOP for now
async function addDeploy(/* version: string */): Promise<string> {
return Promise.resolve("Noop");
}
37 changes: 33 additions & 4 deletions packages/unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import { getReleaseName } from "./getReleaseName";
import { Options } from "./types";
import { makeSentryFacade } from "./facade";

const defaultOptions: Omit<Options, "include"> = {
//TODO: add default options here as we port over options from the webpack plugin
// validate: false
configFile: "~/.sentryclirc",
debug: false,
cleanArtifacts: false,
finalize: true,
};

/**
* The sentry-unplugin concerns itself with two things:
* - Release injection
Expand Down Expand Up @@ -67,7 +76,9 @@ import { makeSentryFacade } from "./facade";
* The sentry-unplugin will also take care of uploading source maps to Sentry. This is all done in the `buildEnd` hook.
* TODO: elaborate a bit on how sourcemaps upload works
*/
const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
const unplugin = createUnplugin<Options>((originalOptions, unpluginMetaContext) => {
const options = { ...defaultOptions, ...originalOptions };

function debugLog(...args: unknown[]) {
if (options?.debugLogging) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -162,9 +173,27 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
}
},
buildEnd() {
const sentryFacade = makeSentryFacade(getReleaseName(options.release), options);
//TODO: do stuff with the facade here lol
debugLog("this is my facade:", sentryFacade);
const release = getReleaseName(options.release);
//TODO:
// 1. validate options to see if we get a valid include property, release name, etc.
// 2. normalize the include property: Users can pass string | string [] | IncludeEntry[].
// That's good for them but a hassle for us. Let's try to normalize this into one data type
// (I vote IncludeEntry[]) and continue with that down the line

const sentryFacade = makeSentryFacade(release, options);

sentryFacade
.createNewRelease()
.then(() => sentryFacade.cleanArtifacts())
.then(() => sentryFacade.uploadSourceMaps())
.then(() => sentryFacade.setCommits()) // this is a noop for now
.then(() => sentryFacade.finalizeRelease())
.then(() => sentryFacade.addDeploy()) // this is a noop for now
.catch((e) => {
//TODO: invoke error handler here
// https://github.com/getsentry/sentry-webpack-plugin/blob/137503f3ac6fe423b16c5c50379859c86e689017/src/index.js#L540-L547
debugLog(e);
});
},
};
});
Expand Down
10 changes: 5 additions & 5 deletions packages/unplugin/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//TODO: JsDoc for all properties
//TODO: compare types w/ webpack plugin (and sentry-cli?)
export type Options = {
debugLogging?: boolean;

Expand All @@ -7,16 +8,16 @@ export type Options = {
project?: string;
authToken?: string;
url?: string;
// configFile: string
configFile?: string;

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

/* --- source maps properties: */
//TODO: make this required
include?: string; //| string[] | IncludeEntry[];
include: string; // | Array<string | IncludeEntry>;
// ignoreFile: string
// ignore: string | string[]
// ext: string[]
Expand All @@ -32,11 +33,10 @@ export type Options = {
// vcsRemote: string,
// customHeader: string,

// finalize?: boolean,
// dryRun?: boolean,
debug?: boolean;
// silent?: boolean,
// cleanArtifacts?: boolean,
cleanArtifacts?: boolean;
// errorHandler?: (err: Error, invokeErr: function(): void, compilation: unknown) => void,
// setCommits?: {
// repo?: string,
Expand Down
Loading