From 9c6a9bd222c62740d0e3460f9618a47a903e2818 Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Fri, 12 Jul 2024 13:41:56 -0700 Subject: [PATCH 1/3] Drop @vue/cli-plugin-typescript and use ts-loader This means we stop using fork-ts-checker, as that does not allow us to correctly set the TypeScript compiler's stack size. Something in our code seems to require more stack than default. Also explicitly set the stack size when invoking Vue CLI from code, for the same reason. Signed-off-by: Mark Yen --- package.json | 2 +- pkg/rancher-desktop/main/tray.ts | 6 +- pkg/rancher-desktop/vue.config.js | 8 ++ scripts/build.ts | 4 +- scripts/dev.ts | 4 +- scripts/e2e.ts | 4 +- yarn.lock | 144 ++++++++---------------------- 7 files changed, 61 insertions(+), 111 deletions(-) diff --git a/package.json b/package.json index 0fa7dbdcd03..1663a64b365 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,6 @@ "@typescript-eslint/parser": "7.16.0", "@vue/cli-plugin-babel": "5.0.8", "@vue/cli-plugin-router": "5.0.8", - "@vue/cli-plugin-typescript": "5.0.8", "@vue/cli-plugin-unit-jest": "5.0.8", "@vue/cli-plugin-vuex": "5.0.8", "@vue/cli-service": "5.0.8", @@ -165,6 +164,7 @@ "sass": "1.77.8", "sass-loader": "14.2.1", "ts-jest": "29.2.2", + "ts-loader": "^9.5.1", "ts-node": "10.9.2", "tsconfig-paths": "4.2.0", "typescript": "5.5.3", diff --git a/pkg/rancher-desktop/main/tray.ts b/pkg/rancher-desktop/main/tray.ts index 015434cb0f5..a87f537b741 100644 --- a/pkg/rancher-desktop/main/tray.ts +++ b/pkg/rancher-desktop/main/tray.ts @@ -130,13 +130,15 @@ export class Tray { * triggered, close the watcher and restart after a duration (one second). */ private async watchForChanges() { - this.abortController = new AbortController(); + const abortController = new AbortController(); + + this.abortController = abortController; const paths = await kubeconfig.getKubeConfigPaths(); const options: fs.WatchOptions = { persistent: false, recursive: !this.isLinux(), // Recursive not implemented in Linux encoding: 'utf-8', - signal: this.abortController.signal, + signal: abortController.signal, }; paths.map(filepath => fs.watch(filepath, options, async(eventType) => { diff --git a/pkg/rancher-desktop/vue.config.js b/pkg/rancher-desktop/vue.config.js index a0b7e793a7c..09a0e97cbbc 100644 --- a/pkg/rancher-desktop/vue.config.js +++ b/pkg/rancher-desktop/vue.config.js @@ -17,9 +17,17 @@ module.exports = { outputDir: path.resolve(rootDir, 'dist', 'app'), productionSourceMap: false, + /** @type { (config: import('webpack-chain')) => void } */ chainWebpack: (config) => { config.target('electron-renderer'); config.resolve.alias.set('@pkg', path.resolve(rootDir, 'pkg', 'rancher-desktop')); + config.resolve.extensions.add('.ts'); + + config.module.rule('ts') + .test(/\.ts$/) + .use('ts-loader') + .loader('ts-loader') + .options({ transpileOnly: process.env.NODE_ENV === 'development' }); config.module.rule('yaml') .test(/\.ya?ml(?:\?[a-z0-9=&.]+)?$/) diff --git a/scripts/build.ts b/scripts/build.ts index cb0177c3bc8..29e07d4cd90 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -52,8 +52,10 @@ class Builder { async buildRenderer() { process.env.VUE_CLI_SERVICE_CONFIG_PATH = 'pkg/rancher-desktop/vue.config.js'; await simpleSpawn( - 'node_modules/.bin/vue-cli-service', + process.execPath, [ + '--stack-size=16384', + 'node_modules/@vue/cli-service/bin/vue-cli-service.js', 'build', '--skip-plugins', 'eslint', diff --git a/scripts/dev.ts b/scripts/dev.ts index 530770e9286..5ddb4437464 100644 --- a/scripts/dev.ts +++ b/scripts/dev.ts @@ -111,7 +111,9 @@ class DevRunner extends events.EventEmitter { this.#rendererProcess = this.spawn( 'Renderer process', - 'node_modules/.bin/vue-cli-service', + process.execPath, + '--stack-size=16384', + 'node_modules/@vue/cli-service/bin/vue-cli-service.js', 'serve', '--host', 'localhost', diff --git a/scripts/e2e.ts b/scripts/e2e.ts index 938db3bf2d0..460ea55b8ad 100644 --- a/scripts/e2e.ts +++ b/scripts/e2e.ts @@ -91,7 +91,9 @@ class E2ETestRunner extends events.EventEmitter { process.env.VUE_CLI_SERVICE_CONFIG_PATH = 'pkg/rancher-desktop/vue.config.js'; return buildUtils.spawn( - 'node_modules/.bin/vue-cli-service', + process.execPath, + '--stack-size=16384', + 'node_modules/@vue/cli-service/bin/vue-cli-service.js', 'build', '--skip-plugins', 'eslint', diff --git a/yarn.lock b/yarn.lock index 5ae6ad53fa6..69cd4eaf653 100644 --- a/yarn.lock +++ b/yarn.lock @@ -29,7 +29,7 @@ "@jridgewell/gen-mapping" "^0.3.0" "@jridgewell/trace-mapping" "^0.3.9" -"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.5", "@babel/code-frame@^7.8.3": +"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.22.5.tgz#234d98e1551960604f1246e6475891a570ad5658" integrity sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ== @@ -2793,7 +2793,7 @@ "@types/tough-cookie" "*" parse5 "^7.0.0" -"@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9": +"@types/json-schema@*", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9": version "7.0.12" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb" integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA== @@ -3058,11 +3058,6 @@ dependencies: "@types/webpack" "^4" -"@types/webpack-env@^1.15.2": - version "1.18.1" - resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.18.1.tgz#49699bb508961e14a3bfb68c78cd87b296889d1d" - integrity sha512-D0HJET2/UY6k9L6y3f5BL+IDxZmPkYmPT4+qBrRdmRLYRuV0qNKizMgTvYxXZYn+36zjPeoDZAEYBCM6XB+gww== - "@types/webpack-hot-middleware@2.25.5": version "2.25.5" resolved "https://registry.yarnpkg.com/@types/webpack-hot-middleware/-/webpack-hot-middleware-2.25.5.tgz#b42c7a00fa3e508b3fb9809cd7261f6dbe01355f" @@ -3446,21 +3441,6 @@ dependencies: "@vue/cli-shared-utils" "^5.0.8" -"@vue/cli-plugin-typescript@5.0.8": - version "5.0.8" - resolved "https://registry.yarnpkg.com/@vue/cli-plugin-typescript/-/cli-plugin-typescript-5.0.8.tgz#dd3d2b3a58f3f93359319958dc0f58a4861a33a7" - integrity sha512-JKJOwzJshBqsmp4yLBexwVMebOZ4VGJgbnYvmHVxasJOStF2RxwyW28ZF+zIvASGdat4sAUuo/3mAQyVhm7JHg== - dependencies: - "@babel/core" "^7.12.16" - "@types/webpack-env" "^1.15.2" - "@vue/cli-shared-utils" "^5.0.8" - babel-loader "^8.2.2" - fork-ts-checker-webpack-plugin "^6.4.0" - globby "^11.0.2" - thread-loader "^3.0.0" - ts-loader "^9.2.5" - webpack "^5.54.0" - "@vue/cli-plugin-unit-jest@5.0.8": version "5.0.8" resolved "https://registry.yarnpkg.com/@vue/cli-plugin-unit-jest/-/cli-plugin-unit-jest-5.0.8.tgz#527da4b94a7957e29e771752b0b4f6bcede81b07" @@ -3896,7 +3876,7 @@ ajv-keywords@^5.1.0: dependencies: fast-deep-equal "^3.1.3" -ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.2, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5: +ajv@^6.10.0, ajv@^6.12.0, ajv@^6.12.3, ajv@^6.12.4, ajv@^6.12.5: version "6.12.6" resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== @@ -4596,6 +4576,13 @@ braces@^3.0.2, braces@~3.0.2: dependencies: fill-range "^7.0.1" +braces@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== + dependencies: + fill-range "^7.1.1" + browser-process-hrtime@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-1.0.0.tgz#3c9b4b7d782c8121e56f10106d84c0d0ffc94626" @@ -4858,7 +4845,7 @@ char-regex@^2.0.0: resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-2.0.1.tgz#6dafdb25f9d3349914079f010ba8d0e6ff9cd01e" integrity sha512-oSvEeo6ZUD7NepqAat3RqoucZ5SeqLJgOvVIwkafu6IP3V0pO38s/ypdVUmDDK6qIIHNlYHJAKX9E7R7HoKElw== -"chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.2, chokidar@^3.4.3, chokidar@^3.5.3: +"chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.3, chokidar@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw== @@ -5272,17 +5259,6 @@ core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ== -cosmiconfig@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-6.0.0.tgz#da4fee853c52f6b1e6935f41c1a2fc50bd4a9982" - integrity sha512-xb3ZL6+L8b9JLLCx3ZdoZy4+2ECphCMo2PwqgP1tlfVq6M6YReyzBJtvWWtbDSpNr9hn96pkCiZqUcFEc+54Qg== - dependencies: - "@types/parse-json" "^4.0.0" - import-fresh "^3.1.0" - parse-json "^5.0.0" - path-type "^4.0.0" - yaml "^1.7.2" - cosmiconfig@^7.0.0: version "7.1.0" resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-7.1.0.tgz#1443b9afa596b670082ea46cbd8f6a62b84635f6" @@ -6823,6 +6799,13 @@ fill-range@^7.0.1: dependencies: to-regex-range "^5.0.1" +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== + dependencies: + to-regex-range "^5.0.1" + finalhandler@1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.2.0.tgz#7d23fe5731b207b4640e4fcd00aec1f9207a7b32" @@ -6907,25 +6890,6 @@ forever-agent@~0.6.1: resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" integrity sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw== -fork-ts-checker-webpack-plugin@^6.4.0: - version "6.5.3" - resolved "https://registry.yarnpkg.com/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-6.5.3.tgz#eda2eff6e22476a2688d10661688c47f611b37f3" - integrity sha512-SbH/l9ikmMWycd5puHJKTkZJKddF4iRLyW3DeZ08HTI7NGyLS38MXd/KGgeWumQO7YNQbW2u/NtPT2YowbPaGQ== - dependencies: - "@babel/code-frame" "^7.8.3" - "@types/json-schema" "^7.0.5" - chalk "^4.1.0" - chokidar "^3.4.2" - cosmiconfig "^6.0.0" - deepmerge "^4.2.2" - fs-extra "^9.0.0" - glob "^7.1.6" - memfs "^3.1.2" - minimatch "^3.0.4" - schema-utils "2.7.0" - semver "^7.3.2" - tapable "^1.0.0" - form-data@^2.5.0: version "2.5.1" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.1.tgz#f2cbec57b5e59e23716e128fe44d4e5dd23895f4" @@ -7679,7 +7643,7 @@ immutable@^4.0.0: resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.0.tgz#eb1738f14ffb39fd068b1dbe1296117484dd34be" integrity sha512-0AOCmOip+xgJwEVTQj1EfiDDOkPmuyllDuTuEX+DDXUgapLAsBIfkg3sxCYyCEA8mQqZrrxPUGjcOQ2JS3WLkg== -import-fresh@^3.1.0, import-fresh@^3.2.1: +import-fresh@^3.2.1: version "3.3.0" resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b" integrity sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw== @@ -9604,7 +9568,7 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== -memfs@^3.1.2, memfs@^3.4.3: +memfs@^3.4.3: version "3.6.0" resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.6.0.tgz#d7a2110f86f79dd950a8b6df6d57bc984aa185f6" integrity sha512-EGowvkkgbMcIChjMTMkESFDbZeSh8xZ7kNSF0hAiAN4Jh6jgHCRS0Ga/+C8y6Au+oqpezRHCfPsmJ2+DwAgiwQ== @@ -9638,7 +9602,15 @@ methods@~1.1.2: resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee" integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w== -micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: +micromatch@^4.0.0: + version "4.0.7" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.7.tgz#33e8190d9fe474a9895525f5618eee136d46c2e5" + integrity sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q== + dependencies: + braces "^3.0.3" + picomatch "^2.3.1" + +micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== @@ -11446,15 +11418,6 @@ saxes@^6.0.0: dependencies: xmlchars "^2.2.0" -schema-utils@2.7.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7" - integrity sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A== - dependencies: - "@types/json-schema" "^7.0.4" - ajv "^6.12.2" - ajv-keywords "^3.4.1" - schema-utils@^2.6.5: version "2.7.1" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7" @@ -11786,7 +11749,7 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@^0.7.3: +source-map@^0.7.3, source-map@^0.7.4: version "0.7.4" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656" integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA== @@ -11976,16 +11939,7 @@ string-length@^5.0.1: char-regex "^2.0.0" strip-ansi "^7.0.1" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^2.1.1, string-width@^4, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.0.1, string-width@^5.1.2: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^2.1.1, string-width@^4, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3, string-width@^5.0.1, string-width@^5.1.2: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -12035,7 +11989,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -12056,13 +12010,6 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^6.0.0, strip-ansi@^6.0.1: - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -12194,11 +12141,6 @@ symbol-tree@^3.2.4: resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw== -tapable@^1.0.0: - version "1.1.3" - resolved "https://registry.yarnpkg.com/tapable/-/tapable-1.1.3.tgz#a1fccc06b58db61fd7a45da2da44f5f3a3e67ba2" - integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== - tapable@^2.0.0, tapable@^2.1.1, tapable@^2.2.0: version "2.2.1" resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" @@ -12450,15 +12392,16 @@ ts-jest@29.2.2: semver "^7.5.3" yargs-parser "^21.0.1" -ts-loader@^9.2.5: - version "9.4.4" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.4.4.tgz#6ceaf4d58dcc6979f84125335904920884b7cee4" - integrity sha512-MLukxDHBl8OJ5Dk3y69IsKVFRA/6MwzEqBgh+OXMPB/OD01KQuWPFd1WAQP8a5PeSCAxfnkhiuWqfmFJzJQt9w== +ts-loader@^9.5.1: + version "9.5.1" + resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.5.1.tgz#63d5912a86312f1fbe32cef0859fb8b2193d9b89" + integrity sha512-rNH3sK9kGZcH9dYzC7CewQm4NtxJTjSEVRJ2DyBZR7f8/wcta+iV44UPCXc5+nzDzivKtlzV6c9P4e+oFhDLYg== dependencies: chalk "^4.1.0" enhanced-resolve "^5.0.0" micromatch "^4.0.0" semver "^7.3.4" + source-map "^0.7.4" ts-node@10.9.2: version "10.9.2" @@ -13346,7 +13289,7 @@ word-wrap@~1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -13372,15 +13315,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" @@ -13478,7 +13412,7 @@ yaml@2.4.5: resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.5.tgz#60630b206dd6d84df97003d33fc1ddf6296cca5e" integrity sha512-aBx2bnqDzVOyNKfsysjA2ms5ZlnjSAW2eG3/L5G/CSujfjLJTJsEw1bGw8kCf04KodQWk1pxlGnZ56CRxiawmg== -yaml@^1.10.0, yaml@^1.10.2, yaml@^1.7.2: +yaml@^1.10.0, yaml@^1.10.2: version "1.10.2" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b" integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg== From f858fa1d596de2639c514e7fb128934a62f60b4f Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Mon, 15 Jul 2024 12:40:19 -0700 Subject: [PATCH 2/3] Fix ipcMain tests to not depend on importing Electron Signed-off-by: Mark Yen --- .../main/__tests__/ipcMain.spec.ts | 21 +---- pkg/rancher-desktop/main/ipcMain.ts | 90 ++++++++++++++++--- 2 files changed, 82 insertions(+), 29 deletions(-) diff --git a/pkg/rancher-desktop/main/__tests__/ipcMain.spec.ts b/pkg/rancher-desktop/main/__tests__/ipcMain.spec.ts index 09fb60debea..f92b6228d12 100644 --- a/pkg/rancher-desktop/main/__tests__/ipcMain.spec.ts +++ b/pkg/rancher-desktop/main/__tests__/ipcMain.spec.ts @@ -12,7 +12,7 @@ describe('IpcMainProxy', () => { let emitter: E; let subject: ReturnType; - class E extends events.EventEmitter { + class E extends events.EventEmitter implements Electron.IpcMain { protected handlers: Record = {}; handle(channel: string, handler: Handler) { @@ -66,24 +66,7 @@ describe('IpcMainProxy', () => { } beforeAll(() => { - const methods: (keyof ReturnType)[] = [ - 'on', 'once', 'removeListener', 'removeAllListeners', - 'handle', 'handleOnce', 'removeHandler', - ]; - emitter = new E(); - - for (const prop of methods) { - (Electron.ipcMain as any)[prop] ??= () => {}; - expect(typeof emitter[prop]).toEqual('function'); - jest.spyOn(Electron.ipcMain, prop as keyof typeof Electron.ipcMain).mockImplementation((...args: any) => { - // TODO: Issue #5544 Don't use Function as a type - // eslint-disable-next-line @typescript-eslint/ban-types - const meth = emitter[prop as keyof typeof emitter] as Function; - - return meth.apply(emitter, args); - }); - } }); afterAll(() => { @@ -95,7 +78,7 @@ describe('IpcMainProxy', () => { for (const meth of ['log', 'error', 'info', 'warn', 'debug', 'debugE'] as const) { jest.spyOn(log, meth); } - subject = getIpcMainProxy(log); + subject = getIpcMainProxy(log, emitter); }); afterEach(() => { diff --git a/pkg/rancher-desktop/main/ipcMain.ts b/pkg/rancher-desktop/main/ipcMain.ts index 75966e2277e..fdb0597021c 100644 --- a/pkg/rancher-desktop/main/ipcMain.ts +++ b/pkg/rancher-desktop/main/ipcMain.ts @@ -66,11 +66,13 @@ type Listener = (event: Electron.IpcMainEvent, ...args: any) => void; type Handler = (event: Electron.IpcMainInvokeEvent, ...args: any) => Promise; class IpcMainProxyImpl implements IpcMainProxy { - constructor(logger: Log) { + constructor(logger: Log, ipcMain?: Electron.IpcMain) { this.logger = logger; + this.ipcMain = ipcMain ?? Electron.ipcMain; } protected logger: Log; + protected ipcMain: Electron.IpcMain; // Bijective weak maps between the user-provided listener and the wrapper that // introduces logging. We do not keep strong references to either; the user- @@ -89,7 +91,26 @@ class IpcMainProxyImpl implements IpcMainProxy { this.listenerWrapperToRaw.set(wrapper, new WeakRef(listener)); this.listenerRawToWrapper.set(listener, new WeakRef(wrapper)); - Electron.ipcMain.on(channel, wrapper); + this.ipcMain.on(channel, wrapper); + + return this; + } + + addListener(channel: string, listener: Listener): this { + return this.on(channel, listener); + } + + prependListener(channel: string, listener: Listener): this { + const wrapper: Listener = (event, ...args) => { + const printableArgs = makeArgsPrintable(args); + + this.logger.debug(`ipcMain: "${ channel }" triggered with arguments: ${ printableArgs.join(', ') }`); + listener(event, ...args); + }; + + this.listenerWrapperToRaw.set(wrapper, new WeakRef(listener)); + this.listenerRawToWrapper.set(listener, new WeakRef(wrapper)); + this.ipcMain.prependListener(channel, wrapper); return this; } @@ -104,7 +125,22 @@ class IpcMainProxyImpl implements IpcMainProxy { this.listenerWrapperToRaw.set(wrapper, new WeakRef(listener)); this.listenerRawToWrapper.set(listener, new WeakRef(wrapper)); - Electron.ipcMain.once(channel, wrapper); + this.ipcMain.once(channel, wrapper); + + return this; + } + + prependOnceListener(channel: string, listener: Listener): this { + const wrapper: Listener = (event, ...args) => { + const printableArgs = makeArgsPrintable(args); + + this.logger.debug(`ipcMain: "${ channel }" triggered with arguments: ${ printableArgs.join(', ') }`); + listener(event, ...args); + }; + + this.listenerWrapperToRaw.set(wrapper, new WeakRef(listener)); + this.listenerRawToWrapper.set(listener, new WeakRef(wrapper)); + this.ipcMain.prependOnceListener(channel, wrapper); return this; } @@ -113,7 +149,7 @@ class IpcMainProxyImpl implements IpcMainProxy { const wrapper = this.listenerRawToWrapper.get(listener)?.deref(); if (wrapper) { - Electron.ipcMain.removeListener(channel, wrapper); + this.ipcMain.removeListener(channel, wrapper); this.listenerWrapperToRaw.delete(wrapper); } this.listenerRawToWrapper.delete(listener); @@ -121,12 +157,46 @@ class IpcMainProxyImpl implements IpcMainProxy { return this; } + off(channel: string, listener: Listener): this { + return this.removeListener(channel, listener); + } + removeAllListeners(channel?: string): this { - Electron.ipcMain.removeAllListeners(channel); + this.ipcMain.removeAllListeners(channel); + + return this; + } + + setMaxListeners(n: number): this { + this.ipcMain.setMaxListeners(n); return this; } + getMaxListeners(): number { + return this.ipcMain.getMaxListeners(); + } + + listeners(eventName: string | symbol) { + return this.ipcMain.listeners(eventName); + } + + rawListeners(eventName: string | symbol) { + return this.ipcMain.rawListeners(eventName); + } + + listenerCount(eventName: string | symbol, listener?: Listener): number { + return this.ipcMain.listenerCount(eventName, listener); + } + + emit(eventName: string | symbol, ...args: any[]): boolean { + return this.ipcMain.emit(eventName, ...args); + } + + eventNames(): (string | symbol)[] { + return this.ipcMain.eventNames(); + } + // For dealing with handlers, we don't need to keep track of the wrappers // (because removeHandler() doesn't actually take the handler to remove). @@ -139,7 +209,7 @@ class IpcMainProxyImpl implements IpcMainProxy { return handler(event, ...args); }; - Electron.ipcMain.handle(channel, wrapper); + this.ipcMain.handle(channel, wrapper); } handleOnce(channel: string, handler: Handler) { @@ -151,14 +221,14 @@ class IpcMainProxyImpl implements IpcMainProxy { return handler(event, ...args); }; - Electron.ipcMain.handleOnce(channel, wrapper); + this.ipcMain.handleOnce(channel, wrapper); } removeHandler(channel: string): void { - Electron.ipcMain.removeHandler(channel); + this.ipcMain.removeHandler(channel); } } -export function getIpcMainProxy(logger: Log): IpcMainProxy { - return new IpcMainProxyImpl(logger); +export function getIpcMainProxy(logger: Log, ipcMain?: Electron.IpcMain): IpcMainProxy { + return new IpcMainProxyImpl(logger, ipcMain); } From 313e893b3d34aa8d8f73b1bcfb80024213e81d6c Mon Sep 17 00:00:00 2001 From: Mark Yen Date: Mon, 15 Jul 2024 12:40:33 -0700 Subject: [PATCH 3/3] E2E: Fix running with ts-loader Signed-off-by: Mark Yen --- .../utils/testUtils/setupElectron.ts | 24 ++++++++++--------- pkg/rancher-desktop/vue.config.js | 12 +++++++++- pkg/rancher-desktop/window/index.ts | 6 +---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/pkg/rancher-desktop/utils/testUtils/setupElectron.ts b/pkg/rancher-desktop/utils/testUtils/setupElectron.ts index b81ec635d34..427d5ea907b 100644 --- a/pkg/rancher-desktop/utils/testUtils/setupElectron.ts +++ b/pkg/rancher-desktop/utils/testUtils/setupElectron.ts @@ -6,15 +6,17 @@ import path from 'path'; -jest.mock('electron', () => { - return { - __esModule: true, - default: { - app: { - isPackaged: false, - getAppPath: () => path.resolve('.'), +if ('jest' in globalThis && 'mock' in jest) { + jest.mock('electron', () => { + return { + __esModule: true, + default: { + app: { + isPackaged: false, + getAppPath: () => path.resolve('.'), + }, + ipcMain: {}, }, - ipcMain: {}, - }, - }; -}); + }; + }); +} diff --git a/pkg/rancher-desktop/vue.config.js b/pkg/rancher-desktop/vue.config.js index 09a0e97cbbc..4dd93273404 100644 --- a/pkg/rancher-desktop/vue.config.js +++ b/pkg/rancher-desktop/vue.config.js @@ -27,7 +27,11 @@ module.exports = { .test(/\.ts$/) .use('ts-loader') .loader('ts-loader') - .options({ transpileOnly: process.env.NODE_ENV === 'development' }); + .options({ + transpileOnly: process.env.NODE_ENV === 'development', + appendTsSuffixTo: ['\\.vue$'], + happyPackMode: true, + }); config.module.rule('yaml') .test(/\.ya?ml(?:\?[a-z0-9=&.]+)?$/) @@ -49,6 +53,12 @@ module.exports = { featureExtensions: true, }), }]); + + config.module.rule('vue').use('vue-loader').tap((options) => { + _.set(options, 'loaders.ts', 'ts-loader'); + + return options; + }); }, css: { diff --git a/pkg/rancher-desktop/window/index.ts b/pkg/rancher-desktop/window/index.ts index 9e7f8e85eba..2016ed1d173 100644 --- a/pkg/rancher-desktop/window/index.ts +++ b/pkg/rancher-desktop/window/index.ts @@ -468,11 +468,7 @@ export function openDialog(id: string, opts?: Electron.BrowserWindowConstructorO } }); - if (Shortcuts.isRegistered(window)) { - return window; - } - - if (escapeKey) { + if (!Shortcuts.isRegistered(window) && escapeKey) { Shortcuts.register( window, { key: 'Escape' },