Skip to content

Commit

Permalink
support node.js args (#92)
Browse files Browse the repository at this point in the history
* support node.js args

* Updated documentation
  • Loading branch information
jkanczler authored Aug 13, 2019
1 parent 09504fc commit c84f7da
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 52 deletions.
3 changes: 3 additions & 0 deletions DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ Name | Required | Default Value | Description
webpack cli arguments | false | | Arguments to pass to the webpack cli.
treat errors as | true | errors | How to treat errors. Options are: errors (breaks build) / warnings (marks build as partially succeeded) / info (reports errors as info).
treat warnings as | true | warnings | How to treat warnings. Options are: errors (breaks build) / warnings (marks build partially succeeded) / info (reports warnings as info).
node cli arguments | false | | Arguments to pass to the node cli.
workingFolder | false | | Working folder where webpack compilation is run. If you leave it blank it is the root of the repository.
webpack cli location | true | ./node_modules/webpack/bin/webpack.js | Location of the webpack cli. By default it's the locally installed webpack cli.
stats.js Location | true | ./node_modules/webpack/lib/Stats.js | Location of the Stats.js. By default it's the Stats.js from the locally installed webpack.

## <a id="release-notes"></a>Release Notes

* 4.2.0 (13/08/2019)
* Node.js arguments are supported.
* 4.1.6 (21/06/2019)
* Security warnings are fixed
* 4.1.5 (18/06/2019)
Expand Down
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
next-version: 4.1.6
next-version: 4.2.0
assembly-informational-format: '{SemVer}'
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ Name | Required | Default Value | Description
webpack cli arguments | false | | Arguments to pass to the webpack cli.
treat errors as | true | errors | How to treat errors. Options are: errors (breaks build) / warnings (marks build as partially succeeded) / info (reports errors as info).
treat warnings as | true | warnings | How to treat warnings. Options are: errors (breaks build) / warnings (marks build partially succeeded) / info (reports warnings as info).
node cli arguments | false | | Arguments to pass to the node cli.
workingFolder | false | | Working folder where webpack compilation is run. If you leave it blank it is the root of the repository.
webpack cli location | true | ./node_modules/webpack/bin/webpack.js | Location of the webpack cli. By default it's the locally installed webpack cli.
stats.js Location | true | ./node_modules/webpack/lib/Stats.js | Location of the Stats.js. By default it's the Stats.js from the locally installed webpack.

## <a id="release-notes"></a>Release Notes

* 4.2.0 (13/08/2019)
* Node.js arguments are supported.
* 4.1.6 (21/06/2019)
* Security warnings are fixed
* 4.1.5 (18/06/2019)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wepback-vsts-extension",
"version": "4.1.6",
"version": "4.2.0",
"description": "webpack Visual Studio Team System (VSTS) Extension",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion tasks/webpack-build-task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function run(): Promise<void> {
let workingFolder = tl.getPathInput("workingFolder", false);
const webpackCliLocation = tl.getInput("webpackCliLocation", true);
const webpackCliArguments = tl.getInput("webpackCliArguments", false);
const nodeCliArguments = tl.getInput("nodeCliArguments", false);
const webpackStatsJsLocation = tl.getInput("statsjsLocation", true);
const treatErrorsAs = tl.getInput("treatErrorsAs", true);
const treatWarningsAs = tl.getInput("treatWarningsAs", true);
Expand All @@ -29,6 +30,7 @@ async function run(): Promise<void> {
console.log(`workingFolder: ${workingFolder}`);
console.log(`webpackCliLocation: ${webpackCliLocation}`);
console.log(`webpackCliArguments: ${webpackCliArguments}`);
console.log(`nodeCliArguments: ${nodeCliArguments}`);
console.log(`statsjsLocation: ${webpackStatsJsLocation}`);

console.log(`treatErrorsAs: ${treatErrorsAs}`);
Expand All @@ -37,7 +39,7 @@ async function run(): Promise<void> {
tl.cd(workingFolder);
process.chdir(workingFolder);

const result = compile(workingFolder, webpackCliLocation, webpackCliArguments, webpackStatsJsLocation);
const result = compile(workingFolder, webpackCliLocation, webpackCliArguments, webpackStatsJsLocation, nodeCliArguments);
await publishTaskResult(taskDisplayName, result, treatErrorsAs, treatWarningsAs, workingFolder, webpackStatsJsLocation, enablePullRequestComments);

} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions tasks/webpack-build-task/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-build-task",
"version": "4.1.6",
"version": "4.2.0",
"description": "Webpack build task for Visual Studio Team System (VSTS)",
"main": "index.js",
"scripts": {},
Expand All @@ -15,9 +15,9 @@
"author": "Dealogic",
"license": "MIT",
"dependencies": {
"filenamify": "2.1.0",
"filenamify": "4.1.0",
"vso-node-api": "6.5.0",
"vsts-task-lib": "2.6.0"
"vsts-task-lib": "2.7.0"
},
"devDependencies": {}
}
13 changes: 11 additions & 2 deletions tasks/webpack-build-task/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"version": {
"Major": 4,
"Minor": 1,
"Patch": 6
"Minor": 2,
"Patch": 0
},
"minimumAgentVersion": "1.95.0",
"groups": [
Expand Down Expand Up @@ -63,6 +63,15 @@
"info": "info"
}
},
{
"name": "nodeCliArguments",
"type": "string",
"label": "node cli arguments",
"defaultValue": "",
"required": false,
"helpMarkDown": "Arguments for node cli.",
"groupName": "advanced"
},
{
"name": "workingFolder",
"type": "filePath",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface ITestRunConfiguration {
workingFolder?: string;
webpackCliLocation?: string;
webpackCliArguments?: string;
nodeCliArguments?: string;
statsjsLocation?: string;
treatErrorsAs?: string;
treatWarningsAs?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const runTestTask = (testRunConfiguration: ITestRunConfiguration) => {
testRunConfiguration.webpackCliArguments = "";
}

if (!testRunConfiguration.nodeCliArguments) {
testRunConfiguration.nodeCliArguments = "";
}

if (!testRunConfiguration.statsjsLocation) {
testRunConfiguration.statsjsLocation = "./node_modules/webpack/lib/Stats.js";
}
Expand All @@ -43,6 +47,7 @@ const runTestTask = (testRunConfiguration: ITestRunConfiguration) => {

taskMockRunner.setInput("webpackCliLocation", testRunConfiguration.webpackCliLocation);
taskMockRunner.setInput("webpackCliArguments", testRunConfiguration.webpackCliArguments);
taskMockRunner.setInput("nodeCliArguments", testRunConfiguration.nodeCliArguments);
taskMockRunner.setInput("statsjsLocation", testRunConfiguration.statsjsLocation);
taskMockRunner.setInput("workingFolder", testRunConfiguration.workingFolder);
taskMockRunner.setInput("treatErrorsAs", testRunConfiguration.treatErrorsAs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import runTestTask from "./shared/testTaskRunner";
import * as path from "path";

runTestTask({
nodeCliArguments: "--max_old_space_size=4096",
workingFolder: path.resolve(__dirname, "../../../../../samples/webpack-ts-config"),
mockWriteFile: true
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as path from "path";
import { MockTestRunner } from "vsts-task-lib/mock-test";
import { assert } from "chai";

const mockRunnerDefinitions = "mockRunnerDefinitions";

export function executeTest(done: MochaDone): void {
// tslint:disable-next-line:no-invalid-this
this.timeout(60000);

const testPath = path.join(__dirname, mockRunnerDefinitions, "shouldBeAbleToUseNodeArgs.js");
const testRunner = new MockTestRunner(testPath);

testRunner.run();
console.log(testRunner.stdout);

assert.isTrue(testRunner.succeeded, "webpack task should be succeeded");

assert.include(testRunner.stdout, "executing the command: node --max_old_space_size=4096", "node args is not included");

done();
}
6 changes: 6 additions & 0 deletions tasks/webpack-build-task/tests/integrationTests/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as shouldSucceedIfNoDisplayNameDefined from "./shouldSucceedIfNoDisplay
import * as shouldSucceedIfNoErrorsAndWarnings from "./shouldSucceedIfNoErrorsAndWarnings";
import * as shouldSucceedIfThereAreErrorsButTreatedAsInfo from "./shouldSucceedIfThereAreErrorsButTreatedAsInfo";
import * as shouldSucceedIfThereAreWarningsButTreatedAsInfo from "./shouldSucceedIfThereAreWarningsButTreatedAsInfo";
import * as shouldBeAbleToUseNodeArgs from "./shouldBeAbleToUseNodeArgs";

describe("webpack build task", () => {
after((done: MochaDone) => {
Expand Down Expand Up @@ -157,4 +158,9 @@ describe("webpack build task", () => {
it(
"should succeed if there are warnings, but those are treated as info",
shouldSucceedIfThereAreWarningsButTreatedAsInfo.executeTest);

it(
"should be able to use node args",
shouldBeAbleToUseNodeArgs.executeTest
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import * as path from "path";
import { execSync, ExecOptionsWithStringEncoding } from "child_process";
import * as tl from "vsts-task-lib/task";

const executeWebpackCli = (workingFolder: string, webpackCliLocation: string, webpackCliArguments: string) => {
const executeWebpackCli = (workingFolder: string, webpackCliLocation: string, webpackCliArguments: string, nodeCliArguments: string) => {
if (webpackCliArguments) {
webpackCliArguments = `--json ${webpackCliArguments}`;
} else {
webpackCliArguments = "--json";
}

if (!nodeCliArguments) {
nodeCliArguments = "";
}

tl.cd(workingFolder);
webpackCliLocation = path.resolve(workingFolder, webpackCliLocation);
const webpackCliCommand = `node "${webpackCliLocation}" ${webpackCliArguments}`;
const webpackCliCommand = `node ${nodeCliArguments} "${webpackCliLocation}" ${webpackCliArguments}`;

console.log(`executing the command: ${webpackCliCommand}`);

Expand Down
10 changes: 8 additions & 2 deletions tasks/webpack-build-task/webpackCompiler/WebpackCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@ const decorateWithShowErrorsAndShowWarnings = (result: IWebpackCompilationResult
}
};

export function compile(workingFolder: string, webpackCliLocation: string, webpackCliArguments: string, statsjsLocation: string): IWebpackCompilationResult {
export function compile(
workingFolder: string,
webpackCliLocation: string,
webpackCliArguments: string,
statsjsLocation: string,
nodeCliArguments: string): IWebpackCompilationResult {

console.log("compilation of the webpack project is started");

let stdout: string;
let result: IWebpackCompilationResult;
let error: any;

try {
stdout = executeWebpackCli(workingFolder, webpackCliLocation, webpackCliArguments);
stdout = executeWebpackCli(workingFolder, webpackCliLocation, webpackCliArguments, nodeCliArguments);
} catch (executeWebpackCliError) {
error = executeWebpackCliError;
stdout = executeWebpackCliError.stdout;
Expand Down
20 changes: 10 additions & 10 deletions tasks/webpack-build-task/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ filename-reserved-regex@^2.0.0:
resolved "https://registry.yarnpkg.com/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
integrity sha1-q/c9+rc10EVECr/qLZHzieu/oik=

filenamify@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-2.1.0.tgz#88faf495fb1b47abfd612300002a16228c677ee9"
integrity sha512-ICw7NTT6RsDp2rnYKVd8Fu4cr6ITzGy3+u4vUujPkabyaz+03F24NWEX7fs5fp+kBonlaqPH8fAO2NM+SXt/JA==
filenamify@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/filenamify/-/filenamify-4.1.0.tgz#54d110810ae74eebfe115c1b995bd07e03cf2184"
integrity sha512-KQV/uJDI9VQgN7sHH1Zbk6+42cD6mnQ2HONzkXUfPJ+K2FC8GZ1dpewbbHw0Sz8Tf5k3EVdHVayM4DoAwWlmtg==
dependencies:
filename-reserved-regex "^2.0.0"
strip-outer "^1.0.0"
strip-outer "^1.0.1"
trim-repeated "^1.0.0"

minimatch@3.0.4:
Expand Down Expand Up @@ -66,7 +66,7 @@ shelljs@^0.3.0:
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.3.0.tgz#3596e6307a781544f591f37da618360f31db57b1"
integrity sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=

strip-outer@^1.0.0:
strip-outer@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/strip-outer/-/strip-outer-1.0.1.tgz#b2fd2abf6604b9d1e6013057195df836b8a9d631"
integrity sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==
Expand Down Expand Up @@ -112,10 +112,10 @@ vso-node-api@6.5.0:
typed-rest-client "^0.12.0"
underscore "1.8.3"

vsts-task-lib@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/vsts-task-lib/-/vsts-task-lib-2.6.0.tgz#c82007e66829a1cd3a24ce031f153410256bf0a8"
integrity sha512-ja2qX4BIUvswcNbGtIoGo1SM5mRVc3Yaf7oM4oY64bNHs04chKfvH6f3cDDG0pd44OrZIGQE9LgECzeau6z2wA==
vsts-task-lib@2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/vsts-task-lib/-/vsts-task-lib-2.7.0.tgz#742973d2e9d6ad2fc30b732061088cdb6c7d2709"
integrity sha512-zQqgneIZG3VY84RoIzkQr07r9fDH3lPpj6Qp07K89co/vyFznWJYpkjcdxubQm1YvgNu/P0yWYLdDruHyGGdtA==
dependencies:
minimatch "3.0.4"
mockery "^1.7.0"
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifestVersion": 1,
"id": "webpack-vsts-extension",
"version": "4.1.6",
"version": "4.2.0",
"name": "webpack",
"description": "bundle your assets, scripts, images, styles",
"publisher": "Dealogic",
Expand Down
Loading

0 comments on commit c84f7da

Please sign in to comment.