From 77964ba512c1160636b8e37c93fca552b4a36039 Mon Sep 17 00:00:00 2001 From: pragya91 Date: Wed, 5 Mar 2025 15:02:51 -0800 Subject: [PATCH] Unused deps with knip --- build-tools/packages/build-cli/knip.config.js | 23 ++++ build-tools/packages/build-cli/package.json | 2 + fluidBuild.config.cjs | 9 +- knip.base.js | 31 +++++ package.json | 10 +- pnpm-lock.yaml | 129 ++++++++++++++++++ 6 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 build-tools/packages/build-cli/knip.config.js create mode 100644 knip.base.js diff --git a/build-tools/packages/build-cli/knip.config.js b/build-tools/packages/build-cli/knip.config.js new file mode 100644 index 000000000000..c391438c5daa --- /dev/null +++ b/build-tools/packages/build-cli/knip.config.js @@ -0,0 +1,23 @@ +/*! + * Copyright (c) Microsoft Corporation and contributors. All rights reserved. + * Licensed under the MIT License. + */ + +// Import the shared config from the root of the repo. +const sharedConfig = require("../../../knip.base.js"); + +module.exports = { + include: [...sharedConfig.include], + ignoreDependencies: [ + ...sharedConfig.ignoreDependencies, + + // Oclif plugins are used dynamically at runtime. + "@oclif/plugin-*", + // Danger is used at runtime in the dangerfile. + "danger", + // Types from this package are used in markdown.ts. + "mdast", + // This is needed by the fluid-build task integration in policy-check. + "tslib", + ], +}; diff --git a/build-tools/packages/build-cli/package.json b/build-tools/packages/build-cli/package.json index 05da08f2897c..5ce1e6e767f2 100644 --- a/build-tools/packages/build-cli/package.json +++ b/build-tools/packages/build-cli/package.json @@ -43,6 +43,7 @@ "build:test:esm": "tsc --project ./src/test/tsconfig.json", "check:biome": "biome check .", "check:format": "npm run check:biome", + "check:knip": "knip", "ci:build:docs": "api-extractor run", "clean": "rimraf --glob dist lib oclif.manifest.json \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc", "clean:manifest": "rimraf --glob oclif.manifest.json", @@ -173,6 +174,7 @@ "eslint-config-oclif-typescript": "^3.1.12", "eslint-config-prettier": "~9.1.0", "jssm-viz-cli": "^5.101.0", + "knip": "^5.45.0", "mocha": "^10.7.3", "mocha-multi-reporters": "^1.5.1", "mocked-env": "^1.3.5", diff --git a/fluidBuild.config.cjs b/fluidBuild.config.cjs index a9f5d1bc4d53..d69b4461cbea 100644 --- a/fluidBuild.config.cjs +++ b/fluidBuild.config.cjs @@ -61,7 +61,7 @@ module.exports = { script: false, }, "checks": { - dependsOn: ["check:format"], + dependsOn: ["check:format", "check:knip"], script: false, }, "checks:fix": { @@ -129,6 +129,7 @@ module.exports = { }, "check:biome": [], "check:prettier": [], + "check:knip": [], // ADO #7297: Review why the direct dependency on 'build:esm:test' is necessary. // Should 'compile' be enough? compile -> build:test -> build:test:esm "eslint": ["compile", "build:test:esm"], @@ -160,6 +161,11 @@ module.exports = { multiCommandExecutables: ["oclif", "syncpack"], declarativeTasks: { + "knip": { + inputGlobs: ["*.*", "src/**"], + outputGlobs: ["*.*", "src/**"], + gitignore: ["input", "output"], + }, // fluid-build lowercases the executable name, so we need to use buildversion instead of buildVersion. "flub check buildversion": { inputGlobs: [ @@ -533,6 +539,7 @@ module.exports = { ["flub", "@fluid-tools/build-cli"], ["fluid-build", "@fluidframework/build-tools"], ["gf", "good-fences"], + ["knip", "knip"], ["mocha", "mocha"], ["nyc", "nyc"], ["oclif", "oclif"], diff --git a/knip.base.js b/knip.base.js new file mode 100644 index 000000000000..ac5f1288d627 --- /dev/null +++ b/knip.base.js @@ -0,0 +1,31 @@ +/*! + * Copyright (c) Microsoft Corporation and contributors. All rights reserved. + * Licensed under the MIT License. + */ + +// Enable TypeScript type-checking for this file. +// See https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check +// @ts-check + +const config = { + include: ["dependencies"], + ignoreDependencies: [ + // The following deps are actually in use, but depcheck reports them unused. + + // These packages are used in the CI pipelines. + "mocha-multi-reporters", + "moment", + + // The following deps are reported as missing, but they are available. + + // We use a 'hack' to make plugins from the shared eslint config available to our packages, those these deps are not + // directly needed in the package. + "@typescript-eslint/eslint-plugin", + "eslint-config-prettier", + "eslint-import-resolver-typescript", + "eslint-plugin-tsdoc", + "eslint-plugin-unicorn", + ], +}; + +module.exports = config; \ No newline at end of file diff --git a/package.json b/package.json index 797e59cfce8e..21324290ab05 100644 --- a/package.json +++ b/package.json @@ -176,6 +176,7 @@ "danger": "^11.3.0", "eslint": "~8.55.0", "jest": "^29.6.2", + "knip": "^5.45.0", "mocha": "^10.8.2", "prettier": "~3.0.3", "pretty-quick": "^4.0.0", @@ -259,6 +260,12 @@ ], "script": false }, + "check:knip": { + "dependsOn": [ + "^check:knip" + ], + "script": false + }, "checks": { "dependsOn": [ "check:format", @@ -267,7 +274,8 @@ "layer-check", "syncpack:deps", "syncpack:versions", - "check:versions" + "check:versions", + "check:knip" ], "script": false }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00a047059718..8820f794e7f9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,6 +86,9 @@ importers: jest: specifier: ^29.6.2 version: 29.7.0(@types/node@22.10.1)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@22.10.1)(typescript@5.4.5)) + knip: + specifier: ^5.45.0 + version: 5.45.0(@types/node@22.10.1)(typescript@5.4.5) mocha: specifier: ^10.8.2 version: 10.8.2 @@ -18916,14 +18919,26 @@ packages: resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} + '@nodelib/fs.scandir@4.0.1': + resolution: {integrity: sha512-vAkI715yhnmiPupY+dq+xenu5Tdf2TBQ66jLvBIcCddtz+5Q8LbMKaf9CIJJreez8fQ8fgaY+RaywQx8RJIWpw==} + engines: {node: '>=18.18.0'} + '@nodelib/fs.stat@2.0.5': resolution: {integrity: sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==} engines: {node: '>= 8'} + '@nodelib/fs.stat@4.0.0': + resolution: {integrity: sha512-ctr6bByzksKRCV0bavi8WoQevU6plSp2IkllIsEqaiKe2mwNNnaluhnRhcsgGZHrrHk57B3lf95MkLMO3STYcg==} + engines: {node: '>=18.18.0'} + '@nodelib/fs.walk@1.2.8': resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} + '@nodelib/fs.walk@3.0.1': + resolution: {integrity: sha512-nIh/M6Kh3ZtOmlY00DaUYB4xeeV6F3/ts1l29iwl3/cfyY/OuCfUx+v08zgx8TKPTifXRcjjqVQ4KB2zOYSbyw==} + engines: {node: '>=18.18.0'} + '@nolyfill/is-core-module@1.0.39': resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==} engines: {node: '>=12.4.0'} @@ -19402,6 +19417,11 @@ packages: '@sinonjs/text-encoding@0.7.3': resolution: {integrity: sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==} + '@snyk/github-codeowners@1.1.0': + resolution: {integrity: sha512-lGFf08pbkEac0NYgVf4hdANpAgApRjNByLXB+WBip3qj1iendOIyAwP2GKkKbQMNVy2r1xxDf0ssfWscoiC+Vw==} + engines: {node: '>=8.10'} + hasBin: true + '@socket.io/component-emitter@3.1.2': resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==} @@ -21898,6 +21918,10 @@ packages: resolution: {integrity: sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==} engines: {node: '>=10.13.0'} + enhanced-resolve@5.18.1: + resolution: {integrity: sha512-ZSW3ma5GkcQBIpwZTSRAI8N71Uuwgs93IezB7mf7R60tC8ZbJideoDNKjHn2O9KIlx6rkGTTEk1xUCK2E1Y2Yg==} + engines: {node: '>=10.13.0'} + enquirer@2.3.6: resolution: {integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==} engines: {node: '>=8.6'} @@ -22344,6 +22368,10 @@ packages: resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} engines: {node: '>=8.6.0'} + fast-glob@3.3.3: + resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==} + engines: {node: '>=8.6.0'} + fast-json-patch@3.1.1: resolution: {integrity: sha512-vf6IHUX2SBcA+5/+4883dsIjpBTqmfBjmYiWK1savxQmFk4JfBMLa7ynTYOs1Rolp/T1betJxHiGD3g1Mn8lUQ==} @@ -23762,6 +23790,10 @@ packages: resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==} hasBin: true + jiti@2.4.2: + resolution: {integrity: sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==} + hasBin: true + jju@1.4.0: resolution: {integrity: sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==} @@ -23966,6 +23998,14 @@ packages: resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} engines: {node: '>=6'} + knip@5.45.0: + resolution: {integrity: sha512-OUyO9FUEVCM6/j0gl+PP/LDeJEs4hIdE8n4vK4xrtjN1g3Qu4Ws1oexbWTCJ+8xt8Tgse4Yvhx96OqF/UVl3Ug==} + engines: {node: '>=18.18.0'} + hasBin: true + peerDependencies: + '@types/node': '>=18' + typescript: '>=5.0.4' + kuler@2.0.0: resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==} @@ -25273,6 +25313,10 @@ packages: parse-link-header@2.0.0: resolution: {integrity: sha512-xjU87V0VyHZybn2RrCX5TIFGxTVZE6zqqZWMPlIKiSKuWh/X5WZdt+w1Ki1nXB+8L/KtL+nZ4iq+sfI6MrhhMw==} + parse-ms@4.0.0: + resolution: {integrity: sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==} + engines: {node: '>=18'} + parse-passwd@1.0.0: resolution: {integrity: sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==} engines: {node: '>=0.10.0'} @@ -25595,6 +25639,10 @@ packages: resolution: {integrity: sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} + pretty-ms@9.2.0: + resolution: {integrity: sha512-4yf0QO/sllf/1zbZWYnvWw3NxCQwLXKzIj0G849LSufP15BXKM0rbD2Z3wVnkMfjdn/CB0Dpp444gYAACdsplg==} + engines: {node: '>=18'} + pretty-quick@4.0.0: resolution: {integrity: sha512-M+2MmeufXb/M7Xw3Afh1gxcYpj+sK0AxEfnfF958ktFeAyi5MsKY5brymVURQLgPLV1QaF5P4pb2oFJ54H3yzQ==} engines: {node: '>=14'} @@ -26556,6 +26604,10 @@ packages: resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==} engines: {node: '>= 6.0.0', npm: '>= 3.0.0'} + smol-toml@1.3.1: + resolution: {integrity: sha512-tEYNll18pPKHroYSmLLrksq233j021G0giwW7P3D24jC54pQ5W5BXMsQ/Mvw1OJCmEYDgY+lrzT+3nNUtoNfXQ==} + engines: {node: '>= 18'} + snake-case@2.1.0: resolution: {integrity: sha512-FMR5YoPFwOLuh4rRz92dywJjyKYZNLpMn1R5ujVpIYkbA9p01fq8RMg0FkO4M+Yobt4MjHeLTJVm5xFFBHSV2Q==} @@ -26891,6 +26943,9 @@ packages: engines: {node: '>=16 || 14 >=14.17'} hasBin: true + summary@2.1.0: + resolution: {integrity: sha512-nMIjMrd5Z2nuB2RZCKJfFMjgS3fygbeyGk9PxPPaJR1RIcyN9yn4A63Isovzm3ZtQuEkLBVgMdPup8UeLH7aQw==} + superagent@3.8.3: resolution: {integrity: sha512-GLQtLMCoEIK4eDv6OGtkOoSMt3D+oq0y3dsxMuYuDvaNUvuT8eFBuLmfR0iYYzHC1e8hpzC6ZsxbuP6DIalMFA==} engines: {node: '>= 4.0'} @@ -28103,6 +28158,12 @@ packages: engines: {node: '>=8.0.0'} hasBin: true + zod-validation-error@3.4.0: + resolution: {integrity: sha512-ZOPR9SVY6Pb2qqO5XHt+MkkTRxGXb4EVtnjc9JpXUOtUB1T9Ru7mZOT361AN3MsetVe7R0a1KZshJDZdgp9miQ==} + engines: {node: '>=18.0.0'} + peerDependencies: + zod: ^3.18.0 + zod@3.21.4: resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} @@ -33042,13 +33103,25 @@ snapshots: '@nodelib/fs.stat': 2.0.5 run-parallel: 1.2.0 + '@nodelib/fs.scandir@4.0.1': + dependencies: + '@nodelib/fs.stat': 4.0.0 + run-parallel: 1.2.0 + '@nodelib/fs.stat@2.0.5': {} + '@nodelib/fs.stat@4.0.0': {} + '@nodelib/fs.walk@1.2.8': dependencies: '@nodelib/fs.scandir': 2.1.5 fastq: 1.17.1 + '@nodelib/fs.walk@3.0.1': + dependencies: + '@nodelib/fs.scandir': 4.0.1 + fastq: 1.17.1 + '@nolyfill/is-core-module@1.0.39': {} '@npmcli/fs@2.1.2': @@ -33894,6 +33967,12 @@ snapshots: '@sinonjs/text-encoding@0.7.3': {} + '@snyk/github-codeowners@1.1.0': + dependencies: + commander: 4.1.1 + ignore: 5.3.2 + p-map: 4.0.0 + '@socket.io/component-emitter@3.1.2': {} '@socket.io/redis-adapter@8.3.0(socket.io-adapter@2.5.5)': @@ -36836,6 +36915,11 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 + enhanced-resolve@5.18.1: + dependencies: + graceful-fs: 4.2.11 + tapable: 2.2.1 + enquirer@2.3.6: dependencies: ansi-colors: 4.1.3 @@ -37489,6 +37573,14 @@ snapshots: merge2: 1.4.1 micromatch: 4.0.8 + fast-glob@3.3.3: + dependencies: + '@nodelib/fs.stat': 2.0.5 + '@nodelib/fs.walk': 1.2.8 + glob-parent: 5.1.2 + merge2: 1.4.1 + micromatch: 4.0.8 + fast-json-patch@3.1.1: {} fast-json-stable-stringify@2.1.0: {} @@ -39329,6 +39421,8 @@ snapshots: jiti@1.21.6: {} + jiti@2.4.2: {} + jju@1.4.0: {} joi@17.13.3: @@ -39588,6 +39682,27 @@ snapshots: kleur@4.1.5: {} + knip@5.45.0(@types/node@22.10.1)(typescript@5.4.5): + dependencies: + '@nodelib/fs.walk': 3.0.1 + '@snyk/github-codeowners': 1.1.0 + '@types/node': 22.10.1 + easy-table: 1.2.0 + enhanced-resolve: 5.18.1 + fast-glob: 3.3.3 + jiti: 2.4.2 + js-yaml: 4.1.0 + minimist: 1.2.8 + picocolors: 1.1.1 + picomatch: 4.0.2 + pretty-ms: 9.2.0 + smol-toml: 1.3.1 + strip-json-comments: 5.0.1 + summary: 2.1.0 + typescript: 5.4.5 + zod: 3.24.0 + zod-validation-error: 3.4.0(zod@3.24.0) + kuler@2.0.0: {} ky@1.7.3: {} @@ -41349,6 +41464,8 @@ snapshots: dependencies: xtend: 4.0.2 + parse-ms@4.0.0: {} + parse-passwd@1.0.0: {} parse5-htmlparser2-tree-adapter@6.0.1: @@ -41701,6 +41818,10 @@ snapshots: ansi-styles: 5.2.0 react-is: 18.3.1 + pretty-ms@9.2.0: + dependencies: + parse-ms: 4.0.0 + pretty-quick@4.0.0(prettier@3.0.3): dependencies: execa: 5.1.1 @@ -42880,6 +43001,8 @@ snapshots: smart-buffer@4.2.0: {} + smol-toml@1.3.1: {} + snake-case@2.1.0: dependencies: no-case: 2.3.2 @@ -43304,6 +43427,8 @@ snapshots: pirates: 4.0.6 ts-interface-checker: 0.1.13 + summary@2.1.0: {} + superagent@3.8.3: dependencies: component-emitter: 1.3.1 @@ -44822,6 +44947,10 @@ snapshots: optionalDependencies: commander: 9.5.0 + zod-validation-error@3.4.0(zod@3.24.0): + dependencies: + zod: 3.24.0 + zod@3.21.4: {} zod@3.23.8: {}