From c2507cdf80c09592ca4266efe90317daf8509914 Mon Sep 17 00:00:00 2001 From: Thomas Winkler Date: Tue, 9 Apr 2024 00:26:03 +0200 Subject: [PATCH 1/3] Using rollup to re-bundle plugin. Mount converted to typescript. Typescript building with es2020. --- package-lock.json | 566 ++++++++++++++++++++++++ package.json | 22 +- rollup.config.mjs | 31 ++ src/lib/commands/mount.d.ts | 19 - src/lib/commands/{mount.js => mount.ts} | 35 +- src/{lib => }/plugin/index.ts | 6 +- src/plugin/tsconfig.json | 11 + tsconfig.json | 6 +- 8 files changed, 661 insertions(+), 35 deletions(-) create mode 100644 rollup.config.mjs delete mode 100644 src/lib/commands/mount.d.ts rename src/lib/commands/{mount.js => mount.ts} (71%) rename src/{lib => }/plugin/index.ts (95%) create mode 100644 src/plugin/tsconfig.json diff --git a/package-lock.json b/package-lock.json index 69c59f7..4a0ad3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "set-cookie-parser": "^2.6.0" }, "devDependencies": { + "@rollup/plugin-json": "^6.1.0", "@types/chai": "^4.3.4", "@types/cookie-parser": "^1.4.6", "@types/express": "^4.17.21", @@ -43,6 +44,10 @@ "eslint-plugin-import": "^2.29.1", "http-server": "^14.1.1", "rimraf": "^5.0.1", + "rollup": "^4.14.1", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-dts": "^6.1.0", + "rollup-plugin-node-resolve": "^5.2.0", "start-server-and-test": "^2.0.0", "typescript": "^5.0.2", "yalc": "^1.0.0-pre.53" @@ -114,6 +119,114 @@ "zone.js": "~0.13.0" } }, + "node_modules/@babel/code-frame": { + "version": "7.24.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", + "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "dev": true, + "optional": true, + "dependencies": { + "@babel/highlight": "^7.24.2", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/helper-validator-identifier": { + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "dev": true, + "optional": true, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/highlight": { + "version": "7.24.2", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.2.tgz", + "integrity": "sha512-Yac1ao4flkTxTteCDZLEvdxg2fZfz1v8M4QpaGypq/WPDqg3ijHYbDfs+LG5hvzSoqaSZ9/Z9lKSP3CjZjv+pA==", + "dev": true, + "optional": true, + "dependencies": { + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/highlight/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "optional": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "optional": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "optional": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/@babel/highlight/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true, + "optional": true + }, + "node_modules/@babel/highlight/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "optional": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "optional": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/runtime": { "version": "7.23.2", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.2.tgz", @@ -590,6 +703,243 @@ "node": ">=14" } }, + "node_modules/@rollup/plugin-json": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", + "integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.1.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.14.1.tgz", + "integrity": "sha512-fH8/o8nSUek8ceQnT7K4EQbSiV7jgkHq81m9lWZFIXjJ7lJzpWXbQFpT/Zh6OZYnpFykvzC3fbEvEAFZu03dPA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.14.1.tgz", + "integrity": "sha512-Y/9OHLjzkunF+KGEoJr3heiD5X9OLa8sbT1lm0NYeKyaM3oMhhQFvPB0bNZYJwlq93j8Z6wSxh9+cyKQaxS7PQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.14.1.tgz", + "integrity": "sha512-+kecg3FY84WadgcuSVm6llrABOdQAEbNdnpi5X3UwWiFVhZIZvKgGrF7kmLguvxHNQy+UuRV66cLVl3S+Rkt+Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.14.1.tgz", + "integrity": "sha512-2pYRzEjVqq2TB/UNv47BV/8vQiXkFGVmPFwJb+1E0IFFZbIX8/jo1olxqqMbo6xCXf8kabANhp5bzCij2tFLUA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.14.1.tgz", + "integrity": "sha512-mS6wQ6Do6/wmrF9aTFVpIJ3/IDXhg1EZcQFYHZLHqw6AzMBjTHWnCG35HxSqUNphh0EHqSM6wRTT8HsL1C0x5g==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.14.1.tgz", + "integrity": "sha512-p9rGKYkHdFMzhckOTFubfxgyIO1vw//7IIjBBRVzyZebWlzRLeNhqxuSaZ7kCEKVkm/kuC9fVRW9HkC/zNRG2w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.14.1.tgz", + "integrity": "sha512-nDY6Yz5xS/Y4M2i9JLQd3Rofh5OR8Bn8qe3Mv/qCVpHFlwtZSBYSPaU4mrGazWkXrdQ98GB//H0BirGR/SKFSw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.14.1.tgz", + "integrity": "sha512-im7HE4VBL+aDswvcmfx88Mp1soqL9OBsdDBU8NqDEYtkri0qV0THhQsvZtZeNNlLeCUQ16PZyv7cqutjDF35qw==", + "cpu": [ + "ppc64le" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.14.1.tgz", + "integrity": "sha512-RWdiHuAxWmzPJgaHJdpvUUlDz8sdQz4P2uv367T2JocdDa98iRw2UjIJ4QxSyt077mXZT2X6pKfT2iYtVEvOFw==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.14.1.tgz", + "integrity": "sha512-VMgaGQ5zRX6ZqV/fas65/sUGc9cPmsntq2FiGmayW9KMNfWVG/j0BAqImvU4KTeOOgYSf1F+k6at1UfNONuNjA==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.14.1.tgz", + "integrity": "sha512-9Q7DGjZN+hTdJomaQ3Iub4m6VPu1r94bmK2z3UeWP3dGUecRC54tmVu9vKHTm1bOt3ASoYtEz6JSRLFzrysKlA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.14.1.tgz", + "integrity": "sha512-JNEG/Ti55413SsreTguSx0LOVKX902OfXIKVg+TCXO6Gjans/k9O6ww9q3oLGjNDaTLxM+IHFMeXy/0RXL5R/g==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.14.1.tgz", + "integrity": "sha512-ryS22I9y0mumlLNwDFYZRDFLwWh3aKaC72CWjFcFvxK0U6v/mOkM5Up1bTbCRAhv3kEIwW2ajROegCIQViUCeA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.14.1.tgz", + "integrity": "sha512-TdloItiGk+T0mTxKx7Hp279xy30LspMso+GzQvV2maYePMAWdmrzqSNZhUpPj3CGw12aGj57I026PgLCTu8CGg==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.14.1.tgz", + "integrity": "sha512-wQGI+LY/Py20zdUPq+XCem7JcPOyzIJBm3dli+56DJsQOHbnXZFEwgmnC6el1TPAfC8lBT3m+z69RmLykNUbew==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@sideway/address": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", @@ -670,6 +1020,12 @@ "@types/express": "*" } }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, "node_modules/@types/express": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", @@ -767,6 +1123,15 @@ "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "devOptional": true }, + "node_modules/@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/semver": { "version": "7.5.8", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", @@ -1638,6 +2003,18 @@ "node": "*" } }, + "node_modules/builtin-modules": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", + "dev": true, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -2860,6 +3237,12 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -3379,6 +3762,20 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -4109,6 +4506,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "dev": true + }, "node_modules/is-negative-zero": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.3.tgz", @@ -4163,6 +4566,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", + "dev": true, + "dependencies": { + "@types/estree": "*" + } + }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -4349,6 +4761,13 @@ "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-3.7.6.tgz", "integrity": "sha512-NPrWuHFxFUknr1KqJRDgUQPexQF0uIJWjeT+2KjEePhitQxQEx5EJBG1lVn5/hc8aLycTpXrDOgPQ6Zq+EDiTA==" }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "dev": true, + "optional": true + }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -4599,6 +5018,15 @@ "node": ">=10" } }, + "node_modules/magic-string": { + "version": "0.25.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", + "integrity": "sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==", + "dev": true, + "dependencies": { + "sourcemap-codec": "^1.4.8" + } + }, "node_modules/make-error": { "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", @@ -5154,6 +5582,13 @@ "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==" }, + "node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==", + "dev": true, + "optional": true + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -5825,6 +6260,129 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.14.1.tgz", + "integrity": "sha512-4LnHSdd3QK2pa1J6dFbfm1HN0D7vSK/ZuZTsdyUAlA6Rr1yTouUTL13HaDOGJVgby461AhrNGBS7sCGXXtT+SA==", + "dev": true, + "dependencies": { + "@types/estree": "1.0.5" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.14.1", + "@rollup/rollup-android-arm64": "4.14.1", + "@rollup/rollup-darwin-arm64": "4.14.1", + "@rollup/rollup-darwin-x64": "4.14.1", + "@rollup/rollup-linux-arm-gnueabihf": "4.14.1", + "@rollup/rollup-linux-arm64-gnu": "4.14.1", + "@rollup/rollup-linux-arm64-musl": "4.14.1", + "@rollup/rollup-linux-powerpc64le-gnu": "4.14.1", + "@rollup/rollup-linux-riscv64-gnu": "4.14.1", + "@rollup/rollup-linux-s390x-gnu": "4.14.1", + "@rollup/rollup-linux-x64-gnu": "4.14.1", + "@rollup/rollup-linux-x64-musl": "4.14.1", + "@rollup/rollup-win32-arm64-msvc": "4.14.1", + "@rollup/rollup-win32-ia32-msvc": "4.14.1", + "@rollup/rollup-win32-x64-msvc": "4.14.1", + "fsevents": "~2.3.2" + } + }, + "node_modules/rollup-plugin-commonjs": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-commonjs/-/rollup-plugin-commonjs-10.1.0.tgz", + "integrity": "sha512-jlXbjZSQg8EIeAAvepNwhJj++qJWNJw1Cl0YnOqKtP5Djx+fFGkp3WRh+W0ASCaFG5w1jhmzDxgu3SJuVxPF4Q==", + "deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-commonjs.", + "dev": true, + "dependencies": { + "estree-walker": "^0.6.1", + "is-reference": "^1.1.2", + "magic-string": "^0.25.2", + "resolve": "^1.11.0", + "rollup-pluginutils": "^2.8.1" + }, + "peerDependencies": { + "rollup": ">=1.12.0" + } + }, + "node_modules/rollup-plugin-commonjs/node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, + "node_modules/rollup-plugin-dts": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.1.0.tgz", + "integrity": "sha512-ijSCPICkRMDKDLBK9torss07+8dl9UpY9z1N/zTeA1cIqdzMlpkV3MOOC7zukyvQfDyxa1s3Dl2+DeiP/G6DOw==", + "dev": true, + "dependencies": { + "magic-string": "^0.30.4" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.22.13" + }, + "peerDependencies": { + "rollup": "^3.29.4 || ^4", + "typescript": "^4.5 || ^5.0" + } + }, + "node_modules/rollup-plugin-dts/node_modules/magic-string": { + "version": "0.30.9", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.9.tgz", + "integrity": "sha512-S1+hd+dIrC8EZqKyT9DstTH/0Z+f76kmmvZnkfQVmOpDEF9iVgdYif3Q/pIWHmCoo59bQVGW0kVL3e2nl+9+Sw==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.15" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/rollup-plugin-node-resolve": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-5.2.0.tgz", + "integrity": "sha512-jUlyaDXts7TW2CqQ4GaO5VJ4PwwaV8VUGA7+km3n6k6xtOEacf61u0VXwN80phY/evMcaS+9eIeJ9MOyDxt5Zw==", + "deprecated": "This package has been deprecated and is no longer maintained. Please use @rollup/plugin-node-resolve.", + "dev": true, + "dependencies": { + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", + "is-module": "^1.0.0", + "resolve": "^1.11.1", + "rollup-pluginutils": "^2.8.1" + }, + "peerDependencies": { + "rollup": ">=1.11.0" + } + }, + "node_modules/rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "dependencies": { + "estree-walker": "^0.6.1" + } + }, + "node_modules/rollup-pluginutils/node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6104,6 +6662,13 @@ "node": ">=8" } }, + "node_modules/sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "deprecated": "Please use @jridgewell/sourcemap-codec instead", + "dev": true + }, "node_modules/split": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", @@ -7292,6 +7857,7 @@ } }, "packages/pactrunner": { + "name": "cumulocity-cypress-pactrunner", "version": "0.3.2", "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 501f8f1..31b1311 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "cumulocity-cypress", "version": "0.3.2", "description": "Cypress commands for Cumulocity IoT", - "main": "src/lib/commands/index.js", "scripts": { "start-server": "http-server test/cypress/app/ --silent --port 8080 --mimetypes test/custom_mime_types.types --ext json", "test": "cross-env TZ=Europe/Berlin start-server-and-test start-server http://localhost:8080 test:run", @@ -11,9 +10,10 @@ "debug": "cross-env CYPRESS_REMOTE_DEBUGGING_PORT=9222 cypress open --project test", "clean": "rimraf dist/ && rimraf packages/pactrunner/dist/ && rimraf packages/pactrunner/.yalc && rimraf packages/pactrunner/yalc.lock", "copy-files": "copyfiles --up 1 src/lib/**/*.*js src/lib/*.*js src/lib/**/*.d.ts dist/ && copyfiles README.md package.json dist/", - "build": "npm run clean && npm run copy-files && tsc -b -v src/lib/ && cd dist/ && npm run clean-package-json", + "build": "npm run clean && npm run copy-files && tsc -b -v src/lib && tsc -b -v src/plugin && npm run build:plugin && cd dist/ && npm run clean-package-json", + "build:plugin": "rollup -c rollup.config.mjs", "yalc:runner": "npm run yalc:publish && cd packages/pactrunner && yalc add cumulocity-cypress", - "yalc:publish": "npm run clean && npm run build && cd dist/ && yalc publish && cd ..", + "yalc:publish": "cd dist/ && yalc publish && cd ..", "clean-package-json": "npm pkg delete 'devDependencies' && npm pkg delete 'scripts'", "lint": "eslint ./" }, @@ -35,6 +35,17 @@ "workspaces": [ "packages/*" ], + "exports": { + "./plugin": { + "types": "./plugin/index.d.ts", + "default": "./plugin/index.js" + }, + "./lib/commands/*": "./lib/commands/*", + "./lib/locale/*": "./lib/locale/*", + "./lib/pact/*": "./lib/pact/*", + "./shared/*": "./shared/*", + "./shared/c8ypact/*": "./shared/c8ypact/*" + }, "dependencies": { "ajv": "^8.12.0", "ajv-formats": "^2.1.1", @@ -49,6 +60,7 @@ "set-cookie-parser": "^2.6.0" }, "devDependencies": { + "@rollup/plugin-json": "^6.1.0", "@types/chai": "^4.3.4", "@types/cookie-parser": "^1.4.6", "@types/express": "^4.17.21", @@ -67,6 +79,10 @@ "eslint-plugin-import": "^2.29.1", "http-server": "^14.1.1", "rimraf": "^5.0.1", + "rollup": "^4.14.1", + "rollup-plugin-commonjs": "^10.1.0", + "rollup-plugin-dts": "^6.1.0", + "rollup-plugin-node-resolve": "^5.2.0", "start-server-and-test": "^2.0.0", "typescript": "^5.0.2", "yalc": "^1.0.0-pre.53" diff --git a/rollup.config.mjs b/rollup.config.mjs new file mode 100644 index 0000000..4be28d6 --- /dev/null +++ b/rollup.config.mjs @@ -0,0 +1,31 @@ +import dts from "rollup-plugin-dts"; +import resolve from "rollup-plugin-node-resolve"; +import commonjs from "rollup-plugin-commonjs"; +// import typescript from "rollup-plugin-typescript2"; +import json from "@rollup/plugin-json"; + +export default [ + { + input: "dist/plugin/index.js", + output: [ + { + name: "c8y", + file: "dist/plugin/index.js", + format: "umd", + sourcemap: true, + }, + ], + plugins: [ + resolve({ + only: ["./src/**"], + }), + commonjs(), + json(), + ], + }, + { + input: "dist/plugin/index.d.ts", + output: [{ file: "dist/plugin/index.d.ts", format: "es", sourcemap: true }], + plugins: [dts()], + }, +]; diff --git a/src/lib/commands/mount.d.ts b/src/lib/commands/mount.d.ts deleted file mode 100644 index 36a2015..0000000 --- a/src/lib/commands/mount.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { mount } from "cypress/angular"; - -import "./auth"; -import "./c8ypact"; -import "./intercept"; - -declare global { - namespace Cypress { - interface Chainable { - /** - * Mount a Cumulocity Angular component. When mounting the component FetchClient - * provider will be C8yPactFetchClient to enable recording and mocking of - * requests and responses. Set base url with C8Y_BASEURL and pass authentication - * via cy.getAuth() or cy.useAuth(). - */ - mount: typeof mount; - } - } -} diff --git a/src/lib/commands/mount.js b/src/lib/commands/mount.ts similarity index 71% rename from src/lib/commands/mount.js rename to src/lib/commands/mount.ts index 23b6180..392af3e 100644 --- a/src/lib/commands/mount.js +++ b/src/lib/commands/mount.ts @@ -8,15 +8,33 @@ import "./oauthlogin"; import { C8yPactFetchClient } from "../pact/fetchclient"; import { FetchClient } from "@c8y/client"; import { getAuthOptionsFromEnv, getBaseUrlFromEnv } from "../utils"; +import { C8yAuthOptions } from "./auth"; + +declare global { + namespace Cypress { + interface Chainable { + /** + * Mount a Cumulocity Angular component. When mounting the component FetchClient + * provider will be C8yPactFetchClient to enable recording and mocking of + * requests and responses. Set base url with C8Y_BASEURL and pass authentication + * via cy.getAuth() or cy.useAuth(). + */ + mount: typeof mount; + } + } +} Cypress.Commands.add( "mount", + // @ts-expect-error { prevSubject: "optional" }, - (subject, component, options) => { - const consoleProps = {}; + (subject: C8yAuthOptions, ...args) => { + const [component, options] = args; + const consoleProps: any = {}; const logger = Cypress.log({ autoEnd: false, name: "mount", + // @ts-expect-error message: isClass(component) ? component.name : component, consoleProps: () => consoleProps, }); @@ -45,7 +63,7 @@ Cypress.Commands.add( throw error; } - const registerFetchClient = (auth) => { + const registerFetchClient = (auth: C8yAuthOptions) => { const fetchClient = new C8yPactFetchClient({ cypresspact: Cypress.c8ypact, auth, @@ -69,18 +87,19 @@ Cypress.Commands.add( return ( Cypress.c8ypact.isRecordingEnabled() || - Cypress.c8ypact.config.strictMocking === false - ? cy.oauthLogin(auth, baseUrl) - : cy.wrap(auth) - ).then((a) => { + Cypress.c8ypact.config?.strictMocking === false + ? cy.oauthLogin(auth) + : cy.wrap(auth) + ).then((a: C8yAuthOptions) => { registerFetchClient(a); logger.end(); + return mount(component, options); }); } ); -function isClass(component) { +function isClass(component: any) { return ( component && typeof component === "function" && diff --git a/src/lib/plugin/index.ts b/src/plugin/index.ts similarity index 95% rename from src/lib/plugin/index.ts rename to src/plugin/index.ts index 80eabd5..00b0bbb 100644 --- a/src/lib/plugin/index.ts +++ b/src/plugin/index.ts @@ -4,9 +4,9 @@ import * as fs from "fs"; import { C8yPactFileAdapter, C8yPactDefaultFileAdapter, -} from "../../shared/c8ypact/fileadapter"; -import { C8yPact } from "../../shared/c8ypact/c8ypact"; -import { C8yAuthOptions, oauthLogin } from "../../shared/c8yclient"; +} from "../shared/c8ypact/fileadapter"; +import { C8yPact } from "../shared/c8ypact/c8ypact"; +import { C8yAuthOptions, oauthLogin } from "../shared/c8yclient"; export { C8yPactFileAdapter, C8yPactDefaultFileAdapter }; diff --git a/src/plugin/tsconfig.json b/src/plugin/tsconfig.json new file mode 100644 index 0000000..1e3d06b --- /dev/null +++ b/src/plugin/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "../../dist/plugin", + "lib": ["ES2020"], + "types": ["node", "cookie-parser", "cypress"], + "composite": true + }, + "references": [{ "path": "./../shared" }] +} diff --git a/tsconfig.json b/tsconfig.json index a266138..bddd685 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { - "target": "es2022", - "module": "Node16", + "rootDir": ".", + "target": "es2020", + "module": "es2020", + "moduleResolution": "node", "declaration": true, "declarationMap": true, "strict": true, From 645979c68c596c6cf70db198d610f49da8452643 Mon Sep 17 00:00:00 2001 From: Thomas Winkler Date: Tue, 9 Apr 2024 08:45:01 +0200 Subject: [PATCH 2/3] Fixed tests and pactrunner to work with new path for plugin. --- package.json | 2 +- packages/pactrunner/cypress.config.ts | 2 +- packages/pactrunner/tsconfig.json | 3 ++- test/cypress.config.ts | 2 +- test/tsconfig.json | 8 ++++++-- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 31b1311..8c582a8 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "npm run clean && npm run copy-files && tsc -b -v src/lib && tsc -b -v src/plugin && npm run build:plugin && cd dist/ && npm run clean-package-json", "build:plugin": "rollup -c rollup.config.mjs", "yalc:runner": "npm run yalc:publish && cd packages/pactrunner && yalc add cumulocity-cypress", - "yalc:publish": "cd dist/ && yalc publish && cd ..", + "yalc:publish": "npm run clean && npm run build && cd dist/ && yalc publish && cd ..", "clean-package-json": "npm pkg delete 'devDependencies' && npm pkg delete 'scripts'", "lint": "eslint ./" }, diff --git a/packages/pactrunner/cypress.config.ts b/packages/pactrunner/cypress.config.ts index d0b468c..162dea0 100644 --- a/packages/pactrunner/cypress.config.ts +++ b/packages/pactrunner/cypress.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from "cypress"; -import { configureC8yPlugin } from "cumulocity-cypress/lib/plugin"; +import { configureC8yPlugin } from "cumulocity-cypress/plugin"; import { C8yPactDefaultFileAdapter } from "cumulocity-cypress/shared/c8ypact/fileadapter"; module.exports = defineConfig({ diff --git a/packages/pactrunner/tsconfig.json b/packages/pactrunner/tsconfig.json index 20d8dd9..50207f0 100644 --- a/packages/pactrunner/tsconfig.json +++ b/packages/pactrunner/tsconfig.json @@ -12,6 +12,7 @@ }, "references": [ { "path": "./../../src/shared" }, - { "path": "./../../src/lib" } + { "path": "./../../src/lib" }, + { "path": "./../../src/plugin" } ] } diff --git a/test/cypress.config.ts b/test/cypress.config.ts index 35c8136..3d49cfb 100644 --- a/test/cypress.config.ts +++ b/test/cypress.config.ts @@ -1,5 +1,5 @@ import { defineConfig } from "cypress"; -import { configureC8yPlugin } from "../src/lib/plugin"; +import { configureC8yPlugin } from "../src/plugin"; module.exports = defineConfig({ e2e: { diff --git a/test/tsconfig.json b/test/tsconfig.json index a5409d2..7e8d3d2 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -10,7 +10,11 @@ "strict": true, "module": "Node16", "skipLibCheck": true, - "composite": true, + "composite": true }, - "references": [{ "path": "./../src/shared" }, { "path": "./../src/lib" }] + "references": [ + { "path": "./../src/shared" }, + { "path": "./../src/lib" }, + { "path": "./../src/plugin" } + ] } From 9203abd5fe1da742f542337a6a8690413719fc67 Mon Sep 17 00:00:00 2001 From: Thomas Winkler Date: Tue, 9 Apr 2024 08:45:39 +0200 Subject: [PATCH 3/3] Converted request to typescript. --- src/lib/commands/request.d.ts | 33 --------- src/lib/commands/{request.js => request.ts} | 77 +++++++++++++++++---- 2 files changed, 63 insertions(+), 47 deletions(-) delete mode 100644 src/lib/commands/request.d.ts rename src/lib/commands/{request.js => request.ts} (60%) diff --git a/src/lib/commands/request.d.ts b/src/lib/commands/request.d.ts deleted file mode 100644 index d4dbc82..0000000 --- a/src/lib/commands/request.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -export {}; - -declare global { - namespace Cypress { - interface Chainable { - /** - * Retry a request for a given number of max retries and delay. When test function - * `testFn` returns `true` stop retrying and continue. - * - * Use `retries` to pass number of retries and `retryDelay` to pass delay in milliseconds. - * - * @example - * cy.retryRequest( - * { - * method: "GET", - * url: "/service/apama-oeeapp/mon/ping", - * retries: Cypress.env("livenessRetries") || 5, - * retryDelay: Cypress.env("livenessRetryTimeout") || 10000, - * }, - * (response) => { - * return response.status === 200; - * } - * ); - */ - retryRequest( - options: Partial & RetryOptions, - testFn: (response: any) => boolean - ): Chainable>; - } - } - - type RetryOptions = { retries: number; retryDelay: number }; -} diff --git a/src/lib/commands/request.js b/src/lib/commands/request.ts similarity index 60% rename from src/lib/commands/request.js rename to src/lib/commands/request.ts index c14f31a..763da1d 100644 --- a/src/lib/commands/request.js +++ b/src/lib/commands/request.ts @@ -1,6 +1,44 @@ import { getAuthOptionsFromEnv, normalizedArgumentsWithAuth } from "../utils"; const { _ } = Cypress; +declare global { + namespace Cypress { + interface Chainable { + /** + * Retry a request for a given number of max retries and delay. When test function + * `testFn` returns `true` stop retrying and continue. + * + * Use `retries` to pass number of retries and `retryDelay` to pass delay in milliseconds. + * + * @example + * cy.retryRequest( + * { + * method: "GET", + * url: "/service/apama-oeeapp/mon/ping", + * retries: Cypress.env("livenessRetries") || 5, + * retryDelay: Cypress.env("livenessRetryTimeout") || 10000, + * }, + * (response) => { + * return response.status === 200; + * } + * ); + */ + retryRequest( + options: C8yRequestOptions, + testFn: (response: any) => boolean + ): Chainable>; + } + interface Cypress { + cy: { + addCommand: (cmd: any) => void; + }; + } + } + + type RetryOptions = { retries: number; retryDelay: number }; + type C8yRequestOptions = Partial & RetryOptions; +} + const methods = [ "GET", "POST", @@ -30,7 +68,7 @@ const methods = [ "CONNECT", ]; -function retryRequest(...args) { +function retryRequest(...args: any[]) { const $args = normalizedArgumentsWithAuth(args); if (!$args || $args.length !== 3) { throw new Error( @@ -38,6 +76,7 @@ function retryRequest(...args) { ); } + // eslint-disable-next-line prefer-const -- auth is not reassigned let [auth, options, testFn] = $args; const orgOptions = _.cloneDeep(options); const retryOptions = _.pick(options, ["retryDelay", "retries"]); @@ -85,14 +124,16 @@ Cypress.Commands.add("retryRequest", { prevSubject: "optional" }, retryRequest); // current solution uses a wrapper for the default request function that adds the authentication // from environment. -const requestCommandWrapper = (wrappedFn) => { - return function (...args) { - const options = {}; +const requestCommandWrapper = ( + wrappedFn: Cypress.CommandFnWithOriginalFn +) => { + return function (...args: any[]) { + const options: Partial = {}; const originalFn = _.isFunction(args[0]) ? args[0] : undefined; const $args = originalFn ? args.slice(1) : args; - const auth = getAuthOptionsFromEnv(...$args); + const auth = getAuthOptionsFromEnv.apply($args); if (_.isObjectLike($args[0])) { _.extend(options, $args[0]); @@ -116,21 +157,29 @@ const requestCommandWrapper = (wrappedFn) => { options.auth = _.omit(auth, "tenant"); } - const wrappedArgs = originalFn ? [args[0], options] : [options]; + const wrappedArgs: any[] = + originalFn && args?.length > 0 ? [args[0], options] : [options]; + + // @ts-expect-error return wrappedFn(...wrappedArgs); }; }; -const requestFn = Cypress.cy["request"]; -Cypress.cy.addCommand({ - name: "request", - fn: requestCommandWrapper(requestFn), - type: "parent", - prevSubject: null, -}); +const requestFn = _.get(Cypress.cy, "request"); +if (requestFn) { + Cypress.cy.addCommand({ + name: "request", + fn: requestCommandWrapper(requestFn), + type: "parent", + prevSubject: null, + }); +} const overwriteFn = Cypress.Commands.overwrite; -Cypress.Commands.overwrite = (name, fn) => { +Cypress.Commands.overwrite = ( + name: keyof Cypress.Chainable, + fn: Cypress.CommandFnWithOriginalFn +) => { if (name === "request") { overwriteFn(name, requestCommandWrapper(fn)); } else {