diff --git a/lib/xcodebuild.js b/lib/xcodebuild.js index 2862cb6a0..54add615e 100644 --- a/lib/xcodebuild.js +++ b/lib/xcodebuild.js @@ -10,7 +10,6 @@ import { } from './utils'; import _ from 'lodash'; import path from 'path'; -import { EOL } from 'os'; import { WDA_RUNNER_BUNDLE_ID } from './constants'; @@ -26,6 +25,13 @@ const IGNORED_ERRORS = [ ERROR_COPYING_ATTACHMENT, 'Failed to remove screenshot at path', ]; +const IGNORED_ERRORS_PATTERN = new RegExp( + '(' + + IGNORED_ERRORS + .map((errStr) => _.escapeRegExp(errStr)) + .join('|') + + ')' +); const RUNNER_SCHEME_TV = 'WebDriverAgentRunner_tvOS'; const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS'; @@ -324,27 +330,26 @@ export class XcodeBuild { ? `Output from xcodebuild ${this.showXcodeLog ? 'will' : 'will not'} be logged` : 'Output from xcodebuild will only be logged if any errors are present there'; this.log.debug(`${logMsg}. To change this, use 'showXcodeLog' desired capability`); - xcodebuild.on('output', (stdout, stderr) => { - let out = stdout || stderr; + const onStreamLine = (/** @type {string} */ line) => { + if (this.showXcodeLog === false || IGNORED_ERRORS_PATTERN.test(line)) { + return; + } // if we have an error we want to output the logs // otherwise the failure is inscrutible // but do not log permission errors from trying to write to attachments folder - const ignoreError = IGNORED_ERRORS.some((x) => out.includes(x)); - if (this.showXcodeLog !== false && out.includes('Error Domain=') && !ignoreError) { + if (line.includes('Error Domain=')) { logXcodeOutput = true; - // handle case where xcode returns 0 but is failing this._didBuildFail = true; } - - // do not log permission errors from trying to write to attachments folder - if (logXcodeOutput && !ignoreError) { - for (const line of out.split(EOL)) { - xcodeLog.error(line); - } + if (logXcodeOutput) { + xcodeLog.info(line); } - }); + }; + for (const streamName of ['stderr', 'stdout']) { + xcodebuild.on(`line-${streamName}`, onStreamLine); + } return xcodebuild; } diff --git a/package.json b/package.json index 116d14b43..9883bc788 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ }, "homepage": "https://github.com/appium/WebDriverAgent#readme", "devDependencies": { - "@appium/eslint-config-appium": "^8.0.4", "@appium/eslint-config-appium-ts": "^0.x", "@appium/test-support": "^3.0.0", "@appium/tsconfig": "^0.x", @@ -86,7 +85,7 @@ "bluebird": "^3.5.5", "lodash": "^4.17.11", "source-map-support": "^0.x", - "teen_process": "^2.0.0" + "teen_process": "^2.2.0" }, "files": [ "index.ts", diff --git a/tsconfig.json b/tsconfig.json index 678d20ad0..e7becfe3b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "extends": "@appium/tsconfig/tsconfig.json", "compilerOptions": { "strict": false, // TODO: make this flag true + "esModuleInterop": true, "outDir": "build", "types": ["node"], "checkJs": true