Skip to content

Commit

Permalink
ref: Fix up some tsconfig schenanigants
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK committed Aug 30, 2024
1 parent 4acbad0 commit 41363b5
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ sentry.properties
junit.xml

# Build artifacts
*.tgz
*.tgz
tsconfig.tsbuildinfo
4 changes: 2 additions & 2 deletions packages/astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions packages/overlay/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default function App({
}
}

const result: Record<string, (event: { data: string | Buffer }) => void> = Object.create(null);
const result: Record<string, (event: { data: string | Uint8Array }) => 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
Expand Down
30 changes: 15 additions & 15 deletions packages/overlay/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/overlay/src/integrations/integration.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -114,15 +114,15 @@ 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>;

// export type IntegrationParameter = Array<Integration<unknown>>;

export async function initIntegrations(
integrations: Integration[] = [],
integrations: Integration[],
context: SpotlightContext,
): Promise<[Integration[], TeardownFunction[]]> {
if (!integrations) {
Expand Down
18 changes: 10 additions & 8 deletions packages/overlay/src/integrations/sentry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions packages/overlay/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"baseUrl": ".",
"paths": {
"~/*": ["src/*"]
}
},
"outDir": "dist",
"rootDir": "src"
},
"include": ["src", "test"],
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
2 changes: 1 addition & 1 deletion packages/sidecar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 2 additions & 4 deletions packages/sidecar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"]
}
6 changes: 2 additions & 4 deletions packages/spotlight/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" }]
}
7 changes: 5 additions & 2 deletions packages/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 41363b5

Please sign in to comment.