chore(repo): replace dep check script with new lint rule (#18060)

This commit is contained in:
Jack Hsu 2023-07-19 17:07:52 -04:00 committed by GitHub
parent b73f980756
commit 28df2057fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 643 additions and 740 deletions

View File

@ -187,7 +187,7 @@ jobs:
pnpm nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD &
pids+=($!)
pnpm nx run-many -t check-imports check-commit check-lock-files depcheck check-codeowners documentation --parallel=1 --no-dte &
pnpm nx run-many -t check-imports check-commit check-lock-files check-codeowners documentation --parallel=1 --no-dte &
pids+=($!)
pnpm nx affected --target=lint --base=$NX_BASE --head=$NX_HEAD --parallel=3 &

View File

@ -161,7 +161,6 @@ pnpm-lock.yaml @nrwl/nx-pipelines-reviewers
/CODEOWNERS @FrozenPandaz @AgentEnder
# Scripts
/scripts/depcheck @FrozenPandaz @vsavkin @jaysoo
/scripts/documentation @nrwl/nx-docs-reviewers
/scripts/angular-support-upgrades @nrwl/nx-angular-reviewers

View File

@ -15,7 +15,6 @@
"nx-release": "ts-node -P ./scripts/tsconfig.release.json ./scripts/nx-release",
"prepublishOnly": "node ./scripts/update-package-group.js",
"version": "pnpm prettier lerna.json --write",
"depcheck": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/depcheck",
"local-registry": "nx local-registry @nx/nx-source",
"documentation": "ts-node -P scripts/tsconfig.scripts.json ./scripts/documentation/generators/main.ts && pnpm check-documentation-map",
"submit-plugin": "node ./scripts/submit-plugin.js",
@ -153,7 +152,6 @@
"cytoscape-popper": "^2.0.0",
"cz-git": "^1.4.0",
"czg": "^1.4.0",
"depcheck": "^1.3.1",
"detect-port": "^1.5.1",
"dotenv": "~10.0.0",
"ejs": "^3.1.7",
@ -352,7 +350,6 @@
"check-imports",
"check-lock-files",
"check-codeowners",
"depcheck",
"documentation"
]
},

View File

@ -33,6 +33,67 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"eslint",
"rxjs",
"semver",
// These are installed by ensurePackage so missing in package.json
"@nx/cypress",
"@nx/jest",
"@nx/rollup",
"@nx/storybook",
"@nx/vite",
"@nx/webpack",
"prettier",
"typescript",
// These are installed by generators
"@angular-devkit/core",
"@angular-devkit/architect",
"@angular-devkit/build-angular",
"@angular-devkit/schematics",
"@angular/compiler",
"@angular/compiler-cli",
"@angular/core",
"@angular/router",
"@ngrx/effects",
"@ngrx/router-store",
"@ngrx/store",
"@storybook/angular",
"@module-federation/node",
// installed dynamically by the library generator
"ng-packagr",
// ng-packagr deps, some are handled if not installed
"injection-js",
"browserslist",
"cacache",
"less",
"node-sass",
"node-sass-tilde-importer",
"ora",
"convert-source-map",
"postcss",
"postcss-import",
"postcss-preset-env",
"postcss-url",
"sass",
"stylus",
"tailwindcss",
// used in the CT angular plugin where Cy is already installed to use it.
"cypress"
]
}
]
}
}
]
}

View File

@ -48,15 +48,14 @@
"@phenomnomnominal/tsquery": "~5.0.1",
"@typescript-eslint/type-utils": "^5.36.1",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"find-cache-dir": "^3.3.2",
"http-server": "^14.1.0",
"ignore": "^5.0.4",
"magic-string": "~0.26.2",
"minimatch": "3.0.5",
"semver": "7.5.3",
"tslib": "^2.3.0",
"webpack": "^5.80.0",
"webpack-merge": "5.7.3",
"webpack-merge": "^5.8.0",
"enquirer": "^2.3.6",
"@nx/cypress": "file:../cypress",
"@nx/devkit": "file:../devkit",

View File

@ -24,6 +24,18 @@
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"]
}
]
}
}
]
}

View File

@ -32,6 +32,7 @@
"create-nx-workspace": "file:../create-nx-workspace",
"chalk": "^4.1.0",
"enquirer": "~2.3.6",
"tslib": "^2.3.0",
"yargs": "^17.6.2"
},
"publishConfig": {

View File

@ -24,6 +24,18 @@
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"]
}
]
}
}
]
}

View File

@ -24,6 +24,26 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
// Type imports only
"eslint",
"rollup",
"vite"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -35,9 +35,10 @@
},
"dependencies": {
"@phenomnomnominal/tsquery": "~5.0.1",
"detect-port": "^1.5.1",
"dotenv": "~10.0.0",
"semver": "7.5.3",
"detect-port": "^1.5.1",
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/linter": "file:../linter"

View File

@ -14,6 +14,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript", "detox"]
}
]
}
}
]
}

View File

@ -29,7 +29,8 @@
"@nx/jest": "file:../jest",
"@nx/js": "file:../js",
"@nx/linter": "file:../linter",
"@nx/react": "file:../react"
"@nx/react": "file:../react",
"tslib": "^2.3.0"
},
"peerDependencies": {
"detox": "^20.9.0"

View File

@ -50,6 +50,29 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"prettier",
// Installed to workspace by plugins
"rxjs",
"@angular-devkit/core",
"@angular-devkit/architect",
"@angular-devkit/schematics",
"webpack"
]
}
]
}
}
]
}

