From e2d8c0200f7a649b684832fea4e7b29b697bd352 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:34:00 +0300 Subject: [PATCH] Use custom init script instead of postinstall (#5384) * Use custom init script instead of postinstall * Revert changes to start scripts in src\electron * feat: add --ignore-scripts flag to npm install commands in batch and shell scripts * feat: add --ignore-scripts flag to npm ci in Dockerfile --- .npmrc | 2 ++ Dockerfile | 2 +- Start.bat | 3 ++- UpdateAndStart.bat | 3 ++- UpdateForkAndStart.bat | 3 ++- docker/docker-entrypoint.sh | 6 +++--- package-lock.json | 1 - package.json | 2 +- src/electron/Start.bat | 2 +- post-install.js => src/server-init.js | 4 ++-- start.sh | 3 ++- 11 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 .npmrc rename post-install.js => src/server-init.js (95%) diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..2143f3df2 --- /dev/null +++ b/.npmrc @@ -0,0 +1,2 @@ +ignore-scripts=true +min-release-age=7 diff --git a/Dockerfile b/Dockerfile index 999164f40..31dab85c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ COPY --chown=node:node . ./ RUN \ echo "*** Install npm packages ***" && \ - npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev && npm cache clean --force + npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts && npm cache clean --force # Create config directory and link config.yaml. Added hardcoded dirs(constants.js?) # that must be present for Non-Root Mode and volumeless docker runs. diff --git a/Start.bat b/Start.bat index 9be1a133e..f86f4333a 100644 --- a/Start.bat +++ b/Start.bat @@ -1,7 +1,8 @@ @echo off pushd %~dp0 set NODE_ENV=production -call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev +call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts +call npm run init node server.js %* pause popd diff --git a/UpdateAndStart.bat b/UpdateAndStart.bat index 766d52e5a..b47d32b92 100644 --- a/UpdateAndStart.bat +++ b/UpdateAndStart.bat @@ -20,7 +20,8 @@ if %errorlevel% neq 0 ( ) ) set NODE_ENV=production -call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev +call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts +call npm run init node server.js %* :end pause diff --git a/UpdateForkAndStart.bat b/UpdateForkAndStart.bat index 68a9885a6..301e114cd 100644 --- a/UpdateForkAndStart.bat +++ b/UpdateForkAndStart.bat @@ -102,7 +102,8 @@ if %errorlevel% neq 0 ( echo Installing npm packages and starting server set NODE_ENV=production -call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev +call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts +call npm run init node server.js %* :end diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index b4b744266..54e6d79b1 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Function to handle startup logic (Config check + Postinstall + Start) +# Function to handle startup logic (Config check + init + Start) start_sillytavern() { local PREFIX="$1" shift # Remove the first argument (PREFIX) so $@ contains the rest @@ -11,8 +11,8 @@ start_sillytavern() { $PREFIX cp "default/config.yaml" "config/config.yaml" fi - # Execute postinstall to auto-populate config.yaml with missing values - $PREFIX npm run postinstall + # Execute init script to auto-populate config.yaml with missing values + $PREFIX npm run init # Start the server exec $PREFIX node server.js --listen "$@" diff --git a/package-lock.json b/package-lock.json index 1f7b82749..c93fcc4b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,6 @@ "": { "name": "sillytavern", "version": "1.17.0", - "hasInstallScript": true, "license": "AGPL-3.0", "dependencies": { "@adobe/css-tools": "^4.4.4", diff --git a/package.json b/package.json index 6e86a216d..786668480 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ }, "version": "1.17.0", "scripts": { + "init": "node src/server-init.js", "start": "node server.js", "debug": "node --inspect server.js", "start:global": "node server.js --global", @@ -122,7 +123,6 @@ "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js", "start:bun": "bun server.js", "start:no-csrf": "node server.js --disableCsrf", - "postinstall": "node post-install.js", "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js", "lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix", "plugins:update": "node plugins update", diff --git a/src/electron/Start.bat b/src/electron/Start.bat index d26dea4df..2854b42af 100644 --- a/src/electron/Start.bat +++ b/src/electron/Start.bat @@ -1,6 +1,6 @@ @echo off pushd %~dp0 -call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev +call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts npm run start server.js %* pause popd diff --git a/post-install.js b/src/server-init.js similarity index 95% rename from post-install.js rename to src/server-init.js index 4908e950e..cc7e0da0a 100644 --- a/post-install.js +++ b/src/server-init.js @@ -7,7 +7,7 @@ import process from 'node:process'; import yaml from 'yaml'; import chalk from 'chalk'; import { createRequire } from 'node:module'; -import { addMissingConfigValues } from './src/config-init.js'; +import { addMissingConfigValues } from './config-init.js'; /** * Colorizes console output. @@ -88,7 +88,7 @@ function createDefaultFiles() { ); } else { throw new Error( - 'FATAL: Unexpected default file format in `post-install.js#createDefaultFiles()`.', + 'FATAL: Unexpected default file format in `server-init.js#createDefaultFiles()`.', ); } } catch (error) { diff --git a/start.sh b/start.sh index ab2f9035a..8dbd26584 100755 --- a/start.sh +++ b/start.sh @@ -10,7 +10,8 @@ fi echo "Installing Node Modules..." export NODE_ENV=production -npm i --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev +npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts +npm run init echo "Entering SillyTavern..." node "server.js" "$@"