feat: init
This commit is contained in:
38
node_modules/@mapbox/node-pre-gyp/lib/mock/http.js
generated
vendored
Normal file
38
node_modules/@mapbox/node-pre-gyp/lib/mock/http.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = http_mock;
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const nock = require('nock');
|
||||
const os = require('os');
|
||||
|
||||
const log = require('../util/log.js');
|
||||
log.heading = 'node-pre-gyp'; // differentiate node-pre-gyp's logs from npm's
|
||||
|
||||
function http_mock() {
|
||||
log.warn('mocking http requests to s3');
|
||||
|
||||
const basePath = `${os.tmpdir()}/mock`;
|
||||
|
||||
nock(new RegExp('([a-z0-9]+[.])*s3[.]us-east-1[.]amazonaws[.]com'))
|
||||
.persist()
|
||||
.get(() => true) //a function that always returns true is a catch all for nock
|
||||
.reply(
|
||||
(uri) => {
|
||||
const bucket = 'npg-mock-bucket';
|
||||
const mockDir = uri.indexOf(bucket) === -1 ? `${basePath}/${bucket}` : basePath;
|
||||
const filepath = path.join(mockDir, uri.replace(new RegExp('%2B', 'g'), '+'));
|
||||
|
||||
try {
|
||||
fs.accessSync(filepath, fs.constants.R_OK);
|
||||
} catch (e) {
|
||||
return [404, 'not found\n'];
|
||||
}
|
||||
|
||||
// mock s3 functions write to disk
|
||||
// return what is read from it.
|
||||
return [200, fs.createReadStream(filepath)];
|
||||
}
|
||||
);
|
||||
}
|
||||
44
node_modules/@mapbox/node-pre-gyp/lib/mock/s3.js
generated
vendored
Normal file
44
node_modules/@mapbox/node-pre-gyp/lib/mock/s3.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = exports = s3_mock;
|
||||
|
||||
const AWSMock = require('mock-aws-s3');
|
||||
const os = require('os');
|
||||
|
||||
const log = require('../util/log.js');
|
||||
log.heading = 'node-pre-gyp'; // differentiate node-pre-gyp's logs from npm's
|
||||
|
||||
function s3_mock() {
|
||||
log.warn('mocking s3 operations');
|
||||
|
||||
AWSMock.config.basePath = `${os.tmpdir()}/mock`;
|
||||
|
||||
const s3 = AWSMock.S3();
|
||||
|
||||
// wrapped callback maker. fs calls return code of ENOENT but AWS.S3 returns
|
||||
// NotFound.
|
||||
const wcb = (fn) => (err, ...args) => {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
err.code = 'NotFound';
|
||||
}
|
||||
return fn(err, ...args);
|
||||
};
|
||||
|
||||
return {
|
||||
listObjects(params, callback) {
|
||||
return s3.listObjects(params, wcb(callback));
|
||||
},
|
||||
headObject(params, callback) {
|
||||
return s3.headObject(params, wcb(callback));
|
||||
},
|
||||
deleteObject(params, callback) {
|
||||
return s3.deleteObject(params, wcb(callback));
|
||||
},
|
||||
putObject(params, callback) {
|
||||
return s3.putObject(params, wcb(callback));
|
||||
},
|
||||
getObject(params, callback) {
|
||||
return s3.getObject(params, wcb(callback));
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user