View File

@ -20,6 +20,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript", "esbuild"]
}
]
}
}
]
}

View File

@ -22,6 +22,26 @@
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
// Installed to workspace by plugins
"@typescript-eslint/parser",
"eslint-config-prettier",
"@angular-eslint/eslint-plugin"
]
}
]
}
}
]
}

View File

@ -40,7 +40,8 @@
"chalk": "^4.1.0",
"confusing-browser-globals": "^1.0.9",
"jsonc-eslint-parser": "^2.1.0",
"semver": "7.5.3"
"semver": "7.5.3",
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"

View File

@ -14,6 +14,30 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"@nx/rollup",
"@nx/webpack",
"typescript",
"eslint",
"expo",
"react",
"@expo/cli",
"eas-cli",
"util" // This is coming from @storybook/builder-manager since it uses the browser polyfill
]
}
]
}
}
]
}

View File

@ -33,6 +33,7 @@
"metro-resolver": "0.76.7",
"node-fetch": "^2.6.7",
"tar-fs": "^2.1.1",
"tslib": "^2.3.0",
"tsconfig-paths": "^4.1.2",
"tsconfig-paths-webpack-plugin": "^4.0.0",
"@nx/detox": "file:../detox",

View File

@ -34,6 +34,25 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"@nx/linter",
"typescript",
"eslint",
"express"
]
}
]
}
}
]
}

View File

@ -31,7 +31,8 @@
},
"dependencies": {
"@nx/devkit": "file:../devkit",
"@nx/node": "file:../node"
"@nx/node": "file:../node",
"tslib": "^2.3.0"
},
"peerDependencies": {
"express": "^4.18.1"

View File

@ -24,6 +24,27 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"prettier",
"jest",
"@jest/types",
// require.resolve is used for these packages
"identity-obj-proxy"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -27,6 +27,37 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"prettier",
"typescript",
"eslint",
"verdaccio", // Optional, used for local registry
// require.resolve is used for these packages
"source-map-support",
"@babel/core",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-decorators",
"@babel/plugin-transform-runtime",
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/runtime",
"babel-plugin-const-enum",
"babel-plugin-macros",
"babel-plugin-transform-typescript-metadata"
]
}
]
}
}
]
}

View File

@ -24,6 +24,27 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"@nx/jest",
"typescript",
"eslint",
"tslint-to-eslint-config",
"@angular-devkit/core",
"@typescript-eslint/eslint-plugin"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -34,6 +34,25 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"eslint",
"nest",
"@nestjs/schematics"
]
}
]
}
}
]
}

View File

@ -36,7 +36,9 @@
"@nx/js": "file:../js",
"@nx/linter": "file:../linter",
"@nx/node": "file:../node",
"@phenomnomnominal/tsquery": "~5.0.1"
"@phenomnomnominal/tsquery": "~5.0.1",
"semver": "7.5.3",
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"

View File

@ -68,6 +68,31 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"@nx/webpack",
"@nx/cypress",
"@nx/jest",
"typescript",
"react",
"webpack",
// require.resovle is used for these
"@babel/plugin-proposal-decorators",
"url-loader",
"@svgr/webpack"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -39,12 +39,11 @@
"chalk": "^4.1.0",
"copy-webpack-plugin": "^10.2.4",
"dotenv": "~10.0.0",
"express": "^4.18.1",
"fs-extra": "^11.1.0",
"http-proxy-middleware": "^2.0.6",
"ignore": "^5.0.4",
"semver": "7.5.3",
"url-loader": "^4.1.1",
"tslib": "^2.3.0",
"webpack-merge": "^5.8.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",

View File

@ -1,34 +0,0 @@
import * as express from 'express';
import { NextServerOptions, ProxyConfig } from '../../../utils/types';
/**
* Adapted from https://github.com/zeit/next.js/blob/master/examples/with-custom-reverse-proxy/server.js
* @param settings
*/
export async function defaultServer(
settings: NextServerOptions,
proxyConfig?: ProxyConfig
): Promise<void> {
const next = require('next');
const app = next(settings);
const handle = app.getRequestHandler();
await app.prepare();
const server: express.Express = express();
server.disable('x-powered-by');
// Set up the proxy.
if (proxyConfig) {
const proxyMiddleware =
require('http-proxy-middleware').createProxyMiddleware;
Object.keys(proxyConfig).forEach((context) => {
server.use(proxyMiddleware(context, proxyConfig[context]));
});
}
// Default catch-all handler to allow Next.js to handle all other routes
server.all('*', (req, res) => handle(req, res));
server.listen(settings.port, settings.hostname);
}

View File

@ -34,6 +34,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript"]
}
]
}
}
]
}

View File

