Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

s3-npm-cache

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

s3-npm-cache - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

lib/process.js

19

lib/archive.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc