From d1ccf38bc37af29d96c1cbacd5a4ef8f37f53e10 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 11 Aug 2022 14:31:31 +0900 Subject: [PATCH 1/4] fix(deps): revert got to v11 got v12: https://github.com/sindresorhus/got/releases/tag/v12.0.0 introduced some breaking changes, including the package becoming pure ESM. For compatibility, the package has been rolled back to v11. --- package.json | 4 +-- yarn.lock | 86 ++++++++++++++++++++++------------------------------ 2 files changed, 39 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index 448c956..55def0a 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ ], "dependencies": { "extract-zip": "^2.0.1", - "got": "^12.0.2", + "got": "^11.8.3", "lodash": "^4.17.21", "regedit": "^5.0.0" }, @@ -56,4 +56,4 @@ "ts-jest": "^27.1.3", "typescript": "^4.4.0" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 9115a73..ed2d356 100644 --- a/yarn.lock +++ b/yarn.lock @@ -553,10 +553,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@sindresorhus/is@^5.2.0": - version "5.3.0" - resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-5.3.0.tgz#0ec9264cf54a527671d990eb874e030b55b70dcc" - integrity sha512-CX6t4SYQ37lzxicAqsBtxA3OseeoVrh9cSJ5PFYam0GksYlupRfy1A+Q4aYD3zvcfECLc0zO2u+ZnR2UYKvCrw== +"@sindresorhus/is@^4.0.0": + version "4.6.0" + resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f" + integrity sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw== "@sinonjs/commons@^1.7.0": version "1.8.3" @@ -572,12 +572,12 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@szmarczak/http-timer@^5.0.1": - version "5.0.1" - resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-5.0.1.tgz#c7c1bf1141cdd4751b0399c8fc7b8b664cd5be3a" - integrity sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw== +"@szmarczak/http-timer@^4.0.5": + version "4.0.6" + resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.6.tgz#b4a914bb62e7c272d4e5989fe4440f812ab1d807" + integrity sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w== dependencies: - defer-to-connect "^2.0.1" + defer-to-connect "^2.0.0" "@tootallnate/once@1": version "1.1.2" @@ -617,7 +617,7 @@ dependencies: "@babel/types" "^7.3.0" -"@types/cacheable-request@^6.0.2": +"@types/cacheable-request@^6.0.1": version "6.0.2" resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.2.tgz#c324da0197de0a98a2312156536ae262429ff6b9" integrity sha512-B3xVo+dlKM6nnKTcmm5ZtY/OL8bOAOd2Olee9M1zft65ox50OzjEHW91sDiU9j6cvW8Ejg1/Qkf4xd2kugApUA== @@ -1062,10 +1062,10 @@ buffer-from@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -cacheable-lookup@^6.0.4: - version "6.0.4" - resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-6.0.4.tgz#65c0e51721bb7f9f2cb513aed6da4a1b93ad7dc8" - integrity sha512-mbcDEZCkv2CZF4G01kr8eBd/5agkt9oCqz75tJMSIsquvRZ2sL6Hi5zGVKi/0OSC9oO1GHfJ2AV0ZIOY9vye0A== +cacheable-lookup@^5.0.3: + version "5.0.4" + resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz#5a6b865b2c44357be3d5ebc2a467b032719a7005" + integrity sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA== cacheable-request@^7.0.2: version "7.0.2" @@ -1294,7 +1294,7 @@ deepmerge@^4.2.2: resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955" integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== -defer-to-connect@^2.0.1: +defer-to-connect@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.1.tgz#8016bdb4143e4632b77a3449c6236277de520587" integrity sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg== @@ -1664,11 +1664,6 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3" integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg== -form-data-encoder@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/form-data-encoder/-/form-data-encoder-2.0.1.tgz#aec41860aca0275cb6026650d139c6701b0992c1" - integrity sha512-Oy+P9w5mnO4TWXVgUiQvggNKPI9/ummcSt5usuIV6HkaLKigwzPpoenhEqmGmx3zHqm6ZLJ+CR/99N8JLinaEw== - form-data@^2.5.0: version "2.5.1" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.1.tgz#f2cbec57b5e59e23716e128fe44d4e5dd23895f4" @@ -1729,7 +1724,7 @@ get-stream@^5.1.0: dependencies: pump "^3.0.0" -get-stream@^6.0.0, get-stream@^6.0.1: +get-stream@^6.0.0: version "6.0.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg== @@ -1777,23 +1772,21 @@ globby@^11.0.3: merge2 "^1.4.1" slash "^3.0.0" -got@^12.0.2: - version "12.2.0" - resolved "https://registry.yarnpkg.com/got/-/got-12.2.0.tgz#0b5de8cd48d0a16cd44789fd5fdd071ba3ee1de5" - integrity sha512-A81ll5Z8wzeCmSdIlWVMDWFKDo82v2nmOaMZDQNHKGInNqDBcle+CSb6BBiZcn/Aiefz/kSpo520WBKi9QAO/A== +got@^11.8.3: + version "11.8.5" + resolved "https://registry.yarnpkg.com/got/-/got-11.8.5.tgz#ce77d045136de56e8f024bebb82ea349bc730046" + integrity sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ== dependencies: - "@sindresorhus/is" "^5.2.0" - "@szmarczak/http-timer" "^5.0.1" - "@types/cacheable-request" "^6.0.2" + "@sindresorhus/is" "^4.0.0" + "@szmarczak/http-timer" "^4.0.5" + "@types/cacheable-request" "^6.0.1" "@types/responselike" "^1.0.0" - cacheable-lookup "^6.0.4" + cacheable-lookup "^5.0.3" cacheable-request "^7.0.2" decompress-response "^6.0.0" - form-data-encoder "^2.0.1" - get-stream "^6.0.1" - http2-wrapper "^2.1.10" - lowercase-keys "^3.0.0" - p-cancelable "^3.0.0" + http2-wrapper "^1.0.0-beta.5.2" + lowercase-keys "^2.0.0" + p-cancelable "^2.0.0" responselike "^2.0.0" graceful-fs@^4.2.9: @@ -1844,13 +1837,13 @@ http-proxy-agent@^4.0.1: agent-base "6" debug "4" -http2-wrapper@^2.1.10: - version "2.1.10" - resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-2.1.10.tgz#307cd0cee2564723692ad34c2d570d12f10e83be" - integrity sha512-QHgsdYkieKp+6JbXP25P+tepqiHYd+FVnDwXpxi/BlUcoIB0nsmTOymTNvETuTO+pDuwcSklPE72VR3DqV+Haw== +http2-wrapper@^1.0.0-beta.5.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.3.tgz#b8f55e0c1f25d4ebd08b3b0c2c079f9590800b3d" + integrity sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg== dependencies: quick-lru "^5.1.1" - resolve-alpn "^1.2.0" + resolve-alpn "^1.0.0" https-proxy-agent@^5.0.0: version "5.0.0" @@ -2593,11 +2586,6 @@ lowercase-keys@^2.0.0: resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== -lowercase-keys@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-3.0.0.tgz#c5e7d442e37ead247ae9db117a9d0a467c89d4f2" - integrity sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ== - lru-cache@^4.0.1: version "4.1.5" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" @@ -2769,10 +2757,10 @@ os-shim@^0.1.2: resolved "https://registry.yarnpkg.com/os-shim/-/os-shim-0.1.3.tgz#6b62c3791cf7909ea35ed46e17658bb417cb3917" integrity sha1-a2LDeRz3kJ6jXtRuF2WLtBfLORc= -p-cancelable@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-3.0.0.tgz#63826694b54d61ca1c20ebcb6d3ecf5e14cd8050" - integrity sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw== +p-cancelable@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.1.1.tgz#aab7fbd416582fa32a3db49859c122487c5ed2cf" + integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg== p-limit@^2.2.0: version "2.3.0" @@ -3011,7 +2999,7 @@ require-from-string@^2.0.2: resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.2.tgz#89a7fdd938261267318eafe14f9c32e598c36909" integrity sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw== -resolve-alpn@^1.2.0: +resolve-alpn@^1.0.0: version "1.2.1" resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.2.1.tgz#b7adbdac3546aaaec20b45e7d8265927072726f9" integrity sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g== From 8173b0faa29e2ca232a0bad7958f36de5a6abd60 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 11 Aug 2022 15:46:02 +0900 Subject: [PATCH 2/4] feat: support apple silicon The mac64 edgedriver works on apple silicon, so it should also be supported. --- src/os.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/os.ts b/src/os.ts index f085f9e..ad281e4 100644 --- a/src/os.ts +++ b/src/os.ts @@ -1,21 +1,24 @@ enum OS { WIN32 = 'win32', WIN64 = 'win64', - MAC32 = 'mac32', MAC64 = 'mac64', + MAC_ARM64 = 'mac64', LINUX = 'linux', + UNSUPPORTED = 'unsupported', } const getOS = (): OS => { - const platform: string = process.platform; - const arch: string = process.arch; + const platform = process.platform; + const arch = process.arch; if (platform === 'win32') { return arch === 'x64' ? OS.WIN64 : OS.WIN32; - } else if (platform === 'darwin') { - return arch === 'x64' ? OS.MAC64 : OS.MAC32; - } else { - return OS.LINUX; } + if (platform === 'darwin') { + if (arch === 'x64') return OS.MAC64; + if (arch === 'arm64') return OS.MAC_ARM64; + return OS.UNSUPPORTED; + } + return OS.LINUX; }; const isWin = (): boolean => { @@ -23,7 +26,7 @@ const isWin = (): boolean => { }; const isSupportedPlatform = (): boolean => { - return [OS.WIN32, OS.WIN64, OS.MAC64].includes(getOS()); + return [OS.WIN32, OS.WIN64, OS.MAC64, OS.MAC_ARM64].includes(getOS()); }; export { getOS, isSupportedPlatform, isWin }; From fcce686025975aef56d806a8dd83db595fd10190 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 11 Aug 2022 23:04:32 +0900 Subject: [PATCH 3/4] feat: add support for linux --- src/browser.ts | 17 ++++++++++++++++- src/os.ts | 8 ++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/browser.ts b/src/browser.ts index 4e5e529..ddff775 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -50,6 +50,19 @@ const getBrowserBinaryOnMac = async (edgeBinaryPath?: string | undefined) => { } }; +const getBrowserBinaryOnLinux = async () => { + try { + let { stdout: path } = await execAsync(`which microsoft-edge`); + // which includes a newline that we should get rid of + path = path.trim(); + const { stdout: fullVer } = await execAsync(`microsoft-edge --version`); + const match = fullVer.toString().match(/\d{1,}.\d{1,}.\d{1,}.\d{1,}/g); + if (match) return { path, version: match[0] }; + } catch (err) { + process.stdout.write('MS Edge Browser was not found'); + } +}; + export const getBrowserData = async ( edgeBinaryPath?: string | undefined, ): Promise< @@ -59,5 +72,7 @@ export const getBrowserData = async ( } | undefined > => { - return await (isWin() ? getBrowserBinaryOnWin() : getBrowserBinaryOnMac(edgeBinaryPath)); + if (isWin()) return await getBrowserBinaryOnWin(); + if (process.platform === 'darwin') return await getBrowserBinaryOnMac(edgeBinaryPath); + if (process.platform === 'linux') return await getBrowserBinaryOnLinux(); }; diff --git a/src/os.ts b/src/os.ts index ad281e4..622a072 100644 --- a/src/os.ts +++ b/src/os.ts @@ -3,7 +3,7 @@ enum OS { WIN64 = 'win64', MAC64 = 'mac64', MAC_ARM64 = 'mac64', - LINUX = 'linux', + LINUX64 = 'linux64', UNSUPPORTED = 'unsupported', } @@ -16,9 +16,9 @@ const getOS = (): OS => { if (platform === 'darwin') { if (arch === 'x64') return OS.MAC64; if (arch === 'arm64') return OS.MAC_ARM64; - return OS.UNSUPPORTED; } - return OS.LINUX; + if (platform === 'linux' && arch === 'x64') return OS.LINUX64; + return OS.UNSUPPORTED; }; const isWin = (): boolean => { @@ -26,7 +26,7 @@ const isWin = (): boolean => { }; const isSupportedPlatform = (): boolean => { - return [OS.WIN32, OS.WIN64, OS.MAC64, OS.MAC_ARM64].includes(getOS()); + return [OS.WIN32, OS.WIN64, OS.MAC64, OS.MAC_ARM64, OS.LINUX64].includes(getOS()); }; export { getOS, isSupportedPlatform, isWin }; From 90d100864154243f2951a40c9699506e8d34f98c Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 11 Aug 2022 23:04:55 +0900 Subject: [PATCH 4/4] refactor: adjust unsupported message --- src/index.spec.ts | 4 ++-- src/index.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index 54ff844..d9edcb9 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -19,7 +19,7 @@ describe('Running module on non-supported platform', function () { let mockStdout: jest.SpyInstance; let mockExit: jest.SpyInstance; const orginalOS = process.platform; - const notSupportedOS = 'linux'; + const notSupportedOS = 'mac32'; beforeAll(function () { // redefine process.platform @@ -44,7 +44,7 @@ describe('Running module on non-supported platform', function () { expect(paths).toEqual(undefined); expect(mockStdout).toBeCalledTimes(2); expect(mockStdout.mock.calls).toEqual([ - [`MS does not provide driver for ${notSupportedOS} platform\n`], + [`MS does not provide driver for your platform - ${notSupportedOS}:${process.arch}\n`], ['Error getting browser data'], ]); }); diff --git a/src/index.ts b/src/index.ts index 0109899..89fee19 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,7 +59,7 @@ const getBrowser = async (edgeBinaryPath: string | undefined, edgeDriverVersion: } } } else { - process.stdout.write(`MS does not provide driver for ${getOS()} platform\n`); + process.stdout.write(`MS does not provide driver for your platform - ${process.platform}:${process.arch}\n`); process.exit(1); } };