New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bigbrother-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bigbrother-webpack-plugin - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

7

History.md
1.1.2 / 2018-11-29
==================
* fix: online report
* fix: 数据格式修改
* feat: merge satori
1.1.1 / 2018-11-16

@@ -3,0 +10,0 @@ ==================

5

lib/adapter/satori.d.ts
import { ISatoriCreateBuild, IAdapter } from '../typings';
export default class SatoriAdapter implements IAdapter {
private prefixHost;
private satoriClient;
constructor();
postBuild(args: ISatoriCreateBuild): Promise<void>;
postDev(args: ISatoriCreateBuild): Promise<void>;
uploadShameimaru(shameimaru: object): Promise<string>;
private ifSkipBuildReport;
private ifDevReport;
}

86

lib/adapter/satori.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var urllib_1 = require("urllib");
var enum_1 = require("../enum");
var SatoriAdapter = /** @class */ (function () {
// private satoriClient;
function SatoriAdapter() {
this.prefixHost = 'http://bigbrother.dockerlab.alipay.net';
// this.satoriClient = new Satori('bigbrother');
var SatoriClient = require('@alipay/satori-client');
this.satoriClient = new SatoriClient('bigfish-build');
}

@@ -14,12 +13,12 @@ SatoriAdapter.prototype.postBuild = function (args) {

return tslib_1.__generator(this, function (_a) {
// TODO: 调用 satori sdk
console.log(args);
urllib_1.request(this.prefixHost + "/api/postBuild", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data: args,
});
return [2 /*return*/];
switch (_a.label) {
case 0:
if (this.ifSkipBuildReport(args)) {
return [2 /*return*/];
}
return [4 /*yield*/, this.satoriClient.postFrontendBuildInfo(args)];
case 1:
_a.sent();
return [2 /*return*/];
}
});

@@ -31,11 +30,5 @@ });

return tslib_1.__generator(this, function (_a) {
// TODO: 调用 satori sdk
console.log(args);
urllib_1.request(this.prefixHost + "/api/postDev", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
data: args,
});
if (this.ifDevReport(args)) {
return [2 /*return*/];
}
return [2 /*return*/];

@@ -45,4 +38,51 @@ });

};
SatoriAdapter.prototype.uploadShameimaru = function (shameimaru) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var url;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.satoriClient.uploadShameimaru(JSON.stringify(shameimaru))];
case 1:
url = _a.sent();
return [2 /*return*/, url];
}
});
});
};
SatoriAdapter.prototype.ifSkipBuildReport = function (data) {
// 环境变量跳过上报: 设置环境变量 NO_BIGBROTHER=true 可以关闭内网环境验证和数据上报
if (process.env.NO_BIGBROTHER === 'true') {
return true;
}
var platform = data.platform;
// 只收集 LinkE 平台的构建与 Basement 平台的构建。本地构建不上传
if (!platform.type) {
return true;
}
// Basement 和 LinkE 都需要传入 appName
if (!platform.appName) {
return true;
}
// Basement 平台需要传入 appType
if (platform.type === enum_1.PLATFORM_TYPE.BASEMENT) {
if (!platform.appType) {
return true;
}
}
return false;
};
SatoriAdapter.prototype.ifDevReport = function (data) {
// 环境变量跳过上报: 设置环境变量 NO_BIGBROTHER=true 可以关闭内网环境验证和数据上报
if (process.env.NO_BIGBROTHER === 'true') {
return true;
}
var git = data.git;
// 本地若无 git 信息,跳过上报
if (!git.repository) {
return true;
}
return false;
};
return SatoriAdapter;
}());
exports.default = SatoriAdapter;

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

import MonitorClient from './MonitorClient';
import SatoriAdapter from './adapter/satori';
import { IOptions, ITYPETOOL } from './typings';