@ -70,6 +70,36 @@
],
"no-restricted-imports": "off"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"typescript",
"@angular-devkit/build-angular",
"@angular-devkit/core",
"@angular-devkit/architect",
"@swc/core", //Optional, used in JS analysis if available
"@swc/node-register", //Optional, used in JS analysis if available
"rxjs",
"@angular-devkit/schematics",
"@pnpm/lockfile-types",
"@nestjs/cli", // nx init nest makes use of nestjs cli (which should be available in NestJS CLI app) to parse the nest-cli.json file
"ts-node", // We *may* fall back on ts-node, but we want to encourage the use of @swc-node instead so we don't explicitly list ts-node as an optional dep
"memfs", // used in mock for handling .node files in tests
"events", // This is coming from @storybook/builder-manager since it uses the browser polyfill
"process", // This is coming from @storybook/builder-manager since it uses the browser polyfill
"prettier", // This is coming from @storybook/builder-manager since it uses the browser polyfill
"util" // This is coming from @storybook/builder-manager since it uses the browser polyfill
]
}
]
}
}
]
}

View File

@ -20,6 +20,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript", "@playwright/test"]
}
]
}
}
]
}

View File

@ -29,7 +29,8 @@
"directory": "packages/playwright"
},
"dependencies": {
"@nx/devkit": "file:../devkit"
"@nx/devkit": "file:../devkit",
"tslib": "^2.3.0"
},
"peerDependencies": {
"@playwright/test": "^1.36.0"

View File

@ -38,6 +38,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript", "eslint"]
}
]
}
}
]
}

View File

@ -14,6 +14,29 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"eslint",
"prettier",
"typescript",
"react",
"react-native",
// These are in ensurePackage
"@nx/rollup",
"@nx/storybook"
]
}
]
}
}
]
}

View File

@ -35,6 +35,7 @@
"minimatch": "3.0.5",
"node-fetch": "^2.6.7",
"tsconfig-paths": "^4.1.2",
"tslib": "^2.3.0",
"@nx/detox": "file:../detox",
"@nx/devkit": "file:../devkit",
"@nx/jest": "file:../jest",

View File

@ -30,6 +30,61 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"eslint",
"prettier",
"typescript",
"react",
// These are installed by ensurePackage so missing in package.json
"@nx/cypress",
"@nx/jest",
"@nx/rollup",
"@nx/storybook",
"@nx/vite",
"@nx/webpack",
// These are brought in by the webpack, rollup, or vite packages via init generators.
"@babel/preset-react",
"@module-federation/node",
"@phenomnomnominal/tsquery",
"@pmmmwh/react-refresh-webpack-plugin",
"@svgr/rollup",
"@rollup/plugin-url",
"@svgr/webpack",
"@swc/jest",
"babel-jest",
"babel-loader",
"babel-plugin-emotion",
"babel-plugin-styled-components",
"css-loader",
"file-loader",
"less-loader",
"react-refresh",
"rollup",
"sass",
"sass-loader",
"style-loader",
"stylus-loader",
"swc-loader",
"tsconfig-paths-webpack-plugin",
"url-loader",
"webpack",
"webpack-merge",
// used via the CT react plugin installed via vite plugin
"vite"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -36,6 +36,7 @@
"chalk": "^4.1.0",
"file-loader": "^6.2.0",
"minimatch": "3.0.5",
"tslib": "^2.3.0",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",
"@nx/linter": "file:../linter",

View File

@ -20,6 +20,26 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"@swc/core", // Installed to workspace and only used in swc() plugin
// Used in require.resolve calls
"babel-plugin-transform-async-to-promises",
"postcss"
]
}
]
}
}
]
}

View File

@ -30,6 +30,25 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"@nx/web", // Just types used
"@storybook/core-server",
"@storybook/types"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -33,6 +33,7 @@
"dotenv": "~10.0.0",
"@phenomnomnominal/tsquery": "~5.0.1",
"semver": "7.5.3",
"tslib": "^2.3.0",
"@nx/cypress": "file:../cypress",
"@nx/devkit": "file:../devkit",
"@nx/js": "file:../js",

View File

@ -22,6 +22,19 @@
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript"]
}
]
}
}
]
}

View File

@ -31,7 +31,8 @@
},
"homepage": "https://nx.dev",
"dependencies": {
"nx": "file:../nx"
"nx": "file:../nx",
"tslib": "^2.3.0"
},
"publishConfig": {
"access": "public"

View File

@ -20,6 +20,19 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": ["nx", "typescript", "vite"]
}
]
}
}
]
}

View File

@ -30,6 +30,30 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"eslint",
"http-server", // Used by readModulePackageJson
// Installed by ensurePackage
"@nx/linter",
"@nx/cypress",
"@nx/vite",
"@nx/webpack",
"@nx/jest"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -20,6 +20,35 @@
"rules": {
"@nx/nx-plugin-checks": "error"
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"typescript",
"eslint",
// Used in require.resolve calls
"@babel/core",
"css-loader",
"less",
"less-loader",
"postcss-loader",
"sass-loader",
"style-loader",
"stylus",
"stylus-loader",
"source-map-loader",
"ts-loader"
]
}
]
}
}
]
}

View File

@ -35,6 +35,26 @@
}
]
}
},
{
"files": ["./package.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/dependency-checks": [
"error",
{
"buildTargets": ["build-base"],
"ignoredDependencies": [
"nx",
"prettier",
"typescript",
"@angular-devkit/schematics",
"@angular-devkit/core",
"@angular-devkit/architect"
]
}
]
}
}
],
"ignorePatterns": ["!**/*"]

View File

