New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

serverless-plugin-git-variables

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serverless-plugin-git-variables - npm Package Compare versions

Comparing version
4.1.0
to
5.0.0
+131
-121
lib/index.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -6,44 +6,29 @@ Object.defineProperty(exports, "__esModule", {

});
exports.default = void 0;
var _promise = require('babel-runtime/core-js/promise');
var _child_process = _interopRequireDefault(require("child_process"));
var _promise2 = _interopRequireDefault(_promise);
var _path = _interopRequireDefault(require("path"));
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _os = _interopRequireDefault(require("os"));
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
let _exec = (() => {
var _ref = (0, _asyncToGenerator3.default)(function* (cmd, options = { timeout: 1000 }) {
return new _promise2.default(function (resolve, reject) {
_child_process2.default.exec(cmd, options, function (err, stdout) {
if (err) {
reject(err);
} else {
resolve(stdout.trim());
}
});
// TODO: Consider using nodegit instead
const GIT_PREFIX = 'git';
async function _exec(cmd, options = {
timeout: 1000
}) {
return new Promise((resolve, reject) => {
_child_process.default.exec(cmd, options, (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.trim());
}
});
});
}
return function _exec(_x) {
return _ref.apply(this, arguments);
};
})();
var _child_process = require('child_process');
var _child_process2 = _interopRequireDefault(_child_process);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _os = require('os');
var _os2 = _interopRequireDefault(_os);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const GIT_PREFIX = 'git'; // TODO: Consider using nodegit instead
class ServerlessGitVariables {

@@ -63,2 +48,3 @@ constructor(serverless, options) {

};
this.hooks = {

@@ -71,107 +57,130 @@ 'after:package:initialize': this.exportGitVariables.bind(this),

_getValue(variable) {
var _this = this;
async _getValue(variable) {
if (this.resolvedValues[variable]) {
return Promise.resolve(this.resolvedValues[variable]);
}
return (0, _asyncToGenerator3.default)(function* () {
if (_this.resolvedValues[variable]) {
return _promise2.default.resolve(_this.resolvedValues[variable]);
}
return _this._getValueFromGit(variable);
})();
return this._getValueFromGit(variable);
}
_getValueFromGit(variable) {
var _this2 = this;
async _getValueFromGit(variable) {
let value = null;
return (0, _asyncToGenerator3.default)(function* () {
let value = null;
switch (variable) {
case 'describe':
value = yield _exec('git describe --always');
break;
case 'describeLight':
value = yield _exec('git describe --always --tags');
break;
case 'sha1':
value = yield _exec('git rev-parse --short HEAD');
break;
case 'commit':
value = yield _exec('git rev-parse HEAD');
break;
case 'branch':
value = yield _exec('git rev-parse --abbrev-ref HEAD');
break;
case 'message':
value = yield _exec('git log -1 --pretty=%B');
break;
case 'user':
value = yield _exec('git config user.name');
break;
case 'email':
value = yield _exec('git config user.email');
break;
case 'isDirty':
const changes = yield _exec(`git diff --stat`);
switch (variable) {
case 'describe':
value = await _exec('git describe --always');
break;
case 'describeLight':
value = await _exec('git describe --always --tags');
break;
case 'sha1':
value = await _exec('git rev-parse --short HEAD');
break;
case 'commit':
value = await _exec('git rev-parse HEAD');
break;
case 'branch':
value = await _exec('git rev-parse --abbrev-ref HEAD');
break;
case 'message':
value = await _exec('git log -1 --pretty=%B');
break;
case 'user':
value = await _exec('git config user.name');
break;
case 'email':
value = await _exec('git config user.email');
break;
case 'isDirty':
{
const changes = await _exec('git diff --stat');
value = `${changes.length > 0}`;
break;
case 'repository':
const pathName = yield _exec('git rev-parse --show-toplevel');
value = _path2.default.basename(pathName);
}
case 'repository':
{
const pathName = await _exec('git rev-parse --show-toplevel');
value = _path.default.basename(pathName);
break;
case 'tags':
value = yield _exec('git tag --points-at HEAD');
value = value.split(_os2.default.EOL).join('::');
if (value === '') {
value = yield _exec('git rev-parse --short HEAD');
}
break;
default:
throw new Error(`Git variable ${variable} is unknown. Candidates are 'describe', 'describeLight', 'sha1', 'commit', 'branch', 'message', 'user', 'email', 'isDirty', 'repository', 'tags'`);
}
}
// TODO: Figure out why if I don't log, the deasync promise
// never resolves. Catching it in the debugger or logging
// causes it to work fine.
process.stdout.write('');
case 'tags':
value = await _exec('git tag --points-at HEAD');
value = value.split(_os.default.EOL).join('::');
// Cache before returning
_this2.resolvedValues[variable] = value;
return value;
})();
}
if (value === '') {
value = await _exec('git rev-parse --short HEAD');
}
exportGitVariables() {
var _this3 = this;
break;
return (0, _asyncToGenerator3.default)(function* () {
const exportGitVariables = _this3.serverless.service.custom && _this3.serverless.service.custom.exportGitVariables;
default:
throw new Error(`Git variable ${variable} is unknown. Candidates are 'describe', 'describeLight', 'sha1', 'commit', 'branch', 'message', 'user', 'email', 'isDirty', 'repository', 'tags'`);
} // TODO: Figure out why if I don't log, the deasync promise
// never resolves. Catching it in the debugger or logging
// causes it to work fine.
let envWhitelist = _this3.serverless.service.custom && _this3.serverless.service.custom.gitVariablesEnvWhitelist;
let tagsWhitelist = _this3.serverless.service.custom && _this3.serverless.service.custom.gitVariablesTagsWhitelist;
if (exportGitVariables === false) {
return;
}
process.stdout.write(''); // Cache before returning
const exportList = [{ value: 'sha1', variableName: 'GIT_COMMIT_SHORT' }, { value: 'commit', variableName: 'GIT_COMMIT_LONG' }, { value: 'branch', variableName: 'GIT_BRANCH' }, { value: 'isDirty', variableName: 'GIT_IS_DIRTY' }, { value: 'repository', variableName: 'GIT_REPOSITORY' }, { value: 'tags', variableName: 'GIT_TAGS' }];
this.resolvedValues[variable] = value;
return value;
}
for (const functionName of _this3.serverless.service.getAllFunctions()) {
const func = _this3.serverless.service.getFunction(functionName);
async exportGitVariables() {
const exportGitVariables = this.serverless.service.custom && this.serverless.service.custom.exportGitVariables;
const envWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesEnvWhitelist;
const tagsWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesTagsWhitelist;
for (const _ref2 of exportList) {
const { value, variableName } = _ref2;
if (exportGitVariables === false) {
return;
}
const setOnEnv = !envWhitelist || envWhitelist.includes(variableName);
const setOnTags = !tagsWhitelist || tagsWhitelist.includes(variableName);
const exportList = [{
value: 'sha1',
variableName: 'GIT_COMMIT_SHORT'
}, {
value: 'commit',
variableName: 'GIT_COMMIT_LONG'
}, {
value: 'branch',
variableName: 'GIT_BRANCH'
}, {
value: 'isDirty',
variableName: 'GIT_IS_DIRTY'
}, {
value: 'repository',
variableName: 'GIT_REPOSITORY'
}, {
value: 'tags',
variableName: 'GIT_TAGS'
}];
if (!setOnEnv && !setOnTags) {
continue;
}
for (const functionName of this.serverless.service.getAllFunctions()) {
const func = this.serverless.service.getFunction(functionName);
const gitValue = yield _this3._getValue(value);
_this3.exportGitVariable(func, variableName, gitValue, setOnEnv, setOnTags);
for (const {
value,
variableName
} of exportList) {
const setOnEnv = !envWhitelist || envWhitelist.includes(variableName);
const setOnTags = !tagsWhitelist || tagsWhitelist.includes(variableName);
if (!setOnEnv && !setOnTags) {
continue;
}
const gitValue = await this._getValue(value);
this.exportGitVariable(func, variableName, gitValue, setOnEnv, setOnTags);
}
})();
}
}

@@ -200,4 +209,5 @@

}
}
exports.default = ServerlessGitVariables;
module.exports = exports['default'];
exports.default = ServerlessGitVariables;
{
"name": "serverless-plugin-git-variables",
"version": "4.1.0",
"version": "5.0.0",
"engines": {
"node": ">=7.0"
"node": ">=12.0"
},

@@ -43,28 +43,25 @@ "description": "Serverless plugin to expose git status to serverless services",

},
"dependencies": {
"babel-runtime": "6.23.0"
},
"devDependencies": {
"ava": "0.20.0",
"babel-cli": "6.18.0",
"babel-core": "6.21.0",
"babel-eslint": "7.1.1",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-transform-object-rest-spread": "6.23.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.4.0",
"babel-register": "6.18.0",
"coveralls": "2.11.15",
"cross-env": "3.1.4",
"eslint": "4.18.2",
"eslint-config-standard": "6.2.1",
"eslint-plugin-ava": "4.0.1",
"eslint-plugin-promise": "3.4.0",
"eslint-plugin-standard": "2.0.1",
"fs-extra": "2.1.2",
"nyc": "10.0.0",
"rimraf": "2.5.4",
"@ava/babel": "1.0.1",
"@babel/cli": "7.12.1",
"@babel/core": "7.12.3",
"@babel/preset-env": "7.12.1",
"@babel/register": "7.12.1",
"ava": "3.13.0",
"coveralls": "3.1.0",
"cross-env": "7.0.2",
"eslint": "7.12.1",
"eslint-config-standard": "16.0.1",
"eslint-plugin-ava": "11.0.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.2",
"fs-extra": "9.0.1",
"nyc": "15.1.0",
"rimraf": "3.0.2",
"serverless": "1.17.0",
"tmp": "0.0.31"
"tmp": "0.2.1"
},
"modules": true,
"peerDependencies": {

@@ -75,6 +72,17 @@ "serverless": ">=1.16.0"

"require": [
"babel-register"
],
"babel": "inherit"
"@babel/register"
]
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": 12
}
}
]
]
}
}

@@ -69,2 +69,4 @@ # serverless-plugin-git-variables

# Version History
* 5.0.0
- Rely on a more modern version of Node, which allows removal of runtime dependencies
* 4.1.0

@@ -71,0 +73,0 @@ - Fix sporadic failure with git write-tree (Thanks to @navrkald and @james-hu)

@@ -76,10 +76,12 @@ // TODO: Consider using nodegit instead

break
case 'isDirty':
const changes = await _exec(`git diff --stat`)
case 'isDirty': {
const changes = await _exec('git diff --stat')
value = `${changes.length > 0}`
break
case 'repository':
}
case 'repository': {
const pathName = await _exec('git rev-parse --show-toplevel')
value = path.basename(pathName)
break
}
case 'tags':

@@ -109,4 +111,4 @@ value = await _exec('git tag --points-at HEAD')

let envWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesEnvWhitelist
let tagsWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesTagsWhitelist
const envWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesEnvWhitelist
const tagsWhitelist = this.serverless.service.custom && this.serverless.service.custom.gitVariablesTagsWhitelist

@@ -113,0 +115,0 @@ if (exportGitVariables === false) {