From a217fec9f9da9eac8159a5274b053f513b77c837 Mon Sep 17 00:00:00 2001 From: Sayan751 Date: Mon, 29 Jul 2019 06:18:31 +0200 Subject: [PATCH] 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. --- build/tasks/release-checks/suite-steps.js | 2 + .../release-checks/tests/webpack/au-build.js | 64 +++++++++++++++++++ .../release-checks/tests/webpack/index.js | 3 +- lib/index.js | 2 + lib/package-managers/base-package-manager.js | 6 +- .../webpack/aurelia_project/tasks/build.ext | 4 +- .../webpack/aurelia_project/tasks/run.ext | 4 +- 7 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 build/tasks/release-checks/tests/webpack/au-build.js diff --git a/build/tasks/release-checks/suite-steps.js b/build/tasks/release-checks/suite-steps.js index ce584c821..4cc3fae1e 100644 --- a/build/tasks/release-checks/suite-steps.js +++ b/build/tasks/release-checks/suite-steps.js @@ -65,6 +65,8 @@ module.exports = function(suite) { if (applicable(features, 'webpack')) { steps.push( + new tests.webpack.AuBuildDoesNotThrowCommandLineErrors(), + new tests.webpack.AuBuildStartsWebpackInWatchMode(), new tests.webpack.AuRunDoesNotThrowCommandLineErrors(), new tests.webpack.AuRunLaunchesServer(), new tests.webpack.AuRunRendersPage(), diff --git a/build/tasks/release-checks/tests/webpack/au-build.js b/build/tasks/release-checks/tests/webpack/au-build.js new file mode 100644 index 000000000..1cf479faa --- /dev/null +++ b/build/tasks/release-checks/tests/webpack/au-build.js @@ -0,0 +1,64 @@ +const Test = require('../test'); +const ExecuteCommand = require('../../tasks/execute-command'); +const path = require('path'); +const fs = require('fs'); + +class AuBuildDoesNotThrowCommandLineErrors extends Test { + constructor() { + super('au build does not throw commandline errors'); + } + + onOutput(message) { + this.debug(message); + + if (message.toLowerCase().indexOf('error') > -1) { + this.executeCommand.stop(); + this.fail(); + } else if (isBuildCompletedMessage(message)) { + this.success(); + this.executeCommand.stop(); + } + } + + execute() { + this.executeCommand = new ExecuteCommand('au', ['build'], (msg) => this.onOutput(msg)); + return this.executeCommand.executeAsNodeScript(); + } +} + +class AuBuildStartsWebpackInWatchMode extends Test { + constructor(fileToChange) { + super('au build --watch starts webpack in watch mode'); + + this.fileToChange = fileToChange || path.join('src', 'app.html'); + this.firstBuildCompleted = false; + } + + onOutput(message) { + this.debug(message); + + if (message.toLowerCase().indexOf('error') > -1) { + this.executeCommand.stop(); + this.fail(); + } else if (message.indexOf('webpack is watching the files') > -1) { + this.success(); + this.executeCommand.stop(); + } + } + + execute(context) { + this.context = context; + + this.executeCommand = new ExecuteCommand('au', ['build', '--watch'], (msg) => this.onOutput(msg)); + return this.executeCommand.executeAsNodeScript(); + } +} + +function isBuildCompletedMessage(msg) { + return msg.indexOf('Built at') > -1; +} + +module.exports = { + AuBuildDoesNotThrowCommandLineErrors, + AuBuildStartsWebpackInWatchMode +}; diff --git a/build/tasks/release-checks/tests/webpack/index.js b/build/tasks/release-checks/tests/webpack/index.js index 1d098164b..86c3f4289 100644 --- a/build/tasks/release-checks/tests/webpack/index.js +++ b/build/tasks/release-checks/tests/webpack/index.js @@ -1,3 +1,4 @@ module.exports = { - ...require('./au-run') + ...require('./au-run'), + ...require('./au-build') }; diff --git a/lib/index.js b/lib/index.js index 07d6d0e49..ef1afe2e1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,3 +8,5 @@ exports.ProjectItem = require('./project-item').ProjectItem; exports.build = require('./build'); exports.Configuration = require('./configuration').Configuration; exports.reportWebpackReadiness = require('./build/webpack-reporter'); +exports.NPM = require('./package-managers/npm').NPM; +exports.Yarn = require('./package-managers/yarn').Yarn; diff --git a/lib/package-managers/base-package-manager.js b/lib/package-managers/base-package-manager.js index 91d4d9a20..bc7534b9d 100644 --- a/lib/package-managers/base-package-manager.js +++ b/lib/package-managers/base-package-manager.js @@ -7,10 +7,14 @@ exports.BasePackageManager = class { } install(packages = [], workingDirectory = process.cwd(), command = 'install') { + return this.run(command, packages, workingDirectory); + } + + run(command, args = [], workingDirectory = process.cwd()) { return new Promise((resolve, reject) => { spawn( this.getExecutablePath(workingDirectory), - [command, ...packages], + [command, ...args], { stdio: 'inherit', cwd: workingDirectory } ) .on('close', resolve) diff --git a/skeleton/webpack/aurelia_project/tasks/build.ext b/skeleton/webpack/aurelia_project/tasks/build.ext index c1835fa35..1ad979d4b 100644 --- a/skeleton/webpack/aurelia_project/tasks/build.ext +++ b/skeleton/webpack/aurelia_project/tasks/build.ext @@ -1,8 +1,8 @@ -import { NPM } from 'aurelia-cli/lib/package-managers/npm'; +import { NPM } from 'aurelia-cli'; export default function() { console.log('`au build` is an alias of the `npm run build`, you may use either of those; see README for more details.'); const args = process.argv.slice(3); - return (new NPM()).install(['--', ...args], process.cwd(), 'run'); + return (new NPM()).run('run', ['build', '--', ...args]); } diff --git a/skeleton/webpack/aurelia_project/tasks/run.ext b/skeleton/webpack/aurelia_project/tasks/run.ext index 742dc17e5..79268fcf3 100644 --- a/skeleton/webpack/aurelia_project/tasks/run.ext +++ b/skeleton/webpack/aurelia_project/tasks/run.ext @@ -1,8 +1,8 @@ -import { NPM } from 'aurelia-cli/lib/package-managers/npm'; +import { NPM } from 'aurelia-cli'; export default function() { console.log('`au run` is an alias of the `npm start`, you may use either of those; see README for more details.'); const args = process.argv.slice(3); - return (new NPM()).install(['--', ...args], process.cwd(), 'start'); + return (new NPM()).run('start',['--', ...args]); }