diff --git a/package.json b/package.json index c5e0e73a..faf5b8b0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ }, "devDependencies": { "@eslint/js": "^9.39.4", - "@linear/sdk": "^81.0.0", "@typescript-eslint/eslint-plugin": "^8.58.2", "@typescript-eslint/parser": "^8.58.2", "eslint": "^9.16.0", diff --git a/packages/outpost/package.json b/packages/outpost/package.json index be74ac3a..176e4510 100644 --- a/packages/outpost/package.json +++ b/packages/outpost/package.json @@ -20,6 +20,10 @@ "types": "./shared/dist/index.d.ts", "import": "./shared/dist/index.js" }, + "./shared/source/sync": { + "types": "./shared/src/sync/index.ts", + "import": "./shared/src/sync/index.ts" + }, "./shared/platforms": { "types": "./shared/dist/platforms/index.d.ts", "import": "./shared/dist/platforms/index.js" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5c65102e..78bc5ea6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: '@eslint/js': specifier: ^9.39.4 version: 9.39.4 - '@linear/sdk': - specifier: ^81.0.0 - version: 81.0.0(graphql@16.13.2) '@typescript-eslint/eslint-plugin': specifier: ^8.58.2 version: 8.58.2(@typescript-eslint/parser@8.58.2(eslint@9.39.4(jiti@2.6.1))(typescript@5.9.3))(eslint@9.39.4(jiti@2.6.1))(typescript@5.9.3) @@ -398,6 +395,31 @@ importers: specifier: ^4.1.4 version: 4.1.4(@types/node@22.19.17)(jsdom@29.0.2)(vite@8.0.8(@types/node@22.19.17)(esbuild@0.27.7)(jiti@2.6.1)(tsx@4.21.0)) + scripts: + dependencies: + '@copilotkit/outpost': + specifier: workspace:* + version: link:../packages/outpost + '@linear/sdk': + specifier: ^81.0.0 + version: 81.0.0(graphql@16.13.2) + '@prisma/client': + specifier: ^6.2.0 + version: 6.19.3(prisma@6.19.3(typescript@5.9.3))(typescript@5.9.3) + devDependencies: + '@types/node': + specifier: ^22.10.0 + version: 22.19.17 + tsx: + specifier: ^4.21.0 + version: 4.21.0 + typescript: + specifier: ^5.7.0 + version: 5.9.3 + vitest: + specifier: ^4.1.4 + version: 4.1.4(@types/node@22.19.17)(jsdom@29.0.2)(vite@8.0.8(@types/node@22.19.17)(esbuild@0.27.7)(jiti@2.6.1)(tsx@4.21.0)) + packages: '@adobe/css-tools@4.4.4': diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4af31626..8c4493ce 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,4 @@ packages: - - "apps/*" - - "packages/*" + - 'apps/*' + - 'packages/*' + - 'scripts' diff --git a/scripts/import-linear.ts b/scripts/import-linear.ts index d336aef2..de9a38d8 100644 --- a/scripts/import-linear.ts +++ b/scripts/import-linear.ts @@ -12,11 +12,12 @@ import { LinearClient } from '@linear/sdk'; import { PrismaClient } from '@prisma/client'; +// Source-only subpath for tsx and vitest; runtime packages import @copilotkit/outpost/shared. import { createLinearStatusMap, createLinearPriorityMap, createLinearLabelMapper, -} from '../packages/outpost/shared/src/sync/index.js'; +} from '@copilotkit/outpost/shared/source/sync'; // ─── Types ──────────────────────────────────────────────────────────────── @@ -78,7 +79,7 @@ let displayIdCounter = 0; async function nextDisplayId(prisma: PrismaClient): Promise { if (displayIdCounter === 0) { - const latest = await (prisma.ticket as { findFirst: (args: Record) => Promise<{ displayId: string } | null> }).findFirst({ + const latest = await prisma.ticket.findFirst({ orderBy: { createdAt: 'desc' }, select: { displayId: true }, }); @@ -132,9 +133,7 @@ export async function importLinearIssues( for (const issue of issuesPage.nodes) { try { // Check if this issue is already linked - const existingLink = await (prisma.ticketExternalLink as { - findUnique: (args: Record) => Promise<{ id: string; ticketId: string } | null>; - }).findUnique({ + const existingLink = await prisma.ticketExternalLink.findUnique({ where: { plugin_externalId: { plugin: 'linear', @@ -145,7 +144,9 @@ export async function importLinearIssues( if (existingLink) { report.skipped++; - console.log(` SKIP ${issue.identifier}: already linked to ${existingLink.ticketId}`); + console.log( + ` SKIP ${issue.identifier}: already linked to ${existingLink.ticketId}`, + ); continue; } @@ -157,9 +158,7 @@ export async function importLinearIssues( const url = attachment.url; if (url && /github\.com\/.*\/(issues|pull)\/\d+/.test(url)) { // Try to find an existing ticket linked to this GitHub URL - const githubLink = await (prisma.ticketExternalLink as { - findFirst: (args: Record) => Promise<{ ticketId: string } | null>; - }).findFirst({ + const githubLink = await prisma.ticketExternalLink.findFirst({ where: { plugin: 'github', externalUrl: url, @@ -175,9 +174,7 @@ export async function importLinearIssues( if (matchedTicketId) { // Cross-reference match: link to existing ticket if (!args.dryRun) { - await (prisma.ticketExternalLink as { - create: (args: Record) => Promise; - }).create({ + await prisma.ticketExternalLink.create({ data: { ticketId: matchedTicketId, plugin: 'linear', @@ -203,16 +200,16 @@ export async function importLinearIssues( const outpostTags = labelMapper.toOutpost(labelNames); if (args.dryRun) { - console.log(` DRY-RUN ${issue.identifier}: would create ticket (${outpostStatus}, ${outpostPriority})`); + console.log( + ` DRY-RUN ${issue.identifier}: would create ticket (${outpostStatus}, ${outpostPriority})`, + ); report.created++; continue; } // Create the Outpost ticket const displayId = await nextDisplayId(prisma); - const ticket = await (prisma.ticket as { - create: (args: Record) => Promise<{ id: string }>; - }).create({ + const ticket = await prisma.ticket.create({ data: { displayId, title: issue.title, @@ -233,9 +230,7 @@ export async function importLinearIssues( }); // Create the external link - await (prisma.ticketExternalLink as { - create: (args: Record) => Promise; - }).create({ + await prisma.ticketExternalLink.create({ data: { ticketId: ticket.id, plugin: 'linear', @@ -249,9 +244,7 @@ export async function importLinearIssues( const comments = await issue.comments(); for (const comment of comments.nodes) { const authorUser = await comment.user; - await (prisma.message as { - create: (args: Record) => Promise; - }).create({ + await prisma.message.create({ data: { ticketId: ticket.id, author: authorUser?.name ?? 'Unknown', @@ -262,7 +255,9 @@ export async function importLinearIssues( } report.created++; - console.log(` CREATE ${issue.identifier} → ${displayId} (${comments.nodes.length} comments)`); + console.log( + ` CREATE ${issue.identifier} → ${displayId} (${comments.nodes.length} comments)`, + ); } catch (err) { const message = err instanceof Error ? err.message : String(err); report.failed++; @@ -275,7 +270,7 @@ export async function importLinearIssues( } hasMore = issuesPage.pageInfo.hasNextPage; - afterCursor = issuesPage.pageInfo.endCursor; + afterCursor = issuesPage.pageInfo.endCursor ?? undefined; } return report; @@ -287,7 +282,9 @@ async function main(): Promise { const args = parseArgs(process.argv); if (!args.teamId) { - console.error('Usage: npx tsx scripts/import-linear.ts --team-id [--dry-run] [--since DATE]'); + console.error( + 'Usage: npx tsx scripts/import-linear.ts --team-id [--dry-run] [--since DATE]', + ); process.exit(1); } @@ -331,7 +328,8 @@ async function main(): Promise { } // Only run when executed directly (not when imported by tests) -const isDirectRun = process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/.*\//, '')); +const isDirectRun = + process.argv[1] && import.meta.url.endsWith(process.argv[1].replace(/.*\//, '')); if (isDirectRun) { main().catch((err) => { console.error('Fatal error:', err); diff --git a/scripts/package.json b/scripts/package.json new file mode 100644 index 00000000..d04fce0b --- /dev/null +++ b/scripts/package.json @@ -0,0 +1,21 @@ +{ + "name": "@copilotkit/outpost-scripts", + "version": "0.1.0", + "private": true, + "type": "module", + "scripts": { + "test": "vitest run", + "typecheck": "tsc --project tsconfig.json --noEmit" + }, + "dependencies": { + "@copilotkit/outpost": "workspace:*", + "@linear/sdk": "^81.0.0", + "@prisma/client": "^6.2.0" + }, + "devDependencies": { + "@types/node": "^22.10.0", + "tsx": "^4.21.0", + "typescript": "^5.7.0", + "vitest": "^4.1.4" + } +} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index cceae7e9..e2749a5a 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -11,6 +11,5 @@ "noEmit": true, "forceConsistentCasingInFileNames": true }, - "include": ["**/*.ts"], - "exclude": ["__tests__"] + "include": ["**/*.ts"] } diff --git a/vitest.config.ts b/scripts/vitest.config.ts similarity index 69% rename from vitest.config.ts rename to scripts/vitest.config.ts index 40f3a2b9..cb8bb282 100644 --- a/vitest.config.ts +++ b/scripts/vitest.config.ts @@ -3,6 +3,6 @@ import { defineConfig } from 'vitest/config'; export default defineConfig({ test: { globals: true, - include: ['scripts/__tests__/**/*.test.ts'], + include: ['__tests__/**/*.test.ts'], }, }); diff --git a/turbo.json b/turbo.json index 2d75b78a..9cbdb06e 100644 --- a/turbo.json +++ b/turbo.json @@ -4,7 +4,7 @@ // EVERY package, so a file listed here busts build and test caches too. tsconfig.json // qualifies — everything builds and typechecks against it. The ESLint config does not, // and lives on the lint task's `inputs` instead; it cannot change a build or test result, - // which is the same reason .prettierrc and the root vitest.config.ts are absent. + // which is the same reason .prettierrc is absent. "globalDependencies": ["tsconfig.json"], // Pinned rather than relying on turbo 2's default, so the reasoning below cannot be // invalidated by a future change to that default: in strict mode a task sees only the