s3-npm-cache
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,16 +0,11 @@ | ||
var AdmZip = require('adm-zip'); | ||
var tar = require('tar.gz2'), | ||
fs = require('fs'), | ||
q = require('q'); | ||
var createZip = function (folder) { | ||
var newZip = new AdmZip(); | ||
newZip.addLocalFolder(folder); | ||
return newZip.toBuffer(); | ||
var createZip = function (folder, fileName) { | ||
return tar({ level: 9, memLevel: 9 }).compress(folder, fileName); | ||
}; | ||
var unzip = function (buffer, location) { | ||
try { | ||
var zip = new AdmZip(buffer); | ||
zip.extractAllTo(location, true); | ||
} catch (err) { | ||
console.error('Error unzipping', err); | ||
} | ||
var unzip = function (fileName, location) { | ||
return tar().extract(fileName, location); | ||
}; | ||
@@ -17,0 +12,0 @@ |
@@ -1,9 +0,4 @@ | ||
var shell = require('shelljs'), | ||
fs = require('fs'); | ||
var fs = require('fs'); | ||
var npmAction = function (packageJsonFileLocation, action) { | ||
shell.exec('npm --prefix ' + packageJsonFileLocation + ' ' + action); | ||
}; | ||
var checkFolderExists = function (folder) { | ||
var checkFileExists = function (folder) { | ||
return fs.existsSync(folder); | ||
@@ -13,4 +8,3 @@ }; | ||
module.exports = { | ||
npmAction: npmAction, | ||
checkFolderExists: checkFolderExists | ||
checkFileExists: checkFileExists | ||
}; |
@@ -18,17 +18,22 @@ var AWS = require('aws-sdk'), | ||
var uploadFileToS3 = function (fileName, zipBuffer) { | ||
var uploadFileToS3 = function (fileName) { | ||
var defer = q.defer(); | ||
s3.putObject({ | ||
Bucket: s3BucketName, | ||
Key: fileName, | ||
ACL: 'bucket-owner-full-control', | ||
ContentType: 'application/zip', | ||
Body: zipBuffer | ||
}, function (err) { | ||
fs.readFile('./' + fileName, function (err, buffer) { | ||
if (err) { | ||
defer.reject('Failed to upload file', err); | ||
} else { | ||
defer.resolve(); | ||
defer.reject(err); | ||
} | ||
s3.putObject({ | ||
Bucket: s3BucketName, | ||
Key: fileName, | ||
ACL: 'bucket-owner-full-control', | ||
ContentType: 'application/gzip', | ||
Body: buffer | ||
}, function (err) { | ||
if (err) { | ||
defer.reject(err); | ||
} else { | ||
defer.resolve(); | ||
} | ||
}); | ||
}); | ||
@@ -49,3 +54,9 @@ | ||
} else if (data && data.Body) { | ||
defer.resolve(data.Body); | ||
fs.writeFile(fileName, data.Body, "binary", function (err) { | ||
if (err) { | ||
defer.reject(err); | ||
} | ||
defer.resolve(fileName); | ||
}); | ||
} else { | ||
@@ -52,0 +63,0 @@ defer.reject('No errors downloading the file but no buffer. Please try again.'); |
{ | ||
"name": "s3-npm-cache", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Lightweight runtime to cache NPM dependencies in S3", | ||
@@ -32,8 +32,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"adm-zip": "^0.4.7", | ||
"aws-sdk": "^2.11.0", | ||
"md5-file": "^3.1.1", | ||
"q": "^1.4.1", | ||
"shelljs": "^0.7.6" | ||
"shelljs": "^0.7.6", | ||
"tar.gz2": "^1.0.0" | ||
} | ||
} |
@@ -7,5 +7,6 @@ /* | ||
path = require('path'), | ||
s3 = require('./lib/s3'), | ||
archive = require('./lib/archive'), | ||
misc = require('./lib/misc'); | ||
fs = require('fs'), | ||
process = require('./lib/process'), | ||
misc = require('./lib/misc'), | ||
s3 = require('./lib/s3'); | ||
@@ -15,42 +16,12 @@ var init = function (s3BucketName, packageJsonFileLocation) { | ||
nodeModulesFolder = packageJsonFileLocation + '/node_modules', | ||
s3PackageName = md5.sync(packageJsonFile) + ".zip"; | ||
s3PackageName = md5.sync(packageJsonFile) + ".tar.gz"; | ||
var unzipNodeModules = function (buffer) { | ||
console.log('Downloaded ZIP file from S3. Unzipping...'); | ||
archive.unzip(buffer, nodeModulesFolder); | ||
process.setProcessMetadata({ | ||
packageJsonFileLocation: packageJsonFileLocation, | ||
packageJsonFile: packageJsonFile, | ||
nodeModulesFolder: nodeModulesFolder, | ||
s3PackageName: s3PackageName | ||
}); | ||
console.log('NPM rebuilding...'); | ||
misc.npmAction(packageJsonFileLocation, 'rebuild'); | ||
console.log('Done!'); | ||
}; | ||
var uploadNewFile = function (err) { | ||
if (err.code !== 'NoSuchKey') { | ||
console.warn('Error occurred attempting connection to S3', err); | ||
console.log('Npm installing...'); | ||
misc.npmAction(packageJsonFileLocation, 'install'); | ||
return; | ||
} | ||
console.log(s3PackageName, 'not found . Npm installing...'); | ||
misc.npmAction(packageJsonFileLocation, 'install'); | ||
console.log('Node modules installed. Zipping...'); | ||
var zipBuffer = archive.createZip(nodeModulesFolder); | ||
console.log('Zip created. Uploading...'); | ||
s3.uploadFileToS3(s3PackageName, zipBuffer) | ||
.then(function () { | ||
console.log('Done!') | ||
}) | ||
.catch(function (err) { | ||
throw new Error(err); | ||
}); | ||
}; | ||
if (misc.checkFolderExists(nodeModulesFolder)) { | ||
if (misc.checkFileExists(nodeModulesFolder)) { | ||
console.log('Node modules already installed. Continuing...'); | ||
@@ -63,3 +34,3 @@ | ||
console.warn('AWS credentials not found. Npm installing...'); | ||
helpers.npmAction(packageJsonFileLocation, 'install'); | ||
process.npmAction('install'); | ||
@@ -73,4 +44,4 @@ return; | ||
s3.getFileFromS3(s3PackageName) | ||
.then(unzipNodeModules) | ||
.catch(uploadNewFile); | ||
.then(process.unzipNodeModules) | ||
.catch(process.uploadNewFile); | ||
}; | ||
@@ -77,0 +48,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7868
11
183
0
6
+ Addedtar.gz2@^1.0.0
+ Addedblock-stream@0.0.9(transitive)
+ Addedbluebird@2.11.0(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedfstream@1.0.12(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedmout@0.11.1(transitive)
+ Addedrimraf@2.7.1(transitive)
+ Addedtar@2.2.2(transitive)
+ Addedtar.gz2@1.0.0(transitive)
- Removedadm-zip@^0.4.7
- Removedadm-zip@0.4.16(transitive)