replace bun with pnpm and added dockerfile for web

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-11-02 11:29:28 +01:00
parent 4dde07704a
commit 9b329ef2f2
15 changed files with 5598 additions and 50 deletions

View File

@@ -1,3 +1,10 @@
**/.env **/.env
**/node_modules **/node_modules
**/dist **/dist
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git

47
apps/web/Dockerfile Normal file
View File

@@ -0,0 +1,47 @@
FROM node:20-slim AS base
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NEXTAUTH_SECRET
ENV NEXTAUTH_SECRET=$NEXTAUTH_SECRET
ARG NEXTAUTH_URL
ENV NEXTAUTH_URL=$NEXTAUTH_URL
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
ARG NODE_VERSION=18
RUN apt update \
&& apt install -y curl \
&& curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n
FROM base AS build
COPY . /app
WORKDIR /app/apps/web
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --ignore-scripts
RUN pnpm dlx prisma generate
RUN pnpm run build
FROM base AS prod
COPY . /app
WORKDIR /app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile --prod --ignore-scripts
FROM base AS runner
COPY --from=build /app/package.json /app/package.json
COPY --from=prod /app/node_modules /app/node_modules
COPY --from=build /app/apps/web /app/apps/web
COPY --from=prod /app/apps/web/node_modules /app/apps/web/node_modules
WORKDIR /app/apps/web
RUN pnpm dlx prisma generate
EXPOSE 3000
CMD [ "pnpm", "start" ]

View File

@@ -1,5 +1,5 @@
{ {
"name": "web", "name": "@mixan/web",
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
@@ -41,7 +41,7 @@
"cmdk": "^0.2.0", "cmdk": "^0.2.0",
"lucide-react": "^0.286.0", "lucide-react": "^0.286.0",
"mitt": "^3.0.1", "mitt": "^3.0.1",
"next": "^13.5.4", "next": "13.4",
"next-auth": "^4.23.0", "next-auth": "^4.23.0",
"ramda": "^0.29.1", "ramda": "^0.29.1",
"random-animal-name": "^0.1.1", "random-animal-name": "^0.1.1",
@@ -81,6 +81,5 @@
}, },
"ct3aMetadata": { "ct3aMetadata": {
"initVersion": "7.21.0" "initVersion": "7.21.0"
}, }
"packageManager": "npm@9.8.1"
} }

View File

