@rocapine/community 0.10.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.
@@ -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
- fs.rmSync(destDir, { recursive: true, force: true });
153
- fs.cpSync(path.join(functionsSrcRoot, fnName), destDir, {
154
- recursive: true,
155
- filter: install_shared_1.isShippedFunctionFile,
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
- const touchedFunctionFiles = touchedFunctionDirs.flatMap((d) => (0, install_shared_1.listFilesRecursive)(d).map((f) => (0, install_shared_1.toRelativePosix)(cwd, f)));
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 functionDirDiffers(srcDir, destDir) {
232
- const rel = (dir) => new Set((0, install_shared_1.listFilesRecursive)(dir)
233
+ function shippedRelFiles(srcDir) {
234
+ return (0, install_shared_1.listFilesRecursive)(srcDir)
233
235
  .filter(install_shared_1.isShippedFunctionFile)
234
- .map((f) => path.relative(dir, f)));
235
- const srcRel = rel(srcDir);
236
- const destRel = rel(destDir);
237
- if (srcRel.size !== destRel.size)
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
- for (const rel of srcRel) {
240
- if (!destRel.has(rel))
241
- return true;
242
- const a = fs.readFileSync(path.join(srcDir, rel));
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocapine/community",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "CLI to install, upgrade and adopt the Rocapine Community SDK's Supabase backend (migrations, Edge Functions) into a project.",
5
5
  "license": "MIT",
6
6
  "repository": {