Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 0 additions & 16 deletions apps/demo/index-react.html

This file was deleted.

2 changes: 1 addition & 1 deletion apps/demo/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function App() {
themes.push(item.options.theme);
}
}
preloadHighlighter({ langs, themes });
void preloadHighlighter({ langs, themes });
}
}, []);

Expand Down
2 changes: 1 addition & 1 deletion apps/demo/src/components/CodeRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function CodeRenderer({ stream, options }: CodeRendererProps) {
const ref = useRef<HTMLPreElement>(null);
useEffect(() => {
if (ref.current != null) {
codeRenderer.setup(stream, ref.current);
void codeRenderer.setup(stream, ref.current);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
20 changes: 11 additions & 9 deletions apps/demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function loadPatchContent() {
loadingPatch =
loadingPatch ??
new Promise((resolve) => {
import('./mocks/diff.patch?raw').then(({ default: content }) =>
void import('./mocks/diff.patch?raw').then(({ default: content }) =>
resolve(content)
);
});
Expand All @@ -47,7 +47,7 @@ function startStreaming() {
const pre = document.createElement('pre');
container.appendChild(pre);
const instance = new CodeRenderer(options);
instance.setup(createFakeContentStream(content, letterByLetter), pre);
void instance.setup(createFakeContentStream(content, letterByLetter), pre);
}
}

Expand All @@ -66,7 +66,7 @@ async function handlePreloadDiff() {
}
}
}
preloadHighlighter({
void preloadHighlighter({
langs: Array.from(langs),
themes: ['tokyo-night', 'solarized-light'],
});
Expand Down Expand Up @@ -135,7 +135,7 @@ function renderDiff(parsedPatches: ParsedPatch[]) {
if (fileAnnotations != null) {
instance.setLineAnnotations(fileAnnotations);
}
instance.render({ fileDiff, wrapper });
void instance.render({ fileDiff, wrapper });
diffInstances.push(instance);
hunkIndex++;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ function handlePreload() {
themes.push(item.options.theme);
}
}
preloadHighlighter({ langs, themes });
void preloadHighlighter({ langs, themes });
}

document.getElementById('toggle-theme')?.addEventListener('click', toggleTheme);
Expand All @@ -178,10 +178,12 @@ if (streamCode != null) {

const loadDiff = document.getElementById('load-diff');
if (loadDiff != null) {
loadDiff.addEventListener('click', async () => {
renderDiff(parsedPatches ?? parsePatchContent(await loadPatchContent()));
loadDiff.addEventListener('click', () => {
void (async () => {
renderDiff(parsedPatches ?? parsePatchContent(await loadPatchContent()));
})();
});
loadDiff.addEventListener('mouseenter', handlePreloadDiff);
loadDiff.addEventListener('mouseenter', () => void handlePreloadDiff);
}

const wrapCheckbox = document.getElementById('wrap-lines');
Expand Down Expand Up @@ -292,7 +294,7 @@ function toggleTheme() {
? 'dark'
: 'light';
const pageTheme =
(document.documentElement.dataset.theme ?? systemTheme === 'dark')
(document.documentElement.dataset.theme ?? systemTheme) === 'dark'
? 'dark'
: 'light';

Expand Down
7 changes: 0 additions & 7 deletions apps/demo/src/main.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/demo/src/utils/createHighlighterCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function createHighlighterCleanup() {
onStreamClose() {
completed++;
if (completed >= totalInstances) {
disposeHighlighter();
void disposeHighlighter();
}
},
};
Expand Down
3 changes: 1 addition & 2 deletions apps/demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../tsconfig.options.json",
"include": ["src/**/*"],
"include": ["src/**/*", "vite.config.ts"],
"compilerOptions": {
"composite": false,
"noEmit": true,
"emitDeclarationOnly": false,
"baseUrl": ".",
"rootDir": "src",
"lib": ["ES2023", "DOM", "DOM.Iterable"]
}
}
31 changes: 3 additions & 28 deletions apps/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,18 @@ export default defineConfig(() => {
}
}

// Handle /react path - serve React version
if (req.url === '/react' || req.url === '/react/') {
const htmlPath = resolve(__dirname, 'index-react.html');
try {
const htmlContent = fs.readFileSync(htmlPath, 'utf-8');
const html = await server.transformIndexHtml('/react', htmlContent);
res.setHeader('Content-Type', 'text/html');
res.end(html);
return;
} catch (e) {
console.error('Error transforming React HTML:', e);
}
}

next();
};

// eslint-disable-next-line @typescript-eslint/no-misused-promises
server.middlewares.use('/', handleRoutes);
},
configurePreviewServer(server: PreviewServer) {
const handleRoutes = async (
req: IncomingMessage,
res: ServerResponse,
next: () => void
// eslint-disable-next-line @typescript-eslint/require-await
) => {
// Handle root path - serve vanilla version
if (req.url === '/' || req.url === '/index.html') {
Expand All @@ -66,22 +54,10 @@ export default defineConfig(() => {
}
}

// Handle /react path - serve React version
if (req.url === '/react' || req.url === '/react/') {
const htmlPath = resolve(__dirname, 'dist/index-react.html');
try {
const htmlContent = fs.readFileSync(htmlPath, 'utf-8');
res.setHeader('Content-Type', 'text/html');
res.end(htmlContent);
return;
} catch (e) {
console.error('Error serving React HTML:', e);
}
}

next();
};

// eslint-disable-next-line @typescript-eslint/no-misused-promises
server.middlewares.use('/', handleRoutes);
},
});
Expand All @@ -92,7 +68,6 @@ export default defineConfig(() => {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
react: resolve(__dirname, 'index-react.html'),
},
},
},
Expand Down
12 changes: 9 additions & 3 deletions apps/docs/app/api/code-storage/github/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextRequest, NextResponse } from 'next/server';
import { type NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
Expand All @@ -7,6 +7,7 @@ export async function GET(request: NextRequest) {
const setupAction = searchParams.get('setup_action');
const state = searchParams.get('state');

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!code) {
return NextResponse.json({ error: 'No code provided' }, { status: 400 });
}
Expand All @@ -28,19 +29,24 @@ export async function GET(request: NextRequest) {
}
);

const tokenData = await tokenResponse.json();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const tokenData: any = await tokenResponse.json();

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (tokenData.error) {
throw new Error(tokenData.error_description || tokenData.error);
throw new Error(tokenData.error_description ?? tokenData.error);
}

const successUrl = new URL('/code-storage/success', request.url);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (setupAction) {
successUrl.searchParams.set('setup_action', setupAction);
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (installationId) {
successUrl.searchParams.set('installation_id', installationId);
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (state) {
successUrl.searchParams.set('state', state);
}
Expand Down
16 changes: 9 additions & 7 deletions apps/docs/app/api/code-storage/github/installations/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { components } from '@octokit/openapi-types';
import { NextRequest, NextResponse } from 'next/server';
import { type NextRequest, NextResponse } from 'next/server';

type Installation = components['schemas']['installation'];

Expand Down Expand Up @@ -34,13 +34,15 @@ function filterInstallations(installations: Installation[]) {
app_id: `${installation.app_id}`,
app_slug: installation.app_slug,
owner_id:
installation.account &&
('id' in installation.account ? `${installation.account.id}` : null),
installation.account != null && 'id' in installation.account
? `${installation.account.id}`
: null,
permissions: installation.permissions,
events: installation.events,
type:
installation.account &&
('type' in installation.account ? installation.account.type : null),
installation.account != null && 'type' in installation.account
? installation.account.type
: null,
} satisfies FilteredInstallation;
});
}
Expand All @@ -65,7 +67,7 @@ function getOwnersFromInstallations(installations: Installation[]) {
export async function GET(request: NextRequest) {
const token = request.cookies.get('github_token')?.value;

if (!token) {
if (token == null || token.trim() === '') {
return NextResponse.json({ data: { installations: [], owners: [] } });
}

Expand All @@ -86,7 +88,7 @@ export async function GET(request: NextRequest) {

const data = (await response.json()) as InstallationResponse;

if (!data?.installations?.length) {
if ((data?.installations?.length ?? 0) > 0) {
return NextResponse.json({
data: {
installations: [],
Expand Down
10 changes: 8 additions & 2 deletions apps/docs/app/api/code-storage/repo/route.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { GitStorage } from '@pierre/storage';
import { NextRequest, NextResponse } from 'next/server';
import { type NextRequest, NextResponse } from 'next/server';

export async function POST(request: NextRequest) {
try {
const store = new GitStorage({
name: 'pierre',
key: process.env.CODE_STORAGE_SYNC_PRIVATE_KEY || '',
key: process.env.CODE_STORAGE_SYNC_PRIVATE_KEY ?? '',
});

const body = await request.json();
const { owner, name, defaultBranch } = body;

// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!owner || !name) {
return NextResponse.json(
{ success: false, error: 'Repository owner and name are required' },
Expand All @@ -24,8 +25,12 @@ export async function POST(request: NextRequest) {
baseRepo: {
owner,
name,
// NOTE(amadeus): Given these types are `any`, not sure the safest way
// to convert fix them...
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/prefer-nullish-coalescing
defaultBranch: defaultBranch || 'main', // Optional, defaults to 'main'
},
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/prefer-nullish-coalescing
defaultBranch: defaultBranch || 'main', // Optional, defaults to 'main' for the Git Storage repo
});

Expand All @@ -40,6 +45,7 @@ export async function POST(request: NextRequest) {
repository: {
owner,
name,
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions, @typescript-eslint/prefer-nullish-coalescing
defaultBranch: defaultBranch || 'main',
},
});
Expand Down
8 changes: 5 additions & 3 deletions apps/docs/app/code-storage/success/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function SuccessPageContent() {
const state = searchParams.get('state');

useEffect(() => {
if (window.opener) {
if (window.opener != null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
window.opener.postMessage(
{
type: appInstallType,
Expand Down Expand Up @@ -43,7 +44,7 @@ function SuccessPageContent() {
Your GitHub App has been successfully{' '}
{setupAction === 'install' ? 'installed' : 'updated'}.
</p>
{installationId && (
{installationId != null && (
<p className="text-sm text-gray-500 mb-6">
Installation ID: {installationId}
</p>
Expand All @@ -54,7 +55,8 @@ function SuccessPageContent() {
</p>
<Button
onClick={() => {
if (window.opener) {
if (window.opener != null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
window.opener.postMessage(
{
type: appInstallType,
Expand Down
5 changes: 3 additions & 2 deletions apps/docs/app/fumadocs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { notFound } from 'next/navigation';
export default async function Page(props: PageProps<'/fumadocs/[[...slug]]'>) {
const params = await props.params;
const page = source.getPage(params.slug);
if (!page) notFound();
if (page == null) notFound();

const MDX = page.data.body;

Expand All @@ -27,6 +27,7 @@ export default async function Page(props: PageProps<'/fumadocs/[[...slug]]'>) {
);
}

// eslint-disable-next-line @typescript-eslint/require-await
export async function generateStaticParams() {
return source.generateParams();
}
Expand All @@ -36,7 +37,7 @@ export async function generateMetadata(
): Promise<Metadata> {
const params = await props.params;
const page = source.getPage(params.slug);
if (!page) notFound();
if (page == null) notFound();

return {
title: page.data.title,
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/app/llms.mdx/[[...slug]]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function GET(
) {
const { slug } = await params;
const page = source.getPage(slug);
if (!page) notFound();
if (page == null) notFound();
return new NextResponse(await getLLMText(page));
}
export function generateStaticParams() {
Expand Down
Loading