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

Port to Bun #3

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.travis
.vscode
.config
.cache
Dockerfile
build/
built/
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Docker Image CI

on:
push:
branches: [ "develop" ]
branches: [ "develop", "c/bun-port" ]
pull_request:
branches: [ "develop" ]

Expand Down
35 changes: 19 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
# syntax = docker/dockerfile:1.4

ARG NODE_VERSION=20.10.0-alpine3.18
ARG BUN_VERSION=1.1.13-alpine

FROM node:${NODE_VERSION} as build

RUN apk add git linux-headers build-base
# FROM node:${NODE_VERSION} as build
FROM oven/bun:${BUN_VERSION} as build

# we need nodejs for node-gyp anyway :sob:
RUN apk add git linux-headers build-base nodejs npm
# RUN apt update && apt install -y git build-essential
ENV PYTHONUNBUFFERED=1
RUN apk add --update python3 && ln -sf python3 /usr/bin/python
# RUN apt install -y python3 python3-pip
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

# TODO: Recursive build script https://github.com/oven-sh/bun/issues/5350
RUN corepack enable

WORKDIR /sharkey

COPY --link . ./

RUN git submodule update --init --recursive
RUN pnpm config set fetch-retries 5
# RUN pnpm config set fetch-retries 5
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
pnpm i --frozen-lockfile --aggregate-output
RUN pnpm build
RUN node scripts/trim-deps.mjs
bun i --aggregate-output --frozen-lockfile --cache-dir=.cache
RUN bun run build
RUN bun scripts/trim-deps.mjs
RUN mv packages/frontend/assets sharkey-assets
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
pnpm prune
RUN rm -r node_modules packages/frontend packages/sw
RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
pnpm i --prod --frozen-lockfile --aggregate-output
# RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
# bun run --bun prune
# RUN rm -r node_modules packages/frontend packages/sw
# RUN --mount=type=cache,target=/root/.local/share/pnpm/store,sharing=locked \
# bun i --aggregate-output --frozen-lockfile
RUN rm -rf .git

FROM oven/bun:1.1.13-alpine
FROM oven/bun:${BUN_VERSION}

ARG UID="991"
ARG GID="991"

