From 025973d27f6fe08d5b9b976fdf96aeb99f23afb5 Mon Sep 17 00:00:00 2001 From: Albert G <516972+alber70g@users.noreply.github.com> Date: Thu, 26 Jun 2025 16:10:47 +0200 Subject: [PATCH 1/2] Revert "fix: typescript types" This reverts commit a06469f0d23f616982fad6d8341c9922189e4cec. --- instrumentation.node.ts | 9 +++------ nextjs/nextjs-routes.d.ts | 40 ++++++++++++++++++++++++++++++++++----- tsconfig.json | 5 ++--- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/instrumentation.node.ts b/instrumentation.node.ts index e2e5c655f7..a42232f4b8 100644 --- a/instrumentation.node.ts +++ b/instrumentation.node.ts @@ -30,12 +30,9 @@ const sdk = new NodeSDK({ metricReader: new PeriodicExportingMetricReader({ exporter: process.env.NODE_ENV === 'production' ? - // eslint-disable-next-line @typescript-eslint/no-explicit-any - new OTLPMetricExporter() as any : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - new ConsoleMetricExporter() as any, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - }) as any, + new OTLPMetricExporter() : + new ConsoleMetricExporter(), + }), instrumentations: [ getNodeAutoInstrumentations({ '@opentelemetry/instrumentation-http': { diff --git a/nextjs/nextjs-routes.d.ts b/nextjs/nextjs-routes.d.ts index 973758fcb2..115e9440a0 100644 --- a/nextjs/nextjs-routes.d.ts +++ b/nextjs/nextjs-routes.d.ts @@ -5,6 +5,11 @@ // prettier-ignore declare module "nextjs-routes" { + import type { + GetServerSidePropsContext as NextGetServerSidePropsContext, + GetServerSidePropsResult as NextGetServerSidePropsResult + } from "nextjs"; + export type Route = | StaticRoute<"/404"> | StaticRoute<"/account/api-key"> @@ -107,6 +112,33 @@ declare module "nextjs-routes" { * route({ pathname: "/foos/[foo]", query: { foo: "bar" }}) will produce "/foos/bar". */ export declare function route(r: Route): string; + + /** + * Nearly identical to GetServerSidePropsContext from next, but further narrows + * types based on nextjs-route's route data. + */ + export type GetServerSidePropsContext< + Pathname extends Route["pathname"] = Route["pathname"], + Preview extends NextGetServerSidePropsContext["previewData"] = NextGetServerSidePropsContext["previewData"] + > = Omit & { + params: Extract["query"]; + query: Query; + defaultLocale?: undefined; + locale?: Locale; + locales?: undefined; + }; + + /** + * Nearly identical to GetServerSideProps from next, but further narrows + * types based on nextjs-route's route data. + */ + export type GetServerSideProps< + Props extends { [key: string]: any } = { [key: string]: any }, + Pathname extends Route["pathname"] = Route["pathname"], + Preview extends NextGetServerSideProps["previewData"] = NextGetServerSideProps["previewData"] + > = ( + context: GetServerSidePropsContext + ) => Promise> } // prettier-ignore @@ -121,13 +153,12 @@ declare module "next/link" { } from "react"; export * from "next/dist/client/link"; - type Query = { query?: { [key: string]: string | string[] | undefined } }; type StaticRoute = Exclude["pathname"]; export interface LinkProps extends Omit, AnchorHTMLAttributes { - href: Route | StaticRoute | Query; + href: Route | StaticRoute | Omit locale?: false; } @@ -155,7 +186,6 @@ declare module "next/router" { type NextTransitionOptions = NonNullable[2]>; type StaticRoute = Exclude["pathname"]; - type Query = { query?: { [key: string]: string | string[] | undefined } }; interface TransitionOptions extends Omit { locale?: false; @@ -177,12 +207,12 @@ declare module "next/router" { locale?: Locale; locales?: undefined; push( - url: Route | StaticRoute | Query, + url: Route | StaticRoute | Omit, as?: string, options?: TransitionOptions ): Promise; replace( - url: Route | StaticRoute | Query, + url: Route | StaticRoute | Omit, as?: string, options?: TransitionOptions ): Promise; diff --git a/tsconfig.json b/tsconfig.json index 0343765492..28f5497201 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,7 @@ "baseUrl": ".", "types": ["node", "jest"], }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.node.ts", "**/*.tsx", "decs.d.ts", "global.d.ts"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.node.ts", "**/*.tsx", "**/*.pw.tsx", "decs.d.ts", "global.d.ts"], "exclude": [ "node_modules", "node_modules_linux", @@ -26,7 +26,6 @@ "./deploy/tools/favicon-generator", "./toolkit/package", "./toolkit/theme/design-system/build", - "./toolkit/theme/design-system/dist", - "**/*.pw.tsx" + "./toolkit/theme/design-system/dist" ], } From 95cb3791412fcd9a317d371cc6418f920040b40e Mon Sep 17 00:00:00 2001 From: Albert G <516972+alber70g@users.noreply.github.com> Date: Thu, 26 Jun 2025 16:17:49 +0200 Subject: [PATCH 2/2] fix: eslint --- eslint.config.mjs | 4 +++- instrumentation.node.ts | 26 +++++++++++++++++++------- tsconfig.json | 5 +++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 115efb9eb1..a596e77f56 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -60,7 +60,7 @@ const gitignorePath = path.resolve(__dirname, '.gitignore'); export default tseslint.config( includeIgnoreFile(gitignorePath), - { files: [ '**/*.{js,mjs,cjs,ts,jsx,tsx}', '**/*.pw.tsx' ] }, + { files: [ '**/*.{js,mjs,cjs,ts,jsx,tsx}' ] }, { ignores: [ 'deploy/tools/', @@ -69,6 +69,8 @@ export default tseslint.config( 'next.config.js', './toolkit/theme/design-system/dist', './toolkit/theme/design-system/build', + // TODO: we ignored these, need to be put back into "files" section :63 + '**/*.pw.tsx', ] }, { languageOptions: { globals: { ...globals.browser, ...globals.node } } }, diff --git a/instrumentation.node.ts b/instrumentation.node.ts index a42232f4b8..da42cb2f6d 100644 --- a/instrumentation.node.ts +++ b/instrumentation.node.ts @@ -4,13 +4,19 @@ import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentation import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'; import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'; import { Resource } from '@opentelemetry/resources'; +import type { + PushMetricExporter } from '@opentelemetry/sdk-metrics'; import { PeriodicExportingMetricReader, ConsoleMetricExporter, } from '@opentelemetry/sdk-metrics'; import { NodeSDK } from '@opentelemetry/sdk-node'; import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node'; -import { SEMRESATTRS_SERVICE_NAME, SEMRESATTRS_SERVICE_VERSION, SEMRESATTRS_SERVICE_INSTANCE_ID } from '@opentelemetry/semantic-conventions'; +import { + SEMRESATTRS_SERVICE_NAME, + SEMRESATTRS_SERVICE_VERSION, + SEMRESATTRS_SERVICE_INSTANCE_ID, +} from '@opentelemetry/semantic-conventions'; diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO); @@ -19,20 +25,26 @@ const traceExporter = new OTLPTraceExporter(); const sdk = new NodeSDK({ resource: new Resource({ [SEMRESATTRS_SERVICE_NAME]: 'blockscout_frontend', - [SEMRESATTRS_SERVICE_VERSION]: process.env.NEXT_PUBLIC_GIT_TAG || process.env.NEXT_PUBLIC_GIT_COMMIT_SHA || 'unknown_version', + [SEMRESATTRS_SERVICE_VERSION]: + process.env.NEXT_PUBLIC_GIT_TAG || + process.env.NEXT_PUBLIC_GIT_COMMIT_SHA || + 'unknown_version', [SEMRESATTRS_SERVICE_INSTANCE_ID]: - process.env.NEXT_PUBLIC_APP_INSTANCE || - process.env.NEXT_PUBLIC_APP_HOST?.replace('.blockscout.com', '').replaceAll('-', '_') || - 'unknown_app', + process.env.NEXT_PUBLIC_APP_INSTANCE || + process.env.NEXT_PUBLIC_APP_HOST?.replace( + '.blockscout.com', + '', + ).replaceAll('-', '_') || + 'unknown_app', }), spanProcessor: new SimpleSpanProcessor(traceExporter), traceExporter, metricReader: new PeriodicExportingMetricReader({ exporter: process.env.NODE_ENV === 'production' ? - new OTLPMetricExporter() : + (new OTLPMetricExporter() as unknown as PushMetricExporter) : new ConsoleMetricExporter(), - }), + }) as unknown as undefined, instrumentations: [ getNodeAutoInstrumentations({ '@opentelemetry/instrumentation-http': { diff --git a/tsconfig.json b/tsconfig.json index 28f5497201..71f0f21987 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,7 @@ "baseUrl": ".", "types": ["node", "jest"], }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.node.ts", "**/*.tsx", "**/*.pw.tsx", "decs.d.ts", "global.d.ts"], + "include": ["next-env.d.ts", "**/*.ts", "**/*.node.ts", "**/*.tsx", "decs.d.ts", "global.d.ts"], "exclude": [ "node_modules", "node_modules_linux", @@ -26,6 +26,7 @@ "./deploy/tools/favicon-generator", "./toolkit/package", "./toolkit/theme/design-system/build", - "./toolkit/theme/design-system/dist" + "./toolkit/theme/design-system/dist", + "**/*.pw.tsx" // TODO: this needs to be put back in the include section :21 ], }