@rocapine/community 0.10.0 → 0.10.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.
@@ -95,7 +95,9 @@ async function runInit(options = {}) {
95
95
  continue;
96
96
  const destDir = path.join(functionsDestRoot, fnName);
97
97
  fs.cpSync(srcDir, destDir, { recursive: true, filter: install_shared_1.isShippedFunctionFile });
98
- writtenPaths.push(...(0, install_shared_1.listFilesRecursive)(destDir));
98
+ // Only what we copied: a host file already in the folder (e.g. `_shared`)
99
+ // must neither land in the manifest nor be deleted by the rollback below.
100
+ writtenPaths.push(...(0, install_shared_1.shippedRelFiles)(srcDir).map((rel) => path.join(destDir, rel)));
99
101
  }
100
102
  }
101
103
  catch (err) {
@@ -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) => (0, install_shared_1.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,25 @@ 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
- .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)
233
+ /** Files a previous upgrade installed in `destDir` (per the manifest) that the
234
+ * current template no longer ships. */
235
+ function staleFiles(srcDir, destDir, cwd, installedFiles) {
236
+ const shipped = new Set((0, install_shared_1.shippedRelFiles)(srcDir).map((rel) => rel.split(path.sep).join("/")));
237
+ const prefix = `${(0, install_shared_1.toRelativePosix)(cwd, destDir)}/`;
238
+ return installedFiles
239
+ .filter((f) => f.startsWith(prefix) && !shipped.has(f.slice(prefix.length)))
240
+ .map((f) => path.join(cwd, f))
241
+ .filter((f) => fs.existsSync(f));
242
+ }
243
+ /** True when a template file is missing or different in `destDir`, or an old
244
+ * SDK file is left over. Files the host added to the folder don't count. */
245
+ function functionDirDiffers(srcDir, destDir, stale) {
246
+ if (stale.length > 0)
238
247
  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;
248
+ return (0, install_shared_1.shippedRelFiles)(srcDir).some((rel) => {
249
+ const dest = path.join(destDir, rel);
250
+ return (!fs.existsSync(dest) || !fs.readFileSync(path.join(srcDir, rel)).equals(fs.readFileSync(dest)));
251
+ });
248
252
  }
249
253
  function printSummary(log, onWarn, summary) {
250
254
  log("");
@@ -54,6 +54,8 @@ export declare function addSeconds(date: Date, seconds: number): Date;
54
54
  * functions, and ignored when diffing a host's function dir. */
55
55
  export declare function isShippedFunctionFile(file: string): boolean;
56
56
  export declare function listFilesRecursive(dir: string): string[];
57
+ /** A template function dir's shipped files, relative to `srcDir`. */
58
+ export declare function shippedRelFiles(srcDir: string): string[];
57
59
  export declare function toRelativePosix(base: string, target: string): string;
58
60
  /** Resolves `dirRel` against `cwd`, throwing if it would escape the project root. */
59
61
  export declare function resolveContainedDir(cwd: string, dirRel: string): string;
@@ -46,6 +46,7 @@ exports.formatTimestamp = formatTimestamp;
46
46
  exports.addSeconds = addSeconds;
47
47
  exports.isShippedFunctionFile = isShippedFunctionFile;
48
48
  exports.listFilesRecursive = listFilesRecursive;
49
+ exports.shippedRelFiles = shippedRelFiles;
49
50
  exports.toRelativePosix = toRelativePosix;
50
51
  exports.resolveContainedDir = resolveContainedDir;
51
52
  exports.settingsSeedSql = settingsSeedSql;
@@ -207,6 +208,12 @@ function listFilesRecursive(dir) {
207
208
  }
208
209
  return files;
209
210
  }
211
+ /** A template function dir's shipped files, relative to `srcDir`. */
212
+ function shippedRelFiles(srcDir) {
213
+ return listFilesRecursive(srcDir)
214
+ .filter(isShippedFunctionFile)
215
+ .map((f) => path.relative(srcDir, f));
216
+ }
210
217
  function toRelativePosix(base, target) {
211
218
  return path.relative(base, target).split(path.sep).join("/");
212
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocapine/community",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
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": {