RUN apk add ffmpeg tini jemalloc \
&& corepack enable \
&& addgroup -g "${GID}" sharkey \
&& adduser -D -u "${UID}" -G sharkey -h /sharkey sharkey \
&& find / -type d -path /sys -prune -o -type d -path /proc -prune -o -type f -perm /u+s -exec chmod u-s {} \; \
Expand Down Expand Up @@ -74,7 +77,7 @@ COPY --chown=sharkey:sharkey packages/misskey-js/package.json ./packages/misskey
COPY --chown=sharkey:sharkey packages/misskey-reversi/package.json ./packages/misskey-reversi/package.json
COPY --chown=sharkey:sharkey packages/misskey-bubble-game/package.json ./packages/misskey-bubble-game/package.json

ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
# ENV LD_PRELOAD=/usr/lib/libjemalloc.so.2
ENV NODE_ENV=production
# RUN corepack enable
ENTRYPOINT ["/sbin/tini", "--"]
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[install.scopes]
"@transfem-org" = "https://activitypub.software/api/v4/packages/npm/"
132 changes: 63 additions & 69 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
{
"name": "sharkey",
"version": "2024.3.3-devel",
"codename": "shonk",
"repository": {
"type": "git",
"url": "https://activitypub.software/TransFem-org/Sharkey.git"
},
"packageManager": "pnpm@8.15.4",
"workspaces": [
"packages/frontend",
"packages/backend",
"packages/sw",
"packages/misskey-js",
"packages/misskey-reversi",
"packages/misskey-bubble-game"
],
"private": true,
"scripts": {
"build-pre": "node ./scripts/build-pre.js",
"build-assets": "node ./scripts/build-assets.mjs",
"build": "pnpm build-pre && pnpm -r build && pnpm build-assets",
"build-storybook": "pnpm --filter frontend build-storybook",
"build-misskey-js-with-types": "pnpm build-pre && pnpm --filter backend... --filter=!misskey-js build && pnpm --filter backend generate-api-json && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && pnpm --filter misskey-js update-autogen-code && pnpm --filter misskey-js build && pnpm --filter misskey-js api",
"start": "cd packages/backend && node ./built/boot/entry.js",
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js",
"init": "pnpm migrate",
"migrate": "cd packages/backend && pnpm migrate",
"revert": "cd packages/backend && pnpm revert",
"check:connect": "cd packages/backend && pnpm check:connect",
"migrateandstart": "pnpm migrate && pnpm start",
"watch": "pnpm dev",
"dev": "node scripts/dev.mjs",
"lint": "pnpm -r lint",
"cy:open": "pnpm cypress open --browser --e2e --config-file=cypress.config.ts",
"cy:run": "pnpm cypress run",
"e2e": "pnpm start-server-and-test start:test http://localhost:61812 cy:run",
"jest": "cd packages/backend && pnpm jest",
"jest-and-coverage": "cd packages/backend && pnpm jest-and-coverage",
"test": "pnpm -r test",
"test-and-coverage": "pnpm -r test-and-coverage",
"clean": "node ./scripts/clean.js",
"clean-all": "node ./scripts/clean-all.js",
"cleanall": "pnpm clean-all"
},
"resolutions": {
"chokidar": "3.5.3",
"lodash": "4.17.21"
},
"dependencies": {
"cssnano": "6.0.5",
"execa": "8.0.1",
"fast-glob": "3.3.2",
"ignore-walk": "6.0.4",
"js-yaml": "4.1.0",
"postcss": "8.4.35",
"tar": "6.2.0",
"terser": "5.28.1",
"typescript": "5.3.3"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "7.1.0",
"@typescript-eslint/parser": "7.1.0",
"cross-env": "7.0.3",
"cypress": "13.6.6",
"eslint": "8.57.0",
"ncp": "2.0.0",
"start-server-and-test": "2.0.3"
}
}
"name": "sharkey",
"version": "2024.3.3-devel",
"codename": "shonk",
"repository": {
"type": "git",
"url": "https://activitypub.software/TransFem-org/Sharkey.git"
},
"packageManager": "bun run --bun@8.15.4",
"workspaces": [
"packages/*"
],
"private": true,
"scripts": {
"build-pre": "node ./scripts/build-pre.js",
"build-assets": "node ./scripts/build-assets.mjs",
"build": "bun run --bun build-pre && pnpm -r build && bun run --bun build-assets",
"build-storybook": "bun run --bun --filter frontend build-storybook",
"build-misskey-js-with-types": "bun run --bun build-pre && bun run --bun --filter backend... --filter=!misskey-js build && bun run --bun --filter backend generate-api-json && ncp packages/backend/built/api.json packages/misskey-js/generator/api.json && bun run --bun --filter misskey-js update-autogen-code && bun run --bun --filter misskey-js build && bun run --bun --filter misskey-js api",
"start": "cd packages/backend && node ./built/boot/entry.js",
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js",
"init": "bun run --bun migrate",
"migrate": "cd packages/backend && bun run --bun migrate",
"revert": "cd packages/backend && bun run --bun revert",
"check:connect": "cd packages/backend && bun run --bun check:connect",
"migrateandstart": "bun run --bun migrate && bun run --bun start",
"watch": "bun run --bun dev",
"dev": "node scripts/dev.mjs",
"lint": "bun run --bun -r lint",
"cy:open": "bun run --bun cypress open --browser --e2e --config-file=cypress.config.ts",
"cy:run": "bun run --bun cypress run",
"e2e": "bun run --bun start-server-and-test start:test http://localhost:61812 cy:run",
"jest": "cd packages/backend && bun run --bun jest",
"jest-and-coverage": "cd packages/backend && bun run --bun jest-and-coverage",
"test": "bun run --bun -r test",
"test-and-coverage": "bun run --bun -r test-and-coverage",
"clean": "node ./scripts/clean.js",
"clean-all": "node ./scripts/clean-all.js",
"cleanall": "bun run --bun clean-all"
},
"resolutions": {
"chokidar": "3.5.3",
"lodash": "4.17.21"
},
"dependencies": {
"cssnano": "^7.0.2",
"fast-glob": "3.3.2",
"ignore-walk": "6.0.4",
"js-yaml": "4.1.0",
"postcss": "^8.4.38",
"tar": "6.2.0",
"terser": "^5.31.1",
"yaml": "^2.4.5"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "7.1.0",
"@typescript-eslint/parser": "7.1.0",
"cross-env": "7.0.3",
"cypress": "13.6.6",
"eslint": "8.57.0",
"ncp": "2.0.0",
"start-server-and-test": "2.0.3"
}
}
11 changes: 9 additions & 2 deletions scripts/build-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,31 @@ import meta from '../package.json' assert { type: "json" };
import buildTarball from './tarball.mjs';

const configDir = fileURLToPath(new URL('../.config', import.meta.url));
console.log(configDir);
const configPath = process.env.MISSKEY_CONFIG_YML
? path.resolve(configDir, process.env.MISSKEY_CONFIG_YML)
: process.env.NODE_ENV === 'test'
? path.resolve(configDir, 'test.yml')
: path.resolve(configDir, 'default.yml');


//
console.log(configPath);

let locales = buildLocales();

async function loadConfig() {
return fs.readFile(configPath, 'utf-8').then(data => yaml.load(data)).catch(() => null);
}

// We are now building with Bun, so these files will now be in the global node_modules folder

async function copyFrontendFonts() {
await fs.cp('./packages/frontend/node_modules/three/examples/fonts', './built/_frontend_dist_/fonts', { dereference: true, recursive: true });
await fs.cp('./node_modules/three/examples/fonts', './built/_frontend_dist_/fonts', { dereference: true, recursive: true });
}

async function copyFrontendTablerIcons() {
await fs.cp('./packages/frontend/node_modules/@phosphor-icons/web/src', './built/_frontend_dist_/phosphor-icons', { dereference: true, recursive: true });
await fs.cp('./node_modules/@phosphor-icons/web/src', './built/_frontend_dist_/phosphor-icons', { dereference: true, recursive: true });
}

async function copyFrontendLocales() {
Expand Down
8 changes: 4 additions & 4 deletions scripts/clean-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const fs = require('fs');
fs.rmSync(__dirname + '/../built', { recursive: true, force: true });
fs.rmSync(__dirname + '/../node_modules', { recursive: true, force: true });

execSync('pnpm store prune', {
cwd: __dirname + '/../',
stdio: 'inherit',
});
// execSync('pnpm store prune', {
// cwd: __dirname + '/../',
// stdio: 'inherit',
// });
})();
Loading
Loading