Skip to content

Commit a217fec

Browse files
committed
fix(webpack): new release check
Additionally small refactor in package manager to easily export NPM and Yarn. Added a new method `run` in base package manager.
1 parent 76ffaef commit a217fec

File tree

7 files changed

+79
-6
lines changed

7 files changed

+79
-6
lines changed

build/tasks/release-checks/suite-steps.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ module.exports = function(suite) {
6565

6666
if (applicable(features, 'webpack')) {
6767
steps.push(
68+
new tests.webpack.AuBuildDoesNotThrowCommandLineErrors(),
69+
new tests.webpack.AuBuildStartsWebpackInWatchMode(),
6870
new tests.webpack.AuRunDoesNotThrowCommandLineErrors(),
6971
new tests.webpack.AuRunLaunchesServer(),
7072
new tests.webpack.AuRunRendersPage(),
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const Test = require('../test');
2+
const ExecuteCommand = require('../../tasks/execute-command');
3+
const path = require('path');
4+
const fs = require('fs');
5+
6+
class AuBuildDoesNotThrowCommandLineErrors extends Test {
7+
constructor() {
8+
super('au build does not throw commandline errors');
9+
}
10+
11+
onOutput(message) {
12+
this.debug(message);
13+
14+
if (message.toLowerCase().indexOf('error') > -1) {
15+
this.executeCommand.stop();
16+
this.fail();
17+
} else if (isBuildCompletedMessage(message)) {
18+
this.success();
19+
this.executeCommand.stop();
20+
}
21+
}
22+
23+
execute() {
24+
this.executeCommand = new ExecuteCommand('au', ['build'], (msg) => this.onOutput(msg));
25+
return this.executeCommand.executeAsNodeScript();
26+
}
27+
}
28+
29+
class AuBuildStartsWebpackInWatchMode extends Test {
30+
constructor(fileToChange) {
31+
super('au build --watch starts webpack in watch mode');
32+
33+
this.fileToChange = fileToChange || path.join('src', 'app.html');
34+
this.firstBuildCompleted = false;
35+
}
36+
37+
onOutput(message) {
38+
this.debug(message);
39+
40+
if (message.toLowerCase().indexOf('error') > -1) {
41+
this.executeCommand.stop();
42+
this.fail();
43+
} else if (message.indexOf('webpack is watching the files') > -1) {
44+
this.success();
45+
this.executeCommand.stop();
46+
}
47+
}
48+
49+
execute(context) {
50+
this.context = context;
51+
52+
this.executeCommand = new ExecuteCommand('au', ['build', '--watch'], (msg) => this.onOutput(msg));
53+
return this.executeCommand.executeAsNodeScript();
54+
}
55+
}
56+
57+
function isBuildCompletedMessage(msg) {
58+
return msg.indexOf('Built at') > -1;
59+
}
60+
61+
module.exports = {
62+
AuBuildDoesNotThrowCommandLineErrors,
63+
AuBuildStartsWebpackInWatchMode
64+
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
2-
...require('./au-run')
2+
...require('./au-run'),
3+
...require('./au-build')
34
};

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ exports.ProjectItem = require('./project-item').ProjectItem;
88
exports.build = require('./build');
99
exports.Configuration = require('./configuration').Configuration;
1010
exports.reportWebpackReadiness = require('./build/webpack-reporter');
11+
exports.NPM = require('./package-managers/npm').NPM;
12+
exports.Yarn = require('./package-managers/yarn').Yarn;

lib/package-managers/base-package-manager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ exports.BasePackageManager = class {
77
}
88

99
install(packages = [], workingDirectory = process.cwd(), command = 'install') {
10+
return this.run(command, packages, workingDirectory);
11+
}
12+
13+
run(command, args = [], workingDirectory = process.cwd()) {
1014
return new Promise((resolve, reject) => {
1115
spawn(
1216
this.getExecutablePath(workingDirectory),
13-
[command, ...packages],
17+
[command, ...args],
1418
{ stdio: 'inherit', cwd: workingDirectory }
1519
)
1620
.on('close', resolve)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { NPM } from 'aurelia-cli/lib/package-managers/npm';
1+
import { NPM } from 'aurelia-cli';
22

33
export default function() {
44
console.log('`au build` is an alias of the `npm run build`, you may use either of those; see README for more details.');
55

66
const args = process.argv.slice(3);
7-
return (new NPM()).install(['--', ...args], process.cwd(), 'run');
7+
return (new NPM()).run('run', ['build', '--', ...args]);
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { NPM } from 'aurelia-cli/lib/package-managers/npm';
1+
import { NPM } from 'aurelia-cli';
22

33
export default function() {
44
console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.');
55

66
const args = process.argv.slice(3);
7-
return (new NPM()).install(['--', ...args], process.cwd(), 'start');
7+
return (new NPM()).run('start',['--', ...args]);
88
}

0 commit comments

Comments
 (0)