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

e2d8c0200f7a649b684832fea4e7b29b697bd352

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
11 files changed, +18 -13Showing whitespace changes
.npmrc+2 -0
@@ -0,0 +1,2 @@
1+ignore-scripts=true
2+min-release-age=7
Dockerfile+1 -1
@@ -19,7 +19,7 @@ COPY --chown=node:node . ./
1919
2020RUN \
2121 echo "*** Install npm packages ***" && \
2222 npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts && npm cache clean --force
2323
2424# Create config directory and link config.yaml. Added hardcoded dirs(constants.js?)
2525# that must be present for Non-Root Mode and volumeless docker runs.
Start.bat+2 -1
@@ -1,7 +1,8 @@
11@echo off
22pushd %~dp0
33set NODE_ENV=production
44call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
5+call npm run init
56node server.js %*
67pause
78popd
UpdateAndStart.bat+2 -1
@@ -20,7 +20,8 @@ if %errorlevel% neq 0 (
2020 )
2121)
2222set NODE_ENV=production
2323call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
24+call npm run init
2425node server.js %*
2526:end
2627pause
UpdateForkAndStart.bat+2 -1
@@ -102,7 +102,8 @@ if %errorlevel% neq 0 (
102102
103103echo Installing npm packages and starting server
104104set NODE_ENV=production
105105call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
106+call npm run init
106107node server.js %*
107108
108109:end
docker/docker-entrypoint.sh+3 -3
@@ -1,6 +1,6 @@
11#!/bin/sh
22
33# Function to handle startup logic (Config check + Postinstallinit + Start)
44start_sillytavern() {
55 local PREFIX="$1"
66 shift # Remove the first argument (PREFIX) so $@ contains the rest
@@ -11,8 +11,8 @@ start_sillytavern() {
1111 $PREFIX cp "default/config.yaml" "config/config.yaml"
1212 fi
1313
1414 # Execute postinstallinit script to auto-populate config.yaml with missing values
1515 $PREFIX npm run postinstallinit
1616
1717 # Start the server
1818 exec $PREFIX node server.js --listen "$@"
package-lock.json+0 -1
@@ -7,7 +7,6 @@
77 "": {
88 "name": "sillytavern",
99 "version": "1.17.0",
10- "hasInstallScript": true,
1110 "license": "AGPL-3.0",
1211 "dependencies": {
1312 "@adobe/css-tools": "^4.4.4",
package.json+1 -1
@@ -115,6 +115,7 @@
115115 },
116116 "version": "1.17.0",
117117 "scripts": {
118+ "init": "node src/server-init.js",
118119 "start": "node server.js",
119120 "debug": "node --inspect server.js",
120121 "start:global": "node server.js --global",
@@ -122,7 +123,6 @@
122123 "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",
123124 "start:bun": "bun server.js",
124125 "start:no-csrf": "node server.js --disableCsrf",
125- "postinstall": "node post-install.js",
126126 "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js",
127127 "lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix",
128128 "plugins:update": "node plugins update",
src/electron/Start.bat+1 -1
@@ -1,6 +1,6 @@
11@echo off
22pushd %~dp0
33call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
44npm run start server.js %*
55pause
66popd
post-install.js → src/server-init.js+2 -2
@@ -7,7 +7,7 @@ import process from 'node:process';
77import yaml from 'yaml';
88import chalk from 'chalk';
99import { createRequire } from 'node:module';
1010import { addMissingConfigValues } from './src/config-init.js';
1111
1212/**
1313 * Colorizes console output.
@@ -88,7 +88,7 @@ function createDefaultFiles() {
8888 );
8989 } else {
9090 throw new Error(
9191 'FATAL: Unexpected default file format in `postserver-installinit.js#createDefaultFiles()`.',
9292 );
9393 }
9494 } catch (error) {
start.sh+2 -1
@@ -10,7 +10,8 @@ fi
1010
1111echo "Installing Node Modules..."
1212export NODE_ENV=production
1313npm iinstall --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
14+npm run init
1415
1516echo "Entering SillyTavern..."
1617node "server.js" "$@"