create-wordjs 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +50 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -46,6 +46,11 @@ const https = require('https');
|
|
|
46
46
|
const crypto = require('crypto');
|
|
47
47
|
const { spawn, spawnSync } = require('child_process');
|
|
48
48
|
|
|
49
|
+
// Every npm this process starts (release:install and the npm installs inside it, the server scripts)
|
|
50
|
+
// inherits this: npm's "new major version of npm available" notice otherwise lands in the middle of
|
|
51
|
+
// the install output, and it is advice about the operator's npm, not about the site.
|
|
52
|
+
process.env.npm_config_update_notifier = 'false';
|
|
53
|
+
|
|
49
54
|
const HELP = `
|
|
50
55
|
create-wordjs — bootstrap or upgrade a WordJS site with one command
|
|
51
56
|
|
|
@@ -103,10 +108,11 @@ Separate mode (three machines) — run one command per machine:
|
|
|
103
108
|
npx create-wordjs@latest join frontend --gateway 10.0.0.1 --token <t> --ca-hash <fp> --advertise 10.0.0.3
|
|
104
109
|
(join needs 'openssl' on PATH. See documentation/separate-mode.md.)
|
|
105
110
|
|
|
106
|
-
Upgrading preserves your database (backend/data), uploads (backend/uploads),
|
|
107
|
-
(wordjs-config.json + gateway secrets) and any user-installed plugins;
|
|
108
|
-
runs the dependency install. Database schema migrations apply
|
|
109
|
-
starts — then restart WordJS (e.g. 'systemctl restart
|
|
111
|
+
Upgrading preserves your database (backend/data), uploads (backend/uploads), backups
|
|
112
|
+
(backend/backups), config (wordjs-config.json + gateway secrets) and any user-installed plugins;
|
|
113
|
+
it replaces the app code and runs the dependency install. Database schema migrations apply
|
|
114
|
+
automatically the next time the server starts — then restart WordJS (e.g. 'systemctl restart
|
|
115
|
+
wordjs', or stop it and 'npm run start:mono').
|
|
110
116
|
`;
|
|
111
117
|
|
|
112
118
|
function fail(message, hint) {
|
|
@@ -999,6 +1005,7 @@ function confirm(question) {
|
|
|
999
1005
|
const PRESERVE_ON_UPGRADE = new Set([
|
|
1000
1006
|
'backend/data', // the database (+ WAL/SHM, ssl/, imports/)
|
|
1001
1007
|
'backend/uploads', // user uploads / media / fonts
|
|
1008
|
+
'backend/backups', // the site's own backups: a bundle never adds to or replaces them
|
|
1002
1009
|
'backend/wordjs-config.json', // site config + secrets
|
|
1003
1010
|
'backend/.env',
|
|
1004
1011
|
'.env',
|
|
@@ -1048,6 +1055,39 @@ async function obtainReleaseToTemp(opts) {
|
|
|
1048
1055
|
}
|
|
1049
1056
|
}
|
|
1050
1057
|
|
|
1058
|
+
/**
|
|
1059
|
+
* The account that owns the site, when this upgrade runs as root and the site is not root's: the files
|
|
1060
|
+
* the upgrade creates are given back to it (restoreInstallOwner). Read from the install directory before
|
|
1061
|
+
* anything is written. Only POSIX root can create files another account would have to own.
|
|
1062
|
+
*/
|
|
1063
|
+
function installDirOwner(installDir) {
|
|
1064
|
+
if (typeof process.getuid !== 'function' || process.getuid() !== 0) return null;
|
|
1065
|
+
try {
|
|
1066
|
+
const st = fs.statSync(installDir);
|
|
1067
|
+
return st.uid === 0 ? null : { uid: st.uid, gid: st.gid };
|
|
1068
|
+
} catch {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* The documented upgrade is `sudo npx create-wordjs upgrade`, and every file it CREATES — the new
|
|
1075
|
+
* frontend/.next and backend/dist, new modules, node_modules from release:install — then belonged to
|
|
1076
|
+
* root while the service runs as the site's account (--systemd: `wordjs`): Next could no longer create
|
|
1077
|
+
* frontend/.next/cache and every render logged EACCES until someone ran chown by hand.
|
|
1078
|
+
*/
|
|
1079
|
+
function restoreInstallOwner(installDir, owner) {
|
|
1080
|
+
if (!owner) return;
|
|
1081
|
+
const spec = `${owner.uid}:${owner.gid}`;
|
|
1082
|
+
// -h: a symbolic link is re-owned itself, never what it points at.
|
|
1083
|
+
const r = spawnSync('chown', ['-R', '-h', spec, installDir], { stdio: 'inherit' });
|
|
1084
|
+
if (r.status === 0) {
|
|
1085
|
+
console.log(`\n Gave the upgraded files back to the site's owner (${spec}).`);
|
|
1086
|
+
} else {
|
|
1087
|
+
console.warn(`\n ⚠ Could not restore the site's owner. Run: chown -R -h ${spec} ${installDir}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1051
1091
|
async function upgrade(opts) {
|
|
1052
1092
|
const installDir = path.resolve(process.cwd(), opts.dir);
|
|
1053
1093
|
const pkgPath = path.join(installDir, 'package.json');
|
|
@@ -1119,6 +1159,9 @@ async function upgrade(opts) {
|
|
|
1119
1159
|
console.warn(` (could not write config backup: ${e.message} — continuing; your DB/uploads/config are still preserved in place)`);
|
|
1120
1160
|
}
|
|
1121
1161
|
|
|
1162
|
+
// Read before the overlay creates any file (restoreInstallOwner).
|
|
1163
|
+
const siteOwner = installDirOwner(installDir);
|
|
1164
|
+
|
|
1122
1165
|
// Clean-replace the build outputs so no stale chunks linger, then overlay the rest.
|
|
1123
1166
|
for (const rel of CLEAN_REPLACE_ON_UPGRADE) {
|
|
1124
1167
|
const target = path.join(installDir, rel);
|
|
@@ -1139,6 +1182,7 @@ async function upgrade(opts) {
|
|
|
1139
1182
|
} else {
|
|
1140
1183
|
console.log('\n --no-install: skipped dependency sync. Run "npm run release:install" yourself if deps changed.');
|
|
1141
1184
|
}
|
|
1185
|
+
restoreInstallOwner(installDir, siteOwner);
|
|
1142
1186
|
|
|
1143
1187
|
const line = '━'.repeat(64);
|
|
1144
1188
|
console.log(`\n${line}`);
|
|
@@ -1424,5 +1468,7 @@ if (require.main === module) {
|
|
|
1424
1468
|
module.exports = {
|
|
1425
1469
|
pickBundleAsset, pickChecksumAsset, extractZip, normalizeSha256, parseChecksumFile, classifyZipSource, sha256File,
|
|
1426
1470
|
parseArgs, buildSystemdFiles, systemdInstallSteps, writeSystemdFiles,
|
|
1471
|
+
copyMerge, PRESERVE_ON_UPGRADE,
|
|
1427
1472
|
sysctlDropIn, serviceUserProblem, systemdPreflight, createSystemdStagingDir, LOW_PORT_ADVICE, HELP, installedFileMode,
|
|
1473
|
+
installDirOwner, restoreInstallOwner,
|
|
1428
1474
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-wordjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Create a WordJS site with one command — the self-hosted CMS where third-party plugins run in an OS-isolated process with per-capability permission grants. SSR/SEO out of the box, SQLite by default, no PHP.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jaime Martinez (https://github.com/jaimemartinez)",
|