@rocapine/community 0.9.0 → 0.10.1
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/lib/commands/upgrade.js
CHANGED
|
@@ -95,7 +95,7 @@ async function runUpgrade(options = {}) {
|
|
|
95
95
|
if (!fs.existsSync(destDir)) {
|
|
96
96
|
newFunctions.push(fnName);
|
|
97
97
|
}
|
|
98
|
-
else if (functionDirDiffers(srcDir, destDir)) {
|
|
98
|
+
else if (functionDirDiffers(srcDir, destDir, staleFiles(srcDir, destDir, cwd, manifest.installedFiles))) {
|
|
99
99
|
changedFunctions.push(fnName);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -145,15 +145,16 @@ async function runUpgrade(options = {}) {
|
|
|
145
145
|
createdFunctionDirs.push(destDir);
|
|
146
146
|
}
|
|
147
147
|
for (const fnName of changedFunctions) {
|
|
148
|
+
const srcDir = path.join(functionsSrcRoot, fnName);
|
|
148
149
|
const destDir = path.join(functionsDestRoot, fnName);
|
|
149
150
|
const backupDir = fs.mkdtempSync(path.join(os.tmpdir(), "community-sdk-upgrade-backup-"));
|
|
150
151
|
fs.cpSync(destDir, backupDir, { recursive: true });
|
|
151
152
|
backups.push({ destDir, backupDir });
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
});
|
|
153
|
+
// Only the SDK's own files: a host keeps its files in the same folder
|
|
154
|
+
// (e.g. its own helpers under `_shared/`), so the folder is never wiped.
|
|
155
|
+
for (const stale of staleFiles(srcDir, destDir, cwd, manifest.installedFiles))
|
|
156
|
+
fs.rmSync(stale, { force: true });
|
|
157
|
+
fs.cpSync(srcDir, destDir, { recursive: true, force: true, filter: install_shared_1.isShippedFunctionFile });
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
catch (err) {
|
|
@@ -179,7 +180,8 @@ async function runUpgrade(options = {}) {
|
|
|
179
180
|
...changedFunctions.map((fnName) => path.join(functionsDestRoot, fnName)),
|
|
180
181
|
];
|
|
181
182
|
const touchedFunctionDirPrefixes = touchedFunctionDirs.map((d) => `${(0, install_shared_1.toRelativePosix)(cwd, d)}/`);
|
|
182
|
-
|
|
183
|
+
// The template's files only — never host files living in the same folder.
|
|
184
|
+
const touchedFunctionFiles = touchedFunctionDirs.flatMap((d) => shippedRelFiles(path.join(functionsSrcRoot, path.basename(d))).map((rel) => (0, install_shared_1.toRelativePosix)(cwd, path.join(d, rel))));
|
|
183
185
|
const survivingOldFiles = manifest.installedFiles.filter((f) => !touchedFunctionDirPrefixes.some((prefix) => f.startsWith(prefix)));
|
|
184
186
|
const installedFiles = [
|
|
185
187
|
...new Set([...survivingOldFiles, ...touchedFunctionFiles, ...addedMigrations]),
|
|
@@ -228,23 +230,30 @@ function reconstructInstalledTemplateIds(installedFiles) {
|
|
|
228
230
|
}
|
|
229
231
|
return ids;
|
|
230
232
|
}
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
+
function shippedRelFiles(srcDir) {
|
|
234
|
+
return (0, install_shared_1.listFilesRecursive)(srcDir)
|
|
233
235
|
.filter(install_shared_1.isShippedFunctionFile)
|
|
234
|
-
.map((f) => path.relative(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
.map((f) => path.relative(srcDir, f));
|
|
237
|
+
}
|
|
238
|
+
/** Files a previous upgrade installed in `destDir` (per the manifest) that the
|
|
239
|
+
* current template no longer ships. */
|
|
240
|
+
function staleFiles(srcDir, destDir, cwd, installedFiles) {
|
|
241
|
+
const shipped = new Set(shippedRelFiles(srcDir).map((rel) => rel.split(path.sep).join("/")));
|
|
242
|
+
const prefix = `${(0, install_shared_1.toRelativePosix)(cwd, destDir)}/`;
|
|
243
|
+
return installedFiles
|
|
244
|
+
.filter((f) => f.startsWith(prefix) && !shipped.has(f.slice(prefix.length)))
|
|
245
|
+
.map((f) => path.join(cwd, f))
|
|
246
|
+
.filter((f) => fs.existsSync(f));
|
|
247
|
+
}
|
|
248
|
+
/** True when a template file is missing or different in `destDir`, or an old
|
|
249
|
+
* SDK file is left over. Files the host added to the folder don't count. */
|
|
250
|
+
function functionDirDiffers(srcDir, destDir, stale) {
|
|
251
|
+
if (stale.length > 0)
|
|
238
252
|
return true;
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const b = fs.readFileSync(path.join(destDir, rel));
|
|
244
|
-
if (!a.equals(b))
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
253
|
+
return shippedRelFiles(srcDir).some((rel) => {
|
|
254
|
+
const dest = path.join(destDir, rel);
|
|
255
|
+
return (!fs.existsSync(dest) || !fs.readFileSync(path.join(srcDir, rel)).equals(fs.readFileSync(dest)));
|
|
256
|
+
});
|
|
248
257
|
}
|
|
249
258
|
function printSummary(log, onWarn, summary) {
|
|
250
259
|
log("");
|
package/package.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- community-sdk reaction/003_retract.sql
|
|
2
|
+
-- A reaction can be withdrawn, like a like: the client deletes its own row.
|
|
3
|
+
-- Until now only select/insert existed, so a delete() was a silent no-op.
|
|
4
|
+
-- The coalesced push only reads rows still present, so a reaction withdrawn
|
|
5
|
+
-- before the digest runs is never announced.
|
|
6
|
+
drop policy if exists "unreact own" on public.post_reactions;
|
|
7
|
+
create policy "unreact own" on public.post_reactions for delete to authenticated
|
|
8
|
+
using (user_id = auth.uid());
|