@tryghost/mg-fs-utils 0.12.1 → 0.12.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.
Files changed (2) hide show
  1. package/lib/FileCache.js +15 -2
  2. package/package.json +2 -2
package/lib/FileCache.js CHANGED
@@ -149,6 +149,10 @@ class FileCache {
149
149
  return src.replace(fileNameNoExt, safeFileNameNoExt);
150
150
  }
151
151
 
152
+ ensureJsonExtension({filename, isJSON = true}) {
153
+ return (isJSON && !filename.endsWith('.json')) ? `${filename}.json` : filename; // Ensure the `.json` extension is only added if needed
154
+ }
155
+
152
156
  resolveImageFileName(filename) {
153
157
  return this.resolveFileName(filename, 'images');
154
158
  }
@@ -220,7 +224,7 @@ class FileCache {
220
224
  * @param {Boolean} isJSON - defaults to write a JSON file
221
225
  */
222
226
  async writeTmpFile(data, filename, isJSON = true) {
223
- let fileNameWithExt = (filename.endsWith('.json')) ? filename : `${filename}.json`; // Ensure the `.json` extension is only added if needed
227
+ let fileNameWithExt = this.ensureJsonExtension({filename, isJSON});
224
228
  let filepath = join(this.tmpDir, fileNameWithExt);
225
229
 
226
230
  if (isJSON) {
@@ -240,7 +244,7 @@ class FileCache {
240
244
  * @param {Boolean} isJSON - defaults to write a JSON file
241
245
  */
242
246
  writeTmpFileSync(data, filename, isJSON = true) {
243
- let fileNameWithExt = (filename.endsWith('.json')) ? filename : `${filename}.json`; // Ensure the `.json` extension is only added if needed
247
+ let fileNameWithExt = this.ensureJsonExtension({filename, isJSON});
244
248
  let filepath = join(this.tmpDir, fileNameWithExt);
245
249
 
246
250
  if (isJSON) {
@@ -385,6 +389,15 @@ class FileCache {
385
389
  return outputFile(storagePath, data);
386
390
  }
387
391
 
392
+ /**
393
+ * Alias fs-extra's 'remove' so we can more easily mock it
394
+ *
395
+ * @param {String} string - absolute path to where file should be deleted
396
+ */
397
+ async deleteFileOrDir(storagePath) {
398
+ return remove(storagePath);
399
+ }
400
+
388
401
  /**
389
402
  * Check if we've got this file already
390
403
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-fs-utils",
3
- "version": "0.12.1",
3
+ "version": "0.12.2",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -37,5 +37,5 @@
37
37
  "sharp": "0.31.3",
38
38
  "transliteration": "2.3.5"
39
39
  },
40
- "gitHead": "c2534e3c865cf26f7598f8f05dee5ca399c7a4f4"
40
+ "gitHead": "5425b18d5b6ffb6f0f7dc9d13a5c0341c6937945"
41
41
  }