diff --git a/.gitignore b/.gitignore index 84051deb..d8409581 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ sentry.properties junit.xml # Build artifacts -*.tgz \ No newline at end of file +*.tgz +tsconfig.tsbuildinfo diff --git a/packages/astro/src/index.ts b/packages/astro/src/index.ts index 4f200ed5..4b48bba8 100644 --- a/packages/astro/src/index.ts +++ b/packages/astro/src/index.ts @@ -2,8 +2,8 @@ import type { SpotlightInitOptions } from '@spotlightjs/spotlight/vite-plugin'; import type { AstroConfig, AstroIntegration } from 'astro'; import { buildServerSnippet } from './snippets'; -import path from 'path'; -import url from 'url'; +import path from 'node:path'; +import url from 'node:url'; import spotlight, { buildClientInit } from '@spotlightjs/spotlight/vite-plugin'; diff --git a/packages/overlay/src/App.tsx b/packages/overlay/src/App.tsx index 5be5a48f..a1266cdb 100644 --- a/packages/overlay/src/App.tsx +++ b/packages/overlay/src/App.tsx @@ -44,9 +44,9 @@ export default function App({ } } - const result: Record void> = Object.create(null); + const result: Record void> = Object.create(null); for (const [contentType, integrations] of contentTypeToIntegrations.entries()) { - const listener = (event: { data: string | Buffer }): void => { + const listener = (event: { data: string | Uint8Array }): void => { log(`Received new ${contentType} event`); for (const integration of integrations) { const newIntegrationData = integration.processEvent diff --git a/packages/overlay/src/index.tsx b/packages/overlay/src/index.tsx index e39abfa9..bfd4ad48 100644 --- a/packages/overlay/src/index.tsx +++ b/packages/overlay/src/index.tsx @@ -2,22 +2,22 @@ import fontStyles from '@fontsource/raleway/index.css?inline'; import { CONTEXT_LINES_ENDPOINT } from '@spotlightjs/sidecar/constants'; import { MemoryRouter } from 'react-router-dom'; import colors from 'tailwindcss/colors'; -import App from './App.tsx'; -import { DEFAULT_ANCHOR, DEFAULT_EXPERIMENTS, DEFAULT_SIDECAR_URL } from './constants.ts'; +import App from './App'; +import { DEFAULT_ANCHOR, DEFAULT_EXPERIMENTS, DEFAULT_SIDECAR_URL } from './constants'; import globalStyles from './index.css?inline'; -import { initIntegrations, type SpotlightContext } from './integrations/integration.ts'; -import { default as sentry } from './integrations/sentry/index.ts'; -import { off, on, trigger } from './lib/eventTarget.ts'; -import { activateLogger, log } from './lib/logger.ts'; -import { SpotlightContextProvider } from './lib/useSpotlightContext.tsx'; -import { React, ReactDOM } from './react-instance.tsx'; // Import specific exports -import type { SpotlightOverlayOptions, WindowWithSpotlight } from './types.ts'; - -export { default as console } from './integrations/console/index.ts'; -export { default as hydrationError } from './integrations/hydration-error/index.ts'; -export { default as sentry } from './integrations/sentry/index.ts'; -export { default as viteInspect } from './integrations/vite-inspect/index.ts'; -export type { SpotlightOverlayOptions, WindowWithSpotlight } from './types.ts'; +import { initIntegrations, type SpotlightContext } from './integrations/integration'; +import { default as sentry } from './integrations/sentry/index'; +import { off, on, trigger } from './lib/eventTarget'; +import { activateLogger, log } from './lib/logger'; +import { SpotlightContextProvider } from './lib/useSpotlightContext'; +import { React, ReactDOM } from './react-instance'; // Import specific exports +import type { SpotlightOverlayOptions, WindowWithSpotlight } from './types'; + +export { default as console } from './integrations/console/index'; +export { default as hydrationError } from './integrations/hydration-error/index'; +export { default as sentry } from './integrations/sentry/index'; +export { default as viteInspect } from './integrations/vite-inspect/index'; +export type { SpotlightOverlayOptions, WindowWithSpotlight } from './types'; export { CONTEXT_LINES_ENDPOINT, DEFAULT_ANCHOR, diff --git a/packages/overlay/src/integrations/integration.ts b/packages/overlay/src/integrations/integration.ts index 4dffdd3e..d279ec70 100644 --- a/packages/overlay/src/integrations/integration.ts +++ b/packages/overlay/src/integrations/integration.ts @@ -1,5 +1,5 @@ -import { type ComponentType } from 'react'; -import { type ExperimentsConfig, type NotificationCount } from '~/types'; +import type { ComponentType } from 'react'; +import type { ExperimentsConfig, NotificationCount } from '../types'; export type SpotlightContext = { open: (path: string | undefined) => void; @@ -114,7 +114,7 @@ export type RawEventContext = { * * Return the processed object or undefined if the event should be ignored. */ - data: string | Buffer; + data: string | Uint8Array; }; type TeardownFunction = () => void | Promise<() => void>; @@ -122,7 +122,7 @@ type TeardownFunction = () => void | Promise<() => void>; // export type IntegrationParameter = Array>; export async function initIntegrations( - integrations: Integration[] = [], + integrations: Integration[], context: SpotlightContext, ): Promise<[Integration[], TeardownFunction[]]> { if (!integrations) { diff --git a/packages/overlay/src/integrations/sentry/index.ts b/packages/overlay/src/integrations/sentry/index.ts index 843ea654..a5eeffef 100644 --- a/packages/overlay/src/integrations/sentry/index.ts +++ b/packages/overlay/src/integrations/sentry/index.ts @@ -117,7 +117,7 @@ function getLineEnd(data: Uint8Array): number { return end; } -function parseJSONFromBuffer(data: Uint8Array) { +function parseJSONFromBuffer(data: Uint8Array): object { return JSON.parse(new TextDecoder().decode(data)); } @@ -144,19 +144,21 @@ export function processEnvelope(rawEvent: RawEventContext) { while (buffer.length) { const itemHeader = parseJSONFromBuffer(readLine()) as EnvelopeItem[0]; const payloadLength = itemHeader.length; - let itemPayload = readLine(payloadLength != null ? payloadLength : undefined); + const itemPayloadRaw = readLine(payloadLength != null ? payloadLength : undefined); + let itemPayload: EnvelopeItem[1]; try { - itemPayload = parseJSONFromBuffer(itemPayload); + itemPayload = parseJSONFromBuffer(itemPayloadRaw); + // data sanitization + if (itemHeader.type) { + // @ts-expect-error ts(2339) -- We should really stop adding type to payloads + itemPayload.type = itemHeader.type; + } } catch (err) { + itemPayload = itemPayloadRaw; log(err); } - // data sanitization - if (itemHeader.type && typeof itemPayload === 'object') { - // @ts-expect-error -- Does not like assigning to `type` on random object - itemPayload.type = itemHeader.type; - } items.push([itemHeader, itemPayload] as EnvelopeItem); } diff --git a/packages/overlay/tsconfig.json b/packages/overlay/tsconfig.json index 3f71a6e7..8a63f429 100644 --- a/packages/overlay/tsconfig.json +++ b/packages/overlay/tsconfig.json @@ -4,8 +4,10 @@ "baseUrl": ".", "paths": { "~/*": ["src/*"] - } + }, + "outDir": "dist", + "rootDir": "src" }, - "include": ["src", "test"], + "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/packages/sidecar/package.json b/packages/sidecar/package.json index f30aff7e..a59442e5 100644 --- a/packages/sidecar/package.json +++ b/packages/sidecar/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "./server.js", "dev": "vite build --watch", - "build": "vite build && tsc", + "build": "vite build && tsc --build", "build:watch": "vite build --watch", "clean": "rimraf dist" }, diff --git a/packages/sidecar/tsconfig.json b/packages/sidecar/tsconfig.json index dc2c9863..3f598a80 100644 --- a/packages/sidecar/tsconfig.json +++ b/packages/sidecar/tsconfig.json @@ -9,11 +9,9 @@ "esModuleInterop": false, "target": "esnext", "module": "nodenext", + /* paths */ "outDir": "dist", - "noEmit": false, - "allowImportingTsExtensions": false, - "declaration": true, - "emitDeclarationOnly": true + "rootDir": "src" }, "include": ["src/*"] } diff --git a/packages/spotlight/tsconfig.json b/packages/spotlight/tsconfig.json index 908d68ed..70ee0641 100644 --- a/packages/spotlight/tsconfig.json +++ b/packages/spotlight/tsconfig.json @@ -3,12 +3,10 @@ "compilerOptions": { "baseUrl": ".", "skipLibCheck": true, - "emitDeclarationOnly": true, - "declaration": true, - "noEmit": false, + /* paths */ "outDir": "dist", "rootDir": "src" }, - "include": ["src"], + "include": ["src", "test"], "references": [{ "path": "./tsconfig.node.json" }] } diff --git a/packages/tsconfig/tsconfig.json b/packages/tsconfig/tsconfig.json index a7fc6fbf..efce7fa8 100644 --- a/packages/tsconfig/tsconfig.json +++ b/packages/tsconfig/tsconfig.json @@ -5,13 +5,16 @@ "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, + "allowImportingTsExtensions": false, + /* cannot enable composite mode yet as vite clears output directory, requiring a tsc rebuild all the time */ + "composite": false, + "declaration": true, + "emitDeclarationOnly": true, /* Bundler mode */ "moduleResolution": "bundler", - "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, - "noEmit": true, "jsx": "react-jsx", /* Linting */