Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Fix up some tsconfig schenanigans #512

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';
import sentryDataCache from '~/integrations/sentry/data/sentryDataCache';
import { processEnvelope } from '~/integrations/sentry/index';
import { processEnvelope } from '../index';
import sentryDataCache from './sentryDataCache';

import fs from 'fs';
import fs from 'node:fs';

describe('SentryDataCache', () => {
// We need to refactor this to make it actually testable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, test } from 'vitest';
import { processEnvelope } from '~/integrations/sentry/index';
import { processEnvelope } from './index';

import { Event } from '@sentry/types';
import fs from 'fs';
import sentryDataCache from '~/integrations/sentry/data/sentryDataCache';
import type { Event } from '@sentry/types';
import fs from 'node:fs';
import sentryDataCache from './data/sentryDataCache';

describe('Sentry Integration', () => {
test('Process Envelope Empty', () => {
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from 'vitest';
import { Span } from '~/integrations/sentry/types';
import { groupSpans } from '~/integrations/sentry/utils/traces';
import { generate_uuidv4 } from '~/lib/uuid';
import { generate_uuidv4 } from '../../../lib/uuid';
import type { Span } from '../types';
import { groupSpans } from './traces';

function mockSpan({ duration, ...span }: Partial<Span> & { duration?: number } = {}): Span {
const defaultTimestamp = new Date().getTime();
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/overlay/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default defineConfig({
reporter: ['json'],
},
globals: true,
include: ['./test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
include: ['./src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
watchExclude: ['.*\\/node_modules\\/.*', '.*\\/dist\\/.*'],
},
resolve: {
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/*"]
}
4 changes: 1 addition & 3 deletions packages/spotlight/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"emitDeclarationOnly": true,
"declaration": true,
"noEmit": false,
/* paths */
"outDir": "dist",
"rootDir": "src"
},
Expand Down
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
Loading