Skip to content

Commit

Permalink
feat: make package work with nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokaito committed Nov 23, 2023
1 parent 2afef7d commit ceeffd0
Show file tree
Hide file tree
Showing 11 changed files with 2,636 additions and 6,482 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: pnpm install

- name: Build
run: pnpm build:packages
run: pnpm build --filter=sdk

- name: Lint
run: pnpm test
Expand Down
2 changes: 1 addition & 1 deletion apps/commerce/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const nextConfig = {
ppr: true
},
reactStrictMode: true,
transpilePackages: ['ui', '@quixer/server'],
transpilePackages: ['ui'],
images: {
formats: ['image/avif', 'image/webp'],
remotePatterns: [
Expand Down
2 changes: 1 addition & 1 deletion apps/commerce/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"*": "prettier --write --ignore-unknown"
},
"dependencies": {
"@quixer/server": "workspace:*",
"@quixer/sdk": "workspace:*",
"@t3-oss/env-nextjs": "^0.7.1",
"@tanstack/react-query": "^4.36.1",
"@tanstack/react-query-devtools": "^5.8.4",
Expand Down
2 changes: 1 addition & 1 deletion apps/commerce/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import env from '@/sdk/env';
import { appRouter, createTRPCContext, integrations } from '@quixer/server';
import { appRouter, createTRPCContext, integrations } from '@quixer/sdk';
import { fetchRequestHandler } from '@trpc/server/adapters/fetch';
import { type NextRequest } from 'next/server';

Expand Down
2 changes: 1 addition & 1 deletion apps/commerce/src/sdk/lib/trpc/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { loggerLink, unstable_httpBatchStreamLink } from '@trpc/client';
import { createTRPCReact } from '@trpc/react-query';
import { useMemo } from 'react';

import { appRouter } from '@quixer/server';
import { appRouter } from '@quixer/sdk';
import { getUrl, transformer } from './shared';

export const api = createTRPCReact<typeof appRouter>();
Expand Down
13 changes: 8 additions & 5 deletions apps/commerce/src/sdk/lib/trpc/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'server-only'; // Make sure you can't import this on client

import env from '@/sdk/env';
import { appRouter, createTRPCContext, integrations } from '@quixer/server';
import { appRouter, createTRPCContext, integrations } from '@quixer/sdk';
import { headers } from 'next/headers';
import { NextRequest } from 'next/server';

type Caller = ReturnType<typeof appRouter.createCaller>;

Expand All @@ -11,13 +12,15 @@ let caller: Caller | null = null;
// Cache the caller, since this runs per-request anyways.
const getCaller = () => {
// This fn should be async if create context is async

if (!caller) {
const req = {
headers: headers()
} as NextRequest;

caller = appRouter.createCaller(
createTRPCContext({
// @ts-expect-error - this is a hack to get the types to work
req: {
headers: headers()
},
req: req,
integrations: {
shopify: {
client: new integrations.shopify.client(
Expand Down
2 changes: 1 addition & 1 deletion apps/commerce/src/sdk/lib/trpc/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type inferRouterInputs, type inferRouterOutputs } from '@trpc/server';
import superjson from 'superjson';

import { appRouter } from '@quixer/server';
import { appRouter } from '@quixer/sdk';

export const transformer = superjson;

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"scripts": {
"build": "turbo run build --no-daemon",
"dev": "turbo run dev --parallel --no-cache --no-daemon",
"build:packages": "turbo run build:packages --no-daemon",
"start": "turbo run start --no-daemon",
"lhci": "turbo run lhci --no-daemon",
"lint": "turbo run lint --no-daemon",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const tsup = defineConfig((options: Options) => ({
outDir: "dist",
dts: true,
sourcemap: true,
clean: true,
clean: false,
splitting: true,
minify: true,
...options,
Expand Down
Loading

0 comments on commit ceeffd0

Please sign in to comment.