@ -61,22 +61,10 @@
}
},
"dependencies": {
"@parcel/watcher": "2.0.4",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"cli-cursor": "3.1.0",
"cli-spinners": "2.6.1",
"dotenv": "~10.0.0",
"figures": "3.2.0",
"flat": "^5.0.2",
"ignore": "^5.0.4",
"minimatch": "3.0.5",
"npm-run-path": "^4.0.1",
"open": "^8.4.0",
"rxjs": "^7.8.0",
"tmp": "~0.2.1",
"tslib": "^2.3.0",
"yargs": "^17.6.2",
"yargs-parser": "21.1.1",
"@nx/devkit": "file:../devkit"
},

138
pnpm-lock.yaml generated
View File

@ -528,9 +528,6 @@ devDependencies:
czg:
specifier: ^1.4.0
version: 1.4.0
depcheck:
specifier: ^1.3.1
version: 1.4.3
detect-port:
specifier: ^1.5.1
version: 1.5.1
@ -2206,14 +2203,6 @@ packages:
chalk: 2.4.2
js-tokens: 4.0.0
/@babel/parser@7.16.4:
resolution: {integrity: sha512-6V0qdPUaiVHH3RtZeLIsc+6pDhbYzHR8ogA8w+f+Wc77DuXto19g2QUwveINoS34Uw+W8/hQDGJCx+i4n7xcng==}
engines: {node: '>=6.0.0'}
hasBin: true
dependencies:
'@babel/types': 7.22.5
dev: true
/@babel/parser@7.21.4:
resolution: {integrity: sha512-alVJj7k7zIxqBZ7BTRhz0IqJFxW1VJbm6N8JbcYhQ186df9ZBPbZBmWSqAMXwHGsCJdYks7z/voa3ibiS5bCIw==}
engines: {node: '>=6.0.0'}
@ -11136,15 +11125,6 @@ packages:
pretty-format: 27.5.1
dev: false
/@vue/compiler-core@3.2.41:
resolution: {integrity: sha512-oA4mH6SA78DT+96/nsi4p9DX97PHcNROxs51lYk7gb9Z4BPKQ3Mh+BLn6CQZBw857Iuhu28BfMSRHAlPvD4vlw==}
dependencies:
'@babel/parser': 7.22.5
'@vue/shared': 3.2.41
estree-walker: 2.0.2
source-map: 0.6.1
dev: true
/@vue/compiler-core@3.3.4:
resolution: {integrity: sha512-cquyDNvZ6jTbf/+x+AgM2Arrp6G4Dzbb0R64jiG804HRMfRiFXWI6kqUVqZ6ZR0bQhIoQjB4+2bhNtVwndW15g==}
dependencies:
@ -11154,13 +11134,6 @@ packages:
source-map-js: 1.0.2
dev: true
/@vue/compiler-dom@3.2.41:
resolution: {integrity: sha512-xe5TbbIsonjENxJsYRbDJvthzqxLNk+tb3d/c47zgREDa/PCp6/Y4gC/skM4H6PIuX5DAxm7fFJdbjjUH2QTMw==}
dependencies:
'@vue/compiler-core': 3.2.41
'@vue/shared': 3.2.41
dev: true
/@vue/compiler-dom@3.3.4:
resolution: {integrity: sha512-wyM+OjOVpuUukIq6p5+nwHYtj9cFroz9cwkfmP9O1nzH68BenTTv0u7/ndggT8cIQlnBeOo6sUT/gvHcIkLA5w==}
dependencies:
@ -11168,21 +11141,6 @@ packages:
'@vue/shared': 3.3.4
dev: true
/@vue/compiler-sfc@3.2.41:
resolution: {integrity: sha512-+1P2m5kxOeaxVmJNXnBskAn3BenbTmbxBxWOtBq3mQTCokIreuMULFantBUclP0+KnzNCMOvcnKinqQZmiOF8w==}
dependencies:
'@babel/parser': 7.22.5
'@vue/compiler-core': 3.2.41
'@vue/compiler-dom': 3.2.41
'@vue/compiler-ssr': 3.2.41
'@vue/reactivity-transform': 3.2.41
'@vue/shared': 3.2.41
estree-walker: 2.0.2
magic-string: 0.25.9
postcss: 8.4.19
source-map: 0.6.1
dev: true
/@vue/compiler-sfc@3.3.4:
resolution: {integrity: sha512-6y/d8uw+5TkCuzBkgLS0v3lSM3hJDntFEiUORM11pQ/hKvkhSKZrXW6i69UyXlJQisJxuUEJKAWEqWbWsLeNKQ==}
dependencies:
@ -11198,13 +11156,6 @@ packages:
source-map-js: 1.0.2
dev: true
/@vue/compiler-ssr@3.2.41:
resolution: {integrity: sha512-Y5wPiNIiaMz/sps8+DmhaKfDm1xgj6GrH99z4gq2LQenfVQcYXmHIOBcs5qPwl7jaW3SUQWjkAPKMfQemEQZwQ==}
dependencies:
'@vue/compiler-dom': 3.2.41
'@vue/shared': 3.2.41
dev: true
/@vue/compiler-ssr@3.3.4:
resolution: {integrity: sha512-m0v6oKpup2nMSehwA6Uuu+j+wEwcy7QmwMkVNVfrV9P2qE5KshC6RwOCq8fjGS/Eak/uNb8AaWekfiXxbBB6gQ==}
dependencies:
@ -11212,16 +11163,6 @@ packages:
'@vue/shared': 3.3.4
dev: true
/@vue/reactivity-transform@3.2.41:
resolution: {integrity: sha512-mK5+BNMsL4hHi+IR3Ft/ho6Za+L3FA5j8WvreJ7XzHrqkPq8jtF/SMo7tuc9gHjLDwKZX1nP1JQOKo9IEAn54A==}
dependencies:
'@babel/parser': 7.22.5
'@vue/compiler-core': 3.2.41
'@vue/shared': 3.2.41
estree-walker: 2.0.2
magic-string: 0.25.9
dev: true
/@vue/reactivity-transform@3.3.4:
resolution: {integrity: sha512-MXgwjako4nu5WFLAjpBnCj/ieqcjE2aJBINUNQzkZQfzIZA4xn+0fV1tIYBJvvva3N3OvKGofRLvQIwEQPpaXw==}
dependencies:
@ -11263,10 +11204,6 @@ packages:
vue: 3.3.4
dev: true
/@vue/shared@3.2.41:
resolution: {integrity: sha512-W9mfWLHmJhkfAmV+7gDjcHeAWALQtgGT3JErxULl0oz6R6+3ug91I7IErs93eCFhPCZPHBs4QJS7YWEV7A3sxw==}
dev: true
/@vue/shared@3.3.4:
resolution: {integrity: sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ==}
dev: true
@ -14923,38 +14860,6 @@ packages:
resolution: {integrity: sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==}
dev: true
/depcheck@1.4.3:
resolution: {integrity: sha512-vy8xe1tlLFu7t4jFyoirMmOR7x7N601ubU9Gkifyr9z8rjBFtEdWHDBMqXyk6OkK+94NXutzddVXJuo0JlUQKQ==}
engines: {node: '>=10'}
hasBin: true
dependencies:
'@babel/parser': 7.16.4
'@babel/traverse': 7.21.4(supports-color@5.5.0)
'@vue/compiler-sfc': 3.2.41
camelcase: 6.3.0
cosmiconfig: 7.0.1
debug: 4.3.4(supports-color@5.5.0)
deps-regex: 0.1.4
ignore: 5.2.0
is-core-module: 2.11.0
js-yaml: 3.14.1
json5: 2.2.3
lodash: 4.17.21
minimatch: 3.1.2
multimatch: 5.0.0
please-upgrade-node: 3.2.0
query-ast: 1.0.4
readdirp: 3.6.0
require-package-name: 2.0.1
resolve: 1.22.1
sass: 1.58.1
scss-parser: 1.0.5
semver: 7.5.3
yargs: 16.2.0
transitivePeerDependencies:
- supports-color
dev: true
/depd@1.1.2:
resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==}
engines: {node: '>= 0.6'}
@ -14973,10 +14878,6 @@ packages:
resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==}
dev: true
/deps-regex@0.1.4:
resolution: {integrity: sha512-3tzwGYogSJi8HoG93R5x9NrdefZQOXgHgGih/7eivloOq6yC6O+yoFxZnkgP661twvfILONfoKRdF9GQOGx2RA==}
dev: true
/dequal@2.0.3:
resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==}
engines: {node: '>=6'}
@ -22386,12 +22287,6 @@ packages:
hasBin: true
dev: true
/please-upgrade-node@3.2.0:
resolution: {integrity: sha512-gQR3WpIgNIKwBMVLkpMUeR3e1/E1y42bqDQZfql+kDeXd8COYfM8PQA4X6y7a8u9Ua9FHmsrrmirW2vHs45hWg==}
dependencies:
semver-compare: 1.0.0
dev: true
/pluralize@8.0.0:
resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==}
engines: {node: '>=4'}
@ -23819,13 +23714,6 @@ packages:
engines: {node: '>=0.6'}
dev: true
/query-ast@1.0.4:
resolution: {integrity: sha512-KFJFSvODCBjIH5HbHvITj9EEZKYUU6VX0T5CuB1ayvjUoUaZkKMi6eeby5Tf8DMukyZHlJQOE1+f3vevKUe6eg==}
dependencies:
invariant: 2.2.4
lodash: 4.17.21
dev: true
/querystringify@2.2.0:
resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==}
dev: true
@ -24455,10 +24343,6 @@ packages:
engines: {node: '>=0.10.0'}
dev: true
/require-package-name@2.0.1:
resolution: {integrity: sha512-uuoJ1hU/k6M0779t3VMVIYpb2VMJk05cehCaABFhXaibcbvfgR8wKiozLjVFSzJPmQMRqIcO0HMyTFqfV09V6Q==}
dev: true
/requireindex@1.2.0:
resolution: {integrity: sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==}
engines: {node: '>=0.10.5'}
@ -24818,16 +24702,6 @@ packages:
immutable: 4.1.0
source-map-js: 1.0.2
/sass@1.58.1:
resolution: {integrity: sha512-bnINi6nPXbP1XNRaranMFEBZWUfdW/AF16Ql5+ypRxfTvCRTTKrLsMIakyDcayUt2t/RZotmL4kgJwNH5xO+bg==}
engines: {node: '>=12.0.0'}
hasBin: true
dependencies:
chokidar: 3.5.3
immutable: 4.1.0
source-map-js: 1.0.2
dev: true
/sass@1.63.2:
resolution: {integrity: sha512-u56TU0AIFqMtauKl/OJ1AeFsXqRHkgO7nCWmHaDwfxDo9GUMSqBA4NEh6GMuh1CYVM7zuROYtZrHzPc2ixK+ww==}
engines: {node: '>=14.0.0'}
@ -24907,14 +24781,6 @@ packages:
ajv-keywords: 5.1.0(ajv@8.12.0)
dev: true
/scss-parser@1.0.5:
resolution: {integrity: sha512-RZOtvCmCnwkDo7kdcYBi807Y5EoTIxJ34AgEgJNDmOH1jl0/xG0FyYZFbH6Ga3Iwu7q8LSdxJ4C5UkzNXjQxKQ==}
engines: {node: '>=6.0.0'}
dependencies:
invariant: 2.2.4
lodash: 4.17.21
dev: true
/secure-compare@3.0.1:
resolution: {integrity: sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==}
dev: true
@ -24930,10 +24796,6 @@ packages:
node-forge: 1.3.1
dev: true
/semver-compare@1.0.0:
resolution: {integrity: sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==}
dev: true
/semver-regex@4.0.5:
resolution: {integrity: sha512-hunMQrEy1T6Jr2uEVjrAIqjwWcQTgOAcIM52C8MY1EZSD3DDNft04XzvYKPqjED65bNVVko0YI38nYeEHCX3yw==}
engines: {node: '>=12'}

