@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.
- package/lib/commands/init.js +3 -1
- package/lib/commands/upgrade.js +27 -23
- package/lib/install-shared.d.ts +2 -0
- package/lib/install-shared.js +7 -0
- package/package.json +1 -1
package/lib/commands/init.js
CHANGED
|
@@ -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
|
-
|
|
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) {
|
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) => (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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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("");
|
package/lib/install-shared.d.ts
CHANGED
|
@@ -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;
|
package/lib/install-shared.js
CHANGED
|
@@ -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