Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to terser-webpack-plugin #115

Merged
merged 5 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"trailingComma": "none",
"bracketSpacing": true,
"overrides": [
{
"files": "*.js",
"options": {
"tabWidth": 2
}
},
{
"files": "*.json",
"options": {
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Types of changes:
- in case of vulnerabilities.
-->

#### Security

- Migrate to [terser-webpack-plugin](https://github.com/webpack-contrib/terser-webpack-plugin) to solve security vulnerability (see #115).

## RobotlegsJS-Macrobot 1.0.0

### [v1.0.3](https://github.com/RobotlegsJS/RobotlegsJS-Macrobot/releases/tag/1.0.3) - 2019-10-24
Expand Down
48 changes: 24 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,50 +82,50 @@
"tslib": "^1.10.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^0.1.3",
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@robotlegsjs/signalcommandmap": "^1.0.2",
"@types/bluebird": "^3.5.28",
"@types/chai": "^4.2.4",
"@types/mocha": "^5.2.7",
"@types/sinon": "^7.5.0",
"@types/webpack-env": "^1.14.1",
"bluebird": "^3.7.1",
"@types/bluebird": "^3.5.29",
"@types/chai": "^4.2.8",
"@types/mocha": "^7.0.1",
"@types/sinon": "^7.5.1",
"@types/webpack-env": "^1.15.1",
"bluebird": "^3.7.2",
"browserify-versionify": "^1.0.6",
"chai": "^4.2.0",
"es6-map": "^0.1.5",
"es6-symbol": "^3.1.2",
"es6-symbol": "^3.1.3",
"glslify": "^7.0.0",
"imports-loader": "^0.8.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-es6-shim": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-sourcemap-writer": "^0.1.2",
"karma-webpack": "^4.0.2",
"mocha": "^6.2.2",
"nyc": "^14.1.1",
"prettier": "^1.18.2",
"mocha": "^7.0.1",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"publish-please": "^5.5.1",
"puppeteer": "^2.0.0",
"puppeteer": "^2.1.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.0",
"sinon": "^7.5.0",
"sinon-chai": "^3.3.0",
"source-map-support": "^0.5.13",
"rimraf": "^3.0.2",
"sinon": "^8.1.1",
"sinon-chai": "^3.4.0",
"source-map-support": "^0.5.16",
"terser-webpack-plugin": "^2.3.4",
"ts-loader": "^6.2.1",
"ts-node": "^8.4.1",
"tslint": "^5.20.0",
"ts-node": "^8.6.2",
"tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.6.4",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.9.0"
"typescript": "^3.7.5",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ISubCommandMapping {

hooks: any[];

payloads: Array<ISubCommandPayload<any>>;
payloads: ISubCommandPayload<any>[];

getOrCreateCommandInstance(injector: IInjector): ICommand;
}
8 changes: 4 additions & 4 deletions src/robotlegs/bender/utilities/macrobot/impl/AbstractMacro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
protected _mappings: SubCommandMappingList;

protected _executeArguments: any;
protected _commandPayloads: Array<ISubCommandPayload<any>> = [];
protected _commandPayloads: ISubCommandPayload<any>[] = [];
protected _commandPayloadsModule: ContainerModule;

constructor(@inject(IContext) context: IContext, @inject(IInjector) injector: IInjector) {
Expand Down Expand Up @@ -76,7 +76,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
protected executeCommand(mapping: ISubCommandMapping): void {
let command: ICommand;
let commandClass: IClass<ICommand> = mapping.commandClass;
let payloads: Array<ISubCommandPayload<any>> = this._commandPayloads.concat(mapping.payloads);
let payloads: ISubCommandPayload<any>[] = this._commandPayloads.concat(mapping.payloads);
let hasPayloads: boolean = payloads.length > 0;

this.mapMacroPayload(this._macroPayload);
Expand Down Expand Up @@ -136,7 +136,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
}
}

protected mapPayloads(payloads: Array<ISubCommandPayload<any>>): void {
protected mapPayloads(payloads: ISubCommandPayload<any>[]): void {
this._commandPayloadsModule = new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind) => {
payloads.forEach((payload: ISubCommandPayload<any>) => {
if (payload.name.length > 0) {
Expand All @@ -151,7 +151,7 @@ export abstract class AbstractMacro extends AsyncCommand implements IMacro {
this._injector.load(this._commandPayloadsModule);
}

protected unmapPayloads(payloads: Array<ISubCommandPayload<any>>): void {
protected unmapPayloads(payloads: ISubCommandPayload<any>[]): void {
this._injector.unload(this._commandPayloadsModule);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class SubCommandMapping implements ISubCommandMapping, ISubCommandConfigu
private _commandClass: IClass<ICommand>;

private _guards: any[] = [];
private _payloads: Array<ISubCommandPayload<any>> = [];
private _payloads: ISubCommandPayload<any>[] = [];
private _hooks: any[] = [];

constructor(commandClass: IClass<ICommand>) {
Expand All @@ -36,7 +36,7 @@ export class SubCommandMapping implements ISubCommandMapping, ISubCommandConfigu
return this._hooks.slice();
}

public get payloads(): Array<ISubCommandPayload<any>> {
public get payloads(): ISubCommandPayload<any>[] {
return this._payloads.slice();
}

Expand Down
52 changes: 21 additions & 31 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const webpack = require("webpack");
const path = require("path");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");

module.exports = env => {

if (!env) env = { production: false, karma: false };

let mode = env.production ? "production" : "development";
let tsconfig = !env.karma ? "tsconfig.json" : "tsconfig.test.json";
let output = env.production ? "dist" : "dist-test";
let filename = env.karma ? "[name].[hash].js" : (env.production ? "robotlegs-macrobot.min.js" : "robotlegs-macrobot.js");
let filename = env.karma ? "[name].[hash].js" : env.production ? "robotlegs-macrobot.min.js" : "robotlegs-macrobot.js";

return {
mode: mode,
Expand All @@ -35,9 +34,7 @@ module.exports = env => {
loader: "ts-loader?configFile=" + tsconfig
},
{
test: ((env.production) /* disable this loader for production builds */
? /^$/
: /^.*(src).*\.ts$/),
test: env.production /* disable this loader for production builds */ ? /^$/ : /^.*(src).*\.ts$/,
loader: "istanbul-instrumenter-loader",
query: {
embedSource: true
Expand All @@ -47,34 +44,27 @@ module.exports = env => {
]
},

plugins: (
(env.production)
? []
: [ new webpack.SourceMapDevToolPlugin({ test: /\.ts$/i }) ]
),
plugins: env.production ? [] : [new webpack.SourceMapDevToolPlugin({ test: /\.ts$/i })],

optimization:
(env.production)
? {
concatenateModules: true,
minimize: true,
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: 4,
uglifyOptions: {
output: {
comments: false
}
optimization: env.production
? {
concatenateModules: true,
minimize: true,
minimizer: [
new TerserPlugin({
cache: true,
parallel: 4,
terserOptions: {
output: {
comments: false
}
})
]
}
: {}
,

}
})
]
}
: {},
resolve: {
extensions: [".ts", ".js", ".json"]
}
}
};
};
Loading