@@ -1,30 +1,27 @@
import { validateSdkRequest } from '@/server/auth' import { validateSdkRequest } from "@/server/auth";
import { db } from '@/server/db' import { db } from "@/server/db";
import { createError, handleError } from '@/server/exceptions' import { createError, handleError } from "@/server/exceptions";
import type { NextApiRequest, NextApiResponse } from 'next' import type { NextApiRequest, NextApiResponse } from "next";
import randomAnimalName from 'random-animal-name' import randomAnimalName from "random-animal-name";
interface Request extends NextApiRequest { interface Request extends NextApiRequest {
body: { body: {
id: string id?: string;
properties?: Record<string, any> properties?: Record<string, any>;
} };
} }
export default async function handler( export default async function handler(req: Request, res: NextApiResponse) {
req: Request, if (req.method !== "POST") {
res: NextApiResponse return handleError(res, createError(405, "Method not allowed"));
) {
if(req.method !== 'POST') {
return handleError(res, createError(405, 'Method not allowed'))
} }
try { try {
// Check client id & secret // Check client id & secret
const projectId = await validateSdkRequest(req) const projectId = await validateSdkRequest(req);
const { id, properties } = req.body const { id, properties } = req.body ?? {};
await db.profile.create({ const profile = await db.profile.create({
data: { data: {
id, id,
external_id: null, external_id: null,
@@ -37,10 +34,10 @@ export default async function handler(
}, },
project_id: projectId, project_id: projectId,
}, },
}) });
res.status(200).end() res.status(200).json({ id: profile.id });
} catch (error) { } catch (error) {
handleError(res, error) handleError(res, error);
} }
} }

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,17 +1,16 @@
{ {
"name": "@mixan/root", "name": "@mixan/root",
"version": "1.0.0", "version": "1.0.0",
"workspaces": ["apps/*", "packages/*"],
"keywords": [], "keywords": [],
"author": "", "author": "",
"packageManager": "pnpm@8.7.6",
"license": "ISC", "license": "ISC",
"module": "index.ts", "module": "index.ts",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "cd apps/web && bun dev" "dev": "pnpm -r dev"
}, },
"devDependencies": { "devDependencies": {
"bun-types": "latest",
"semver": "^7.5.4" "semver": "^7.5.4"
}, },
"peerDependencies": { "peerDependencies": {

View File

@@ -34,7 +34,7 @@ class Fetcher {
post<Response extends unknown>( post<Response extends unknown>(
path: string, path: string,
data: Record<string, any> = {}, data: Record<string, any> = {},
options: FetchRequestInit = {} options: RequestInit = {}
): Promise<Response | null> { ): Promise<Response | null> {
const url = `${this.url}${path}` const url = `${this.url}${path}`
this.logger(`Mixan request: ${url}`, JSON.stringify(data, null, 2)) this.logger(`Mixan request: ${url}`, JSON.stringify(data, null, 2))
@@ -49,9 +49,7 @@ class Fetcher {
...options, ...options,
}) })
.then(async (res) => { .then(async (res) => {
const response = await res.json< const response = await res.json() as (MixanErrorResponse | Response)
MixanErrorResponse | Response
>()
if(!response) { if(!response) {
return null return null
@@ -78,7 +76,7 @@ class Fetcher {
class Batcher<T extends any> { class Batcher<T extends any> {
queue: T[] = [] queue: T[] = []
timer?: Timer timer?: NodeJS.Timeout
callback: (queue: T[]) => void callback: (queue: T[]) => void
maxBatchSize: number maxBatchSize: number
batchInterval: number batchInterval: number

View File

@@ -8,7 +8,6 @@
}, },
"devDependencies": { "devDependencies": {
"@types/uuid": "^9.0.5", "@types/uuid": "^9.0.5",
"bun-types": "latest",
"tsup": "^7.2.0", "tsup": "^7.2.0",
"typescript": "^5.0.0" "typescript": "^5.0.0"
} }

View File

@@ -17,9 +17,5 @@
"outDir": "dist", "outDir": "dist",
"allowImportingTsExtensions": false, "allowImportingTsExtensions": false,
"noEmit": false, "noEmit": false,
"types": [
"bun-types" // add Bun global
],
} }
} }

View File

@@ -3,13 +3,11 @@
To install dependencies: To install dependencies:
```bash ```bash
bun install pnpm install
``` ```
To run: To run:
```bash ```bash
bun run index.ts pnpm run index.ts
``` ```
This project was created using `bun init` in bun v1.0.4. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

View File

@@ -4,7 +4,6 @@
"type": "module", "type": "module",
"module": "index.ts", "module": "index.ts",
"devDependencies": { "devDependencies": {
"bun-types": "latest",
"tsup": "^7.2.0", "tsup": "^7.2.0",
"typescript": "^5.0.0" "typescript": "^5.0.0"
} }

View File

@@ -14,9 +14,6 @@
"jsx": "react-jsx", "jsx": "react-jsx",
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"allowJs": true, "allowJs": true
"types": [
"bun-types" // add Bun global
]
} }
} }

5509
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,3 @@
packages:
- 'apps/*'
- 'packages/*'

View File

@@ -47,10 +47,10 @@ function main() {
}) })
try { try {
execSync('bunx tsup', { execSync('pnpm dlx tsup', {
cwd: './packages/sdk', cwd: './packages/sdk',
}) })
execSync('bunx tsup', { execSync('pnpm dlx tsup', {
cwd: './packages/types', cwd: './packages/types',
}) })
} catch(error) { } catch(error) {