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 -13Ignore whitespace
.npmrc+2 -0
@@ -0,0 +1,2 @@
1ignore-scripts=true
2min-release-age=7
Dockerfile+1 -1
@@ -19,7 +19,7 @@ COPY --chown=node:node . ./
1919
20RUN \20RUN \
21 echo "*** Install npm packages ***" && \21 echo "*** Install npm packages ***" && \
22 npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev && npm cache clean --force22 npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts && npm cache clean --force
2323
24# Create config directory and link config.yaml. Added hardcoded dirs(constants.js?)24# Create config directory and link config.yaml. Added hardcoded dirs(constants.js?)
25# that must be present for Non-Root Mode and volumeless docker runs.25# that must be present for Non-Root Mode and volumeless docker runs.
Start.bat+2 -1
@@ -1,7 +1,8 @@
1@echo off1@echo off
2pushd %~dp02pushd %~dp0
3set NODE_ENV=production3set NODE_ENV=production
4call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev4call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
5call npm run init
5node server.js %*6node server.js %*
6pause7pause
7popd8popd
UpdateAndStart.bat+2 -1
@@ -20,7 +20,8 @@ if %errorlevel% neq 0 (
20 )20 )
21)21)
22set NODE_ENV=production22set NODE_ENV=production
23call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev23call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
24call npm run init
24node server.js %*25node server.js %*
25:end26:end
26pause27pause
UpdateForkAndStart.bat+2 -1
@@ -102,7 +102,8 @@ if %errorlevel% neq 0 (
102102
103echo Installing npm packages and starting server103echo Installing npm packages and starting server
104set NODE_ENV=production104set NODE_ENV=production
105call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev105call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
106call npm run init
106node server.js %*107node server.js %*
107108
108:end109:end
docker/docker-entrypoint.sh+3 -3
@@ -1,6 +1,6 @@
1#!/bin/sh1#!/bin/sh
22
3# Function to handle startup logic (Config check + Postinstall + Start)3# Function to handle startup logic (Config check + init + Start)
4start_sillytavern() {4start_sillytavern() {
5 local PREFIX="$1"5 local PREFIX="$1"
6 shift # Remove the first argument (PREFIX) so $@ contains the rest6 shift # Remove the first argument (PREFIX) so $@ contains the rest
@@ -11,8 +11,8 @@ start_sillytavern() {
11 $PREFIX cp "default/config.yaml" "config/config.yaml"11 $PREFIX cp "default/config.yaml" "config/config.yaml"
12 fi12 fi
1313
14 # Execute postinstall to auto-populate config.yaml with missing values14 # Execute init script to auto-populate config.yaml with missing values
15 $PREFIX npm run postinstall15 $PREFIX npm run init
1616
17 # Start the server17 # Start the server
18 exec $PREFIX node server.js --listen "$@"18 exec $PREFIX node server.js --listen "$@"
package-lock.json+0 -1
@@ -7,7 +7,6 @@
7 "": {7 "": {
8 "name": "sillytavern",8 "name": "sillytavern",
9 "version": "1.17.0",9 "version": "1.17.0",
10 "hasInstallScript": true,
11 "license": "AGPL-3.0",10 "license": "AGPL-3.0",
12 "dependencies": {11 "dependencies": {
13 "@adobe/css-tools": "^4.4.4",12 "@adobe/css-tools": "^4.4.4",
package.json+1 -1
@@ -115,6 +115,7 @@
115 },115 },
116 "version": "1.17.0",116 "version": "1.17.0",
117 "scripts": {117 "scripts": {
118 "init": "node src/server-init.js",
118 "start": "node server.js",119 "start": "node server.js",
119 "debug": "node --inspect server.js",120 "debug": "node --inspect server.js",
120 "start:global": "node server.js --global",121 "start:global": "node server.js --global",
@@ -122,7 +123,6 @@
122 "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",123 "start:deno": "deno run --allow-run --allow-net --allow-read --allow-write --allow-sys --allow-env server.js",
123 "start:bun": "bun server.js",124 "start:bun": "bun server.js",
124 "start:no-csrf": "node server.js --disableCsrf",125 "start:no-csrf": "node server.js --disableCsrf",
125 "postinstall": "node post-install.js",
126 "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js",126 "lint": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js",
127 "lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix",127 "lint:fix": "eslint \"src/**/*.js\" \"public/**/*.js\" ./*.js --fix",
128 "plugins:update": "node plugins update",128 "plugins:update": "node plugins update",
src/electron/Start.bat+1 -1
@@ -1,6 +1,6 @@
1@echo off1@echo off
2pushd %~dp02pushd %~dp0
3call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev3call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
4npm run start server.js %*4npm run start server.js %*
5pause5pause
6popd6popd
post-install.js → src/server-init.js+2 -2
@@ -7,7 +7,7 @@ import process from 'node:process';
7import yaml from 'yaml';7import yaml from 'yaml';
8import chalk from 'chalk';8import chalk from 'chalk';
9import { createRequire } from 'node:module';9import { createRequire } from 'node:module';
10import { addMissingConfigValues } from './src/config-init.js';10import { addMissingConfigValues } from './config-init.js';
1111
12/**12/**
13 * Colorizes console output.13 * Colorizes console output.
@@ -88,7 +88,7 @@ function createDefaultFiles() {
88 );88 );
89 } else {89 } else {
90 throw new Error(90 throw new Error(
91 'FATAL: Unexpected default file format in `post-install.js#createDefaultFiles()`.',91 'FATAL: Unexpected default file format in `server-init.js#createDefaultFiles()`.',
92 );92 );
93 }93 }
94 } catch (error) {94 } catch (error) {
start.sh+2 -1
@@ -10,7 +10,8 @@ fi
1010
11echo "Installing Node Modules..."11echo "Installing Node Modules..."
12export NODE_ENV=production12export NODE_ENV=production
13npm i --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev13npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts
14npm run init
1415
15echo "Entering SillyTavern..."16echo "Entering SillyTavern..."
16node "server.js" "$@"17node "server.js" "$@"