diff --git a/hooks/lando-setup-build-engine-win32.js b/hooks/lando-setup-build-engine-win32.js index 5d022b276..89eb1e1ea 100644 --- a/hooks/lando-setup-build-engine-win32.js +++ b/hooks/lando-setup-build-engine-win32.js @@ -113,14 +113,13 @@ module.exports = async (lando, options) => { }, requiresRestart: async () => { // if wsl is not installed then this requires a restart - const opts = {debug, ignoreReturnCode: true}; - const {code, stdout} = await require('../utils/run-command')('powershell', ['-Command', 'wsl --status'], opts); + const {code, stdout} = await require('../utils/get-wsl-status')({debug}); console.log(stdout); console.log(Buffer.from(stdout, 'utf8').toString('utf16le')); const hasFeaturesEnabled = !stdout.includes('"Virtual Machine Platform"') && !stdout.includes('"Windows Subsystem for Linux"'); // eslint-disable-line max-len const installed = code === 0 && hasFeaturesEnabled; - lando.log.debug('wsl installed=%o, restart %o', installed, installed ? 'not required' : 'required'); + debug('wsl installed=%o, restart %o', installed, installed ? 'not required' : 'required'); return !installed; }, task: async (ctx, task) => { diff --git a/utils/get-wsl-status.js b/utils/get-wsl-status.js new file mode 100644 index 000000000..3d395acc0 --- /dev/null +++ b/utils/get-wsl-status.js @@ -0,0 +1,22 @@ +'use strict'; + +// Modules +const merge = require('lodash/merge'); + +// get the bosmang +const defaults = { + debug: require('debug')('@lando/get-wsl-status'), + ignoreReturnCode: true, + env: {...process.env, WSL_UTF8: 1}, +}; + +module.exports = async (options = {}) => { + const args = ['-Command', 'wsl --status']; + const opts = merge({}, defaults, options); + const {debug} = opts; + const {code, stdout} = await require('./run-command')('powershell', args, opts); + debug('wsl status', opts); + + return {code, stdout}; +}; + diff --git a/utils/run-command.js b/utils/run-command.js index f26ab2c03..a437fec6d 100644 --- a/utils/run-command.js +++ b/utils/run-command.js @@ -1,3 +1,5 @@ + + 'use strict'; // Modules @@ -18,10 +20,6 @@ module.exports = (command, args = [], options = {}, stdout = '', stderr = '') => options = merge({}, defaults, options); const debug = options.debug; - // this is a weirdly odd and specific thing we need to do - // @TODO: do we need to scope this at all or is it fine to just set regardless? - options.env.WSL_UTF8 = 1; - // birth debug('running command %o %o', command, args); const child = spawn(command, args, options);