Replaced zip tools with @tryghost/zip

- Moved zipFolder to a new package
- also exposing extract-zip from the new package
- new package has the API pre-promisified
- also uses @tryghost/extract-zip instead of extract-zip, which has bugfixes
This commit is contained in:
Hannah Wolfe 2020-03-20 20:36:05 +00:00
parent 51e382cd0f
commit 5ea10b47bd
7 changed files with 32 additions and 114 deletions

View File

@ -1,10 +1,9 @@
var fs = require('fs-extra'),
os = require('os'),
path = require('path'),
Promise = require('bluebird'),
config = require('../../../server/config'),
security = require('../../../server/lib/security'),
fsLib = require('../../../server/lib/fs'),
{zipFolder} = require('@tryghost/zip'),
LocalFileStorage = require('../../../server/adapters/storage/LocalFileStorage');
/**
@ -35,7 +34,7 @@ class ThemeStorage extends LocalFileStorage {
fs.ensureDir(zipBasePath)
.then(function () {
return Promise.promisify(fsLib.zipFolder)(themePath, zipPath);
return zipFolder(themePath, zipPath);
})
.then(function (length) {
res.set({

View File

@ -5,7 +5,7 @@ var _ = require('lodash'),
os = require('os'),
glob = require('glob'),
uuid = require('uuid'),
extract = require('extract-zip'),
{extract} = require('@tryghost/zip'),
sequence = require('../../lib/promise/sequence'),
pipeline = require('../../lib/promise/pipeline'),
common = require('../../lib/common'),
@ -172,7 +172,7 @@ _.extend(ImportManager.prototype, {
const tmpDir = path.join(os.tmpdir(), uuid.v4());
this.fileToDelete = tmpDir;
return Promise.promisify(extract)(filePath, {dir: tmpDir}).then(function () {
return extract(filePath, {dir: tmpDir}).then(function () {
return tmpDir;
});
},

View File

@ -5,9 +5,5 @@ module.exports = {
get formatCSV() {
return require('./format-csv');
},
get zipFolder() {
return require('./zip-folder');
}
};

View File

@ -1,27 +0,0 @@
const fs = require('fs-extra');
module.exports = function zipFolder(folderToZip, destination, callback) {
var archiver = require('archiver'),
output = fs.createWriteStream(destination),
archive = archiver.create('zip', {});
// If folder to zip is a symlink, we want to get the target
// of the link and zip that instead of zipping the symlink
if (fs.lstatSync(folderToZip).isSymbolicLink()) {
folderToZip = fs.realpathSync(folderToZip);
}
output.on('close', function () {
callback(null, archive.pointer());
});
archive.on('error', function (err) {
callback(err, null);
});
archive.glob(`**/*`, {
cwd: folderToZip,
ignore: ['node_modules/**']
});
archive.pipe(output);
archive.finalize();
};

View File

@ -1,49 +0,0 @@
var should = require('should'),
path = require('path'),
fs = require('fs-extra'),
extract = require('extract-zip'),
fsLib = require('../../../../server/lib/fs');
describe('lib/fs: read csv', function () {
const symlinkPath = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink'),
folderToSymlink = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'casper'),
zipDestination = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink.zip'),
unzipDestination = path.join(__dirname, '..', '..', '..', 'utils', 'fixtures', 'themes', 'theme-symlink-unzipped');
before(function () {
fs.removeSync(symlinkPath);
fs.removeSync(zipDestination);
fs.removeSync(unzipDestination);
});
after(function () {
fs.removeSync(symlinkPath);
fs.removeSync(zipDestination);
fs.removeSync(unzipDestination);
});
it('ensure symlinks work', function (done) {
fs.symlink(folderToSymlink, symlinkPath);
fsLib.zipFolder(symlinkPath, zipDestination, function (err) {
if (err) {
return done(err);
}
extract(zipDestination, {dir: unzipDestination}, function (err) {
if (err) {
return done(err);
}
fs.readdir(unzipDestination, function (err, files) {
if (err) {
return done(err);
}
files.length.should.eql(16);
done();
});
});
});
});
});

View File

@ -48,10 +48,10 @@
"@tryghost/string": "^0.1.3",
"@tryghost/url-utils": "0.6.14",
"@tryghost/vhost-middleware": "1.0.1",
"@tryghost/zip": "^0.1.0",
"ajv": "6.12.0",
"amperize": "0.6.1",
"analytics-node": "3.4.0-beta.1",
"archiver": "3.1.1",
"bcryptjs": "2.4.3",
"bluebird": "3.7.2",
"body-parser": "1.19.0",
@ -74,7 +74,6 @@
"express-jwt": "5.3.1",
"express-query-boolean": "2.0.0",
"express-session": "1.17.0",
"extract-zip": "1.6.7",
"fs-extra": "9.0.0",
"ghost-ignition": "4.1.0",
"ghost-storage-base": "0.0.4",

View File

@ -282,7 +282,7 @@
dependencies:
defer-to-connect "^2.0.0"
"@tryghost/extract-zip@1.6.6":
"@tryghost/extract-zip@1.6.6", "@tryghost/extract-zip@^1.6.6":
version "1.6.6"
resolved "https://registry.yarnpkg.com/@tryghost/extract-zip/-/extract-zip-1.6.6.tgz#937e0e775fec6dea937ac49d73a068bcafb67f50"
integrity sha512-HZ8Q/HgH36Fn0fOcAC2lGjTylu5ctMQn8jvwtCCiDfkg03BaBYv8xbEqqbDbz2/3v0i9pFrNdXHWheQGM1jXgw==
@ -411,6 +411,16 @@
ghost-ignition "^3.1.0"
lodash "^4.17.15"
"@tryghost/zip@^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/@tryghost/zip/-/zip-0.1.0.tgz#2c3c3186e5f40e00197a06f3b2513a6bab14267c"
integrity sha512-0XkzIC9w1+M2WOBhR6ohXWOe7pn6wBtXlLVnDgYbZv2sbDmbz0jDiibU/A3eC/4iXABiYA6qeOlXoH8YHR2tIg==
dependencies:
"@tryghost/extract-zip" "^1.6.6"
archiver "^3.1.1"
bluebird "^3.7.2"
fs-extra "^9.0.0"
"@types/bluebird@^3.5.26", "@types/bluebird@^3.5.27":
version "3.5.27"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.27.tgz#61eb4d75dc6bfbce51cf49ee9bbebe941b2cb5d0"
@ -754,19 +764,6 @@ archiver-utils@^2.1.0:
normalize-path "^3.0.0"
readable-stream "^2.0.0"
archiver@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-3.1.1.tgz#9db7819d4daf60aec10fe86b16cb9258ced66ea0"
integrity sha512-5Hxxcig7gw5Jod/8Gq0OneVgLYET+oNHcxgWItq4TbhOzRLKNAFUb9edAftiMKXvXfCB0vbGrJdZDNq0dWMsxg==
dependencies:
archiver-utils "^2.1.0"
async "^2.6.3"
buffer-crc32 "^0.2.1"
glob "^7.1.4"
readable-stream "^3.4.0"
tar-stream "^2.1.0"
zip-stream "^2.1.2"
archiver@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-1.3.0.tgz#4f2194d6d8f99df3f531e6881f14f15d55faaf22"
@ -782,6 +779,19 @@ archiver@^1.3.0:
walkdir "^0.0.11"
zip-stream "^1.1.0"
archiver@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-3.1.1.tgz#9db7819d4daf60aec10fe86b16cb9258ced66ea0"
integrity sha512-5Hxxcig7gw5Jod/8Gq0OneVgLYET+oNHcxgWItq4TbhOzRLKNAFUb9edAftiMKXvXfCB0vbGrJdZDNq0dWMsxg==
dependencies:
archiver-utils "^2.1.0"
async "^2.6.3"
buffer-crc32 "^0.2.1"
glob "^7.1.4"
readable-stream "^3.4.0"
tar-stream "^2.1.0"
zip-stream "^2.1.2"
are-we-there-yet@~1.1.2:
version "1.1.5"
resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz#4b35c2944f062a8bfcda66410760350fe9ddfc21"
@ -1037,7 +1047,7 @@ bl@^3.0.0:
dependencies:
readable-stream "^3.0.1"
bluebird@3.7.2, bluebird@^3.4.3, bluebird@^3.7.0:
bluebird@3.7.2, bluebird@^3.4.3, bluebird@^3.7.0, bluebird@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f"
integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==
@ -1789,7 +1799,7 @@ concat-stream@1.6.0:
readable-stream "^2.2.2"
typedarray "^0.0.6"
concat-stream@1.6.2, concat-stream@^1.5.2:
concat-stream@^1.5.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
integrity sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==
@ -2933,16 +2943,6 @@ extglob@^2.0.4:
snapdragon "^0.8.1"
to-regex "^3.0.1"
extract-zip@1.6.7:
version "1.6.7"
resolved "https://registry.yarnpkg.com/extract-zip/-/extract-zip-1.6.7.tgz#a840b4b8af6403264c8db57f4f1a74333ef81fe9"
integrity sha1-qEC0uK9kAyZMjbV/Txp0Mz74H+k=
dependencies:
concat-stream "1.6.2"
debug "2.6.9"
mkdirp "0.5.1"
yauzl "2.4.1"
extsprintf@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
@ -3227,7 +3227,7 @@ fs-constants@^1.0.0:
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==
fs-extra@9.0.0:
fs-extra@9.0.0, fs-extra@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==