@@ -8,6 +8,6 @@ declare class BigBrotherWebpackPlugin implements IOptions {

buildConfig?: object;
monitorClient: MonitorClient;
satori: SatoriAdapter;
constructor(options: any);
apply(compiler: any): void;
report(stats: any): void;
report(stats: any): Promise<void>;
private getReportData;

@@ -14,0 +14,0 @@ private getStages;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var path_1 = require("path");
var assert = require("assert");
var uuid_1 = require("uuid");
var MonitorClient_1 = require("./MonitorClient");
var satori_1 = require("./adapter/satori");
var utils_1 = require("./utils");

@@ -18,3 +19,3 @@ var BigBrotherWebpackPlugin = /** @class */ (function () {

try {
this.monitorClient = new MonitorClient_1.default();
this.satori = new satori_1.default();
}

@@ -37,39 +38,72 @@ catch (_) { }

BigBrotherWebpackPlugin.prototype.report = function (stats) {
var data = this.getReportData(stats);
var fun = process.env.NODE_ENV === 'production' ? 'postBuild' : 'postDev';
try {
this.monitorClient[fun](data);
}
catch (_) {
}
return tslib_1.__awaiter(this, void 0, void 0, function () {
var data, fun;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getReportData(stats)];
case 1:
data = _a.sent();
fun = process.env.NODE_ENV === 'production' ? 'postBuild' : 'postDev';
try {
this.satori[fun](data);
}
catch (_) {
}
return [2 /*return*/];
}
});
});
};
BigBrotherWebpackPlugin.prototype.getReportData = function (stats) {
var _a = process.versions, node = _a.node, _b = _a.alinode, alinode = _b === void 0 ? '' : _b;
return {
buildTimeRef: uuid_1.v4(),
cwd: this.cwd,
success: !stats.hasErrors(),
startAt: stats.startTime,
endedAt: stats.endTime,
tool: this.tool,
pkg: utils_1.getPkg(this.cwd),
buildConfig: this.buildConfig,
artifact: utils_1.getArtifactInfo(stats),
errors: stats.compilation.errors.slice(0, 2).map(function (_a) {
var name = _a.name, message = _a.message;
return ({
name: name,
message: message ? message(0, 200) : '',
});
}),
stages: this.getStages(stats),
node: {
node: node,
alinode: alinode,
},
git: utils_1.getGitInfo(this.cwd),
platform: utils_1.getPlatformInfo(),
envs: process.env,
hardware: utils_1.getHardware(),
};
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, node, _b, alinode, depTreeOssUrl, depTree, _1;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = process.versions, node = _a.node, _b = _a.alinode, alinode = _b === void 0 ? '' : _b;
_c.label = 1;
case 1:
_c.trys.push([1, 4, , 5]);
return [4 /*yield*/, utils_1.getDepTree(this.cwd)];
case 2:
depTree = _c.sent();
return [4 /*yield*/, this.satori.uploadShameimaru(depTree)];
case 3:
depTreeOssUrl = _c.sent();
return [3 /*break*/, 5];
case 4:
_1 = _c.sent();
depTreeOssUrl = '';
return [3 /*break*/, 5];
case 5: return [2 /*return*/, {
buildTimeRef: uuid_1.v4(),
cwd: this.cwd,
success: !stats.hasErrors(),
startedAt: stats.startTime,
endedAt: stats.endTime,
tool: this.tool,
pkg: utils_1.getPkg(this.cwd),
buildConfig: this.buildConfig,
artifact: utils_1.getArtifactInfo(stats),
errors: stats.compilation.errors.slice(0, 2).map(function (_a) {
var name = _a.name, message = _a.message;
return ({
name: name,
message: message ? message(0, 200) : '',
});
}),
stages: this.getStages(stats),
node: {
node: node,
alinode: alinode,
},
git: utils_1.getGitInfo(this.cwd),
platform: utils_1.getPlatformInfo(),
envs: process.env,
hardware: utils_1.getHardware(),
shameimaruUrl: depTreeOssUrl,
}];
}
});
});
};

@@ -76,0 +110,0 @@ // 取 stages

@@ -11,2 +11,3 @@ import * as webpack from 'webpack';

cloudBuildLog?: string;
appType?: string;
appName?: string;

@@ -25,3 +26,3 @@ }

memory?: number;
hostName?: string;
hostname?: string;
platform?: string;

@@ -46,3 +47,3 @@ }

success: boolean;
startAt: Date;
startedAt: Date;
endedAt: Date;

@@ -69,2 +70,3 @@ cwd: string;

hardware: IHardware;
shameimaruUrl: string;
}

