Skip to content

Commit d557526

Browse files
authored
chore(core): Cleanup code and JSDocs (#108)
clean up some code, left-over TODOs and adds a few JSDoc improvements
1 parent 8661b6a commit d557526

File tree

4 files changed

+36
-33
lines changed

4 files changed

+36
-33
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ import { Hub } from "@sentry/node";
2323
const RELEASE_INJECTOR_ID = "\0sentry-release-injector";
2424

2525
/**
26-
* The sentry-unplugin concerns itself with two things:
26+
* The sentry bundler plugin concerns itself with two things:
2727
* - Release injection
2828
* - Sourcemaps upload
2929
*
3030
* Release injection:
3131
*
32-
* Per default the sentry-unpugin will inject a global `SENTRY_RELEASE` variable into the entrypoint of all bundles. On
33-
* a technical level this is done by appending an import (`import "sentry-release-injector;"`) to all entrypoint files
34-
* of the user code (see `transformInclude` and `transform` hooks). This import is then resolved by the sentry-unplugin
32+
* Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` variable into the entrypoint of all bundles.
33+
* On a technical level this is done by appending an import (`import "sentry-release-injector;"`) to all entrypoint files
34+
* of the user code (see `transformInclude` and `transform` hooks). This import is then resolved by the sentry plugin
3535
* to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
3636
*
3737
* The resulting output approximately looks like this:
3838
*
3939
* ```text
4040
* entrypoint1.js (user file)
41-
* ┌─────────────────── ┌─────────────────────────────────────────────────┐
42-
* │ │ import { myFunction } from "./my-library.js"; │
43-
* │ sentry-unplugin │ │
44-
* │ │ const myResult = myFunction(); │
45-
* └---------│--------- │ export { myResult }; │
41+
* ┌─────────────────────────┐ ┌─────────────────────────────────────────────────┐
42+
* │ │ import { myFunction } from "./my-library.js"; │
43+
* │ sentry-bundler-plugin │ │ │
44+
* │ │ const myResult = myFunction(); │
45+
* └---------│--------------- │ export { myResult }; │
4646
* │ │ │
47-
* │ injects │ // injected by sentry-unplugin
47+
* │ injects │ // injected by sentry plugin
4848
* ├───────────────────► import "sentry-release-injector"; ─────────────────────┐
4949
* │ └─────────────────────────────────────────────────┘ │
5050
* │ │
@@ -55,24 +55,33 @@ const RELEASE_INJECTOR_ID = "\0sentry-release-injector";
5555
* │ │ return "Hello world!"; │ │
5656
* │ │ } │ │
5757
* │ │ │ │
58-
* │ injects │ // injected by sentry-unplugin │ │
58+
* │ injects │ // injected by sentry plugin │ │
5959
* └───────────────────► import "sentry-release-injector"; ─────────────────────┤
6060
* └─────────────────────────────────────────────────┘ │
6161
* │
6262
* │
6363
* sentry-release-injector │
6464
* ┌──────────────────────────────────┐ │
6565
* │ │ is resolved │
66-
* │ global.SENTRY_RELEASE = { ... } │ by unplugin
66+
* │ global.SENTRY_RELEASE = { ... } │ by plugin
6767
* │ // + a little more logic │<─────────────────────┘
6868
* │ │ (only once)
6969
* └──────────────────────────────────┘
7070
* ```
7171
*
7272
* Source maps upload:
7373
*
74-
* The sentry-unplugin will also take care of uploading source maps to Sentry. This is all done in the `writeBundle` hook.
75-
* TODO: elaborate a bit on how sourcemaps upload works
74+
* The sentry bundler plugin will also take care of uploading source maps to Sentry. This is all done in the
75+
* `writeBundle` hook. In this hook the sentry plugin will execute the release creation pipeline:
76+
*
77+
* 1. Create a new release
78+
* 2. Delete already uploaded artifacts for this release (if `cleanArtifacts` is enabled)
79+
* 3. Upload sourcemaps based on `include` and source-map-specific options
80+
* 4. Associate a range of commits with the release (if `setCommits` is specified)
81+
* 5. Finalize the release (unless `finalize` is disabled)
82+
* 6. Add deploy information to the release (if `deploy` is specified)
83+
*
84+
* This release creation pipeline relies on Sentry CLI to execute the different steps.
7685
*/
7786
const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
7887
const internalOptions = normalizeUserOptions(options);
@@ -188,7 +197,6 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
188197

189198
loadInclude(id) {
190199
logger.info(`Called "loadInclude": ${JSON.stringify({ id })}`);
191-
192200
return id === RELEASE_INJECTOR_ID;
193201
},
194202

@@ -218,11 +226,11 @@ const unplugin = createUnplugin<Options>((options, unpluginMetaContext) => {
218226
},
219227

220228
/**
221-
* This hook determines whether we want to transform a module. In the unplugin we want to transform every entrypoint
229+
* This hook determines whether we want to transform a module. In the sentry bundler plugin we want to transform every entrypoint
222230
* unless configured otherwise with the `entries` option.
223231
*
224232
* @param id Always the absolute (fully resolved) path to the module.
225-
* @returns `true` or `false` depending on whether we want to transform the module. For the sentry-unplugin we only
233+
* @returns `true` or `false` depending on whether we want to transform the module. For the sentry bundler plugin we only
226234
* want to transform the release injector file.
227235
*/
228236
transformInclude(id) {

packages/bundler-plugin-core/src/options-mapping.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,11 @@ function normalizeEntries(
136136
function normalizeInclude(userOptions: UserOptions): InternalIncludeEntry[] {
137137
return arrayify(userOptions.include)
138138
.map((includeItem) =>
139-
typeof includeItem === "string" ? convertIncludePathToIncludeEntry(includeItem) : includeItem
139+
typeof includeItem === "string" ? { paths: [includeItem] } : includeItem
140140
)
141141
.map((userIncludeEntry) => normalizeIncludeEntry(userOptions, userIncludeEntry));
142142
}
143143

144-
function convertIncludePathToIncludeEntry(includePath: string): UserIncludeEntry {
145-
return {
146-
paths: [includePath],
147-
};
148-
}
149-
150144
/**
151145
* Besides array-ifying the `ignore` option, this function hoists top level options into the items of the `include`
152146
* option. This is to simplify the handling of of the `include` items later on.

packages/bundler-plugin-core/src/sentry/telemetry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export function makeSentryClient(
2727

2828
stackParser: defaultStackParser,
2929
transport: makeNodeTransport,
30-
31-
debug: true,
3230
});
3331

3432
const hub = new Hub(client);

packages/bundler-plugin-core/src/types.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ export type Options = Omit<IncludeEntry, "paths"> & {
6363
dist?: string;
6464

6565
/**
66-
* Filter for bundle entry points that should contain the provided release. By default, the release will be injected
67-
* into all entry points.
66+
* Filter for bundle entry points that should contain the provided release.
6867
*
6968
* This option takes a string, a regular expression, or an array containing strings, regular expressions, or both.
7069
* It's also possible to provide a filter function that takes the absolute path of a processed entrypoint and should
7170
* return `true` if the release should be injected into the entrypoint and `false` otherwise. String values of this
7271
* option require a full match with the absolute path of the bundle.
72+
*
73+
* By default, the release will be injected into all entry points.
7374
*/
7475
entries?: (string | RegExp)[] | RegExp | string | ((filePath: string) => boolean);
7576

@@ -85,14 +86,15 @@ export type Options = Omit<IncludeEntry, "paths"> & {
8586

8687
/**
8788
* One or more paths that Sentry CLI should scan recursively for sources.
88-
* It will upload all .map files and match associated .js files.
89+
* It will upload all .map files and match associated .js files. Other file
90+
* types can be uploaded by using the `ext` option.
8991
* Each path can be given as a string or an object with path-specific options
9092
*
9193
* This is a required field.
9294
*/
9395
include: string | IncludeEntry | Array<string | IncludeEntry>;
9496

95-
/* --- other unimportant (for now) stuff- properties: */
97+
/* --- other properties: */
9698

9799
/**
98100
* Version control system remote name.
@@ -112,7 +114,8 @@ export type Options = Omit<IncludeEntry, "paths"> & {
112114
customHeader?: string;
113115

114116
/**
115-
* Attempts a dry run (useful for dev environments).
117+
* Attempts a dry run (useful for dev environments), making release creation
118+
* a no-op.
116119
*
117120
* Defaults to `false`, but may be automatically set to `true` in development environments
118121
* by some framework integrations (Next.JS, possibly others).
@@ -158,12 +161,12 @@ export type Options = Omit<IncludeEntry, "paths"> & {
158161
errorHandler?: (err: Error) => void;
159162

160163
/**
161-
* Adds commits to Sentry.
164+
* Associates the release with its commits in Sentry.
162165
*/
163166
setCommits?: SetCommitsOptions;
164167

165168
/**
166-
* Creates a new release deployment in Sentry.
169+
* Adds deployment information to the release in Sentry.
167170
*/
168171
deploy?: DeployOptions;
169172

0 commit comments

Comments
 (0)