rootless-config 1.8.1 → 1.8.3
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/package.json +1 -1
- package/src/cli/commands/migrate.js +18 -2
- package/src/core/scriptPatcher.js +19 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*-------- rootless migrate — moves existing root configs into .root container --------*/
|
|
2
2
|
|
|
3
3
|
import path from 'node:path'
|
|
4
|
-
import { readdir, unlink } from 'node:fs/promises'
|
|
4
|
+
import { readdir, readFile, unlink } from 'node:fs/promises'
|
|
5
5
|
import { createLogger } from '../../utils/logger.js'
|
|
6
6
|
import { fileExists, ensureDir, atomicWrite, copyFile, readJsonFile } from '../../utils/fsUtils.js'
|
|
7
7
|
import { confirm } from '../../utils/prompt.js'
|
|
@@ -94,7 +94,7 @@ export default {
|
|
|
94
94
|
if (isCleanMode) {
|
|
95
95
|
// For PS1 server scripts: patch $root before writing to .root/assets/
|
|
96
96
|
if (name.endsWith('.ps1')) {
|
|
97
|
-
const raw = await
|
|
97
|
+
const raw = await readFile(src, 'utf8')
|
|
98
98
|
const patched = patchServerScript(raw)
|
|
99
99
|
if (patched) {
|
|
100
100
|
await atomicWrite(dest, patched)
|
|
@@ -103,6 +103,22 @@ export default {
|
|
|
103
103
|
continue
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
// For .cmd/.bat launcher scripts: fix relative path to .ps1 → use %~dp0
|
|
107
|
+
// so the ps1 is found relative to the cmd file's own location
|
|
108
|
+
if (name.endsWith('.cmd') || name.endsWith('.bat')) {
|
|
109
|
+
const raw = await readFile(src, 'utf8')
|
|
110
|
+
// Replace: -File .server.ps1 → -File "%~dp0.server.ps1"
|
|
111
|
+
const patched = raw.replace(
|
|
112
|
+
/(-File\s+)(?!")([^\s"]+\.ps1)/gi,
|
|
113
|
+
(_, flag, ps1) => `${flag}"%~dp0${ps1}"`
|
|
114
|
+
)
|
|
115
|
+
if (patched !== raw) {
|
|
116
|
+
await atomicWrite(dest, patched)
|
|
117
|
+
await unlink(src)
|
|
118
|
+
logger.success(`Moved+patched .root/${destSubdir}/${name} (ps1 path → %~dp0-relative)`)
|
|
119
|
+
continue
|
|
120
|
+
}
|
|
121
|
+
}
|
|
106
122
|
// Binary-safe stream copy — works for .png, .js, .css, etc.
|
|
107
123
|
await copyFile(src, dest)
|
|
108
124
|
await unlink(src)
|
|
@@ -524,6 +524,25 @@ $root = (Get-Item "$PSScriptRoot\\..\\..").FullName.TrimEnd('\\') + '\
|
|
|
524
524
|
)
|
|
525
525
|
}
|
|
526
526
|
|
|
527
|
+
// 4. Null guard + assets fallback for directory-with-no-index case
|
|
528
|
+
// When $root has the directory but no index.html, $filePath becomes $null → Test-Path throws.
|
|
529
|
+
// Fix: check $assetsRoot for the same path, then add null guard on the leaf check.
|
|
530
|
+
const leafCheckLine = ' if (Test-Path $filePath -PathType Leaf) {'
|
|
531
|
+
if (out.includes(leafCheckLine)) {
|
|
532
|
+
out = out.replace(
|
|
533
|
+
leafCheckLine,
|
|
534
|
+
` # rootless: if $root dir had no index, check $assetsRoot dir too
|
|
535
|
+
if ($filePath -eq $null -and $relPath -ne '') {
|
|
536
|
+
$assetsDir = [System.IO.Path]::GetFullPath((Join-Path $assetsRoot $relPath))
|
|
537
|
+
foreach ($idx in @("index.html", "index.htm")) {
|
|
538
|
+
$idxPath = Join-Path $assetsDir $idx
|
|
539
|
+
if (Test-Path $idxPath -PathType Leaf) { $filePath = $idxPath; break }
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if ($filePath -ne $null -and (Test-Path $filePath -PathType Leaf)) {`
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
|
|
527
546
|
return out === content ? null : out
|
|
528
547
|
}
|
|
529
548
|
|