@@ -71,0 +73,0 @@ export interface ICreateRuntime extends ICommonArgs {

@@ -1,4 +0,3 @@

import getHardware from './getHardware';
import { IPkg, IBuildGitInfo, IPlatformInfo, IHardware } from '../typings';
import GitInfo from './GitInfo';
import { IPkg, IBuildGitInfo, IPlatformInfo } from '../typings';
declare function getPkg(cwd: any): IPkg;

@@ -12,2 +11,4 @@ declare function getArtifactInfo(stats: any): {

declare function getPlatformInfo(): IPlatformInfo;
export { GitInfo, getHardware, getPkg, getArtifactInfo, getGitInfo, getPlatformInfo, };
declare function getHardware(): IHardware;
declare function getDepTree(cwd: string): Promise<any>;
export { GitInfo, getHardware, getPkg, getArtifactInfo, getGitInfo, getPlatformInfo, getDepTree, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var getHardware_1 = require("./getHardware");
exports.getHardware = getHardware_1.default;
var tslib_1 = require("tslib");
var os = require("os");
var path_1 = require("path");
var fs_1 = require("fs");
var enum_1 = require("../enum");
var GitInfo_1 = require("./GitInfo");
exports.GitInfo = GitInfo_1.default;
var enum_1 = require("../enum");
var path_1 = require("path");
var fs_1 = require("fs");
function getPkg(cwd) {

@@ -48,7 +48,3 @@ var pkg = {};

function getPlatformInfo() {
var _a = process.env, PLATFORM_TYPE = _a.PLATFORM_TYPE,
// basement
CLOUD_BUILD_ID = _a.CLOUD_BUILD_ID, CLOUD_BUILD_LOG = _a.CLOUD_BUILD_LOG,
// linke
APP_NAME = _a.APP_NAME;
var _a = process.env, PLATFORM_TYPE = _a.PLATFORM_TYPE, CLOUD_BUILD_ID = _a.CLOUD_BUILD_ID, CLOUD_BUILD_LOG = _a.CLOUD_BUILD_LOG, APP_NAME = _a.APP_NAME, APP_TYPE = _a.APP_TYPE;
var type = [enum_1.PLATFORM_TYPE.BASEMENT, enum_1.PLATFORM_TYPE.LINKE].indexOf(PLATFORM_TYPE) > -1

@@ -60,8 +56,30 @@ ? PLATFORM_TYPE

// basement
cloudBuildId: (CLOUD_BUILD_ID || ''),
cloudBuildLog: CLOUD_BUILD_LOG || '',
cloudBuildId: (CLOUD_BUILD_ID || null),
cloudBuildLog: CLOUD_BUILD_LOG || null,
// appname
appName: APP_NAME,
appType: APP_TYPE,
};
}
exports.getPlatformInfo = getPlatformInfo;
function getHardware() {
return {
cpuLength: os.cpus().length,
arch: os.arch(),
memory: os.totalmem() / 1024 / 1024 / 1024,
hostname: os.hostname(),
platform: os.platform(),
};
}
exports.getHardware = getHardware;
function getDepTree(cwd) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var Shameimaru, shameimaru;
return tslib_1.__generator(this, function (_a) {
Shameimaru = require('shameimaru');
shameimaru = new Shameimaru(cwd);
return [2 /*return*/, shameimaru.traverse()];
});
});
}
exports.getDepTree = getDepTree;
{
"name": "bigbrother-webpack-plugin",
"version": "1.1.1",
"version": "1.1.2",
"description": "bigbrother client",

@@ -13,3 +13,3 @@ "main": "lib/index.js",

"build": "npm run clean && tsc",
"test": "npm run build && TEST=1 mocha -r ts-node/register test/**/*.test.ts",
"test": "npm run build && TEST=1 mocha -r ts-node/register test/*.test.ts test/**/*.test.ts",
"ci": "npm run lint && npm run test",

@@ -63,6 +63,6 @@ "lint": "tslint --project ./tsconfig.json",

"is-ali-env": "^0.1.4",
"shameimaru": "^1.0.1",
"tslib": "^1.9.3",
"urllib": "^2.31.2",
"uuid": "^3.3.2"
}
}
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