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
Signed| @@ -0,0 +1,2 @@ | |||
| 1 | ignore-scripts=true | ||
| 2 | min-release-age=7 | ||
| @@ -19,7 +19,7 @@ COPY --chown=node:node . ./ | |||
| 19 | 19 | ||
| 20 | RUN \ | 20 | RUN \ |
| 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 --force | 22 | npm ci --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts && npm cache clean --force |
| 23 | 23 | ||
| 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. |
| @@ -1,7 +1,8 @@ | |||
| 1 | @echo off | 1 | @echo off |
| 2 | pushd %~dp0 | 2 | pushd %~dp0 |
| 3 | set NODE_ENV=production | 3 | set NODE_ENV=production |
| 4 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev | 4 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts |
| 5 | call npm run init | ||
| 5 | node server.js %* | 6 | node server.js %* |
| 6 | pause | 7 | pause |
| 7 | popd | 8 | popd |
| @@ -20,7 +20,8 @@ if %errorlevel% neq 0 ( | |||
| 20 | ) | 20 | ) |
| 21 | ) | 21 | ) |
| 22 | set NODE_ENV=production | 22 | set NODE_ENV=production |
| 23 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev | 23 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts |
| 24 | call npm run init | ||
| 24 | node server.js %* | 25 | node server.js %* |
| 25 | :end | 26 | :end |
| 26 | pause | 27 | pause |
| @@ -102,7 +102,8 @@ if %errorlevel% neq 0 ( | |||
| 102 | 102 | ||
| 103 | echo Installing npm packages and starting server | 103 | echo Installing npm packages and starting server |
| 104 | set NODE_ENV=production | 104 | set NODE_ENV=production |
| 105 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev | 105 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts |
| 106 | call npm run init | ||
| 106 | node server.js %* | 107 | node server.js %* |
| 107 | 108 | ||
| 108 | :end | 109 | :end |
| @@ -1,6 +1,6 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | 2 | ||
| 3 | # Function to handle startup logic (Config check + Postinstall + Start) | 3 | # Function to handle startup logic (Config check + init + Start) |
| 4 | start_sillytavern() { | 4 | start_sillytavern() { |
| 5 | local PREFIX="$1" | 5 | local PREFIX="$1" |
| 6 | shift # Remove the first argument (PREFIX) so $@ contains the rest | 6 | 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 | fi | 12 | fi |
| 13 | 13 | ||
| 14 | # Execute postinstall to auto-populate config.yaml with missing values | 14 | # Execute init script to auto-populate config.yaml with missing values |
| 15 | $PREFIX npm run postinstall | 15 | $PREFIX npm run init |
| 16 | 16 | ||
| 17 | # Start the server | 17 | # Start the server |
| 18 | exec $PREFIX node server.js --listen "$@" | 18 | exec $PREFIX node server.js --listen "$@" |
| @@ -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", |
| @@ -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", |
| @@ -1,6 +1,6 @@ | |||
| 1 | @echo off | 1 | @echo off |
| 2 | pushd %~dp0 | 2 | pushd %~dp0 |
| 3 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev | 3 | call npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts |
| 4 | npm run start server.js %* | 4 | npm run start server.js %* |
| 5 | pause | 5 | pause |
| 6 | popd | 6 | popd |
| @@ -7,7 +7,7 @@ import process from 'node:process'; | |||
| 7 | import yaml from 'yaml'; | 7 | import yaml from 'yaml'; |
| 8 | import chalk from 'chalk'; | 8 | import chalk from 'chalk'; |
| 9 | import { createRequire } from 'node:module'; | 9 | import { createRequire } from 'node:module'; |
| 10 | import { addMissingConfigValues } from './src/config-init.js'; | 10 | import { addMissingConfigValues } from './config-init.js'; |
| 11 | 11 | ||
| 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) { |
| @@ -10,7 +10,8 @@ fi | |||
| 10 | 10 | ||
| 11 | echo "Installing Node Modules..." | 11 | echo "Installing Node Modules..." |
| 12 | export NODE_ENV=production | 12 | export NODE_ENV=production |
| 13 | npm i --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev | 13 | npm install --no-save --no-audit --no-fund --loglevel=error --no-progress --omit=dev --ignore-scripts |
| 14 | npm run init | ||
| 14 | 15 | ||
| 15 | echo "Entering SillyTavern..." | 16 | echo "Entering SillyTavern..." |
| 16 | node "server.js" "$@" | 17 | node "server.js" "$@" |