@tryghost/mg-fs-utils 0.12.21 → 0.13.0
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/read-zip.js +10 -10
- package/lib/zip.js +12 -1
- package/package.json +3 -4
package/lib/read-zip.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import errors from '@tryghost/errors';
|
|
2
|
-
import
|
|
2
|
+
import fsZip from './zip.js';
|
|
3
3
|
|
|
4
4
|
const readZipEntries = async (zipPath = null) => {
|
|
5
5
|
if (!zipPath) {
|
|
6
6
|
throw new errors.InternalServerError({message: `No zip path provided ${zipPath}`});
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
let zipEntries = [];
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
fsZip.read(zipPath, (entryName, zipEntry) => {
|
|
12
|
+
zipEntries[entryName] = zipEntry;
|
|
13
|
+
});
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
let files = [];
|
|
14
16
|
|
|
15
|
-
for (const entry of Object.
|
|
16
|
-
if ((entry.name.match(/^__MACOSX/) || entry.name.match(/\.DS_Store$/))) {
|
|
17
|
+
for (const entry of Object.entries(zipEntries)) {
|
|
18
|
+
if ((entry[1].name.match(/^__MACOSX/) || entry[1].name.match(/\.DS_Store$/))) {
|
|
17
19
|
continue;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
if (entry && !entry.isDirectory) {
|
|
21
|
-
files.push(entry
|
|
22
|
+
if (entry && !entry[1].isDirectory) {
|
|
23
|
+
files.push(entry[0]);
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
await zip.close();
|
|
26
|
-
|
|
27
27
|
return files;
|
|
28
28
|
};
|
|
29
29
|
|
package/lib/zip.js
CHANGED
|
@@ -13,7 +13,6 @@ _private.openZipForRead = (zipPath) => {
|
|
|
13
13
|
/**
|
|
14
14
|
* Read a Zip File
|
|
15
15
|
* - Flattens the structure if there's one top-level directory, so we only get the files inside
|
|
16
|
-
* @TODO: Refactor to use @tryghost/zip to extract zip files and drop adm-zip dependency
|
|
17
16
|
*/
|
|
18
17
|
const read = (zipPath, callback) => {
|
|
19
18
|
let zip; // eslint-disable-line no-shadow
|
|
@@ -23,6 +22,18 @@ const read = (zipPath, callback) => {
|
|
|
23
22
|
throw new errors.InternalServerError({message: `Unable to read zip file ${zipPath}: ${error}`});
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
// If the zip has one entry and its another zip, unzip & read that instead
|
|
26
|
+
const preCheckEntries = zip.getEntries().filter((entry) => {
|
|
27
|
+
return !(entry.entryName.match(/^__MACOSX/) || entry.entryName.match(/\.DS_Store$/));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (preCheckEntries.length === 1 && preCheckEntries[0].entryName.includes('.zip')) {
|
|
31
|
+
const childZipBuffer = preCheckEntries[0].getData();
|
|
32
|
+
|
|
33
|
+
// Redeclare the results array, we don't want to lust parent zip files
|
|
34
|
+
zip = _private.openZipForRead(childZipBuffer);
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
// Entries is cleaned first
|
|
27
38
|
let entries = zip.getEntries().filter((entry) => {
|
|
28
39
|
return !(entry.entryName.match(/^__MACOSX/) || entry.entryName.match(/\.DS_Store$/));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/mg-fs-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-fs-utils",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "8.
|
|
23
|
+
"eslint": "8.56.0",
|
|
24
24
|
"jest": "29.7.0",
|
|
25
25
|
"jest-extended": "4.0.2"
|
|
26
26
|
},
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"date-fns": "2.30.0",
|
|
35
35
|
"fs-extra": "11.2.0",
|
|
36
36
|
"lodash": "4.17.21",
|
|
37
|
-
"node-stream-zip": "1.15.0",
|
|
38
37
|
"sharp": "0.32.6",
|
|
39
38
|
"transliteration": "2.3.5"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "1e250c8bacc23b674d5e9c42e2529bf07ff0aba0"
|
|
42
41
|
}
|