From 6b603e45b4d873c9ddda74732d4ad07cc6c3fddc Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Wed, 15 Jan 2025 11:00:03 -0800 Subject: [PATCH 1/8] add additional checklist verification for previous app release --- .github/libs/GithubUtils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/libs/GithubUtils.ts b/.github/libs/GithubUtils.ts index ae74621b356a..be88f0299771 100644 --- a/.github/libs/GithubUtils.ts +++ b/.github/libs/GithubUtils.ts @@ -356,7 +356,11 @@ class GithubUtils { // eslint-disable-next-line max-len issueBody += `\r\n- [${ isFirebaseChecked ? 'x' : ' ' - }] I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).`; + }] I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **this release version** and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).`; + // eslint-disable-next-line max-len + issueBody += `\r\n- [${ + isFirebaseChecked ? 'x' : ' ' + }] I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **the previous release version** and verified that the release did not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).`; // eslint-disable-next-line max-len issueBody += `\r\n- [${isGHStatusChecked ? 'x' : ' '}] I checked [GitHub Status](https://www.githubstatus.com/) and verified there is no reported incident with Actions.`; From f4393f728070e34e2f83b1fad369cd9804b5928b Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Wed, 15 Jan 2025 11:15:42 -0800 Subject: [PATCH 2/8] disable eslint which shouldn't apply to Github workflow automation --- .github/libs/GithubUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/libs/GithubUtils.ts b/.github/libs/GithubUtils.ts index be88f0299771..d007782673a5 100644 --- a/.github/libs/GithubUtils.ts +++ b/.github/libs/GithubUtils.ts @@ -463,6 +463,7 @@ class GithubUtils { */ static getLatestWorkflowRunID(workflow: string | number): Promise { console.log(`Fetching New Expensify workflow runs for ${workflow}...`); + // eslint-disable-next-line rulesdir/no-default-id-values return this.octokit.actions .listWorkflowRuns({ owner: CONST.GITHUB_OWNER, From cf214abcd6d8c95cb58eabad445b0dfe3fb9a4f9 Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Wed, 15 Jan 2025 11:41:09 -0800 Subject: [PATCH 3/8] update checklist test cases with new firebase verification --- tests/unit/GithubUtilsTest.ts | 31 +++++++++++++------ tests/unit/createOrUpdateStagingDeployTest.ts | 19 ++++++++---- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/tests/unit/GithubUtilsTest.ts b/tests/unit/GithubUtilsTest.ts index 73bd27bf99e9..c5a4e09bc7f1 100644 --- a/tests/unit/GithubUtilsTest.ts +++ b/tests/unit/GithubUtilsTest.ts @@ -417,8 +417,11 @@ describe('GithubUtils', () => { const timingDashboardVerification = 'I checked the [App Timing Dashboard](https://graphs.expensify.com/grafana/d/yj2EobAGz/app-timing?orgId=1) and verified this release does not cause a noticeable performance regression.'; // eslint-disable-next-line max-len - const firebaseVerification = - 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; + const firebaseVerificationCurrentRelease = + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **this release version** and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; + // eslint-disable-next-line max-len + const firebaseVerificationPreviousRelease = + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **the previous release version** and verified that the release did not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; // eslint-disable-next-line max-len const ghVerification = 'I checked [GitHub Status](https://www.githubstatus.com/) and verified there is no reported incident with Actions.'; @@ -446,7 +449,8 @@ describe('GithubUtils', () => { `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -469,7 +473,8 @@ describe('GithubUtils', () => { `${lineBreak}${closedCheckbox}${basePRList.at(5)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -487,7 +492,8 @@ describe('GithubUtils', () => { `${allVerifiedExpectedOutput}` + `${lineBreak}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -508,7 +514,8 @@ describe('GithubUtils', () => { `${lineBreak}${openCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}${lineBreak}` + `${lineBreak}${ccApplauseLeads}`, ); @@ -529,7 +536,8 @@ describe('GithubUtils', () => { `${lineBreak}${openCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -554,7 +562,8 @@ describe('GithubUtils', () => { `${lineBreak}${closedCheckbox}${baseDeployBlockerList.at(1)}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -580,7 +589,8 @@ describe('GithubUtils', () => { `${lineBreak}${openCheckbox}${internalQAPRList.at(1)}${assignOctocat}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); @@ -606,7 +616,8 @@ describe('GithubUtils', () => { `${lineBreak}${openCheckbox}${internalQAPRList.at(1)}${assignOctocat}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, ); diff --git a/tests/unit/createOrUpdateStagingDeployTest.ts b/tests/unit/createOrUpdateStagingDeployTest.ts index 59ed5b247ca3..90119f48d8ac 100644 --- a/tests/unit/createOrUpdateStagingDeployTest.ts +++ b/tests/unit/createOrUpdateStagingDeployTest.ts @@ -126,8 +126,11 @@ const deployerVerificationsHeader = '**Deployer verifications:**'; const timingDashboardVerification = 'I checked the [App Timing Dashboard](https://graphs.expensify.com/grafana/d/yj2EobAGz/app-timing?orgId=1) and verified this release does not cause a noticeable performance regression.'; // eslint-disable-next-line max-len -const firebaseVerification = - 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; +const firebaseVerificationCurrentRelease = + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **this release version** and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; +// eslint-disable-next-line max-len +const firebaseVerificationPreviousRelease = + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **the previous release version** and verified that the release did not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; // eslint-disable-next-line max-len const ghVerification = 'I checked [GitHub Status](https://www.githubstatus.com/) and verified there is no reported incident with Actions.'; const ccApplauseLeads = 'cc @Expensify/applauseleads\r\n'; @@ -199,7 +202,8 @@ describe('createOrUpdateStagingDeployCash', () => { `${lineBreak}${openCheckbox}${basePRList.at(7)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, }); @@ -223,7 +227,8 @@ describe('createOrUpdateStagingDeployCash', () => { `${lineBreak}${closedCheckbox}${basePRList.at(9)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${closedCheckbox}${timingDashboardVerification}` + - `${lineBreak}${closedCheckbox}${firebaseVerification}` + + `${lineBreak}${closedCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${closedCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${closedCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, state: 'open', @@ -323,7 +328,8 @@ describe('createOrUpdateStagingDeployCash', () => { `${lineBreakDouble}${deployerVerificationsHeader}` + // Note: these will be unchecked with a new app version, and that's intentional `${lineBreak}${openCheckbox}${timingDashboardVerification}` + - `${lineBreak}${openCheckbox}${firebaseVerification}` + + `${lineBreak}${openCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${openCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${openCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, }); @@ -396,7 +402,8 @@ describe('createOrUpdateStagingDeployCash', () => { `${lineBreak}${openCheckbox}${baseIssueList.at(1)}${lineBreak}` + `${lineBreakDouble}${deployerVerificationsHeader}` + `${lineBreak}${closedCheckbox}${timingDashboardVerification}` + - `${lineBreak}${closedCheckbox}${firebaseVerification}` + + `${lineBreak}${closedCheckbox}${firebaseVerificationCurrentRelease}` + + `${lineBreak}${closedCheckbox}${firebaseVerificationPreviousRelease}` + `${lineBreak}${closedCheckbox}${ghVerification}` + `${lineBreakDouble}${ccApplauseLeads}`, }); From 68709b8d905bf165f0db1ba2e5d5039bbb363838 Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Wed, 15 Jan 2025 11:49:40 -0800 Subject: [PATCH 4/8] commit prettier diff --- tests/unit/GithubUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/GithubUtilsTest.ts b/tests/unit/GithubUtilsTest.ts index c5a4e09bc7f1..fb2b551c5b1f 100644 --- a/tests/unit/GithubUtilsTest.ts +++ b/tests/unit/GithubUtilsTest.ts @@ -418,10 +418,10 @@ describe('GithubUtils', () => { 'I checked the [App Timing Dashboard](https://graphs.expensify.com/grafana/d/yj2EobAGz/app-timing?orgId=1) and verified this release does not cause a noticeable performance regression.'; // eslint-disable-next-line max-len const firebaseVerificationCurrentRelease = - 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **this release version** and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **this release version** and verified that this release does not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; // eslint-disable-next-line max-len const firebaseVerificationPreviousRelease = - 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **the previous release version** and verified that the release did not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; + 'I checked [Firebase Crashlytics](https://console.firebase.google.com/u/0/project/expensify-chat/crashlytics/app/android:com.expensify.chat/issues?state=open&time=last-seven-days&tag=all) for **the previous release version** and verified that the release did not introduce any new crashes. More detailed instructions on this verification can be found [here](https://stackoverflowteams.com/c/expensify/questions/15095/15096).'; // eslint-disable-next-line max-len const ghVerification = 'I checked [GitHub Status](https://www.githubstatus.com/) and verified there is no reported incident with Actions.'; From c99ee36a71d5a76771de793861241775dc4b1c0c Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Wed, 15 Jan 2025 11:53:50 -0800 Subject: [PATCH 5/8] run npm run gh-actions-build --- .../javascript/authorChecklist/index.js | 3376 +++++++---------- .../javascript/awaitStagingDeploys/index.js | 5 +- .../javascript/checkAndroidStatus/index.js | 15 +- .../javascript/checkDeployBlockers/index.js | 5 +- .../createOrUpdateStagingDeploy/index.js | 5 +- .../getAndroidRolloutPercentage/index.js | 10 +- .../javascript/getArtifactInfo/index.js | 5 +- .../getDeployPullRequestList/index.js | 5 +- .../javascript/getPullRequestDetails/index.js | 5 +- .../javascript/isStagingDeployLocked/index.js | 5 +- .../markPullRequestsAsDeployed/index.js | 5 +- .../javascript/postTestBuildComment/index.js | 5 +- .../javascript/proposalPoliceComment/index.js | 7 +- .../reopenIssueWithComment/index.js | 5 +- .../javascript/reviewerChecklist/index.js | 5 +- .../javascript/verifySignedCommits/index.js | 5 +- 16 files changed, 1366 insertions(+), 2102 deletions(-) diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 20fdd2990005..4b7fe9699c6d 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -3482,332 +3482,6 @@ exports.checkBypass = checkBypass; //# sourceMappingURL=gen-mapping.umd.js.map -/***/ }), - -/***/ 9105: -/***/ ((module) => { - -"use strict"; - - -const object = {}; -const hasOwnProperty = object.hasOwnProperty; -const forOwn = (object, callback) => { - for (const key in object) { - if (hasOwnProperty.call(object, key)) { - callback(key, object[key]); - } - } -}; - -const extend = (destination, source) => { - if (!source) { - return destination; - } - forOwn(source, (key, value) => { - destination[key] = value; - }); - return destination; -}; - -const forEach = (array, callback) => { - const length = array.length; - let index = -1; - while (++index < length) { - callback(array[index]); - } -}; - -const fourHexEscape = (hex) => { - return '\\u' + ('0000' + hex).slice(-4); -} - -const hexadecimal = (code, lowercase) => { - let hexadecimal = code.toString(16); - if (lowercase) return hexadecimal; - return hexadecimal.toUpperCase(); -}; - -const toString = object.toString; -const isArray = Array.isArray; -const isBuffer = (value) => { - return typeof Buffer === 'function' && Buffer.isBuffer(value); -}; -const isObject = (value) => { - // This is a very simple check, but it’s good enough for what we need. - return toString.call(value) == '[object Object]'; -}; -const isString = (value) => { - return typeof value == 'string' || - toString.call(value) == '[object String]'; -}; -const isNumber = (value) => { - return typeof value == 'number' || - toString.call(value) == '[object Number]'; -}; -const isFunction = (value) => { - return typeof value == 'function'; -}; -const isMap = (value) => { - return toString.call(value) == '[object Map]'; -}; -const isSet = (value) => { - return toString.call(value) == '[object Set]'; -}; - -/*--------------------------------------------------------------------------*/ - -// https://mathiasbynens.be/notes/javascript-escapes#single -const singleEscapes = { - '\\': '\\\\', - '\b': '\\b', - '\f': '\\f', - '\n': '\\n', - '\r': '\\r', - '\t': '\\t' - // `\v` is omitted intentionally, because in IE < 9, '\v' == 'v'. - // '\v': '\\x0B' -}; -const regexSingleEscape = /[\\\b\f\n\r\t]/; - -const regexDigit = /[0-9]/; -const regexWhitespace = /[\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/; - -const escapeEverythingRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^]/g; -const escapeNonAsciiRegex = /([\uD800-\uDBFF][\uDC00-\uDFFF])|([\uD800-\uDFFF])|(['"`])|[^ !#-&\(-\[\]-_a-~]/g; - -const jsesc = (argument, options) => { - const increaseIndentation = () => { - oldIndent = indent; - ++options.indentLevel; - indent = options.indent.repeat(options.indentLevel) - }; - // Handle options - const defaults = { - 'escapeEverything': false, - 'minimal': false, - 'isScriptContext': false, - 'quotes': 'single', - 'wrap': false, - 'es6': false, - 'json': false, - 'compact': true, - 'lowercaseHex': false, - 'numbers': 'decimal', - 'indent': '\t', - 'indentLevel': 0, - '__inline1__': false, - '__inline2__': false - }; - const json = options && options.json; - if (json) { - defaults.quotes = 'double'; - defaults.wrap = true; - } - options = extend(defaults, options); - if ( - options.quotes != 'single' && - options.quotes != 'double' && - options.quotes != 'backtick' - ) { - options.quotes = 'single'; - } - const quote = options.quotes == 'double' ? - '"' : - (options.quotes == 'backtick' ? - '`' : - '\'' - ); - const compact = options.compact; - const lowercaseHex = options.lowercaseHex; - let indent = options.indent.repeat(options.indentLevel); - let oldIndent = ''; - const inline1 = options.__inline1__; - const inline2 = options.__inline2__; - const newLine = compact ? '' : '\n'; - let result; - let isEmpty = true; - const useBinNumbers = options.numbers == 'binary'; - const useOctNumbers = options.numbers == 'octal'; - const useDecNumbers = options.numbers == 'decimal'; - const useHexNumbers = options.numbers == 'hexadecimal'; - - if (json && argument && isFunction(argument.toJSON)) { - argument = argument.toJSON(); - } - - if (!isString(argument)) { - if (isMap(argument)) { - if (argument.size == 0) { - return 'new Map()'; - } - if (!compact) { - options.__inline1__ = true; - options.__inline2__ = false; - } - return 'new Map(' + jsesc(Array.from(argument), options) + ')'; - } - if (isSet(argument)) { - if (argument.size == 0) { - return 'new Set()'; - } - return 'new Set(' + jsesc(Array.from(argument), options) + ')'; - } - if (isBuffer(argument)) { - if (argument.length == 0) { - return 'Buffer.from([])'; - } - return 'Buffer.from(' + jsesc(Array.from(argument), options) + ')'; - } - if (isArray(argument)) { - result = []; - options.wrap = true; - if (inline1) { - options.__inline1__ = false; - options.__inline2__ = true; - } - if (!inline2) { - increaseIndentation(); - } - forEach(argument, (value) => { - isEmpty = false; - if (inline2) { - options.__inline2__ = false; - } - result.push( - (compact || inline2 ? '' : indent) + - jsesc(value, options) - ); - }); - if (isEmpty) { - return '[]'; - } - if (inline2) { - return '[' + result.join(', ') + ']'; - } - return '[' + newLine + result.join(',' + newLine) + newLine + - (compact ? '' : oldIndent) + ']'; - } else if (isNumber(argument)) { - if (json) { - // Some number values (e.g. `Infinity`) cannot be represented in JSON. - return JSON.stringify(argument); - } - if (useDecNumbers) { - return String(argument); - } - if (useHexNumbers) { - let hexadecimal = argument.toString(16); - if (!lowercaseHex) { - hexadecimal = hexadecimal.toUpperCase(); - } - return '0x' + hexadecimal; - } - if (useBinNumbers) { - return '0b' + argument.toString(2); - } - if (useOctNumbers) { - return '0o' + argument.toString(8); - } - } else if (!isObject(argument)) { - if (json) { - // For some values (e.g. `undefined`, `function` objects), - // `JSON.stringify(value)` returns `undefined` (which isn’t valid - // JSON) instead of `'null'`. - return JSON.stringify(argument) || 'null'; - } - return String(argument); - } else { // it’s an object - result = []; - options.wrap = true; - increaseIndentation(); - forOwn(argument, (key, value) => { - isEmpty = false; - result.push( - (compact ? '' : indent) + - jsesc(key, options) + ':' + - (compact ? '' : ' ') + - jsesc(value, options) - ); - }); - if (isEmpty) { - return '{}'; - } - return '{' + newLine + result.join(',' + newLine) + newLine + - (compact ? '' : oldIndent) + '}'; - } - } - - const regex = options.escapeEverything ? escapeEverythingRegex : escapeNonAsciiRegex; - result = argument.replace(regex, (char, pair, lone, quoteChar, index, string) => { - if (pair) { - if (options.minimal) return pair; - const first = pair.charCodeAt(0); - const second = pair.charCodeAt(1); - if (options.es6) { - // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - const codePoint = (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; - const hex = hexadecimal(codePoint, lowercaseHex); - return '\\u{' + hex + '}'; - } - return fourHexEscape(hexadecimal(first, lowercaseHex)) + fourHexEscape(hexadecimal(second, lowercaseHex)); - } - - if (lone) { - return fourHexEscape(hexadecimal(lone.charCodeAt(0), lowercaseHex)); - } - - if ( - char == '\0' && - !json && - !regexDigit.test(string.charAt(index + 1)) - ) { - return '\\0'; - } - - if (quoteChar) { - if (quoteChar == quote || options.escapeEverything) { - return '\\' + quoteChar; - } - return quoteChar; - } - - if (regexSingleEscape.test(char)) { - // no need for a `hasOwnProperty` check here - return singleEscapes[char]; - } - - if (options.minimal && !regexWhitespace.test(char)) { - return char; - } - - const hex = hexadecimal(char.charCodeAt(0), lowercaseHex); - if (json || hex.length > 2) { - return fourHexEscape(hex); - } - - return '\\x' + ('00' + hex).slice(-2); - }); - - if (quote == '`') { - result = result.replace(/\$\{/g, '\\${'); - } - if (options.isScriptContext) { - // https://mathiasbynens.be/notes/etago - result = result - .replace(/<\/(script|style)/gi, '<\\/$1') - .replace(/