stackpatch 1.1.1 ā 1.1.2
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/bin/stackpatch.ts +79 -8
- package/package.json +1 -1
package/bin/stackpatch.ts
CHANGED
|
@@ -1911,24 +1911,95 @@ async function main() {
|
|
|
1911
1911
|
}
|
|
1912
1912
|
}
|
|
1913
1913
|
|
|
1914
|
-
// Step 3: Restore modified files from
|
|
1914
|
+
// Step 3: Restore modified files from originalContent in manifest
|
|
1915
|
+
// This is more reliable than backups since it contains the true original content
|
|
1915
1916
|
console.log(chalk.white("\nš Restoring modified files..."));
|
|
1916
1917
|
for (const modified of manifest.files.modified) {
|
|
1917
|
-
const backupPath = path.join(target, ".stackpatch", "backups", modified.path.replace(/\//g, "_").replace(/\\/g, "_"));
|
|
1918
1918
|
const originalPath = path.join(target, modified.path);
|
|
1919
1919
|
|
|
1920
|
-
if (
|
|
1920
|
+
if (modified.originalContent !== undefined) {
|
|
1921
1921
|
try {
|
|
1922
|
-
|
|
1922
|
+
// Restore from originalContent in manifest (most reliable)
|
|
1923
|
+
const originalDir = path.dirname(originalPath);
|
|
1924
|
+
if (!fs.existsSync(originalDir)) {
|
|
1925
|
+
fs.mkdirSync(originalDir, { recursive: true });
|
|
1926
|
+
}
|
|
1927
|
+
fs.writeFileSync(originalPath, modified.originalContent, "utf-8");
|
|
1923
1928
|
console.log(chalk.green(` ā Restored: ${modified.path}`));
|
|
1924
1929
|
restoredCount++;
|
|
1925
1930
|
} catch (error) {
|
|
1926
|
-
|
|
1927
|
-
|
|
1931
|
+
// Fallback to backup file if originalContent restore fails
|
|
1932
|
+
const backupPath = path.join(target, ".stackpatch", "backups", modified.path.replace(/\//g, "_").replace(/\\/g, "_"));
|
|
1933
|
+
if (fs.existsSync(backupPath)) {
|
|
1934
|
+
try {
|
|
1935
|
+
restoreFile(backupPath, originalPath);
|
|
1936
|
+
console.log(chalk.green(` ā Restored (from backup): ${modified.path}`));
|
|
1937
|
+
restoredCount++;
|
|
1938
|
+
} catch (backupError) {
|
|
1939
|
+
console.log(chalk.yellow(` ā Could not restore: ${modified.path}`));
|
|
1940
|
+
failedRestorations.push(modified.path);
|
|
1941
|
+
}
|
|
1942
|
+
} else {
|
|
1943
|
+
console.log(chalk.yellow(` ā Could not restore: ${modified.path} (no backup found)`));
|
|
1944
|
+
failedRestorations.push(modified.path);
|
|
1945
|
+
}
|
|
1928
1946
|
}
|
|
1929
1947
|
} else {
|
|
1930
|
-
|
|
1931
|
-
|
|
1948
|
+
// Fallback: try to restore from backup file
|
|
1949
|
+
const backupPath = path.join(target, ".stackpatch", "backups", modified.path.replace(/\//g, "_").replace(/\\/g, "_"));
|
|
1950
|
+
if (fs.existsSync(backupPath)) {
|
|
1951
|
+
try {
|
|
1952
|
+
restoreFile(backupPath, originalPath);
|
|
1953
|
+
console.log(chalk.green(` ā Restored (from backup): ${modified.path}`));
|
|
1954
|
+
restoredCount++;
|
|
1955
|
+
} catch (error) {
|
|
1956
|
+
console.log(chalk.yellow(` ā Could not restore: ${modified.path}`));
|
|
1957
|
+
failedRestorations.push(modified.path);
|
|
1958
|
+
}
|
|
1959
|
+
} else {
|
|
1960
|
+
console.log(chalk.yellow(` ā Backup not found and no originalContent: ${modified.path}`));
|
|
1961
|
+
failedRestorations.push(modified.path);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// Safety check: If file still contains StackPatch components after restore, manually remove them
|
|
1966
|
+
if (fs.existsSync(originalPath) && modified.path.includes("layout.tsx")) {
|
|
1967
|
+
try {
|
|
1968
|
+
let content = fs.readFileSync(originalPath, "utf-8");
|
|
1969
|
+
let needsUpdate = false;
|
|
1970
|
+
|
|
1971
|
+
// Remove AuthSessionProvider import
|
|
1972
|
+
if (content.includes("AuthSessionProvider") && content.includes("session-provider")) {
|
|
1973
|
+
content = content.replace(/import\s*{\s*AuthSessionProvider\s*}\s*from\s*["'][^"']*session-provider[^"']*["'];\s*\n?/g, "");
|
|
1974
|
+
needsUpdate = true;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
// Remove Toaster import
|
|
1978
|
+
if (content.includes("Toaster") && content.includes("toaster")) {
|
|
1979
|
+
content = content.replace(/import\s*{\s*Toaster\s*}\s*from\s*["'][^"']*toaster[^"']*["'];\s*\n?/g, "");
|
|
1980
|
+
needsUpdate = true;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// Remove AuthSessionProvider wrapper
|
|
1984
|
+
if (content.includes("<AuthSessionProvider>") && content.includes("</AuthSessionProvider>")) {
|
|
1985
|
+
content = content.replace(/<AuthSessionProvider>\s*/g, "");
|
|
1986
|
+
content = content.replace(/\s*<\/AuthSessionProvider>/g, "");
|
|
1987
|
+
needsUpdate = true;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
// Remove Toaster component
|
|
1991
|
+
if (content.includes("<Toaster")) {
|
|
1992
|
+
content = content.replace(/<Toaster\s*\/?>\s*\n?\s*/g, "");
|
|
1993
|
+
needsUpdate = true;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
if (needsUpdate) {
|
|
1997
|
+
fs.writeFileSync(originalPath, content, "utf-8");
|
|
1998
|
+
console.log(chalk.green(` ā Cleaned up StackPatch components from: ${modified.path}`));
|
|
1999
|
+
}
|
|
2000
|
+
} catch (error) {
|
|
2001
|
+
// Ignore errors in cleanup
|
|
2002
|
+
}
|
|
1932
2003
|
}
|
|
1933
2004
|
}
|
|
1934
2005
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stackpatch",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Composable frontend features for modern React & Next.js apps - Add authentication, UI components, and more with zero configuration",
|
|
5
5
|
"main": "bin/stackpatch.ts",
|
|
6
6
|
"type": "module",
|