Skip to content

Commit

Permalink
Remove some ts-ignores and fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
0Calories committed Jan 27, 2024
1 parent 5f9913f commit fd748b8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 25 deletions.
17 changes: 9 additions & 8 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { transformAsync } from "@babel/core";
import * as fs from "fs";
import * as path from "path";
import MagicString from "magic-string";
import { createUnplugin, UnpluginOptions } from "unplugin";
import { createUnplugin, TransformResult, UnpluginOptions } from "unplugin";
import { normalizeUserOptions, validateOptions } from "./options-mapping";
import { createDebugIdUploadFunction } from "./debug-id-upload";
import { releaseManagementPlugin } from "./plugins/release-management";
Expand All @@ -26,7 +26,8 @@ import { glob } from "glob";
import pkg from "@sentry/utils";
const { logger } = pkg;

// @ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Importing the annotate plugin which is not concerned with types
import reactAnnotate from "./plugins/react-annotate-plugin";

interface SentryUnpluginFactoryOptions {
Expand Down Expand Up @@ -533,7 +534,7 @@ export function createRollupDebugIdUploadHooks(

export function createReactAnnotateHooks() {
return {
async transform(code: string, id: string) {
async transform(code: string, id: string): Promise<TransformResult> {
// id may contain query and hash which will trip up our file extension logic below
const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);

Expand Down Expand Up @@ -561,7 +562,8 @@ export function createReactAnnotateHooks() {
parserOpts: {
sourceType: "module",
allowAwaitOutsideFunction: true,
// @ts-ignore Parser plugins will always be valid here
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore This array will always be type compliant when using 'jsx' or 'typescript'
plugins: parserPlugins,
},
generatorOpts: {
Expand All @@ -571,15 +573,14 @@ export function createReactAnnotateHooks() {
});

return {
code: result?.code,
code: result?.code ?? code,
map: result?.map,
};
} catch (e) {
logger.error(e);
console.dir(e);
logger.error(`Failed to apply react annotate plugin: ${e}`);
}

return null;
return { code };
},
};
}
Expand Down
11 changes: 0 additions & 11 deletions packages/bundler-plugin-core/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,6 @@ export interface Options {
* Whether the react annotate plugin should be enabled or not
*/
enabled?: boolean;
/**
* The name of the library that React is being imported from.
* Defaults to `'react'`.
* Should be changed only if you are using React from a custom library.
*/
importSource?: string;
/**
* A list of component names that you do not want the annotate plugin to apply to.
* I.e. if you want to prevent a component named `MyComponent` from being annotated, you would pass this in as `['MyComponent']`.
*/
excludedComponents?: string[];
};
/**
* Options that are considered experimental and subject to change.
Expand Down
8 changes: 5 additions & 3 deletions packages/esbuild-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ function esbuildReactAnnotatePlugin(): UnpluginOptions {
esbuild: {
setup({ onLoad }) {
onLoad({ filter: /\.(t|j)sx$/ }, async (args) => {
let code = await fsPromises.readFile(args.path, "utf8");
const code = await fsPromises.readFile(args.path, "utf8");
const loader = args.path.endsWith(".tsx") ? "tsx" : "jsx";
const results = await createReactAnnotateHooks().transform(code, args.path);
console.dir(results);

return {
loader,
pluginName,
contents: results?.code ?? undefined,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Weird typing on TransformResult, it will not ever return just a string in this case
contents: results?.code ?? code,
};
});
},
Expand Down
1 change: 0 additions & 1 deletion packages/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function rollupReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
function rollupReactAnnotatePlugin(): UnpluginOptions {
return {
name: "sentry-rollup-react-annotate-plugin",
// @ts-ignore
rollup: createReactAnnotateHooks(),
};
}
Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function viteReactAnnotatePlugin(): UnpluginOptions {
return {
name: "sentry-vite-react-annotate-plugin",
enforce: "pre" as const,
// @ts-ignore
vite: createReactAnnotateHooks(),
};
}
Expand Down
1 change: 0 additions & 1 deletion packages/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function webpackReactAnnotatePlugin(): UnpluginOptions {
transformInclude(id) {
return id.endsWith(".tsx") || id.endsWith(".jsx");
},
// @ts-ignore
transform: createReactAnnotateHooks().transform,
};
}
Expand Down

0 comments on commit fd748b8

Please sign in to comment.