View File

@ -1,32 +0,0 @@
import * as chalk from 'chalk';
import { satisfies } from 'semver';
// Ignore packages that are defined here per package
const IGNORE_MATCHES = {
'*': [] as string[],
angular: ['webpack-merge', '@phenomnomnominal/tsquery'],
cypress: ['webpack', '@babel/core', 'babel-loader'],
};
export default function getDiscrepancies(
name: string,
projectDependencies: JSON,
devDependencies: JSON
) {
return Object.keys(projectDependencies ?? ({} as Record<string, string>))
.filter((p) => !p.startsWith('@nx/') && p !== 'nx')
.filter((p) =>
!IGNORE_MATCHES['*'].includes(p) && IGNORE_MATCHES[name]
? !IGNORE_MATCHES[name].includes(p)
: true
)
.filter(
(p) =>
devDependencies[p] &&
projectDependencies[p] !== devDependencies[p] &&
!satisfies(devDependencies[p], projectDependencies[p])
)
.map(
(p) => `${p}@${devDependencies[p]} ${chalk.dim(projectDependencies[p])}`
);
}

View File

@ -1,132 +0,0 @@
import { readFileSync, readdirSync } from 'fs';
import { join } from 'path';
import * as chalk from 'chalk';
import getDiscrepancies from './discrepancies';
import getMissingDependencies from './missing';
import getUnusedDependencies from './unused';
const argv = require('yargs')
.usage('Check projects for dependency discrepancies.')
.option('projects', {
alias: 'p',
type: 'array',
description: 'Projects to check',
})
.option('unused', {
alias: 'm',
type: 'boolean',
default: true,
description: 'Check for unused dependencies',
})
.option('missing', {
alias: 'm',
type: 'boolean',
default: true,
description: 'Check for missing dependencies',
})
.option('discrepancies', {
alias: 'd',
type: 'boolean',
default: true,
description: 'Check for discrepancies between package and dev dependencies',
})
.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging',
}).argv;
(async () => {
const { devDependencies } = JSON.parse(
readFileSync(`./package.json`).toString()
);
const packagesDirectory = join(__dirname, '../..', 'packages');
const projects =
argv.projects ||
readdirSync(packagesDirectory, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const results = await Promise.all(
projects
.sort()
.map((name) => ({ name }))
.map(async (project) => {
const projectPath = join(packagesDirectory, project.name);
const { dependencies, peerDependencies } = JSON.parse(
readFileSync(`${projectPath}/package.json`).toString()
);
const missing = argv.missing
? await getMissingDependencies(
project.name,
projectPath,
{ ...dependencies, ...(peerDependencies || {}) },
argv.verbose
)
: [];
const unused = argv.unused
? await getUnusedDependencies(
project.name,
projectPath,
{ ...dependencies, ...(peerDependencies || {}) },
argv.verbose
)
: [];
const discrepancies = argv.discrepancies
? getDiscrepancies(project.name, dependencies, devDependencies)
: [];
return { ...project, missing, discrepancies, unused };
})
);
const total = { missing: 0, discrepancies: 0, unused: 0 };
results.forEach(({ name, missing, discrepancies, unused }) => {
if (!missing.length && !discrepancies.length && !unused.length) {
return;
}
console.log(`${chalk.inverse.bold.cyan(` ${name.toUpperCase()} `)}`);
if (missing.length > 0) {
total.missing += missing.length;
console.log(
`⚠️ ${chalk.bold.inverse(` Missing `)}\n${missing
.sort()
.map(
(p) => ` ${devDependencies[p] ? `${p}@${devDependencies[p]}` : p}`
)
.join(`\n`)}\n`
);
}
if (unused.length > 0) {
total.unused += unused.length;
console.log(
`⚠️ ${chalk.bold.inverse(` Unused`)}\n ${unused.join('\n ')}\n`
);
}
if (discrepancies.length > 0) {
total.discrepancies += discrepancies.length;
console.log(
`${chalk.bold.inverse(` Discrepancies `)}\n${discrepancies
.map((d) => ` ${d}`)
.join(`\n`)}\n`
);
}
});
if (total.discrepancies > 0 || total.missing > 0 || total.unused > 0) {
process.exit(1);
}
process.exit(0);
})().catch((err) => console.log(err));

View File

@ -1,271 +0,0 @@
import * as depcheck from 'depcheck';
import { join } from 'path';
// Ignore packages that are defined here per package
const IGNORE_MATCHES_IN_PACKAGE = {
'*': [
'nx',
'prettier',
'typescript',
// These are installed as needed and should not be added to package.json
'@nx/cypress',
'@nx/jest',
'@nx/rollup',
'@nx/storybook',
'@nx/vite',
'@nx/webpack',
],
angular: [
'@angular-devkit/architect',
'@angular-devkit/build-angular',
'@angular-devkit/core',
'@angular/compiler',
'@angular/compiler-cli',
'@angular/core',
'@angular/router',
'@ngrx/effects',
'@ngrx/router-store',
'@ngrx/store',
'@storybook/angular',
'@module-federation/node',
'rxjs',
'semver',
// installed dynamically by the library generator
'ng-packagr',
// ng-packagr deps, some are handled if not installed
'injection-js',
'browserslist',
'cacache',
'less',
'node-sass',
'node-sass-tilde-importer',
'ora',
'convert-source-map',
'postcss',
'postcss-import',
'postcss-preset-env',
'postcss-url',
'sass',
'stylus',
'tailwindcss',
// used in the CT angular plugin where Cy is already installed to use it.
'cypress',
],
cli: ['nx'],
cypress: ['cypress', '@angular-devkit/schematics', 'vite'],
devkit: [
'@angular-devkit/architect',
'@angular-devkit/schematics',
'rxjs',
'webpack',
],
'eslint-plugin': ['@angular-eslint/eslint-plugin'],
jest: [
'jest',
'@jest/types',
'identity-obj-proxy',
'@angular-devkit/schematics',
],
js: [],
linter: [
'eslint',
'@angular-devkit/schematics',
'@angular-devkit/architect',
// Installed and uninstalled dynamically when the conversion generator runs
'tslint-to-eslint-config',
// Resolved from the end user's own workspace installation dynamically
'@typescript-eslint/eslint-plugin',
],
next: [
'@angular-devkit/architect',
'express',
'http-proxy-middleware',
'next',
'rxjs',
'tsconfig-paths-webpack-plugin',
'webpack',
],
react: [
// These are brought in by the webpack, rollup, or vite packages via init generators.
'@babel/preset-react',
'@module-federation/node',
'@phenomnomnominal/tsquery',
'@pmmmwh/react-refresh-webpack-plugin',
'@svgr/rollup',
'@rollup/plugin-url',
'@svgr/webpack',
'@swc/jest',
'babel-jest',
'babel-loader',
'babel-plugin-emotion',
'babel-plugin-styled-components',
'css-loader',
'file-loader',
'less-loader',
'react-refresh',
'rollup',
'sass',
'sass-loader',
'style-loader',
'stylus-loader',
'swc-loader',
'tsconfig-paths-webpack-plugin',
'url-loader',
'webpack',
'webpack-merge',
// used via the CT react plugin installed via vite plugin
'vite',
],
'react-native': ['@nx/storybook'],
rollup: ['@swc/core'],
storybook: [
'@angular-devkit/architect',
'@angular-devkit/core',
'@angular-devkit/schematics',
'@storybook/addon-knobs',
'@storybook/addon-essentials',
'@storybook/core',
'@storybook/core-server',
'@storybook/types',
// lazy installed with ensurePackage
'@nx/web',
'@nx/jest',
'@nx/rollup',
'@nx/vite',
'@nx/webpack',
'rxjs',
],
nx: [
'@angular-devkit/build-angular',
'@angular-devkit/schematics',
'@angular-devkit/core',
'@angular-devkit/architect',
'@angular/cli',
'@nrwl/angular',
'@nx/angular',
'@nrwl/cli',
'rxjs',
'@nestjs/cli', // nx init nest makes use of nestjs cli (which should be available in NestJS CLI app) to parse the nest-cli.json file
'ts-node', // We *may* fall back on ts-node, but we want to encourage the use of @swc-node instead so we don't explicitly list ts-node as an optional dep
'@nx/nx-android-arm-eabi', // native optional deps
'@nx/nx-android-arm64', // native optional deps
'@nx/nx-darwin-arm64', // native optional deps
'@nx/nx-darwin-universal', // native optional deps
'@nx/nx-darwin-x64', // native optional deps
'@nx/nx-freebsd-x64', // native optional deps
'@nx/nx-linux-arm-gnueabihf', // native optional deps
'@nx/nx-linux-arm64-gnu', // native optional deps
'@nx/nx-linux-arm64-musl', // native optional deps
'@nx/nx-linux-x64-gnu', // native optional deps
'@nx/nx-linux-x64-musl', // native optional deps
'@nx/nx-win32-arm64-msvc', // native optional deps
'@nx/nx-win32-ia32-msvc', // native optional deps
'@nx/nx-win32-x64-msvc', // native optional deps
'memfs', // used in mock for handling .node files in tests
],
web: [
// we don't want to bloat the install of @nx/web by including @swc/core and swc-loader as a dependency.
'@swc/core',
'swc-loader',
'@nx/cypress',
'@nx/jest',
'@nx/rollup',
'@nx/vite',
'@nx/webpack',
'fibers',
'node-sass',
],
webpack: ['@swc/core', 'style-loader', 'swc-loader'],
workspace: [
'@angular-devkit/architect',
'@angular-devkit/core',
'@angular-devkit/schematics',
'@phenomnomnominal/tsquery',
],
nest: ['semver'],
};
const IGNORE_MATCHES_BY_FILE: Record<string, string[]> = {
'@storybook/core': [
join(
__dirname,
'../../packages/angular/src/migrations/update-12-3-0/update-storybook.ts'
),
],
'@nx/plugin': [
join(
__dirname,
'../../packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.spec.ts'
),
join(
__dirname,
'../../packages/workspace/src/migrations/update-16-0-0/move-workspace-generators-to-local-plugin.ts'
),
],
};
export default async function getMissingDependencies(
name: string,
path: string,
dependencies: JSON,
verbose: boolean
) {
const options: any = {
/**
* If a dependency is exclusively used via a TypeScript type import
* e.g. `import type { Foo } from 'bar';`
* ...then we do not want it to trigger a missing dependency warning
* because it is not required at runtime.
*
* We can achieve this by overriding the default detector for
* ImportDeclaration nodes to check the `importKind` value.
*/
detectors: [
...Object.entries(depcheck.detector).map(([detectorName, detectorFn]) => {
// Use all the default detectors, apart from 'importDeclaration'
if (detectorName !== 'importDeclaration') {
return detectorFn;
}
const customImportDeclarationDetector: depcheck.Detector = (node) => {
return node.type === 'ImportDeclaration' &&
node.source &&
node.source.value &&
node.importKind !== 'type'
? [node.source.value]
: [];
};
return customImportDeclarationDetector;
}),
],
skipMissing: false, // skip calculation of missing dependencies
ignorePatterns: [
'*.d.ts',
'.eslintrc.json',
'*.spec*',
'src/schematics/**/files/**',
],
};
let { missing } = await depcheck(path, {
...options,
package: { dependencies },
});
const packagesMissing = Object.keys(missing).filter(
(m) =>
!IGNORE_MATCHES_IN_PACKAGE['*'].includes(m) &&
!(IGNORE_MATCHES_IN_PACKAGE[name] || []).includes(m) &&
missing[m].filter(
(occurence) => !IGNORE_MATCHES_BY_FILE[m]?.includes(occurence)
).length
);
if (verbose) {
console.log(`> ${name}`);
packagesMissing.map((p) => {
console.log(p, missing[p]);
});
}
return packagesMissing;
}

View File

@ -1,104 +0,0 @@
import * as depcheck from 'depcheck';
// Ignore packages that are defined here per package.
// Note: If @babel/parser fails to parse a file, then its imports will not be detected.
const IGNORE_MATCHES = {
'*': ['@nx/devkit', '@nx/workspace', 'chalk', 'tslib', '@swc/helpers'],
angular: ['@angular-devkit/schematics', '@schematics/angular', 'http-server'],
cli: [],
cypress: [],
devkit: [],
'eslint-plugin': [],
jest: [
// This is used for the type import only, we should remove it.
'jest-resolve',
],
linter: [],
nest: ['@nestjs/schematics'],
next: [],
node: [],
'nx-plugin': [],
react: [],
rollup: [],
storybook: [],
nx: ['glob'],
vite: [],
web: ['http-server'],
webpack: [
// These are not being picked up because @babel/parser is failing on the files that import them.
'css-loader',
'style-loader',
'ts-loader',
'webpack-merge',
],
workspace: [
'@parcel/watcher',
'cli-cursor',
'cli-spinners',
'dotenv',
'figures',
'flat',
'minimatch',
'npm-run-path',
'open',
'tmp',
'yargs',
],
};
export default async function getUnusedDependencies(
name: string,
path: string,
dependencies: JSON,
verbose: boolean
) {
const options: any = {
detectors: [
...Object.entries(depcheck.detector).map(([detectorName, detectorFn]) => {
// Use all the default detectors, apart from 'importDeclaration'
if (detectorName !== 'importDeclaration') {
return detectorFn;
}
const customImportDeclarationDetector: depcheck.Detector = (node) => {
switch (node.type) {
case 'ImportDeclaration':
return node.source &&
node.source.value &&
node.importKind !== 'type'
? [node.source.value]
: [];
case 'CallExpression':
return (node.callee?.name === 'require' ||
(node.callee?.object?.name === 'require' &&
node.callee?.property?.name === 'resolve')) &&
node.arguments[0]?.value
? [node.arguments[0].value]
: [];
default:
return [];
}
};
return customImportDeclarationDetector;
}),
],
skipMissing: false, // skip calculation of missing dependencies
ignorePatterns: [
'*.d.ts',
'.eslintrc.json',
'*.spec*',
'src/schematics/**/files/**',
],
};
let { dependencies: unused } = await depcheck(path, {
...options,
package: { dependencies },
});
const unusedPackages = unused.filter(
(m) =>
!IGNORE_MATCHES['*'].includes(m) &&
!(IGNORE_MATCHES[name] || []).includes(m)
);
return unusedPackages;
}