From 787bafe3f2598ac68041c90bb3c885a76407ec9b Mon Sep 17 00:00:00 2001 From: Spencer Miskoviak <5247455+skovy@users.noreply.github.com> Date: Tue, 4 Jun 2019 14:59:22 -0700 Subject: [PATCH] Add webpack-bugsnag-plugins types (#35931) * Generate the types/webpack-bugsnag-plugins files * Fill in the type definitions and tests * Add a typescript version * Decrease the TypeScript version to match webpack's --- types/webpack-bugsnag-plugins/index.d.ts | 151 ++++++++++++++++++ types/webpack-bugsnag-plugins/tsconfig.json | 23 +++ types/webpack-bugsnag-plugins/tslint.json | 1 + .../webpack-bugsnag-plugins-tests.ts | 81 ++++++++++ 4 files changed, 256 insertions(+) create mode 100644 types/webpack-bugsnag-plugins/index.d.ts create mode 100644 types/webpack-bugsnag-plugins/tsconfig.json create mode 100644 types/webpack-bugsnag-plugins/tslint.json create mode 100644 types/webpack-bugsnag-plugins/webpack-bugsnag-plugins-tests.ts diff --git a/types/webpack-bugsnag-plugins/index.d.ts b/types/webpack-bugsnag-plugins/index.d.ts new file mode 100644 index 0000000000..4e632f40b0 --- /dev/null +++ b/types/webpack-bugsnag-plugins/index.d.ts @@ -0,0 +1,151 @@ +// Type definitions for webpack-bugsnag-plugins 1.4 +// Project: https://github.com/bugsnag/webpack-bugsnag-plugins#readme +// Definitions by: Spencer Miskoviak +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as webpack from "webpack"; + +export interface SourceMapUploaderOptions { + /** + * Your Bugsnag API key + */ + apiKey: string; + + /** + * The path to your bundled assets (as the browser will see them). + * This option must either be provided here, or as `output.publicPath` in + * your Webpack config. + * + * @default output.publicPath + */ + publicPath?: string; + + /** + * The version of the application you are building + */ + appVersion?: string; + + /** + * Whether you want to overwrite previously uploaded sourcemaps + */ + overwrite?: boolean; + + /** + * Post the build payload to a URL other than the default + * + * @default https://upload.bugsnag.com + */ + endpoint?: string; + + /** + * A list of bundle file extensions which shouldn't be uploaded + * + * @default ['.css'] + */ + ignoredBundleExtensions?: string[]; +} + +export class BugsnagSourceMapUploaderPlugin extends webpack.Plugin { + constructor(options: SourceMapUploaderOptions); +} + +export interface BuildReporterBuild { + /** + * Your Bugsnag API key + */ + apiKey: string; + + /** + * The version of the application you are building (this should match the + * `appVersion` configured in your notifier) + */ + appVersion: string; + + /** + * 'production', 'staging' etc. (leave blank if this build can be released to + * different releaseStages) + */ + releaseStage?: string; + + /** + * An object describing the source control of the build (if not specified, + * the module will attempt to detect source control information from .git, . + * hg and the nearest package.json) + */ + sourceControl?: { + /** + * The source control provider. + */ + provider: + | "github" + | "github-enterprise" + | "gitlab" + | "gitlab-onpremise" + | "bitbucket" + | "bitbucket-server"; + + /** + * A URL (git/ssh/https) pointing to the repository, or webpage representing + * the repository + */ + repository: string; + + /** + * The unique identifier for the commit (e.g. git SHA) + */ + revision: string; + }; + + /** + * The name of the person/machine that created this build (defaults to the + * result of the `whoami` command) + */ + builderName?: string; + + /** + * Automatically associate this build with any new error events and sessions + * that are received for the releaseStage until a subsequent build + * notification is received. If this is set to true and no `releaseStage` + * is provided the build will be applied to 'production'. You should only use + * this option if you aren’t able to set an `appVersion` in your notifier. + */ + autoAssignRelease?: boolean; +} + +export interface BuildReporterOptions { + /** + * The minimum severity of log to output + * + * @default warn + */ + logLevel?: "debug" | "info" | "warn" | "error"; + + /** + * Provide a different logger object + */ + logger?: { + debug?: any; + info?: any; + warn?: any; + error?: any; + }; + + /** + * The path to search for source control info + * + * @default process.cwd() + */ + path?: string; + + /** + * Post the build payload to a specified URL + * + * @default https://build.bugsnag.com + */ + endpoint?: string; +} + +export class BugsnagBuildReporterPlugin extends webpack.Plugin { + constructor(build: BuildReporterBuild, options?: BuildReporterOptions); +} diff --git a/types/webpack-bugsnag-plugins/tsconfig.json b/types/webpack-bugsnag-plugins/tsconfig.json new file mode 100644 index 0000000000..96cd216561 --- /dev/null +++ b/types/webpack-bugsnag-plugins/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "webpack-bugsnag-plugins-tests.ts" + ] +} diff --git a/types/webpack-bugsnag-plugins/tslint.json b/types/webpack-bugsnag-plugins/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/webpack-bugsnag-plugins/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/webpack-bugsnag-plugins/webpack-bugsnag-plugins-tests.ts b/types/webpack-bugsnag-plugins/webpack-bugsnag-plugins-tests.ts new file mode 100644 index 0000000000..98662d38b9 --- /dev/null +++ b/types/webpack-bugsnag-plugins/webpack-bugsnag-plugins-tests.ts @@ -0,0 +1,81 @@ +import { + BugsnagSourceMapUploaderPlugin, + BugsnagBuildReporterPlugin +} from "webpack-bugsnag-plugins"; + +/** + * Missing or invalid options + */ + +// $ExpectError +new BugsnagSourceMapUploaderPlugin(); + +// $ExpectError +new BugsnagBuildReporterPlugin(); + +// $ExpectError +new BugsnagSourceMapUploaderPlugin({}); + +// $ExpectError +new BugsnagBuildReporterPlugin({}); + +// $ExpectError +new BugsnagBuildReporterPlugin({ + apiKey: "123456789" +}); + +/** + * Minimal valid options + */ + +// $ExpectType BugsnagSourceMapUploaderPlugin +new BugsnagSourceMapUploaderPlugin({ + apiKey: "123456789" +}); + +// $ExpectType BugsnagBuildReporterPlugin +new BugsnagBuildReporterPlugin({ + apiKey: "123456789", + appVersion: "1.2.3" +}); + +/** + * All possible options + */ + +// $ExpectType BugsnagSourceMapUploaderPlugin +new BugsnagSourceMapUploaderPlugin({ + apiKey: "123456789", + publicPath: "*/dist", + appVersion: "1.2.3", + overwrite: true, + endpoint: "https://upload.bugsnag.com", + ignoredBundleExtensions: [".css"] +}); + +// $ExpectType BugsnagBuildReporterPlugin +new BugsnagBuildReporterPlugin( + { + apiKey: "123456789", + appVersion: "1.2.3", + releaseStage: "staging", + sourceControl: { + provider: "github", + repository: "https://github.com/bugsnag/webpack-bugsnag-plugins", + revision: "123456789" + }, + builderName: "whoami", + autoAssignRelease: false + }, + { + logLevel: "debug", + logger: { + debug: () => null, + info: () => null, + warn: () => null, + error: () => null + }, + path: process.cwd(), + endpoint: "https://build.bugsnag.com" + } +);