From 808be7735b044d118fed04bf94028ab1113b9241 Mon Sep 17 00:00:00 2001 From: outslept <135520429+outslept@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:10:08 +0300 Subject: [PATCH 1/3] test: replace tsd with vitest type checking --- package-lock.json | 502 ------------------ packages/build/package.json | 7 +- packages/build/test-d/config/build.test-d.ts | 24 + packages/build/test-d/config/build.ts | 26 - .../build/test-d/config/functions.test-d.ts | 19 + packages/build/test-d/config/functions.ts | 19 - packages/build/test-d/config/inputs.test-d.ts | 28 + packages/build/test-d/config/inputs.ts | 21 - .../test-d/config/netlify_config.test-d.ts | 42 ++ .../build/test-d/config/netlify_config.ts | 58 -- .../build/test-d/netlify_plugin.test-d.ts | 24 + packages/build/test-d/netlify_plugin.ts | 22 - .../test-d/netlify_plugin_options.test-d.ts | 21 + .../build/test-d/netlify_plugin_options.ts | 21 - .../netlify_plugin_build_util.test-d.ts | 26 + .../options/netlify_plugin_build_util.ts | 37 -- .../netlify_plugin_cache_util.test-d.ts | 51 ++ .../options/netlify_plugin_cache_util.ts | 67 --- .../netlify_plugin_functions_util.test-d.ts | 18 + .../options/netlify_plugin_functions_util.ts | 32 -- .../options/netlify_plugin_git_util.test-d.ts | 27 + .../test-d/options/netlify_plugin_git_util.ts | 30 -- .../options/netlify_plugin_run_util.test-d.ts | 23 + .../test-d/options/netlify_plugin_run_util.ts | 11 - .../netlify_plugin_status_util.test-d.ts | 9 + .../options/netlify_plugin_status_util.ts | 12 - 26 files changed, 315 insertions(+), 862 deletions(-) create mode 100644 packages/build/test-d/config/build.test-d.ts delete mode 100644 packages/build/test-d/config/build.ts create mode 100644 packages/build/test-d/config/functions.test-d.ts delete mode 100644 packages/build/test-d/config/functions.ts create mode 100644 packages/build/test-d/config/inputs.test-d.ts delete mode 100644 packages/build/test-d/config/inputs.ts create mode 100644 packages/build/test-d/config/netlify_config.test-d.ts delete mode 100644 packages/build/test-d/config/netlify_config.ts create mode 100644 packages/build/test-d/netlify_plugin.test-d.ts delete mode 100644 packages/build/test-d/netlify_plugin.ts create mode 100644 packages/build/test-d/netlify_plugin_options.test-d.ts delete mode 100644 packages/build/test-d/netlify_plugin_options.ts create mode 100644 packages/build/test-d/options/netlify_plugin_build_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_build_util.ts create mode 100644 packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_cache_util.ts create mode 100644 packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_functions_util.ts create mode 100644 packages/build/test-d/options/netlify_plugin_git_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_git_util.ts create mode 100644 packages/build/test-d/options/netlify_plugin_run_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_run_util.ts create mode 100644 packages/build/test-d/options/netlify_plugin_status_util.test-d.ts delete mode 100644 packages/build/test-d/options/netlify_plugin_status_util.ts diff --git a/package-lock.json b/package-lock.json index 97c8ac0a59..dfe838caf9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5129,16 +5129,6 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "license": "MIT" }, - "node_modules/@tsd/typescript": { - "version": "5.8.3", - "resolved": "https://registry.npmjs.org/@tsd/typescript/-/typescript-5.8.3.tgz", - "integrity": "sha512-oKarNCN1QUhG148M88mtZdOlBZWWGcInquef+U8QL7gwJkRuNo5WS45Fjsd+3hM9cDJWGpqSZ4Oo097KDx4IWA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=14.17" - } - }, "node_modules/@tufjs/canonical-json": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz", @@ -5210,17 +5200,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/eslint": { - "version": "7.29.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.29.0.tgz", - "integrity": "sha512-VNcvioYDH8/FxaeTKkM4/TiTwt6pBV9E3OfGmvaw8tPl0rrHCJ4Ll15HRT+pMiFAf/MLQvAzC+6RzUMEL9Ceng==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -10729,188 +10708,6 @@ "eslint": ">=7.0.0" } }, - "node_modules/eslint-formatter-pretty": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/eslint-formatter-pretty/-/eslint-formatter-pretty-4.1.0.tgz", - "integrity": "sha512-IsUTtGxF1hrH6lMWiSl1WbGaiP01eT6kzywdY1U+zLc0MP+nwEnUiS9UI8IaOTUhTeQJLlCEWIbXINBH4YJbBQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/eslint": "^7.2.13", - "ansi-escapes": "^4.2.1", - "chalk": "^4.1.0", - "eslint-rule-docs": "^1.1.5", - "log-symbols": "^4.0.0", - "plur": "^4.0.0", - "string-width": "^4.2.0", - "supports-hyperlinks": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/ansi-escapes": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.2.tgz", - "integrity": "sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "type-fest": "^0.21.3" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true, - "license": "MIT" - }, - "node_modules/eslint-formatter-pretty/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/plur": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/plur/-/plur-4.0.0.tgz", - "integrity": "sha512-4UGewrYgqDFw9vV6zNV+ADmPAUAfJPKtGvb/VdpQAx25X5f3xXdGdyOEVFwkl8Hl/tl7+xbeHqSEM+D5/TirUg==", - "dev": true, - "license": "MIT", - "dependencies": { - "irregular-plurals": "^3.2.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/type-fest": { - "version": "0.21.3", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", - "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint-import-resolver-node": { "version": "0.3.9", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz", @@ -11246,13 +11043,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint-rule-docs": { - "version": "1.1.235", - "resolved": "https://registry.npmjs.org/eslint-rule-docs/-/eslint-rule-docs-1.1.235.tgz", - "integrity": "sha512-+TQ+x4JdTnDoFEXXb3fDvfGOwnyNV7duH8fXWTPD1ieaBmB8omj7Gw/pMBBu4uI2uJCCU8APDaQJzWuXnTsH4A==", - "dev": true, - "license": "MIT" - }, "node_modules/eslint-scope": { "version": "8.4.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.4.0.tgz", @@ -21334,33 +21124,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/supports-hyperlinks": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.3.0.tgz", - "integrity": "sha512-RpsAZlpWcDwOPQA22aCH4J0t7L8JmAvsCxfOSEwm7cQs3LshN36QaTkwd70DnBOXDWGssw2eUoc8CaRWT0XunA==", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0", - "supports-color": "^7.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/supports-hyperlinks/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", @@ -21881,270 +21644,6 @@ "node": ">=4" } }, - "node_modules/tsd": { - "version": "0.32.0", - "resolved": "https://registry.npmjs.org/tsd/-/tsd-0.32.0.tgz", - "integrity": "sha512-R5lBZCbxGBowOcW0gpQaiIjGYrG5NmU+PfFDKcc3zbtzWjML1o/zAwzdDnS2ZheSlPu9GW51azpFqEPUBq9DoQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@tsd/typescript": "~5.8.3", - "eslint-formatter-pretty": "^4.1.0", - "globby": "^11.0.1", - "jest-diff": "^29.0.3", - "meow": "^9.0.0", - "path-exists": "^4.0.0", - "read-pkg-up": "^7.0.0" - }, - "bin": { - "tsd": "dist/cli.js" - }, - "engines": { - "node": ">=14.16" - } - }, - "node_modules/tsd/node_modules/find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "dev": true, - "license": "MIT", - "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "license": "MIT", - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tsd/node_modules/hosted-git-info": { - "version": "2.8.9", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", - "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", - "dev": true, - "license": "ISC" - }, - "node_modules/tsd/node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, - "license": "MIT", - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/meow": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/meow/-/meow-9.0.0.tgz", - "integrity": "sha512-+obSblOQmRhcyBt62furQqRAQpNyWXo8BuQ5bN7dG8wmwQ+vwHKp/rCFD4CrTP8CsDQD1sjoZ94K417XEUk8IQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/minimist": "^1.2.0", - "camelcase-keys": "^6.2.2", - "decamelize": "^1.2.0", - "decamelize-keys": "^1.1.0", - "hard-rejection": "^2.1.0", - "minimist-options": "4.1.0", - "normalize-package-data": "^3.0.0", - "read-pkg-up": "^7.0.1", - "redent": "^3.0.0", - "trim-newlines": "^3.0.0", - "type-fest": "^0.18.0", - "yargs-parser": "^20.2.3" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tsd/node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "dev": true, - "license": "MIT", - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tsd/node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "dev": true, - "license": "MIT", - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/read-pkg": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", - "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/normalize-package-data": "^2.4.0", - "normalize-package-data": "^2.5.0", - "parse-json": "^5.0.0", - "type-fest": "^0.6.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/read-pkg-up": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", - "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", - "dev": true, - "license": "MIT", - "dependencies": { - "find-up": "^4.1.0", - "read-pkg": "^5.2.0", - "type-fest": "^0.8.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tsd/node_modules/read-pkg-up/node_modules/type-fest": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", - "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/read-pkg/node_modules/normalize-package-data": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", - "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "hosted-git-info": "^2.1.4", - "resolve": "^1.10.0", - "semver": "2 || 3 || 4 || 5", - "validate-npm-package-license": "^3.0.1" - } - }, - "node_modules/tsd/node_modules/read-pkg/node_modules/type-fest": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", - "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=8" - } - }, - "node_modules/tsd/node_modules/resolve": { - "version": "1.22.10", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", - "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", - "dev": true, - "license": "MIT", - "dependencies": { - "is-core-module": "^2.16.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/tsd/node_modules/semver": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", - "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", - "dev": true, - "license": "ISC", - "bin": { - "semver": "bin/semver" - } - }, - "node_modules/tsd/node_modules/type-fest": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", - "integrity": "sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tsd/node_modules/yargs-parser": { - "version": "20.2.9", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", - "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=10" - } - }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", @@ -23793,7 +23292,6 @@ "process-exists": "^5.0.0", "tinyspy": "^4.0.3", "tmp-promise": "^3.0.2", - "tsd": "^0.32.0", "vitest": "^3.0.0", "yarn": "^1.22.22" }, diff --git a/packages/build/package.json b/packages/build/package.json index 0a52e5a506..463eb953d6 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -25,11 +25,11 @@ "prebuild": "rm -rf lib", "postbuild": "npx cpy \"src/**/*.yml\" \"lib/\"", "build": "tsc", - "test:types": "tsd", - "test": "ava && tsd && vitest run", + "test:types": "vitest --typecheck", + "test": "ava && vitest --typecheck && vitest run", "test:dev": "ava -w", "test:ci": "run-p test:ci:*", - "test:ci:types": "tsd", + "test:ci:types": "vitest --typecheck", "test:ci:ava": "c8 -r lcovonly -r text -r json ava", "test:ci:vitest": "vitest run" }, @@ -135,7 +135,6 @@ "process-exists": "^5.0.0", "tinyspy": "^4.0.3", "tmp-promise": "^3.0.2", - "tsd": "^0.32.0", "vitest": "^3.0.0", "yarn": "^1.22.22" }, diff --git a/packages/build/test-d/config/build.test-d.ts b/packages/build/test-d/config/build.test-d.ts new file mode 100644 index 0000000000..0f37a51910 --- /dev/null +++ b/packages/build/test-d/config/build.test-d.ts @@ -0,0 +1,24 @@ +import type { NetlifyConfig } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('netlify config build types', () => { + type Build = NetlifyConfig['build'] + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) + +test('netlify config build processing types', () => { + type Processing = NetlifyConfig['build']['processing'] + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) diff --git a/packages/build/test-d/config/build.ts b/packages/build/test-d/config/build.ts deleted file mode 100644 index d2662f9f19..0000000000 --- a/packages/build/test-d/config/build.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { OnPreBuild } from '@netlify/build' -import { expectType } from 'tsd' - -export const testNetlifyConfigBuild: OnPreBuild = function ({ netlifyConfig: { build } }) { - expectType(build.command) - expectType(build.publish) - expectType(build.base) - expectType(build.services.testVar) - expectType(build.ignore) - expectType(build.edge_handlers) - expectType(build.environment.TEST_VAR) -} - -export const testNetlifyConfigBuildProcessing: OnPreBuild = function ({ - netlifyConfig: { - build: { processing }, - }, -}) { - expectType(processing.skip_processing) - expectType(processing.css.bundle) - expectType(processing.css.minify) - expectType(processing.js.bundle) - expectType(processing.js.minify) - expectType(processing.html.pretty_url) - expectType(processing.images.compress) -} diff --git a/packages/build/test-d/config/functions.test-d.ts b/packages/build/test-d/config/functions.test-d.ts new file mode 100644 index 0000000000..a6de0b212a --- /dev/null +++ b/packages/build/test-d/config/functions.test-d.ts @@ -0,0 +1,19 @@ +import type { NetlifyConfig } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('netlify config functions types', () => { + type Functions = NetlifyConfig['functions']['*'] + + expectTypeOf().toExtend() + expectTypeOf().toEqualTypeOf() + + // available when node_bundler is 'esbuild' + type EsbuildFunctions = Functions & { node_bundler: 'esbuild' } + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + + // NOT available when node_bundler is not 'esbuild' + type NonEsbuildFunctions = Functions & { node_bundler: 'webpack' } + expectTypeOf().toBeNever() + expectTypeOf().toBeNever() +}) diff --git a/packages/build/test-d/config/functions.ts b/packages/build/test-d/config/functions.ts deleted file mode 100644 index d971b2d8dc..0000000000 --- a/packages/build/test-d/config/functions.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { OnPreBuild } from '@netlify/build' -import { expectAssignable, expectType, expectError } from 'tsd' - -export const testNetlifyConfigFunctions: OnPreBuild = function ({ - netlifyConfig: { - functions: { '*': functions }, - }, -}) { - expectAssignable(functions.node_bundler) - expectType(functions.included_files) - - if (functions.node_bundler === 'esbuild') { - expectType(functions.external_node_modules) - expectType(functions.ignored_node_modules) - } else { - expectError(functions.external_node_modules) - expectError(functions.ignored_node_modules) - } -} diff --git a/packages/build/test-d/config/inputs.test-d.ts b/packages/build/test-d/config/inputs.test-d.ts new file mode 100644 index 0000000000..065ef7ae5c --- /dev/null +++ b/packages/build/test-d/config/inputs.test-d.ts @@ -0,0 +1,28 @@ +import type { OnPreBuild } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' +import type { JSONValue } from '../../lib/types/utils/json_value.js' + +test('generic inputs types', () => { + type GenericInputs = Parameters[0]['inputs'] + expectTypeOf().toExtend() +}) + +test('specific inputs types', () => { + type SpecificInputs = Parameters>[0]['inputs'] + expectTypeOf().toEqualTypeOf() + + // @ts-expect-error - non-existent property + expectTypeOf().toBeNever() +}) + +test('specific inputs interface types', () => { + interface InputsInterface { + testVar: string + } + + type InterfaceInputs = Parameters>[0]['inputs'] + expectTypeOf().toEqualTypeOf() + + // @ts-expect-error - non-existent property + expectTypeOf().toBeNever() +}) diff --git a/packages/build/test-d/config/inputs.ts b/packages/build/test-d/config/inputs.ts deleted file mode 100644 index b3a8430802..0000000000 --- a/packages/build/test-d/config/inputs.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { OnPreBuild } from '@netlify/build' -import { expectAssignable, expectError, expectType } from 'tsd' -import type { JSONValue } from '../../lib/types/utils/json_value.js' - -export const testGenericInputs: OnPreBuild = function ({ inputs }) { - expectAssignable(inputs.testVar) -} - -export const testSpecificInputs: OnPreBuild<{ testVar: boolean }> = function ({ inputs }) { - expectType(inputs.testVar) - expectError(inputs.otherTestVar) -} - -interface InputsInterface { - testVar: string -} - -export const testSpecificInputsInterface: OnPreBuild = function ({ inputs }) { - expectType(inputs.testVar) - expectError(inputs.otherTestVar) -} diff --git a/packages/build/test-d/config/netlify_config.test-d.ts b/packages/build/test-d/config/netlify_config.test-d.ts new file mode 100644 index 0000000000..77a2294d84 --- /dev/null +++ b/packages/build/test-d/config/netlify_config.test-d.ts @@ -0,0 +1,42 @@ +import type { NetlifyConfig } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' +import type { JSONValue } from '../../lib/types/utils/json_value.js' + +test('netlify config plugins types', () => { + type Plugin = NetlifyConfig['plugins'][number] + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) + +test('netlify config edge functions types', () => { + type EdgeFunction = NetlifyConfig['edge_functions'][number] + expectTypeOf().toExtend() + expectTypeOf().toEqualTypeOf() +}) + +test('netlify config headers types', () => { + type Header = NetlifyConfig['headers'][number] + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) + +test('netlify config redirects types', () => { + type Redirect = NetlifyConfig['redirects'][number] + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + + type QueryTestVar = NonNullable['testVar'] + expectTypeOf().toEqualTypeOf() + + type HeadersTestVar = NonNullable['testVar'] + expectTypeOf().toEqualTypeOf() + + type Conditions = NonNullable + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) diff --git a/packages/build/test-d/config/netlify_config.ts b/packages/build/test-d/config/netlify_config.ts deleted file mode 100644 index 956d0d07b1..0000000000 --- a/packages/build/test-d/config/netlify_config.ts +++ /dev/null @@ -1,58 +0,0 @@ -import type { OnPreBuild, NetlifyConfig } from '@netlify/build' -import { expectAssignable, expectType } from 'tsd' -import type { JSONValue } from '../../lib/types/utils/json_value.js' - -export const testNetlifyConfigPlugins: OnPreBuild = function ({ - netlifyConfig: { - plugins: [plugin], - }, -}: { - netlifyConfig: NetlifyConfig -}) { - expectType(plugin.package) - expectType(plugin.inputs.testVar) -} - -export const testNetlifyConfigEdgeHandlers: OnPreBuild = function ({ - netlifyConfig: { - edge_functions: [edgeFunction], - }, -}: { - netlifyConfig: NetlifyConfig -}) { - expectAssignable(edgeFunction.path) - expectType(edgeFunction.function) -} - -export const testNetlifyConfigHeaders: OnPreBuild = function ({ - netlifyConfig: { - headers: [header], - }, -}: { - netlifyConfig: NetlifyConfig -}) { - expectType(header.for) - expectType(header.values.testVar) -} - -export const testNetlifyConfigRedirects: OnPreBuild = function ({ - netlifyConfig: { - redirects: [redirect], - }, -}: { - netlifyConfig: NetlifyConfig -}) { - expectType(redirect.from) - expectType(redirect.to) - expectType(redirect.status) - expectType(redirect.force) - expectType(redirect.signed) - expectType(redirect.query && redirect.query.testVar) - expectType(redirect.headers && redirect.headers.testVar) - if (redirect.conditions !== undefined) { - expectType(redirect.conditions.Language) - expectType(redirect.conditions.Cookie) - expectType(redirect.conditions.Country) - expectType(redirect.conditions.Role) - } -} diff --git a/packages/build/test-d/netlify_plugin.test-d.ts b/packages/build/test-d/netlify_plugin.test-d.ts new file mode 100644 index 0000000000..4a435797cd --- /dev/null +++ b/packages/build/test-d/netlify_plugin.test-d.ts @@ -0,0 +1,24 @@ +import type { NetlifyPlugin, OnPreBuild, OnBuild, OnPostBuild, OnError, OnSuccess, OnEnd } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('event types', () => { + const noop = function () {} + + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() + expectTypeOf(noop).toExtend() +}) + +test('onError event types', () => { + type ErrorParams = Parameters[0] + expectTypeOf().toEqualTypeOf() +}) + +test('onEnd event types', () => { + type EndParams = Parameters[0] + expectTypeOf().toEqualTypeOf() +}) diff --git a/packages/build/test-d/netlify_plugin.ts b/packages/build/test-d/netlify_plugin.ts deleted file mode 100644 index a551d9788d..0000000000 --- a/packages/build/test-d/netlify_plugin.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { NetlifyPlugin, OnPreBuild, OnBuild, OnPostBuild, OnError, OnSuccess, OnEnd } from '@netlify/build' -import { expectAssignable, expectType } from 'tsd' - -export const testEventNames = function () { - expectAssignable(noop) - expectAssignable(noop) - expectAssignable(noop) - expectAssignable(noop) - expectAssignable(noop) - expectAssignable(noop) - expectAssignable(noop) -} - -const noop = function () {} - -export const testOnError: OnError = function ({ error }) { - expectType(error) -} - -export const testOnEnd: OnEnd = function ({ error }) { - expectType(error) -} diff --git a/packages/build/test-d/netlify_plugin_options.test-d.ts b/packages/build/test-d/netlify_plugin_options.test-d.ts new file mode 100644 index 0000000000..349af6833e --- /dev/null +++ b/packages/build/test-d/netlify_plugin_options.test-d.ts @@ -0,0 +1,21 @@ +import type { NetlifyPluginConstants, NetlifyPluginOptions } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' +import type { JSONValue } from '../lib/types/utils/json_value.js' + +test('constants types', () => { + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) + +test('package json types', () => { + expectTypeOf().toEqualTypeOf() +}) diff --git a/packages/build/test-d/netlify_plugin_options.ts b/packages/build/test-d/netlify_plugin_options.ts deleted file mode 100644 index 97f01d713b..0000000000 --- a/packages/build/test-d/netlify_plugin_options.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { NetlifyPluginConstants, NetlifyPluginOptions, OnPreBuild } from '@netlify/build' -import { expectType } from 'tsd' -import type { JSONValue } from '../lib/types/utils/json_value.js' - -export const testConstants: OnPreBuild = function ({ constants }: { constants: NetlifyPluginConstants }) { - expectType(constants.CONFIG_PATH) - expectType(constants.PUBLISH_DIR) - expectType(constants.FUNCTIONS_SRC) - expectType(constants.INTERNAL_EDGE_FUNCTIONS_SRC) - expectType(constants.INTERNAL_FUNCTIONS_SRC) - expectType(constants.FUNCTIONS_DIST) - expectType(constants.EDGE_FUNCTIONS_SRC) - expectType(constants.EDGE_FUNCTIONS_DIST) - expectType(constants.IS_LOCAL) - expectType(constants.NETLIFY_BUILD_VERSION) - expectType(constants.SITE_ID) -} - -export const testPackageJson: OnPreBuild = function ({ packageJson }: NetlifyPluginOptions) { - expectType(packageJson.version) -} diff --git a/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts new file mode 100644 index 0000000000..d01d6e7463 --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts @@ -0,0 +1,26 @@ +import type { NetlifyPluginUtils } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils build failBuild types', () => { + type BuildFailBuild = NetlifyPluginUtils['build']['failBuild'] + + expectTypeOf().toBeCallableWith('message') + expectTypeOf().toBeCallableWith('message', {}) + expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +}) + +test('utils build failPlugin types', () => { + type BuildFailPlugin = NetlifyPluginUtils['build']['failPlugin'] + + expectTypeOf().toBeCallableWith('message') + expectTypeOf().toBeCallableWith('message', {}) + expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +}) + +test('utils build cancelBuild types', () => { + type BuildCancelBuild = NetlifyPluginUtils['build']['cancelBuild'] + + expectTypeOf().toBeCallableWith('message') + expectTypeOf().toBeCallableWith('message', {}) + expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +}) diff --git a/packages/build/test-d/options/netlify_plugin_build_util.ts b/packages/build/test-d/options/netlify_plugin_build_util.ts deleted file mode 100644 index 49afbf6fb6..0000000000 --- a/packages/build/test-d/options/netlify_plugin_build_util.ts +++ /dev/null @@ -1,37 +0,0 @@ -import type { OnPreBuild, NetlifyPluginUtils } from '@netlify/build' - -export const testUtilsBuildFailBuild: OnPreBuild = function ({ - utils: { - build: { failBuild }, - }, -}: { - utils: NetlifyPluginUtils -}) { - failBuild('message') - failBuild('message', {}) - failBuild('message', { error: new Error('message') }) -} - -export const testUtilsBuildFailPlugin: OnPreBuild = function ({ - utils: { - build: { failPlugin }, - }, -}: { - utils: NetlifyPluginUtils -}) { - failPlugin('message') - failPlugin('message', {}) - failPlugin('message', { error: new Error('message') }) -} - -export const testUtilsBuildCancelBuild: OnPreBuild = function ({ - utils: { - build: { cancelBuild }, - }, -}: { - utils: NetlifyPluginUtils -}) { - cancelBuild('message') - cancelBuild('message', {}) - cancelBuild('message', { error: new Error('message') }) -} diff --git a/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts new file mode 100644 index 0000000000..3d71374712 --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts @@ -0,0 +1,51 @@ +import type { NetlifyPluginUtils } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils cache save types', () => { + type CacheSave = NetlifyPluginUtils['cache']['save'] + + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { ttl: 1, digests: ['digest'], cwd: '.' }) +}) + +test('utils cache list types', () => { + type CacheList = NetlifyPluginUtils['cache']['list'] + + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith({}) + expectTypeOf().toBeCallableWith() + expectTypeOf().toBeCallableWith({ depth: 1, cwd: '.' }) +}) + +test('utils cache restore types', () => { + type CacheRestore = NetlifyPluginUtils['cache']['restore'] + + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +}) + +test('utils cache remove types', () => { + type CacheRemove = NetlifyPluginUtils['cache']['remove'] + + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +}) + +test('utils cache has types', () => { + type CacheHas = NetlifyPluginUtils['cache']['has'] + + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +}) diff --git a/packages/build/test-d/options/netlify_plugin_cache_util.ts b/packages/build/test-d/options/netlify_plugin_cache_util.ts deleted file mode 100644 index 8b49c54f70..0000000000 --- a/packages/build/test-d/options/netlify_plugin_cache_util.ts +++ /dev/null @@ -1,67 +0,0 @@ -import type { OnPreBuild, NetlifyPluginUtils } from '@netlify/build' -import { expectType } from 'tsd' - -export const testUtilsCacheSave: OnPreBuild = function ({ - utils: { - cache: { save }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(save('file')) - save(['file']) - save('file', {}) - save('file', { ttl: 1, digests: ['digest'], cwd: '.' }) -} - -export const testUtilsCacheList: OnPreBuild = function ({ - utils: { - cache: { list }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(list({})) - list() - list({}) - list({ depth: 1, cwd: '.' }) -} - -export const testUtilsRestore: OnPreBuild = function ({ - utils: { - cache: { restore }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(restore('file')) - restore(['file']) - restore('file', {}) - restore('file', { cwd: '.' }) -} - -export const testUtilsCacheRemove: OnPreBuild = function ({ - utils: { - cache: { remove }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(remove('file')) - remove(['file']) - remove('file', {}) - remove('file', { cwd: '.' }) -} - -export const testUtilsCacheHas: OnPreBuild = function ({ - utils: { - cache: { has }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(has('file')) - has(['file']) - has('file', {}) - has('file', { cwd: '.' }) -} diff --git a/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts new file mode 100644 index 0000000000..4ba98f36c8 --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts @@ -0,0 +1,18 @@ +import type { NetlifyPluginUtils, ListedFunction, ListedFunctionFile } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils functions list types', () => { + type FunctionsList = NetlifyPluginUtils['functions']['list'] + expectTypeOf>().toEqualTypeOf>() +}) + +test('utils functions listAll types', () => { + type FunctionsListAll = NetlifyPluginUtils['functions']['listAll'] + expectTypeOf>().toEqualTypeOf>() +}) + +test('utils functions add types', () => { + type FunctionsAdd = NetlifyPluginUtils['functions']['add'] + expectTypeOf>().toEqualTypeOf>() + expectTypeOf().toBeCallableWith('functionName') +}) diff --git a/packages/build/test-d/options/netlify_plugin_functions_util.ts b/packages/build/test-d/options/netlify_plugin_functions_util.ts deleted file mode 100644 index 3c9cf12bec..0000000000 --- a/packages/build/test-d/options/netlify_plugin_functions_util.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { OnPreBuild, NetlifyPluginUtils, ListedFunction, ListedFunctionFile } from '@netlify/build' -import { expectType } from 'tsd' - -export const testUtilsFunctionsList: OnPreBuild = function ({ - utils: { - functions: { list }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(list()) -} - -export const testUtilsListAll: OnPreBuild = function ({ - utils: { - functions: { listAll }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(listAll()) -} - -export const testUtilsFunctionsAdd: OnPreBuild = function ({ - utils: { - functions: { add }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType>(add('functionName')) -} diff --git a/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts new file mode 100644 index 0000000000..38186bceaa --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts @@ -0,0 +1,27 @@ +import type { NetlifyPluginUtils } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils git types', () => { + type Git = NetlifyPluginUtils['git'] + + expectTypeOf>().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf>() +}) + +test('utils git commits types', () => { + type Git = NetlifyPluginUtils['git'] + type Commit = Git['commits'][number] + + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() +}) diff --git a/packages/build/test-d/options/netlify_plugin_git_util.ts b/packages/build/test-d/options/netlify_plugin_git_util.ts deleted file mode 100644 index bfdc58f880..0000000000 --- a/packages/build/test-d/options/netlify_plugin_git_util.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { NetlifyPluginUtils, OnPreBuild } from '@netlify/build' -import { expectType } from 'tsd' - -export const testUtilsGit: OnPreBuild = function ({ utils: { git } }: { utils: NetlifyPluginUtils }) { - expectType(git.fileMatch('*')) - expectType(git.modifiedFiles) - expectType(git.createdFiles) - expectType(git.deletedFiles) - expectType>(git.linesOfCode()) -} - -export const testUtilsGitCommits: OnPreBuild = function ({ - utils: { - git: { - commits: [commit], - }, - }, -}: { - utils: NetlifyPluginUtils -}) { - expectType(commit.sha) - expectType(commit.parents) - expectType(commit.author.name) - expectType(commit.author.email) - expectType(commit.author.date) - expectType(commit.committer.name) - expectType(commit.committer.email) - expectType(commit.committer.date) - expectType(commit.message) -} diff --git a/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts new file mode 100644 index 0000000000..ab9bd37de0 --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts @@ -0,0 +1,23 @@ +import type { NetlifyPluginUtils } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils run types', () => { + type RunFunction = NetlifyPluginUtils['run'] + + type RunResult = ReturnType + expectTypeOf().toExtend>() + + expectTypeOf().toBeCallableWith('command') + expectTypeOf().toBeCallableWith('command', ['arg']) + expectTypeOf().toBeCallableWith('command', ['arg'], { preferLocal: false }) + + type RunCommand = NetlifyPluginUtils['run']['command'] + expectTypeOf().toBeCallableWith('command') +}) + +test('utils run invalid options', () => { + type RunFunction = NetlifyPluginUtils['run'] + + // @ts-expect-error - testing invalid + expectTypeOf().toBeCallableWith('command', ['arg'], { unknownOption: false }) +}) diff --git a/packages/build/test-d/options/netlify_plugin_run_util.ts b/packages/build/test-d/options/netlify_plugin_run_util.ts deleted file mode 100644 index 51695bb494..0000000000 --- a/packages/build/test-d/options/netlify_plugin_run_util.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { NetlifyPluginUtils, OnPreBuild } from '@netlify/build' -import { expectAssignable, expectError } from 'tsd' - -export const testUtilsRun: OnPreBuild = function ({ utils: { run } }: { utils: NetlifyPluginUtils }) { - expectAssignable>(run('command')) - run('command', ['arg']) - run('command', ['arg'], { preferLocal: false }) - expectError(run('command', ['arg'], { unknownOption: false })) - - run.command('command') -} diff --git a/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts new file mode 100644 index 0000000000..61a9dc9ee0 --- /dev/null +++ b/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts @@ -0,0 +1,9 @@ +import type { NetlifyPluginUtils } from '@netlify/build' +import { expectTypeOf, test } from 'vitest' + +test('utils status types', () => { + type StatusShow = NetlifyPluginUtils['status']['show'] + + expectTypeOf().toBeCallableWith({ summary: 'summary' }) + expectTypeOf().toBeCallableWith({ summary: 'summary', title: 'title', text: 'text' }) +}) diff --git a/packages/build/test-d/options/netlify_plugin_status_util.ts b/packages/build/test-d/options/netlify_plugin_status_util.ts deleted file mode 100644 index f1f81a4fe6..0000000000 --- a/packages/build/test-d/options/netlify_plugin_status_util.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { NetlifyPluginUtils, OnPreBuild } from '@netlify/build' - -export const testUtilsStatus: OnPreBuild = function ({ - utils: { - status: { show }, - }, -}: { - utils: NetlifyPluginUtils -}) { - show({ summary: 'summary' }) - show({ summary: 'summary', title: 'title', text: 'text' }) -} From f8cb8e854351e35ba795c4636b6764026f168420 Mon Sep 17 00:00:00 2001 From: outslept <135520429+outslept@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:29:20 +0300 Subject: [PATCH 2/3] fix: update JSONValue import paths from lib to src vitest type checking works with source files directly and tsd works with compiled output --- packages/build/test-d/config/inputs.test-d.ts | 2 +- packages/build/test-d/config/netlify_config.test-d.ts | 2 +- packages/build/test-d/netlify_plugin_options.test-d.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/build/test-d/config/inputs.test-d.ts b/packages/build/test-d/config/inputs.test-d.ts index 065ef7ae5c..90d8e6edba 100644 --- a/packages/build/test-d/config/inputs.test-d.ts +++ b/packages/build/test-d/config/inputs.test-d.ts @@ -1,6 +1,6 @@ import type { OnPreBuild } from '@netlify/build' import { expectTypeOf, test } from 'vitest' -import type { JSONValue } from '../../lib/types/utils/json_value.js' +import type { JSONValue } from '../../src/types/utils/json_value.js' test('generic inputs types', () => { type GenericInputs = Parameters[0]['inputs'] diff --git a/packages/build/test-d/config/netlify_config.test-d.ts b/packages/build/test-d/config/netlify_config.test-d.ts index 77a2294d84..9da0dec04f 100644 --- a/packages/build/test-d/config/netlify_config.test-d.ts +++ b/packages/build/test-d/config/netlify_config.test-d.ts @@ -1,6 +1,6 @@ import type { NetlifyConfig } from '@netlify/build' import { expectTypeOf, test } from 'vitest' -import type { JSONValue } from '../../lib/types/utils/json_value.js' +import type { JSONValue } from '../../src/types/utils/json_value.js' test('netlify config plugins types', () => { type Plugin = NetlifyConfig['plugins'][number] diff --git a/packages/build/test-d/netlify_plugin_options.test-d.ts b/packages/build/test-d/netlify_plugin_options.test-d.ts index 349af6833e..d04c73862b 100644 --- a/packages/build/test-d/netlify_plugin_options.test-d.ts +++ b/packages/build/test-d/netlify_plugin_options.test-d.ts @@ -1,6 +1,6 @@ import type { NetlifyPluginConstants, NetlifyPluginOptions } from '@netlify/build' import { expectTypeOf, test } from 'vitest' -import type { JSONValue } from '../lib/types/utils/json_value.js' +import type { JSONValue } from '../src/types/utils/json_value.js' test('constants types', () => { expectTypeOf().toEqualTypeOf() From f9db2a50c7b0062786207501bf89c03cead0a438 Mon Sep 17 00:00:00 2001 From: outslept <135520429+outslept@users.noreply.github.com> Date: Fri, 8 Aug 2025 10:18:03 +0300 Subject: [PATCH 3/3] fix: refactor type tests to address suggestions --- packages/build/test-d/config/build.test-d.ts | 48 +++++---- .../build/test-d/config/functions.test-d.ts | 35 ++++--- packages/build/test-d/config/inputs.test-d.ts | 33 ++++--- .../test-d/config/netlify_config.test-d.ts | 89 ++++++++++------- .../build/test-d/netlify_plugin.test-d.ts | 33 +++++-- .../test-d/netlify_plugin_options.test-d.ts | 38 ++++--- .../netlify_plugin_build_util.test-d.ts | 43 ++++---- .../netlify_plugin_cache_util.test-d.ts | 98 +++++++++++-------- .../netlify_plugin_functions_util.test-d.ts | 32 +++--- .../options/netlify_plugin_git_util.test-d.ts | 49 ++++++---- .../options/netlify_plugin_run_util.test-d.ts | 30 +++--- .../netlify_plugin_status_util.test-d.ts | 15 +-- 12 files changed, 317 insertions(+), 226 deletions(-) diff --git a/packages/build/test-d/config/build.test-d.ts b/packages/build/test-d/config/build.test-d.ts index 0f37a51910..427f9f11ff 100644 --- a/packages/build/test-d/config/build.test-d.ts +++ b/packages/build/test-d/config/build.test-d.ts @@ -1,24 +1,32 @@ -import type { NetlifyConfig } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('netlify config build types', () => { - type Build = NetlifyConfig['build'] - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.build types', () => { + const handler: OnPreBuild = ({ netlifyConfig: { build } }) => { + expectTypeOf(build.command).toEqualTypeOf() + expectTypeOf(build.publish).toEqualTypeOf() + expectTypeOf(build.base).toEqualTypeOf() + expectTypeOf(build.services.testVar).toEqualTypeOf() + expectTypeOf(build.ignore).toEqualTypeOf() + expectTypeOf(build.edge_handlers).toEqualTypeOf() + expectTypeOf(build.environment.TEST_VAR).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('netlify config build processing types', () => { - type Processing = NetlifyConfig['build']['processing'] - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.build.processing types', () => { + const handler: OnPreBuild = ({ + netlifyConfig: { + build: { processing }, + }, + }) => { + expectTypeOf(processing.skip_processing).toEqualTypeOf() + expectTypeOf(processing.css.bundle).toEqualTypeOf() + expectTypeOf(processing.css.minify).toEqualTypeOf() + expectTypeOf(processing.js.bundle).toEqualTypeOf() + expectTypeOf(processing.js.minify).toEqualTypeOf() + expectTypeOf(processing.html.pretty_url).toEqualTypeOf() + expectTypeOf(processing.images.compress).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/config/functions.test-d.ts b/packages/build/test-d/config/functions.test-d.ts index a6de0b212a..bdde7ae906 100644 --- a/packages/build/test-d/config/functions.test-d.ts +++ b/packages/build/test-d/config/functions.test-d.ts @@ -1,19 +1,22 @@ -import type { NetlifyConfig } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('netlify config functions types', () => { - type Functions = NetlifyConfig['functions']['*'] +test('netlifyConfig.functions types', () => { + const handler: OnPreBuild = ({ + netlifyConfig: { + functions: { '*': functions }, + }, + }) => { + expectTypeOf(functions.node_bundler).toExtend() + expectTypeOf(functions.included_files).toEqualTypeOf() - expectTypeOf().toExtend() - expectTypeOf().toEqualTypeOf() - - // available when node_bundler is 'esbuild' - type EsbuildFunctions = Functions & { node_bundler: 'esbuild' } - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - - // NOT available when node_bundler is not 'esbuild' - type NonEsbuildFunctions = Functions & { node_bundler: 'webpack' } - expectTypeOf().toBeNever() - expectTypeOf().toBeNever() + if (functions.node_bundler === 'esbuild') { + expectTypeOf(functions.external_node_modules).toEqualTypeOf() + expectTypeOf(functions.ignored_node_modules).toEqualTypeOf() + } else { + expectTypeOf(functions).not.toHaveProperty('external_node_modules') + expectTypeOf(functions).not.toHaveProperty('ignored_node_modules') + } + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/config/inputs.test-d.ts b/packages/build/test-d/config/inputs.test-d.ts index 90d8e6edba..831f4a1f9b 100644 --- a/packages/build/test-d/config/inputs.test-d.ts +++ b/packages/build/test-d/config/inputs.test-d.ts @@ -1,28 +1,31 @@ import type { OnPreBuild } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import { test, expectTypeOf } from 'vitest' import type { JSONValue } from '../../src/types/utils/json_value.js' -test('generic inputs types', () => { - type GenericInputs = Parameters[0]['inputs'] - expectTypeOf().toExtend() +test('inputs generic types', () => { + const handler: OnPreBuild = (ctx) => { + expectTypeOf(ctx.inputs.testVar).toExtend() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('specific inputs types', () => { - type SpecificInputs = Parameters>[0]['inputs'] - expectTypeOf().toEqualTypeOf() - - // @ts-expect-error - non-existent property - expectTypeOf().toBeNever() +test('inputs specific types', () => { + const handler: OnPreBuild<{ testVar: boolean }> = (ctx) => { + expectTypeOf(ctx.inputs.testVar).toEqualTypeOf() + expectTypeOf(ctx.inputs).not.toHaveProperty('otherTestVar') + } + expectTypeOf(handler).toEqualTypeOf>() }) -test('specific inputs interface types', () => { +test('inputs interface types', () => { interface InputsInterface { testVar: string } - type InterfaceInputs = Parameters>[0]['inputs'] - expectTypeOf().toEqualTypeOf() + const handler: OnPreBuild = (ctx) => { + expectTypeOf(ctx.inputs.testVar).toEqualTypeOf() + expectTypeOf(ctx.inputs).not.toHaveProperty('otherTestVar') + } - // @ts-expect-error - non-existent property - expectTypeOf().toBeNever() + expectTypeOf(handler).toEqualTypeOf>() }) diff --git a/packages/build/test-d/config/netlify_config.test-d.ts b/packages/build/test-d/config/netlify_config.test-d.ts index 9da0dec04f..fbff8ce746 100644 --- a/packages/build/test-d/config/netlify_config.test-d.ts +++ b/packages/build/test-d/config/netlify_config.test-d.ts @@ -1,42 +1,65 @@ -import type { NetlifyConfig } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' import type { JSONValue } from '../../src/types/utils/json_value.js' -test('netlify config plugins types', () => { - type Plugin = NetlifyConfig['plugins'][number] - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.plugins types', () => { + const handler: OnPreBuild = (ctx) => { + const [plugin] = ctx.netlifyConfig.plugins + + expectTypeOf(plugin.package).toEqualTypeOf() + expectTypeOf(plugin.inputs.testVar).toEqualTypeOf() + } + + expectTypeOf(handler).toEqualTypeOf() }) -test('netlify config edge functions types', () => { - type EdgeFunction = NetlifyConfig['edge_functions'][number] - expectTypeOf().toExtend() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.edge_functions types', () => { + const handler: OnPreBuild = (ctx) => { + const [edgeFunction] = ctx.netlifyConfig.edge_functions + + expectTypeOf(edgeFunction.path).toExtend() + expectTypeOf(edgeFunction.function).toEqualTypeOf() + } + + expectTypeOf(handler).toEqualTypeOf() }) -test('netlify config headers types', () => { - type Header = NetlifyConfig['headers'][number] - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.headers types', () => { + const handler: OnPreBuild = (ctx) => { + const [header] = ctx.netlifyConfig.headers + + expectTypeOf(header.for).toEqualTypeOf() + expectTypeOf(header.values.testVar).toEqualTypeOf() + } + + expectTypeOf(handler).toEqualTypeOf() }) -test('netlify config redirects types', () => { - type Redirect = NetlifyConfig['redirects'][number] - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - - type QueryTestVar = NonNullable['testVar'] - expectTypeOf().toEqualTypeOf() - - type HeadersTestVar = NonNullable['testVar'] - expectTypeOf().toEqualTypeOf() - - type Conditions = NonNullable - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() +test('netlifyConfig.redirects types', () => { + const handler: OnPreBuild = (ctx) => { + const [redirect] = ctx.netlifyConfig.redirects + + expectTypeOf(redirect.from).toEqualTypeOf() + expectTypeOf(redirect.to).toEqualTypeOf() + expectTypeOf(redirect.status).toEqualTypeOf() + expectTypeOf(redirect.force).toEqualTypeOf() + expectTypeOf(redirect.signed).toEqualTypeOf() + + if (redirect.query !== undefined) { + expectTypeOf(redirect.query.testVar).toEqualTypeOf() + } + + if (redirect.headers !== undefined) { + expectTypeOf(redirect.headers.testVar).toEqualTypeOf() + } + + if (redirect.conditions !== undefined) { + expectTypeOf(redirect.conditions.Language).toEqualTypeOf() + expectTypeOf(redirect.conditions.Cookie).toEqualTypeOf() + expectTypeOf(redirect.conditions.Country).toEqualTypeOf() + expectTypeOf(redirect.conditions.Role).toEqualTypeOf() + } + } + + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/netlify_plugin.test-d.ts b/packages/build/test-d/netlify_plugin.test-d.ts index 4a435797cd..db3b2b5742 100644 --- a/packages/build/test-d/netlify_plugin.test-d.ts +++ b/packages/build/test-d/netlify_plugin.test-d.ts @@ -1,24 +1,37 @@ import type { NetlifyPlugin, OnPreBuild, OnBuild, OnPostBuild, OnError, OnSuccess, OnEnd } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import { test, expectTypeOf } from 'vitest' -test('event types', () => { - const noop = function () {} +test('events noop types', () => { + const noop = () => {} - expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() expectTypeOf(noop).toExtend() + + const plugin: NetlifyPlugin = { + onPreBuild: noop, + onBuild: noop, + onPostBuild: noop, + onError: noop, + onSuccess: noop, + onEnd: noop, + } + expectTypeOf(plugin).toEqualTypeOf() }) -test('onError event types', () => { - type ErrorParams = Parameters[0] - expectTypeOf().toEqualTypeOf() +test('onError argument types', () => { + const handler: OnError = ({ error }) => { + expectTypeOf(error).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('onEnd event types', () => { - type EndParams = Parameters[0] - expectTypeOf().toEqualTypeOf() +test('onEnd argument types', () => { + const handler: OnEnd = ({ error }) => { + expectTypeOf(error).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/netlify_plugin_options.test-d.ts b/packages/build/test-d/netlify_plugin_options.test-d.ts index d04c73862b..08e3aee11e 100644 --- a/packages/build/test-d/netlify_plugin_options.test-d.ts +++ b/packages/build/test-d/netlify_plugin_options.test-d.ts @@ -1,21 +1,29 @@ -import type { NetlifyPluginConstants, NetlifyPluginOptions } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { NetlifyPluginConstants, NetlifyPluginOptions, OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' import type { JSONValue } from '../src/types/utils/json_value.js' test('constants types', () => { - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() + const handler: OnPreBuild = ({ constants }) => { + expectTypeOf(constants).toEqualTypeOf() + expectTypeOf(constants.CONFIG_PATH).toEqualTypeOf() + expectTypeOf(constants.PUBLISH_DIR).toEqualTypeOf() + expectTypeOf(constants.FUNCTIONS_SRC).toEqualTypeOf() + expectTypeOf(constants.INTERNAL_EDGE_FUNCTIONS_SRC).toEqualTypeOf() + expectTypeOf(constants.INTERNAL_FUNCTIONS_SRC).toEqualTypeOf() + expectTypeOf(constants.FUNCTIONS_DIST).toEqualTypeOf() + expectTypeOf(constants.EDGE_FUNCTIONS_SRC).toEqualTypeOf() + expectTypeOf(constants.EDGE_FUNCTIONS_DIST).toEqualTypeOf() + expectTypeOf(constants.IS_LOCAL).toEqualTypeOf() + expectTypeOf(constants.NETLIFY_BUILD_VERSION).toEqualTypeOf() + expectTypeOf(constants.SITE_ID).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('package json types', () => { - expectTypeOf().toEqualTypeOf() +test('package.json types', () => { + const handler: OnPreBuild = ({ packageJson }) => { + expectTypeOf(packageJson).toEqualTypeOf() + expectTypeOf(packageJson.version).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts index d01d6e7463..3ede8390e2 100644 --- a/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_build_util.test-d.ts @@ -1,26 +1,29 @@ -import type { NetlifyPluginUtils } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils build failBuild types', () => { - type BuildFailBuild = NetlifyPluginUtils['build']['failBuild'] - - expectTypeOf().toBeCallableWith('message') - expectTypeOf().toBeCallableWith('message', {}) - expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +test('utils.build.failBuild types', () => { + const handler: OnPreBuild = ({ utils }) => { + utils.build.failBuild('message') + utils.build.failBuild('message', {}) + utils.build.failBuild('message', { error: new Error('message') }) + } + expectTypeOf(handler).toEqualTypeOf() }) -test('utils build failPlugin types', () => { - type BuildFailPlugin = NetlifyPluginUtils['build']['failPlugin'] - - expectTypeOf().toBeCallableWith('message') - expectTypeOf().toBeCallableWith('message', {}) - expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +test('utils.build.failPlugin types', () => { + const handler: OnPreBuild = ({ utils }) => { + utils.build.failPlugin('message') + utils.build.failPlugin('message', {}) + utils.build.failPlugin('message', { error: new Error('message') }) + } + expectTypeOf(handler).toEqualTypeOf() }) -test('utils build cancelBuild types', () => { - type BuildCancelBuild = NetlifyPluginUtils['build']['cancelBuild'] - - expectTypeOf().toBeCallableWith('message') - expectTypeOf().toBeCallableWith('message', {}) - expectTypeOf().toBeCallableWith('message', { error: new Error('message') }) +test('utils.build.cancelBuild types', () => { + const handler: OnPreBuild = ({ utils }) => { + utils.build.cancelBuild('message') + utils.build.cancelBuild('message', {}) + utils.build.cancelBuild('message', { error: new Error('message') }) + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts index 3d71374712..9f2358703e 100644 --- a/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_cache_util.test-d.ts @@ -1,51 +1,67 @@ -import type { NetlifyPluginUtils } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild, NetlifyPluginUtils } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils cache save types', () => { - type CacheSave = NetlifyPluginUtils['cache']['save'] - - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith('file') - expectTypeOf().toBeCallableWith(['file']) - expectTypeOf().toBeCallableWith('file', {}) - expectTypeOf().toBeCallableWith('file', { ttl: 1, digests: ['digest'], cwd: '.' }) +test('utils.cache.save types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.cache.save('file') + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { + ttl: 1, + digests: ['digest'], + cwd: '.', + }) + expectTypeOf(handler).toEqualTypeOf() }) -test('utils cache list types', () => { - type CacheList = NetlifyPluginUtils['cache']['list'] - - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith({}) - expectTypeOf().toBeCallableWith() - expectTypeOf().toBeCallableWith({ depth: 1, cwd: '.' }) +test('utils.cache.list types', () => { + const handler: OnPreBuild = ({ utils }) => { + const r1 = utils.cache.list() + const r2 = utils.cache.list({}) + expectTypeOf(r1).toEqualTypeOf>() + expectTypeOf(r2).toEqualTypeOf>() + } + expectTypeOf().toBeCallableWith() + expectTypeOf().toBeCallableWith({}) + expectTypeOf().toBeCallableWith({ depth: 1, cwd: '.' }) + expectTypeOf(handler).toEqualTypeOf() }) -test('utils cache restore types', () => { - type CacheRestore = NetlifyPluginUtils['cache']['restore'] - - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith('file') - expectTypeOf().toBeCallableWith(['file']) - expectTypeOf().toBeCallableWith('file', {}) - expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +test('utils.cache.restore types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.cache.restore('file') + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) + expectTypeOf(handler).toEqualTypeOf() }) -test('utils cache remove types', () => { - type CacheRemove = NetlifyPluginUtils['cache']['remove'] - - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith('file') - expectTypeOf().toBeCallableWith(['file']) - expectTypeOf().toBeCallableWith('file', {}) - expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +test('utils.cache.remove types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.cache.remove('file') + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) + expectTypeOf(handler).toEqualTypeOf() }) -test('utils cache has types', () => { - type CacheHas = NetlifyPluginUtils['cache']['has'] - - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith('file') - expectTypeOf().toBeCallableWith(['file']) - expectTypeOf().toBeCallableWith('file', {}) - expectTypeOf().toBeCallableWith('file', { cwd: '.' }) +test('utils.cache.has types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.cache.has('file') + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf().toBeCallableWith('file') + expectTypeOf().toBeCallableWith(['file']) + expectTypeOf().toBeCallableWith('file', {}) + expectTypeOf().toBeCallableWith('file', { cwd: '.' }) + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts index 4ba98f36c8..111576d008 100644 --- a/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_functions_util.test-d.ts @@ -1,18 +1,26 @@ -import type { NetlifyPluginUtils, ListedFunction, ListedFunctionFile } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild, ListedFunction, ListedFunctionFile } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils functions list types', () => { - type FunctionsList = NetlifyPluginUtils['functions']['list'] - expectTypeOf>().toEqualTypeOf>() +test('utils.functions.list types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.functions.list() + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('utils functions listAll types', () => { - type FunctionsListAll = NetlifyPluginUtils['functions']['listAll'] - expectTypeOf>().toEqualTypeOf>() +test('utils.functions.listAll types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.functions.listAll() + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('utils functions add types', () => { - type FunctionsAdd = NetlifyPluginUtils['functions']['add'] - expectTypeOf>().toEqualTypeOf>() - expectTypeOf().toBeCallableWith('functionName') +test('utils.functions.add types', () => { + const handler: OnPreBuild = ({ utils }) => { + const ret = utils.functions.add('functionName') + expectTypeOf(ret).toEqualTypeOf>() + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts index 38186bceaa..7b12b5ba88 100644 --- a/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_git_util.test-d.ts @@ -1,27 +1,34 @@ -import type { NetlifyPluginUtils } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils git types', () => { - type Git = NetlifyPluginUtils['git'] +test('utils.git types', () => { + const handler: OnPreBuild = ({ utils }) => { + const matched = utils.git.fileMatch('*') + expectTypeOf(matched).toEqualTypeOf() - expectTypeOf>().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf>().toEqualTypeOf>() + expectTypeOf(utils.git.modifiedFiles).toEqualTypeOf() + expectTypeOf(utils.git.createdFiles).toEqualTypeOf() + expectTypeOf(utils.git.deletedFiles).toEqualTypeOf() + + const loc = utils.git.linesOfCode() + expectTypeOf(loc).toEqualTypeOf>() + } + expectTypeOf(handler).toEqualTypeOf() }) -test('utils git commits types', () => { - type Git = NetlifyPluginUtils['git'] - type Commit = Git['commits'][number] +test('utils.git commits types', () => { + const handler: OnPreBuild = ({ utils }) => { + const [commit] = utils.git.commits - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() - expectTypeOf().toEqualTypeOf() + expectTypeOf(commit.sha).toEqualTypeOf() + expectTypeOf(commit.parents).toEqualTypeOf() + expectTypeOf(commit.author.name).toEqualTypeOf() + expectTypeOf(commit.author.email).toEqualTypeOf() + expectTypeOf(commit.author.date).toEqualTypeOf() + expectTypeOf(commit.committer.name).toEqualTypeOf() + expectTypeOf(commit.committer.email).toEqualTypeOf() + expectTypeOf(commit.committer.date).toEqualTypeOf() + expectTypeOf(commit.message).toEqualTypeOf() + } + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts index ab9bd37de0..91c4aa97bf 100644 --- a/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_run_util.test-d.ts @@ -1,23 +1,21 @@ -import type { NetlifyPluginUtils } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils run types', () => { - type RunFunction = NetlifyPluginUtils['run'] +test('utils.run types', () => { + const handler: OnPreBuild = async ({ utils }) => { + expectTypeOf(utils.run('command')).toExtend>() - type RunResult = ReturnType - expectTypeOf().toExtend>() + const r0 = await utils.run('command') + expectTypeOf(r0).toBeObject() - expectTypeOf().toBeCallableWith('command') - expectTypeOf().toBeCallableWith('command', ['arg']) - expectTypeOf().toBeCallableWith('command', ['arg'], { preferLocal: false }) + await utils.run('command', ['arg']) + await utils.run('command', ['arg'], { preferLocal: false }) - type RunCommand = NetlifyPluginUtils['run']['command'] - expectTypeOf().toBeCallableWith('command') -}) + // @ts-expect-error - TypeScript has no negative-call assertion; this error is the test + await utils.run('command', ['arg'], { unknownOption: false }) -test('utils run invalid options', () => { - type RunFunction = NetlifyPluginUtils['run'] + await utils.run.command('command') + } - // @ts-expect-error - testing invalid - expectTypeOf().toBeCallableWith('command', ['arg'], { unknownOption: false }) + expectTypeOf(handler).toEqualTypeOf() }) diff --git a/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts b/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts index 61a9dc9ee0..71982b767d 100644 --- a/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts +++ b/packages/build/test-d/options/netlify_plugin_status_util.test-d.ts @@ -1,9 +1,10 @@ -import type { NetlifyPluginUtils } from '@netlify/build' -import { expectTypeOf, test } from 'vitest' +import type { OnPreBuild } from '@netlify/build' +import { test, expectTypeOf } from 'vitest' -test('utils status types', () => { - type StatusShow = NetlifyPluginUtils['status']['show'] - - expectTypeOf().toBeCallableWith({ summary: 'summary' }) - expectTypeOf().toBeCallableWith({ summary: 'summary', title: 'title', text: 'text' }) +test('utils.status.show types', () => { + const handler: OnPreBuild = ({ utils }) => { + utils.status.show({ summary: 'summary' }) + utils.status.show({ summary: 'summary', title: 'title', text: 'text' }) + } + expectTypeOf(handler).toEqualTypeOf() })