Skip to content

Replace bundled dependencies with proper package management #3

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ out/

# ts build
tsconfig.tsbuildinfo

# engines
public/engines/
74 changes: 74 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,80 @@ import { withSentryConfig } from "@sentry/nextjs";
import { NextConfig } from "next";
import { PHASE_PRODUCTION_BUILD } from "next/constants";

import fs from "fs";
import path from "path";

const engines = [
{
version: "stockfish-16",
src: "node_modules/stockfish-16/src",
files: [
"nn-5af11540bbfe.nnue",
"stockfish-nnue-16.js",
"stockfish-nnue-16-single.js",
"stockfish-nnue-16-single.wasm",
"stockfish-nnue-16.wasm"
]
},
{
version: "stockfish-16.1",
src: "node_modules/stockfish-16.1/src",
files: [
"stockfish-16.1.js",
"stockfish-16.1-lite.js",
"stockfish-16.1-lite-single.js",
"stockfish-16.1-lite-single.wasm",
"stockfish-16.1-lite.wasm",
"stockfish-16.1-single.js",
"stockfish-16.1-single.wasm",
"stockfish-16.1.wasm"
]
},
{
version: "stockfish-17",
src: "node_modules/stockfish-17/src",
files: [
"stockfish-17.js",
"stockfish-17-part-0.wasm",
"stockfish-17-part-1.wasm",
"stockfish-17-part-2.wasm",
"stockfish-17-part-3.wasm",
"stockfish-17-part-4.wasm",
"stockfish-17-part-5.wasm",
"stockfish-17-lite.js",
"stockfish-17-lite.wasm"
]
}
];

const enginesPublicDir = path.resolve("public/engines");

fs.mkdirSync(enginesPublicDir, { recursive: true });

fs.copyFileSync(
path.resolve("node_modules/stockfish.js/stockfish.js"),
path.join(enginesPublicDir, "stockfish-11.js")
);

engines.forEach(({ version, src, files }) => {
const destDir = path.join(enginesPublicDir, version);
fs.mkdirSync(destDir, { recursive: true });

files.forEach((file) => {
const srcFile = path.join(src, file);
const destFile = path.join(destDir, file);

if (fs.existsSync(srcFile)) {
fs.copyFileSync(srcFile, destFile);
console.log(`✅ Copied: ${file} → ${destDir}`);
} else {
console.warn(`⚠️ File not found: ${file}`);
}
});
});

console.log("🚀 Stockfish engines copied.");

const nextConfig = (phase: string): NextConfig => ({
output: phase === PHASE_PRODUCTION_BUILD ? "export" : undefined,
trailingSlash: false,
Expand Down
35 changes: 34 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
"react": "18.3.1",
"react-chessboard": "^4.7.2",
"react-dom": "18.3.1",
"recharts": "^2.15.0"
"recharts": "^2.15.0",
"stockfish.js": "^10.0.2",
"stockfish-17": "nmrugg/stockfish.js#fe65b88",
"stockfish-16.1": "nmrugg/stockfish.js#v16.1.0",
"stockfish-16": "nmrugg/stockfish.js#v16.0.0"
},
"devDependencies": {
"@types/node": "^22.10.2",
Expand Down
37 changes: 0 additions & 37 deletions public/engines/stockfish-11.js

This file was deleted.

11 changes: 0 additions & 11 deletions public/engines/stockfish-16.1/stockfish-16.1-lite-single.js

This file was deleted.

Binary file not shown.
11 changes: 0 additions & 11 deletions public/engines/stockfish-16.1/stockfish-16.1-lite.js

This file was deleted.

Binary file not shown.
8 changes: 0 additions & 8 deletions public/engines/stockfish-16.1/stockfish-16.1-single.js

This file was deleted.

Loading