knip 2.0.0-alpha.1 → 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -145
- package/dist/binaries/bash-parser.d.ts +6 -0
- package/dist/binaries/bash-parser.js +57 -0
- package/dist/binaries/index.d.ts +2 -0
- package/dist/binaries/index.js +22 -0
- package/dist/binaries/resolvers/fallback.d.ts +2 -0
- package/dist/binaries/resolvers/fallback.js +14 -0
- package/dist/binaries/resolvers/index.d.ts +4 -0
- package/dist/binaries/resolvers/index.js +4 -0
- package/dist/binaries/resolvers/node.d.ts +3 -0
- package/dist/binaries/resolvers/node.js +20 -0
- package/dist/binaries/resolvers/npx.d.ts +2 -0
- package/dist/binaries/resolvers/npx.js +5 -0
- package/dist/binaries/resolvers/pnpm.d.ts +2 -0
- package/dist/binaries/resolvers/pnpm.js +45 -0
- package/dist/binaries/resolvers/yarn.d.ts +2 -0
- package/dist/binaries/resolvers/yarn.js +46 -0
- package/dist/binaries/types.d.ts +18 -0
- package/dist/binaries/types.js +1 -0
- package/dist/cli.js +2 -3
- package/dist/commonjs.test.d.ts +1 -0
- package/dist/commonjs.test.js +29 -0
- package/dist/compilers.test.d.ts +1 -0
- package/dist/compilers.test.js +18 -0
- package/dist/configuration-chief.d.ts +7 -12
- package/dist/configuration-chief.js +25 -23
- package/dist/console-streamer.d.ts +12 -0
- package/dist/console-streamer.js +34 -0
- package/dist/constants.js +6 -2
- package/dist/definitely-typed.test.d.ts +1 -0
- package/dist/definitely-typed.test.js +35 -0
- package/dist/dependencies.test.d.ts +1 -0
- package/dist/dependencies.test.js +76 -0
- package/dist/dependency-deputy.d.ts +2 -8
- package/dist/dependency-deputy.js +21 -17
- package/dist/entry-js.test.d.ts +1 -0
- package/dist/entry-js.test.js +38 -0
- package/dist/exports.test.d.ts +1 -0
- package/dist/exports.test.js +48 -0
- package/dist/fixtures/binaries/dir/index.d.ts +1 -0
- package/dist/fixtures/binaries/dir/index.js +1 -0
- package/dist/fixtures/binaries/main.d.ts +1 -0
- package/dist/fixtures/binaries/main.js +1 -0
- package/dist/fixtures/binaries/require.d.ts +1 -0
- package/dist/fixtures/binaries/require.js +1 -0
- package/dist/fixtures/binaries/script.d.ts +1 -0
- package/dist/fixtures/binaries/script.js +1 -0
- package/dist/fixtures/commonjs/dir/mod.d.ts +1 -0
- package/dist/fixtures/commonjs/dir/mod.js +5 -0
- package/dist/fixtures/commonjs/dir/mod1.d.ts +7 -0
- package/dist/fixtures/commonjs/dir/mod1.js +5 -0
- package/dist/fixtures/commonjs/dir/mod2.d.ts +4 -0
- package/dist/fixtures/commonjs/dir/mod2.js +4 -0
- package/dist/fixtures/commonjs/dir/mod3.d.ts +2 -0
- package/dist/fixtures/commonjs/dir/mod3.js +4 -0
- package/dist/fixtures/commonjs/export-is.d.ts +2 -0
- package/dist/fixtures/commonjs/export-is.js +2 -0
- package/dist/fixtures/commonjs/index.d.ts +1 -0
- package/dist/fixtures/commonjs/index.js +31 -0
- package/dist/fixtures/commonjs/odd.d.ts +1 -0
- package/dist/fixtures/commonjs/odd.js +7 -0
- package/dist/fixtures/compilers/component.d.ts +2 -0
- package/dist/fixtures/compilers/component.jsx +1 -0
- package/dist/fixtures/compilers/index.d.ts +1 -0
- package/dist/fixtures/compilers/index.js +1 -0
- package/dist/fixtures/compilers/knip.d.ts +0 -0
- package/dist/fixtures/compilers/knip.js +7 -0
- package/dist/fixtures/definitely-typed/index.d.ts +1 -0
- package/dist/fixtures/definitely-typed/index.js +1 -0
- package/dist/fixtures/dependencies/entry.d.ts +1 -0
- package/dist/fixtures/dependencies/entry.js +6 -0
- package/dist/fixtures/dependencies/my-module.d.ts +3 -0
- package/dist/fixtures/dependencies/my-module.js +6 -0
- package/dist/fixtures/dependencies/unused-module.d.ts +1 -0
- package/dist/fixtures/dependencies/unused-module.js +6 -0
- package/dist/fixtures/entry-js/dangling.d.ts +1 -0
- package/dist/fixtures/entry-js/dangling.js +1 -0
- package/dist/fixtures/entry-js/index.d.ts +1 -0
- package/dist/fixtures/entry-js/index.js +2 -0
- package/dist/fixtures/entry-js/my-module.d.ts +4 -0
- package/dist/fixtures/entry-js/my-module.js +6 -0
- package/dist/fixtures/entry-js/my-namespace.d.ts +5 -0
- package/dist/fixtures/entry-js/my-namespace.js +3 -0
- package/dist/fixtures/exports/dangling.d.ts +1 -0
- package/dist/fixtures/exports/dangling.js +1 -0
- package/dist/fixtures/exports/default-arrow-function.d.ts +2 -0
- package/dist/fixtures/exports/default-arrow-function.js +1 -0
- package/dist/fixtures/exports/default-class.d.ts +2 -0
- package/dist/fixtures/exports/default-class.js +2 -0
- package/dist/fixtures/exports/default-function.d.ts +1 -0
- package/dist/fixtures/exports/default-function.js +1 -0
- package/dist/fixtures/exports/default-generator-function.d.ts +1 -0
- package/dist/fixtures/exports/default-generator-function.js +1 -0
- package/dist/fixtures/exports/default-named-class.d.ts +2 -0
- package/dist/fixtures/exports/default-named-class.js +2 -0
- package/dist/fixtures/exports/default-named-function.d.ts +1 -0
- package/dist/fixtures/exports/default-named-function.js +1 -0
- package/dist/fixtures/exports/default-named-generator-function.d.ts +1 -0
- package/dist/fixtures/exports/default-named-generator-function.js +1 -0
- package/dist/fixtures/exports/default.d.ts +3 -0
- package/dist/fixtures/exports/default.js +2 -0
- package/dist/fixtures/exports/dynamic-import.d.ts +4 -0
- package/dist/fixtures/exports/dynamic-import.js +3 -0
- package/dist/fixtures/exports/index.d.ts +2 -0
- package/dist/fixtures/exports/index.js +6 -0
- package/dist/fixtures/exports/my-module.d.ts +5 -0
- package/dist/fixtures/exports/my-module.js +7 -0
- package/dist/fixtures/exports/my-namespace.d.ts +5 -0
- package/dist/fixtures/exports/my-namespace.js +3 -0
- package/dist/fixtures/exports/named.d.ts +11 -0
- package/dist/fixtures/exports/named.js +11 -0
- package/dist/fixtures/exports/types.d.ts +9 -0
- package/dist/fixtures/exports/types.js +3 -0
- package/dist/fixtures/gitignore/packages/a/build/dist.d.ts +2 -0
- package/dist/fixtures/gitignore/packages/a/build/dist.js +1 -0
- package/dist/fixtures/gitignore/packages/a/dist.d.ts +1 -0
- package/dist/fixtures/gitignore/packages/a/dist.js +1 -0
- package/dist/fixtures/gitignore/packages/a/index.d.ts +1 -0
- package/dist/fixtures/gitignore/packages/a/index.js +1 -0
- package/dist/fixtures/imports/dir/import-b.d.ts +2 -0
- package/dist/fixtures/imports/dir/import-b.js +1 -0
- package/dist/fixtures/imports/dir/mod.d.ts +1 -0
- package/dist/fixtures/imports/dir/mod.js +1 -0
- package/dist/fixtures/imports/index.d.ts +1 -0
- package/dist/fixtures/imports/index.js +35 -0
- package/dist/fixtures/js-only/dangling.d.ts +1 -0
- package/dist/fixtures/js-only/dangling.js +1 -0
- package/dist/fixtures/js-only/index.d.ts +1 -0
- package/dist/fixtures/js-only/index.js +2 -0
- package/dist/fixtures/js-only/my-namespace.d.ts +3 -0
- package/dist/fixtures/js-only/my-namespace.js +3 -0
- package/dist/fixtures/jsdoc/index.d.ts +4 -0
- package/dist/fixtures/jsdoc/index.js +8 -0
- package/dist/fixtures/members/index.d.ts +1 -0
- package/dist/fixtures/members/index.js +16 -0
- package/dist/fixtures/members/members.d.ts +23 -0
- package/dist/fixtures/members/members.js +38 -0
- package/dist/fixtures/namespace/index.d.ts +1 -0
- package/dist/fixtures/namespace/index.js +5 -0
- package/dist/fixtures/namespace/namespace.d.ts +3 -0
- package/dist/fixtures/namespace/namespace.js +3 -0
- package/dist/fixtures/namespace/re-exported-module.d.ts +2 -0
- package/dist/fixtures/namespace/re-exported-module.js +2 -0
- package/dist/fixtures/pathless/src/dir/module-a.d.ts +2 -0
- package/dist/fixtures/pathless/src/dir/module-a.js +1 -0
- package/dist/fixtures/pathless/src/index.d.ts +2 -0
- package/dist/fixtures/pathless/src/index.js +2 -0
- package/dist/fixtures/pathless/src/same.d.ts +2 -0
- package/dist/fixtures/pathless/src/same.js +1 -0
- package/dist/fixtures/paths-knip-config/abc/main.d.ts +0 -0
- package/dist/fixtures/paths-knip-config/abc/main.js +1 -0
- package/dist/fixtures/paths-knip-config/index.d.ts +1 -0
- package/dist/fixtures/paths-knip-config/index.js +1 -0
- package/dist/fixtures/paths-knip-config/knip.d.ts +3 -0
- package/dist/fixtures/paths-knip-config/knip.js +9 -0
- package/dist/fixtures/paths-knip-config/lib/fn.d.ts +2 -0
- package/dist/fixtures/paths-knip-config/lib/fn.js +1 -0
- package/dist/fixtures/paths-knip-config/lib/index.d.ts +2 -0
- package/dist/fixtures/paths-knip-config/lib/index.js +1 -0
- package/dist/fixtures/paths-knip-config/my-module.d.ts +2 -0
- package/dist/fixtures/paths-knip-config/my-module.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/index.d.ts +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/index.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/lib/fn.d.ts +2 -0
- package/dist/fixtures/paths-knip-config-workspaces/lib/fn.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/lib/index.d.ts +2 -0
- package/dist/fixtures/paths-knip-config-workspaces/lib/index.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/my-module.d.ts +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/my-module.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/index.d.ts +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/index.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/lib/main.d.ts +0 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/lib/main.js +1 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/util/lang.d.ts +2 -0
- package/dist/fixtures/paths-knip-config-workspaces/ws/util/lang.js +1 -0
- package/dist/fixtures/peer-dependencies/index.d.ts +1 -0
- package/dist/fixtures/peer-dependencies/index.js +1 -0
- package/dist/fixtures/plugins/ava/ava.config.d.mts +13 -0
- package/dist/fixtures/plugins/ava/ava.config.mjs +13 -0
- package/dist/fixtures/plugins/babel/babel.config.d.ts +14 -0
- package/dist/fixtures/plugins/babel/babel.config.js +47 -0
- package/dist/fixtures/plugins/capacitor/capacitor.config.d.ts +3 -0
- package/dist/fixtures/plugins/capacitor/capacitor.config.js +15 -0
- package/dist/fixtures/plugins/commitlint/commitlint.config.d.ts +2 -0
- package/dist/fixtures/plugins/commitlint/commitlint.config.js +2 -0
- package/dist/fixtures/plugins/cypress/cypress/support/commands.d.ts +1 -0
- package/dist/fixtures/plugins/cypress/cypress/support/commands.js +5 -0
- package/dist/fixtures/plugins/cypress/cypress/support/e2e.d.ts +2 -0
- package/dist/fixtures/plugins/cypress/cypress/support/e2e.js +2 -0
- package/dist/fixtures/plugins/cypress/cypress.config.d.ts +2 -0
- package/dist/fixtures/plugins/cypress/cypress.config.js +9 -0
- package/dist/fixtures/plugins/eslint/eslint.config.d.ts +7 -0
- package/dist/fixtures/plugins/eslint/eslint.config.js +11 -0
- package/dist/fixtures/plugins/eslint/index.d.ts +1 -0
- package/dist/fixtures/plugins/eslint/index.js +1 -0
- package/dist/fixtures/plugins/gatsby/gatsby-config.d.ts +17 -0
- package/dist/fixtures/plugins/gatsby/gatsby-config.js +40 -0
- package/dist/fixtures/plugins/gatsby/gatsby-node.d.ts +3 -0
- package/dist/fixtures/plugins/gatsby/gatsby-node.js +15 -0
- package/dist/fixtures/plugins/github-actions/comment.d.ts +0 -0
- package/dist/fixtures/plugins/github-actions/comment.js +1 -0
- package/dist/fixtures/plugins/github-actions/scripts/check-dependencies.d.ts +0 -0
- package/dist/fixtures/plugins/github-actions/scripts/check-dependencies.js +1 -0
- package/dist/fixtures/plugins/jest/jest.config.d.ts +2 -0
- package/dist/fixtures/plugins/jest/jest.config.js +7 -0
- package/dist/fixtures/plugins/jest/jest.config.shared.d.ts +2 -0
- package/dist/fixtures/plugins/jest/jest.config.shared.js +15 -0
- package/dist/fixtures/plugins/jest/jest.setup.d.ts +1 -0
- package/dist/fixtures/plugins/jest/jest.setup.js +1 -0
- package/dist/fixtures/plugins/jest/jest.transform.d.ts +1 -0
- package/dist/fixtures/plugins/jest/jest.transform.js +2 -0
- package/dist/fixtures/plugins/lefthook/example.d.mts +2 -0
- package/dist/fixtures/plugins/lefthook/example.mjs +1 -0
- package/dist/fixtures/plugins/next/next.config.d.ts +2 -0
- package/dist/fixtures/plugins/next/next.config.js +9 -0
- package/dist/fixtures/plugins/next/pages/[[...route]].d.ts +3 -0
- package/dist/fixtures/plugins/next/pages/[[...route]].jsx +3 -0
- package/dist/fixtures/plugins/next/pages/page.d.ts +3 -0
- package/dist/fixtures/plugins/next/pages/page.jsx +3 -0
- package/dist/fixtures/plugins/playwright/playwright.config.d.ts +3 -0
- package/dist/fixtures/plugins/playwright/playwright.config.js +10 -0
- package/dist/fixtures/plugins/playwright/test/some.spec.d.ts +1 -0
- package/dist/fixtures/plugins/playwright/test/some.spec.js +6 -0
- package/dist/fixtures/plugins/postcss/postcss.config.d.ts +1 -0
- package/dist/fixtures/plugins/postcss/postcss.config.js +4 -0
- package/dist/fixtures/plugins/remix/app/entry.client.d.ts +1 -0
- package/dist/fixtures/plugins/remix/app/entry.client.jsx +11 -0
- package/dist/fixtures/plugins/remix/app/entry.server.jsx +3 -0
- package/dist/fixtures/plugins/remix/app/root.d.ts +5 -0
- package/dist/fixtures/plugins/remix/app/root.jsx +31 -0
- package/dist/fixtures/plugins/remix/app/routes/index.d.ts +1 -0
- package/dist/fixtures/plugins/remix/app/routes/index.jsx +8 -0
- package/dist/fixtures/plugins/remix/app/utils.d.ts +1 -0
- package/dist/fixtures/plugins/remix/app/utils.js +1 -0
- package/dist/fixtures/plugins/remix/remix.config.d.ts +2 -0
- package/dist/fixtures/plugins/remix/remix.config.js +5 -0
- package/dist/fixtures/plugins/remix/remix.init/index.d.ts +4 -0
- package/dist/fixtures/plugins/remix/remix.init/index.js +4 -0
- package/dist/fixtures/plugins/remix/server.d.ts +0 -0
- package/dist/fixtures/plugins/remix/server.js +1 -0
- package/dist/fixtures/plugins/rollup/rollup.config.d.ts +16 -0
- package/dist/fixtures/plugins/rollup/rollup.config.js +26 -0
- package/dist/fixtures/plugins/sentry/sentry.client.config.d.ts +1 -0
- package/dist/fixtures/plugins/sentry/sentry.client.config.js +6 -0
- package/dist/fixtures/plugins/sentry/sentry.server.config.d.ts +1 -0
- package/dist/fixtures/plugins/sentry/sentry.server.config.js +1 -0
- package/dist/fixtures/plugins/storybook/addon/register.d.ts +0 -0
- package/dist/fixtures/plugins/storybook/addon/register.js +1 -0
- package/dist/fixtures/plugins/storybook/main.d.ts +10 -0
- package/dist/fixtures/plugins/storybook/main.js +38 -0
- package/dist/fixtures/plugins/storybook/preview.d.ts +13 -0
- package/dist/fixtures/plugins/storybook/preview.js +14 -0
- package/dist/fixtures/plugins/stryker/stryker.conf.cjs +6 -0
- package/dist/fixtures/plugins/stryker/stryker.conf.d.cts +3 -0
- package/dist/fixtures/plugins/stryker/stryker.conf.d.mts +6 -0
- package/dist/fixtures/plugins/stryker/stryker.conf.mjs +6 -0
- package/dist/fixtures/plugins/svelte/knip.d.ts +11 -0
- package/dist/fixtures/plugins/svelte/knip.js +10 -0
- package/dist/fixtures/plugins/svelte/src/routes/+page.d.ts +1 -0
- package/dist/fixtures/plugins/svelte/src/routes/+page.js +1 -0
- package/dist/fixtures/plugins/svelte/svelte.config.d.ts +2 -0
- package/dist/fixtures/plugins/svelte/svelte.config.js +9 -0
- package/dist/fixtures/plugins/svelte/vite.config.d.ts +2 -0
- package/dist/fixtures/plugins/svelte/vite.config.js +5 -0
- package/dist/fixtures/plugins/vitest/test/basic.spec.d.ts +1 -0
- package/dist/fixtures/plugins/vitest/test/basic.spec.js +8 -0
- package/dist/fixtures/plugins/vitest/vite.config.d.ts +2 -0
- package/dist/fixtures/plugins/vitest/vite.config.js +10 -0
- package/dist/fixtures/plugins/vitest/vitest.config.d.ts +2 -0
- package/dist/fixtures/plugins/vitest/vitest.config.js +10 -0
- package/dist/fixtures/plugins/webpack/merge.d.ts +2 -0
- package/dist/fixtures/plugins/webpack/merge.js +9 -0
- package/dist/fixtures/plugins/webpack/src/app-dep.d.ts +2 -0
- package/dist/fixtures/plugins/webpack/src/app-dep.js +1 -0
- package/dist/fixtures/plugins/webpack/src/app.d.ts +1 -0
- package/dist/fixtures/plugins/webpack/src/app.js +1 -0
- package/dist/fixtures/plugins/webpack/src/entry.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/entry.js +1 -0
- package/dist/fixtures/plugins/webpack/src/unused.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/unused.js +1 -0
- package/dist/fixtures/plugins/webpack/src/vendor.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/vendor.js +1 -0
- package/dist/fixtures/plugins/webpack/webpack.common.d.ts +65 -0
- package/dist/fixtures/plugins/webpack/webpack.common.js +81 -0
- package/dist/fixtures/plugins/webpack/webpack.config.d.ts +2 -0
- package/dist/fixtures/plugins/webpack/webpack.config.js +4 -0
- package/dist/fixtures/plugins/webpack/webpack.dev.d.ts +2 -0
- package/dist/fixtures/plugins/webpack/webpack.dev.js +19 -0
- package/dist/fixtures/plugins/webpack/webpack.prod.d.ts +2 -0
- package/dist/fixtures/plugins/webpack/webpack.prod.js +16 -0
- package/dist/fixtures/re-exports/barrel.d.ts +1 -0
- package/dist/fixtures/re-exports/barrel.js +1 -0
- package/dist/fixtures/re-exports/entry.d.ts +1 -0
- package/dist/fixtures/re-exports/entry.js +2 -0
- package/dist/fixtures/re-exports/my-module.d.ts +4 -0
- package/dist/fixtures/re-exports/my-module.js +6 -0
- package/dist/fixtures/react/App.d.ts +1 -0
- package/dist/fixtures/react/App.jsx +7 -0
- package/dist/fixtures/react/Component.d.ts +1 -0
- package/dist/fixtures/react/Component.jsx +4 -0
- package/dist/fixtures/self-reference/entry.d.ts +1 -0
- package/dist/fixtures/self-reference/entry.js +8 -0
- package/dist/fixtures/self-reference/lib/module.d.ts +2 -0
- package/dist/fixtures/self-reference/lib/module.js +1 -0
- package/dist/fixtures/self-reference/out/entry.d.ts +1 -0
- package/dist/fixtures/self-reference/out/entry.js +11 -0
- package/dist/fixtures/self-reference/out/lib/module.d.mts +3 -0
- package/dist/fixtures/self-reference/out/lib/module.mjs +4 -0
- package/dist/fixtures/self-reference-from-plugin/entry.d.ts +0 -0
- package/dist/fixtures/self-reference-from-plugin/entry.js +2 -0
- package/dist/fixtures/self-reference-from-plugin/file.d.ts +2 -0
- package/dist/fixtures/self-reference-from-plugin/file.js +1 -0
- package/dist/fixtures/tsconfig-paths/aliased-dir/a.d.ts +1 -0
- package/dist/fixtures/tsconfig-paths/aliased-dir/a.js +1 -0
- package/dist/fixtures/tsconfig-paths/index.d.ts +1 -0
- package/dist/fixtures/tsconfig-paths/index.js +6 -0
- package/dist/fixtures/tsconfig-paths/internal-package/index.d.ts +2 -0
- package/dist/fixtures/tsconfig-paths/internal-package/index.js +2 -0
- package/dist/fixtures/tsconfig-paths/unprefixed/module.d.ts +2 -0
- package/dist/fixtures/tsconfig-paths/unprefixed/module.js +2 -0
- package/dist/fixtures/tsconfig-paths-extends/src/cli.d.ts +1 -0
- package/dist/fixtures/tsconfig-paths-extends/src/cli.js +3 -0
- package/dist/fixtures/tsconfig-paths-extends/src/index.d.ts +3 -0
- package/dist/fixtures/tsconfig-paths-extends/src/index.js +3 -0
- package/dist/fixtures/tsconfig-paths-extends/src/lib/main.d.ts +2 -0
- package/dist/fixtures/tsconfig-paths-extends/src/lib/main.js +1 -0
- package/dist/fixtures/tsconfig-paths-extends/src/util/index.d.ts +2 -0
- package/dist/fixtures/tsconfig-paths-extends/src/util/index.js +1 -0
- package/dist/fixtures/tsconfig-paths-implicit/src/hello/world.d.ts +1 -0
- package/dist/fixtures/tsconfig-paths-implicit/src/hello/world.js +1 -0
- package/dist/fixtures/tsconfig-paths-implicit/src/index.d.ts +1 -0
- package/dist/fixtures/tsconfig-paths-implicit/src/index.js +2 -0
- package/dist/fixtures/workspaces/apps/a/index.d.ts +1 -0
- package/dist/fixtures/workspaces/apps/a/index.js +6 -0
- package/dist/fixtures/workspaces/apps/b/index.d.ts +1 -0
- package/dist/fixtures/workspaces/apps/b/index.js +4 -0
- package/dist/fixtures/workspaces/docs/dangling.d.ts +1 -0
- package/dist/fixtures/workspaces/docs/dangling.js +1 -0
- package/dist/fixtures/workspaces/packages/lib-a/index.d.ts +4 -0
- package/dist/fixtures/workspaces/packages/lib-a/index.js +3 -0
- package/dist/fixtures/workspaces/packages/lib-b/ignored/index.d.ts +0 -0
- package/dist/fixtures/workspaces/packages/lib-b/ignored/index.js +1 -0
- package/dist/fixtures/workspaces/packages/lib-b/index.d.ts +3 -0
- package/dist/fixtures/workspaces/packages/lib-b/index.js +2 -0
- package/dist/fixtures/workspaces-nested/level-1-1/index.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/index.js +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/index.spec.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/index.spec.js +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.js +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.spec.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.spec.js +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.js +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.spec.d.ts +1 -0
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.spec.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/dir/module-a.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/dir/module-a.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/index.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/index.js +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/same.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/same.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/dir/module-b.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/dir/module-b.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/index.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/index.js +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/dir/module.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/dir/module.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/index.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/index.js +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/dir/module.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/dir/module.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/index.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/index.js +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/dir/module-e.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/dir/module-e.js +1 -0
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/index.d.ts +2 -0
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/index.js +2 -0
- package/dist/fixtures/workspaces-pnpm/apps/a/index.d.ts +1 -0
- package/dist/fixtures/workspaces-pnpm/apps/a/index.js +6 -0
- package/dist/fixtures/workspaces-pnpm/apps/b/index.d.ts +1 -0
- package/dist/fixtures/workspaces-pnpm/apps/b/index.js +4 -0
- package/dist/fixtures/workspaces-pnpm/docs/dangling.d.ts +1 -0
- package/dist/fixtures/workspaces-pnpm/docs/dangling.js +1 -0
- package/dist/fixtures/workspaces-pnpm/packages/lib-a/index.d.ts +4 -0
- package/dist/fixtures/workspaces-pnpm/packages/lib-a/index.js +3 -0
- package/dist/fixtures/workspaces-pnpm/packages/lib-b/index.d.ts +3 -0
- package/dist/fixtures/workspaces-pnpm/packages/lib-b/index.js +2 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference/entry.d.ts +1 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference/entry.js +4 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/entry.d.ts +0 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/entry.js +2 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/file.d.ts +2 -0
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/file.js +1 -0
- package/dist/fixtures/zero-config/exclude.d.ts +1 -0
- package/dist/fixtures/zero-config/exclude.js +1 -0
- package/dist/fixtures/zero-config/index.d.ts +1 -0
- package/dist/fixtures/zero-config/index.js +2 -0
- package/dist/fixtures/zero-config/my-module.d.ts +4 -0
- package/dist/fixtures/zero-config/my-module.js +6 -0
- package/dist/fixtures/zero-config/my-namespace.d.ts +5 -0
- package/dist/fixtures/zero-config/my-namespace.js +3 -0
- package/dist/gitignore.test.d.ts +1 -0
- package/dist/gitignore.test.js +22 -0
- package/dist/helpers/baseArguments.d.ts +8 -0
- package/dist/helpers/baseArguments.js +8 -0
- package/dist/helpers/baseCounters.d.ts +17 -0
- package/dist/helpers/baseCounters.js +7 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.js +4 -0
- package/dist/imports.test.d.ts +1 -0
- package/dist/imports.test.js +39 -0
- package/dist/index.js +130 -169
- package/dist/issue-collector.d.ts +4 -11
- package/dist/issue-collector.js +9 -23
- package/dist/issues/initializers.d.ts +1 -2
- package/dist/issues/initializers.js +0 -1
- package/dist/js-only.test.d.ts +1 -0
- package/dist/js-only.test.js +26 -0
- package/dist/jsdoc.test.d.ts +1 -0
- package/dist/jsdoc.test.js +21 -0
- package/dist/manifest/helpers.d.ts +7 -1
- package/dist/manifest/helpers.js +5 -5
- package/dist/manifest/index.d.ts +2 -3
- package/dist/manifest/index.js +12 -9
- package/dist/members.test.d.ts +1 -0
- package/dist/members.test.js +28 -0
- package/dist/namespace.test.d.ts +1 -0
- package/dist/namespace.test.js +18 -0
- package/dist/npm-scripts.test.d.ts +1 -0
- package/dist/npm-scripts.test.js +78 -0
- package/dist/pathless.test.d.ts +1 -0
- package/dist/pathless.test.js +14 -0
- package/dist/paths-knip-config-workspaces.test.d.ts +1 -0
- package/dist/paths-knip-config-workspaces.test.js +18 -0
- package/dist/paths-knip-config.test.d.ts +1 -0
- package/dist/paths-knip-config.test.js +18 -0
- package/dist/peer-dependencies.test.d.ts +1 -0
- package/dist/peer-dependencies.test.js +20 -0
- package/dist/plugins/_template/index.js +2 -3
- package/dist/plugins/_template.test.d.ts +1 -0
- package/dist/plugins/_template.test.js +12 -0
- package/dist/plugins/ava/index.d.ts +6 -0
- package/dist/plugins/ava/index.js +21 -0
- package/dist/plugins/ava/types.d.ts +4 -0
- package/dist/plugins/ava/types.js +1 -0
- package/dist/plugins/ava.test.d.ts +1 -0
- package/dist/plugins/ava.test.js +18 -0
- package/dist/plugins/babel/index.d.ts +2 -2
- package/dist/plugins/babel/index.js +3 -7
- package/dist/plugins/babel/types.d.ts +5 -3
- package/dist/plugins/babel.test.d.ts +1 -0
- package/dist/plugins/babel.test.js +62 -0
- package/dist/plugins/capacitor/index.js +2 -3
- package/dist/plugins/capacitor.test.d.ts +1 -0
- package/dist/plugins/capacitor.test.js +31 -0
- package/dist/plugins/changesets/index.js +2 -3
- package/dist/plugins/changesets.test.d.ts +1 -0
- package/dist/plugins/changesets.test.js +12 -0
- package/dist/plugins/commitlint/index.js +11 -5
- package/dist/plugins/commitlint.test.d.ts +1 -0
- package/dist/plugins/commitlint.test.js +22 -0
- package/dist/plugins/cspell/index.d.ts +6 -0
- package/dist/plugins/cspell/index.js +17 -0
- package/dist/plugins/cspell/types.d.ts +3 -0
- package/dist/plugins/cspell/types.js +1 -0
- package/dist/plugins/cspell.test.d.ts +1 -0
- package/dist/plugins/cspell.test.js +10 -0
- package/dist/plugins/cypress.test.d.ts +1 -0
- package/dist/plugins/cypress.test.js +23 -0
- package/dist/plugins/eslint/fallback.js +1 -2
- package/dist/plugins/eslint/helpers.js +9 -12
- package/dist/plugins/eslint.test.d.ts +1 -0
- package/dist/plugins/eslint.test.js +43 -0
- package/dist/plugins/gatsby/index.js +2 -3
- package/dist/plugins/gatsby.test.d.ts +1 -0
- package/dist/plugins/gatsby.test.js +31 -0
- package/dist/plugins/github-actions/index.js +4 -4
- package/dist/plugins/github-actions.test.d.ts +1 -0
- package/dist/plugins/github-actions.test.js +25 -0
- package/dist/plugins/husky/index.js +2 -2
- package/dist/plugins/husky.test.d.ts +1 -0
- package/dist/plugins/husky.test.js +32 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/jest/index.d.ts +0 -1
- package/dist/plugins/jest/index.js +21 -36
- package/dist/plugins/jest.test.d.ts +1 -0
- package/dist/plugins/jest.test.js +18 -0
- package/dist/plugins/lefthook/index.js +6 -7
- package/dist/plugins/lefthook.test.d.ts +1 -0
- package/dist/plugins/lefthook.test.js +16 -0
- package/dist/plugins/lint-staged/index.js +3 -4
- package/dist/plugins/lint-staged.test.d.ts +1 -0
- package/dist/plugins/lint-staged.test.js +18 -0
- package/dist/plugins/markdownlint/helpers.d.ts +1 -0
- package/dist/plugins/markdownlint/helpers.js +6 -0
- package/dist/plugins/markdownlint/index.js +4 -5
- package/dist/plugins/markdownlint.test.d.ts +1 -0
- package/dist/plugins/markdownlint.test.js +12 -0
- package/dist/plugins/mocha/index.d.ts +0 -1
- package/dist/plugins/mocha/index.js +3 -6
- package/dist/plugins/mocha.test.d.ts +1 -0
- package/dist/plugins/mocha.test.js +22 -0
- package/dist/plugins/next.test.d.ts +1 -0
- package/dist/plugins/next.test.js +24 -0
- package/dist/plugins/npm-package-json-lint/index.js +2 -3
- package/dist/plugins/npm-package-json-lint.test.d.ts +1 -0
- package/dist/plugins/npm-package-json-lint.test.js +12 -0
- package/dist/plugins/nx/index.js +4 -5
- package/dist/plugins/nx.test.d.ts +1 -0
- package/dist/plugins/nx.test.js +15 -0
- package/dist/plugins/nyc/index.js +2 -3
- package/dist/plugins/nyc.test.d.ts +1 -0
- package/dist/plugins/nyc.test.js +10 -0
- package/dist/plugins/playwright/index.js +1 -1
- package/dist/plugins/playwright.test.d.ts +1 -0
- package/dist/plugins/playwright.test.js +20 -0
- package/dist/plugins/postcss/index.js +3 -7
- package/dist/plugins/postcss.test.d.ts +1 -0
- package/dist/plugins/postcss.test.js +33 -0
- package/dist/plugins/prettier/index.js +3 -5
- package/dist/plugins/prettier.test.d.ts +1 -0
- package/dist/plugins/prettier.test.js +10 -0
- package/dist/plugins/release-it/index.js +3 -4
- package/dist/plugins/release-it.test.d.ts +1 -0
- package/dist/plugins/release-it.test.js +10 -0
- package/dist/plugins/remark/index.js +1 -2
- package/dist/plugins/remark.test.d.ts +1 -0
- package/dist/plugins/remark.test.js +12 -0
- package/dist/plugins/remix.test.d.ts +1 -0
- package/dist/plugins/remix.test.js +39 -0
- package/dist/plugins/rollup.test.d.ts +1 -0
- package/dist/plugins/rollup.test.js +24 -0
- package/dist/plugins/semantic-release/index.d.ts +6 -0
- package/dist/plugins/semantic-release/index.js +17 -0
- package/dist/plugins/semantic-release/types.d.ts +3 -0
- package/dist/plugins/semantic-release/types.js +1 -0
- package/dist/plugins/semantic-release.test.d.ts +1 -0
- package/dist/plugins/semantic-release.test.js +31 -0
- package/dist/plugins/sentry.test.d.ts +1 -0
- package/dist/plugins/sentry.test.js +14 -0
- package/dist/plugins/storybook/index.js +5 -26
- package/dist/plugins/storybook.test.d.ts +1 -0
- package/dist/plugins/storybook.test.js +18 -0
- package/dist/plugins/stryker/index.js +2 -3
- package/dist/plugins/stryker.test.d.ts +1 -0
- package/dist/plugins/stryker.test.js +44 -0
- package/dist/plugins/svelte/index.d.ts +7 -0
- package/dist/plugins/svelte/index.js +9 -0
- package/dist/plugins/svelte.test.d.ts +1 -0
- package/dist/plugins/svelte.test.js +21 -0
- package/dist/plugins/typedoc/index.js +5 -6
- package/dist/plugins/typedoc/types.d.ts +1 -1
- package/dist/plugins/typedoc.test.d.ts +1 -0
- package/dist/plugins/typedoc.test.js +14 -0
- package/dist/plugins/typescript/index.js +3 -5
- package/dist/plugins/vitest/index.d.ts +0 -1
- package/dist/plugins/vitest/index.js +2 -4
- package/dist/plugins/vitest.test.d.ts +1 -0
- package/dist/plugins/vitest.test.js +17 -0
- package/dist/plugins/webpack/index.js +14 -24
- package/dist/plugins/webpack.test.d.ts +1 -0
- package/dist/plugins/webpack.test.js +56 -0
- package/dist/principal-factory.d.ts +0 -1
- package/dist/principal-factory.js +10 -10
- package/dist/project-principal.d.ts +5 -3
- package/dist/project-principal.js +22 -13
- package/dist/re-exports.test.d.ts +1 -0
- package/dist/re-exports.test.js +18 -0
- package/dist/react.test.d.ts +1 -0
- package/dist/react.test.js +19 -0
- package/dist/reporters/codeowners.js +4 -5
- package/dist/reporters/json.js +3 -4
- package/dist/reporters/symbols.js +2 -2
- package/dist/reporters/util.js +3 -3
- package/dist/self-reference-from-plugin.test.d.ts +1 -0
- package/dist/self-reference-from-plugin.test.js +47 -0
- package/dist/self-reference.test.d.ts +1 -0
- package/dist/self-reference.test.js +46 -0
- package/dist/source-lab.d.ts +21 -0
- package/dist/source-lab.js +135 -0
- package/dist/tsconfig-paths-extends.test.d.ts +1 -0
- package/dist/tsconfig-paths-extends.test.js +18 -0
- package/dist/tsconfig-paths-implicit.test.d.ts +1 -0
- package/dist/tsconfig-paths-implicit.test.js +18 -0
- package/dist/tsconfig-paths.test.d.ts +1 -0
- package/dist/tsconfig-paths.test.js +26 -0
- package/dist/types/plugins.d.ts +1 -4
- package/dist/typescript/SourceFileManager.js +3 -3
- package/dist/typescript/ast-helpers.d.ts +1 -0
- package/dist/typescript/ast-helpers.js +1 -0
- package/dist/typescript/ast-walker.d.ts +5 -3
- package/dist/typescript/ast-walker.js +42 -27
- package/dist/typescript/createHosts.js +4 -2
- package/dist/typescript/resolveModuleNames.js +2 -3
- package/dist/util/array.d.ts +1 -0
- package/dist/util/array.js +7 -0
- package/dist/util/binaries/resolvers/node.js +2 -3
- package/dist/util/find-import-specifiers.d.ts +5 -0
- package/dist/util/find-import-specifiers.js +48 -0
- package/dist/util/fs.d.ts +4 -1
- package/dist/util/fs.js +18 -13
- package/dist/util/get-included-issue-types.d.ts +16 -0
- package/dist/util/get-included-issue-types.js +30 -0
- package/dist/util/get-included-issue-types.test.d.ts +1 -0
- package/dist/util/get-included-issue-types.test.js +70 -0
- package/dist/util/getReferencesFromScripts.test.d.ts +1 -0
- package/dist/util/getReferencesFromScripts.test.js +126 -0
- package/dist/util/glob.js +4 -5
- package/dist/util/loader.js +9 -7
- package/dist/util/log.d.ts +1 -0
- package/dist/util/log.js +1 -0
- package/dist/util/members.d.ts +3 -0
- package/dist/util/members.js +25 -0
- package/dist/util/module.test.d.ts +1 -0
- package/dist/util/module.test.js +12 -0
- package/dist/util/modules.d.ts +1 -1
- package/dist/util/modules.js +4 -8
- package/dist/util/os.d.ts +1 -0
- package/dist/util/os.js +1 -0
- package/dist/util/path.d.ts +8 -2
- package/dist/util/path.js +9 -4
- package/dist/util/plugin.d.ts +1 -1
- package/dist/util/plugin.js +3 -6
- package/dist/util/project.d.ts +13 -0
- package/dist/util/project.js +48 -0
- package/dist/util/require.d.ts +3 -2
- package/dist/util/require.js +23 -6
- package/dist/util/resolve-included-issue-types.js +1 -1
- package/dist/util/tsconfig-loader.d.ts +2 -1
- package/dist/util/tsconfig-loader.js +4 -1
- package/dist/util/type.d.ts +2 -0
- package/dist/util/type.js +9 -0
- package/dist/util/workspace.test.d.ts +1 -0
- package/dist/util/workspace.test.js +13 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace-worker.d.ts +22 -22
- package/dist/workspace-worker.js +50 -48
- package/dist/workspaces-nested.test.d.ts +1 -0
- package/dist/workspaces-nested.test.js +44 -0
- package/dist/workspaces-paths.test.d.ts +1 -0
- package/dist/workspaces-paths.test.js +21 -0
- package/dist/workspaces-pnpm.test.d.ts +1 -0
- package/dist/workspaces-pnpm.test.js +21 -0
- package/dist/workspaces.test.d.ts +1 -0
- package/dist/workspaces.test.js +56 -0
- package/dist/zero-config.test.d.ts +1 -0
- package/dist/zero-config.test.js +37 -0
- package/package.json +20 -18
- package/schema.json +19 -1
- package/dist/progress-updater.d.ts +0 -13
- package/dist/progress-updater.js +0 -22
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ for the full story.
|
|
|
40
40
|
## Issues
|
|
41
41
|
|
|
42
42
|
Are you seeing false positives? Please report them by [opening an issue in this repo][9]. Bonus points for linking to a
|
|
43
|
-
public repository using Knip, or even opening a pull request with a directory and example files in `
|
|
43
|
+
public repository using Knip, or even opening a pull request with a directory and example files in `tests/fixtures`.
|
|
44
44
|
Correctness and bug fixes have priority over performance and new features.
|
|
45
45
|
|
|
46
46
|
Also see the [FAQ][10].
|
|
@@ -59,19 +59,19 @@ with a configuration file (or a `knip` property in `package.json`). Here's a `kn
|
|
|
59
59
|
```json
|
|
60
60
|
{
|
|
61
61
|
"$schema": "https://unpkg.com/knip@next/schema.json",
|
|
62
|
-
"entry": ["index.{js,mjs,cjs,jsx,ts,tsx}", "src/index.{js,mjs,cjs,jsx,ts,tsx}"],
|
|
63
|
-
"project": ["**/*.{js,mjs,cjs,jsx,ts,tsx}"]
|
|
62
|
+
"entry": ["index.{js,mjs,cjs,jsx,ts,tsx,mts,cts}", "src/index.{js,mjs,cjs,jsx,ts,tsx,mts,cts}"],
|
|
63
|
+
"project": ["**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}"]
|
|
64
64
|
}
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
If this matches your project, you don't need any configuration. But let's say you are using `.ts` files excusively and
|
|
68
|
-
have all source files in the `
|
|
68
|
+
have all source files only in the `src` directory:
|
|
69
69
|
|
|
70
70
|
```json
|
|
71
71
|
{
|
|
72
72
|
"$schema": "https://unpkg.com/knip@next/schema.json",
|
|
73
|
-
"entry": ["
|
|
74
|
-
"project": ["
|
|
73
|
+
"entry": ["src/index.ts"],
|
|
74
|
+
"project": ["src/**/*.ts"]
|
|
75
75
|
}
|
|
76
76
|
```
|
|
77
77
|
|
|
@@ -196,8 +196,8 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
196
196
|
|
|
197
197
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
198
198
|
|
|
199
|
-
Still not happy with the results? Getting too much output/false positives? The [FAQ][
|
|
200
|
-
an issue and I'm happy to look into it. Also see the next section on how to [ignore][11] certain false positives:
|
|
199
|
+
Still not happy with the results? Getting too much output/false positives? The [FAQ][10] may be useful. Feel free to
|
|
200
|
+
open an issue and I'm happy to look into it. Also see the next section on how to [ignore][11] certain false positives:
|
|
201
201
|
|
|
202
202
|
## Ignore
|
|
203
203
|
|
|
@@ -281,38 +281,42 @@ Use `--debug` to get more verbose output.
|
|
|
281
281
|
|
|
282
282
|
Knip contains a growing list of plugins:
|
|
283
283
|
|
|
284
|
-
- [
|
|
285
|
-
- [
|
|
286
|
-
- [
|
|
287
|
-
- [
|
|
288
|
-
- [
|
|
289
|
-
- [
|
|
290
|
-
- [
|
|
291
|
-
- [
|
|
292
|
-
- [
|
|
293
|
-
- [
|
|
294
|
-
- [
|
|
295
|
-
- [
|
|
296
|
-
- [
|
|
297
|
-
- [
|
|
298
|
-
- [
|
|
299
|
-
- [
|
|
300
|
-
- [
|
|
301
|
-
- [
|
|
302
|
-
- [
|
|
303
|
-
- [
|
|
304
|
-
- [
|
|
305
|
-
- [
|
|
306
|
-
- [
|
|
307
|
-
- [
|
|
308
|
-
- [
|
|
309
|
-
- [
|
|
310
|
-
- [
|
|
311
|
-
- [
|
|
312
|
-
- [
|
|
313
|
-
- [
|
|
314
|
-
- [
|
|
315
|
-
- [
|
|
284
|
+
- [Ava][plugin-ava]
|
|
285
|
+
- [Babel][plugin-babel]
|
|
286
|
+
- [Capacitor][plugin-capacitor]
|
|
287
|
+
- [Changesets][plugin-changesets]
|
|
288
|
+
- [commitlint][plugin-commitlint]
|
|
289
|
+
- [cspell][plugin-cspell]
|
|
290
|
+
- [Cypress][plugin-cypress]
|
|
291
|
+
- [ESLint][plugin-eslint]
|
|
292
|
+
- [Gatsby][plugin-gatsby]
|
|
293
|
+
- [GitHub Actions][plugin-github-actions]
|
|
294
|
+
- [husky][plugin-husky]
|
|
295
|
+
- [Jest][plugin-jest]
|
|
296
|
+
- [Lefthook][plugin-lefthook]
|
|
297
|
+
- [lint-staged][plugin-lint-staged]
|
|
298
|
+
- [markdownlint][plugin-markdownlint]
|
|
299
|
+
- [Mocha][plugin-mocha]
|
|
300
|
+
- [Next.js][plugin-next]
|
|
301
|
+
- [npm-package-json-lint][plugin-npm-package-json-lint]
|
|
302
|
+
- [Nx][plugin-nx]
|
|
303
|
+
- [nyc][plugin-nyc]
|
|
304
|
+
- [Playwright][plugin-playwright]
|
|
305
|
+
- [PostCSS][plugin-postcss]
|
|
306
|
+
- [Prettier][plugin-prettier]
|
|
307
|
+
- [Release It][plugin-release-it]
|
|
308
|
+
- [Remark][plugin-remark]
|
|
309
|
+
- [Remix][plugin-remix]
|
|
310
|
+
- [Rollup][plugin-rollup]
|
|
311
|
+
- [Semantic Release][plugin-semantic-release]
|
|
312
|
+
- [Sentry][plugin-sentry]
|
|
313
|
+
- [Storybook][plugin-storybook]
|
|
314
|
+
- [Stryker][plugin-stryker]
|
|
315
|
+
- [Svelte][plugin-svelte]
|
|
316
|
+
- [TypeDoc][plugin-typedoc]
|
|
317
|
+
- [TypeScript][plugin-typescript]
|
|
318
|
+
- [Vitest][plugin-vitest]
|
|
319
|
+
- [Webpack][plugin-webpack]
|
|
316
320
|
|
|
317
321
|
Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
|
|
318
322
|
whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
|
|
@@ -320,25 +324,16 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
|
|
|
320
324
|
|
|
321
325
|
Most plugins use one or both of the following file types:
|
|
322
326
|
|
|
323
|
-
- `config` - custom dependency resolvers are applied to the [config files][
|
|
327
|
+
- `config` - custom dependency resolvers are applied to the [config files][12]
|
|
324
328
|
- `entry` - files to include with the analysis of the rest of the source code
|
|
325
329
|
|
|
326
330
|
See each plugin's documentation for its default values.
|
|
327
331
|
|
|
328
332
|
### `config`
|
|
329
333
|
|
|
330
|
-
Plugins may include `config` files. They are parsed by the plugin's custom dependency
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
- The `eslint` plugin tells Knip that the `"prettier"` entry in the array of `plugins` means that the
|
|
334
|
-
`eslint-plugin-prettier` dependency should be installed. Or that the `"airbnb"` entry in `extends` requires the
|
|
335
|
-
`eslint-config-airbnb` dependency.
|
|
336
|
-
- The `storybook` plugin understands that `core.builder: 'webpack5'` in `main.js` means that the
|
|
337
|
-
`@storybook/builder-webpack5` and `@storybook/manager-webpack5` dependencies are required.
|
|
338
|
-
- Static configuration files such as JSON and YAML always require a custom dependency resolver.
|
|
339
|
-
|
|
340
|
-
Custom dependency resolvers return all referenced dependencies for the configuration files it is given. Knip handles the
|
|
341
|
-
rest to find which of those dependencies are unused or missing.
|
|
334
|
+
Plugins may include `config` files. They are parsed by the plugin's custom dependency finder. Custom dependency finders
|
|
335
|
+
return all dependencies referenced in the configuration files it is given. Knip handles the rest to determine which of
|
|
336
|
+
those dependencies are unused or missing.
|
|
342
337
|
|
|
343
338
|
### `entry`
|
|
344
339
|
|
|
@@ -351,15 +346,13 @@ In case a plugin causes issues, it can be disabled by using `false` as its value
|
|
|
351
346
|
|
|
352
347
|
### Create a new plugin
|
|
353
348
|
|
|
354
|
-
Getting false positives because a plugin is missing? Want to help out?
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
npm run create-plugin -- --name [myplugin]
|
|
349
|
+
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][13]. This
|
|
350
|
+
guide also contains more details if you want to learn more about plugins and why they are useful.
|
|
358
351
|
|
|
359
352
|
## Compilers
|
|
360
353
|
|
|
361
354
|
Knip v2 introduces compilers which allows to include files that are not JavaScript or TypeScript in the process of
|
|
362
|
-
finding unused or missing dependencies.
|
|
355
|
+
finding unused or missing dependencies. For instance, `.mdx`, `.vue` and `.svelte` files come to mind.
|
|
363
356
|
|
|
364
357
|
Currently this is only supported by using `knip.js` or `knip.ts`. Provide a `compilers` object in the configuration
|
|
365
358
|
where each key represents the extension and the value is a function that takes the contents of these files as input and
|
|
@@ -375,6 +368,8 @@ export default {
|
|
|
375
368
|
};
|
|
376
369
|
```
|
|
377
370
|
|
|
371
|
+
Read [Compilers][14] for more details and examples.
|
|
372
|
+
|
|
378
373
|
## Production Mode
|
|
379
374
|
|
|
380
375
|
The default mode for Knip is holistic and targets all project code, including configuration files and tests. Test files
|
|
@@ -403,17 +398,16 @@ Here's what's included in production mode analysis:
|
|
|
403
398
|
|
|
404
399
|
Additionally, the `--strict` flag can be used to:
|
|
405
400
|
|
|
406
|
-
- Consider
|
|
407
|
-
-
|
|
408
|
-
-
|
|
409
|
-
|
|
401
|
+
- Consider `dependencies` (not `devDependencies`) when finding unused or unlisted dependencies.
|
|
402
|
+
- Include `peerDependencies` when finding unused or unlisted dependencies.
|
|
403
|
+
- Ignore type-only imports (`import type {}`).
|
|
404
|
+
- Verify each workspace is self-contained: have their own `dependencies` (and not use packages of ancestor workspaces).
|
|
410
405
|
|
|
411
406
|
### Plugins
|
|
412
407
|
|
|
413
408
|
Plugins also have this distinction. For instance, Next.js entry files for pages (`pages/**/*.tsx`) and Remix routes
|
|
414
|
-
(`app/routes/**/*.tsx`) are production code, while Jest and
|
|
415
|
-
this is handled automatically by Knip and its plugins.
|
|
416
|
-
locations. The more plugins Knip will have, the more projects can be analyzed out of the box!
|
|
409
|
+
(`app/routes/**/*.tsx`) are production code, while Jest and Storybook entry files (e.g. `*.spec.ts` or `*.stories.js`)
|
|
410
|
+
are not. All of this is handled automatically by Knip and its plugins.
|
|
417
411
|
|
|
418
412
|
## Paths
|
|
419
413
|
|
|
@@ -440,10 +434,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
|
|
|
440
434
|
|
|
441
435
|
Knip provides the following built-in reporters:
|
|
442
436
|
|
|
443
|
-
-
|
|
444
|
-
-
|
|
445
|
-
-
|
|
446
|
-
-
|
|
437
|
+
- codeowners
|
|
438
|
+
- compact
|
|
439
|
+
- json
|
|
440
|
+
- symbol
|
|
447
441
|
|
|
448
442
|
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
449
443
|
|
|
@@ -470,13 +464,12 @@ type ReporterOptions = {
|
|
|
470
464
|
|
|
471
465
|
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
472
466
|
|
|
473
|
-
Find more details and ideas in [custom reporters][
|
|
467
|
+
Find more details and ideas in [custom reporters][15].
|
|
474
468
|
|
|
475
|
-
##
|
|
469
|
+
## Public exports
|
|
476
470
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
in libraries can be marked with the JSDoc `@public` tag:
|
|
471
|
+
Sometimes a file that's not an entry file has one or more exports that are public, and should not be reported as unused.
|
|
472
|
+
Such variables and types can be marked with the JSDoc `@public` tag:
|
|
480
473
|
|
|
481
474
|
```js
|
|
482
475
|
/**
|
|
@@ -528,7 +521,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
|
|
|
528
521
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
529
522
|
to match the custom location(s).
|
|
530
523
|
|
|
531
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
524
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][16].
|
|
532
525
|
|
|
533
526
|
#### Too many unused exports
|
|
534
527
|
|
|
@@ -536,7 +529,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
536
529
|
|
|
537
530
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
538
531
|
add the containing file to the `entry` array in the configuration.
|
|
539
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
532
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][17]
|
|
540
533
|
|
|
541
534
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
542
535
|
|
|
@@ -556,22 +549,23 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
556
549
|
|
|
557
550
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
558
551
|
|
|
559
|
-
| Feature
|
|
560
|
-
|
|
|
561
|
-
| Unused files
|
|
562
|
-
| Unused dependencies
|
|
563
|
-
| Unlisted dependencies
|
|
564
|
-
| [Plugins][
|
|
565
|
-
|
|
|
566
|
-
| Unused
|
|
567
|
-
| Unused
|
|
568
|
-
|
|
|
569
|
-
|
|
|
570
|
-
|
|
|
571
|
-
|
|
|
572
|
-
|
|
|
573
|
-
|
|
|
574
|
-
|
|
|
552
|
+
| Feature | **knip** | [depcheck][18] | [unimported][19] | [ts-unused-exports][20] | [ts-prune][21] |
|
|
553
|
+
| :-------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
554
|
+
| Unused files | ✅ | - | ✅ | - | - |
|
|
555
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
556
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - |
|
|
557
|
+
| [Plugins][2] | ✅ | ✅ | ❌ | - | - |
|
|
558
|
+
| [Compilers][3] | ✅ | - | - | - | - |
|
|
559
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ |
|
|
560
|
+
| Unused class members | ✅ | - | - | - | - |
|
|
561
|
+
| Unused enum members | ✅ | - | - | - | - |
|
|
562
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ |
|
|
563
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ |
|
|
564
|
+
| Custom reporters | ✅ | - | - | - | - |
|
|
565
|
+
| JavaScript support | ✅ | ✅ | ✅ | - | - |
|
|
566
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
567
|
+
| [Support workspaces/monorepos][1] | ✅ | ❌ | ❌ | - | - |
|
|
568
|
+
| ESLint plugin available | - | - | - | ✅ | - |
|
|
575
569
|
|
|
576
570
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
577
571
|
|
|
@@ -591,7 +585,7 @@ The following commands are similar:
|
|
|
591
585
|
unimported
|
|
592
586
|
knip --production --dependencies --include files
|
|
593
587
|
|
|
594
|
-
Also see [production mode][
|
|
588
|
+
Also see [production mode][22].
|
|
595
589
|
|
|
596
590
|
### ts-unused-exports
|
|
597
591
|
|
|
@@ -609,13 +603,6 @@ The following commands are similar:
|
|
|
609
603
|
knip --include exports,types
|
|
610
604
|
knip --exports # Adds unused exports/types in namespaces and unused enum/class members
|
|
611
605
|
|
|
612
|
-
## TypeScript language services
|
|
613
|
-
|
|
614
|
-
TypeScript language services could play a major role in most of the "unused" areas, as they have an overview of the
|
|
615
|
-
project as a whole. This powers things in VS Code like "Find references" or the "Module "./some" declares 'Thing'
|
|
616
|
-
locally, but it is not exported" message. I think features like "duplicate exports" or "custom dependency resolvers" are
|
|
617
|
-
userland territory, much like code linters.
|
|
618
|
-
|
|
619
606
|
## Knip?!
|
|
620
607
|
|
|
621
608
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
@@ -632,48 +619,50 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
632
619
|
[9]: https://github.com/webpro/knip/issues
|
|
633
620
|
[10]: #faq
|
|
634
621
|
[11]: #ignore
|
|
635
|
-
[12]:
|
|
636
|
-
[13]: ./
|
|
637
|
-
[14]: ./
|
|
638
|
-
[15]: ./
|
|
639
|
-
[16]:
|
|
640
|
-
[17]:
|
|
641
|
-
[18]:
|
|
642
|
-
[19]:
|
|
643
|
-
[20]:
|
|
644
|
-
[21]:
|
|
645
|
-
[22]:
|
|
646
|
-
[
|
|
647
|
-
[
|
|
648
|
-
[
|
|
649
|
-
[
|
|
650
|
-
[
|
|
651
|
-
[
|
|
652
|
-
[
|
|
653
|
-
[
|
|
654
|
-
[
|
|
655
|
-
[
|
|
656
|
-
[
|
|
657
|
-
[
|
|
658
|
-
[
|
|
659
|
-
[
|
|
660
|
-
[
|
|
661
|
-
[
|
|
662
|
-
[
|
|
663
|
-
[
|
|
664
|
-
[
|
|
665
|
-
[
|
|
666
|
-
[
|
|
667
|
-
[
|
|
668
|
-
[
|
|
669
|
-
[
|
|
670
|
-
[
|
|
671
|
-
[
|
|
672
|
-
[
|
|
673
|
-
[
|
|
674
|
-
[
|
|
675
|
-
[
|
|
676
|
-
[
|
|
677
|
-
[
|
|
678
|
-
[
|
|
679
|
-
[
|
|
622
|
+
[12]: #config
|
|
623
|
+
[13]: ./docs/writing-a-plugin.md
|
|
624
|
+
[14]: ./docs/compilers.md
|
|
625
|
+
[15]: ./docs/custom-reporters.md
|
|
626
|
+
[16]: #create-a-new-plugin
|
|
627
|
+
[17]: #public-exports
|
|
628
|
+
[18]: https://github.com/depcheck/depcheck
|
|
629
|
+
[19]: https://github.com/smeijer/unimported
|
|
630
|
+
[20]: https://github.com/pzavolinsky/ts-unused-exports
|
|
631
|
+
[21]: https://github.com/nadeesha/ts-prune
|
|
632
|
+
[22]: #production-mode
|
|
633
|
+
[plugin-ava]: ./src/plugins/ava
|
|
634
|
+
[plugin-babel]: ./src/plugins/babel
|
|
635
|
+
[plugin-capacitor]: ./src/plugins/capacitor
|
|
636
|
+
[plugin-changesets]: ./src/plugins/changesets
|
|
637
|
+
[plugin-commitlint]: ./src/plugins/commitlint
|
|
638
|
+
[plugin-cspell]: ./src/plugins/cspell
|
|
639
|
+
[plugin-cypress]: ./src/plugins/cypress
|
|
640
|
+
[plugin-eslint]: ./src/plugins/eslint
|
|
641
|
+
[plugin-gatsby]: ./src/plugins/gatsby
|
|
642
|
+
[plugin-github-actions]: ./src/plugins/github-actions
|
|
643
|
+
[plugin-husky]: ./src/plugins/husky
|
|
644
|
+
[plugin-jest]: ./src/plugins/jest
|
|
645
|
+
[plugin-lefthook]: ./src/plugins/lefthook
|
|
646
|
+
[plugin-lint-staged]: ./src/plugins/lint-staged
|
|
647
|
+
[plugin-markdownlint]: ./src/plugins/markdownlint
|
|
648
|
+
[plugin-mocha]: ./src/plugins/mocha
|
|
649
|
+
[plugin-next]: ./src/plugins/next
|
|
650
|
+
[plugin-npm-package-json-lint]: ./src/plugins/npm-package-json-lint
|
|
651
|
+
[plugin-nx]: ./src/plugins/nx
|
|
652
|
+
[plugin-nyc]: ./src/plugins/nyc
|
|
653
|
+
[plugin-playwright]: ./src/plugins/playwright
|
|
654
|
+
[plugin-postcss]: ./src/plugins/postcss
|
|
655
|
+
[plugin-prettier]: ./src/plugins/prettier
|
|
656
|
+
[plugin-release-it]: ./src/plugins/release-it
|
|
657
|
+
[plugin-remark]: ./src/plugins/remark
|
|
658
|
+
[plugin-remix]: ./src/plugins/remix
|
|
659
|
+
[plugin-rollup]: ./src/plugins/rollup
|
|
660
|
+
[plugin-semantic-release]: ./src/plugins/semantic-release
|
|
661
|
+
[plugin-sentry]: ./src/plugins/sentry
|
|
662
|
+
[plugin-storybook]: ./src/plugins/storybook
|
|
663
|
+
[plugin-stryker]: ./src/plugins/stryker
|
|
664
|
+
[plugin-svelte]: ./src/plugins/svelte
|
|
665
|
+
[plugin-typedoc]: ./src/plugins/typedoc
|
|
666
|
+
[plugin-typescript]: ./src/plugins/typescript
|
|
667
|
+
[plugin-vitest]: ./src/plugins/vitest
|
|
668
|
+
[plugin-webpack]: ./src/plugins/webpack
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import parse from 'bash-parser';
|
|
2
|
+
import parseArgs from 'minimist';
|
|
3
|
+
import * as FallbackResolver from './resolvers/fallback.js';
|
|
4
|
+
import * as KnownResolvers from './resolvers/index.js';
|
|
5
|
+
const spawningBinaries = ['cross-env', 'dotenv'];
|
|
6
|
+
export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly = false }) => {
|
|
7
|
+
if (!script)
|
|
8
|
+
return [];
|
|
9
|
+
const fromArgs = (args) => getBinariesFromScript(args.join(' '), { cwd, manifest });
|
|
10
|
+
const getBinariesFromNodes = (nodes) => nodes.flatMap(node => {
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Command': {
|
|
13
|
+
const binary = node.name?.text;
|
|
14
|
+
const commandExpansions = node.prefix?.flatMap(prefix => prefix.expansion?.filter(expansion => expansion.type === 'CommandExpansion') ?? []) ?? [];
|
|
15
|
+
if (commandExpansions.length > 0) {
|
|
16
|
+
return commandExpansions.flatMap(expansion => getBinariesFromNodes(expansion.commandAST.commands)) ?? [];
|
|
17
|
+
}
|
|
18
|
+
if (!binary || binary === '.' || binary === 'source')
|
|
19
|
+
return [];
|
|
20
|
+
if (binary.startsWith('-') || binary.startsWith('"') || binary.startsWith('..'))
|
|
21
|
+
return [];
|
|
22
|
+
if (['bun', 'deno'].includes(binary))
|
|
23
|
+
return [];
|
|
24
|
+
const args = node.suffix?.map(arg => arg.text) ?? [];
|
|
25
|
+
if (['!', 'test'].includes(binary))
|
|
26
|
+
return fromArgs(args);
|
|
27
|
+
if (binary in KnownResolvers) {
|
|
28
|
+
return KnownResolvers[binary].resolve(binary, args, { cwd, manifest, fromArgs });
|
|
29
|
+
}
|
|
30
|
+
if (knownGlobalsOnly)
|
|
31
|
+
return [];
|
|
32
|
+
if (spawningBinaries.includes(binary)) {
|
|
33
|
+
const parsedArgs = parseArgs(args);
|
|
34
|
+
const [spawnedBinary] = parsedArgs._;
|
|
35
|
+
if (spawnedBinary) {
|
|
36
|
+
const restArgs = args.slice(args.indexOf(spawnedBinary));
|
|
37
|
+
return [binary, ...fromArgs(restArgs)];
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return FallbackResolver.resolve(binary, args, { cwd, manifest, fromArgs });
|
|
44
|
+
}
|
|
45
|
+
case 'LogicalExpression':
|
|
46
|
+
return getBinariesFromNodes([node.left, node.right]);
|
|
47
|
+
case 'If':
|
|
48
|
+
return getBinariesFromNodes([...node.clause.commands, ...node.then.commands]);
|
|
49
|
+
case 'For':
|
|
50
|
+
return getBinariesFromNodes(node.do.commands);
|
|
51
|
+
default:
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
const parsed = parse(script);
|
|
56
|
+
return parsed?.commands ? getBinariesFromNodes(parsed.commands) : [];
|
|
57
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IGNORED_GLOBAL_BINARIES } from '../constants.js';
|
|
2
|
+
import { compact } from '../util/array.js';
|
|
3
|
+
import { partition } from '../util/array.js';
|
|
4
|
+
import { getPackageNameFromModuleSpecifier, stripBinary } from '../util/modules.js';
|
|
5
|
+
import { isInternal } from '../util/path.js';
|
|
6
|
+
import { timerify } from '../util/performance.js';
|
|
7
|
+
import { getBinariesFromScript } from './bash-parser.js';
|
|
8
|
+
const defaultCwd = process.cwd();
|
|
9
|
+
const getReferencesFromScripts = (npmScripts, options = {}) => {
|
|
10
|
+
const { cwd = defaultCwd, manifest = {}, ignore = [], knownGlobalsOnly = false } = options;
|
|
11
|
+
const scripts = [npmScripts].flat();
|
|
12
|
+
const results = scripts.flatMap(script => getBinariesFromScript(script, { cwd, manifest, knownGlobalsOnly }));
|
|
13
|
+
const [entryFiles, binaries] = partition(compact(results), isInternal);
|
|
14
|
+
return {
|
|
15
|
+
entryFiles,
|
|
16
|
+
binaries: binaries
|
|
17
|
+
.map(stripBinary)
|
|
18
|
+
.map(getPackageNameFromModuleSpecifier)
|
|
19
|
+
.filter(binaryName => !IGNORED_GLOBAL_BINARIES.includes(binaryName) && !ignore.includes(binaryName)),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export const _getReferencesFromScripts = timerify(getReferencesFromScripts);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
import { tryResolveFilePaths } from './node.js';
|
|
3
|
+
const argResolvers = {
|
|
4
|
+
'babel-node': parsed => [parsed._[0], parsed.require].flat(),
|
|
5
|
+
'ts-node': parsed => [parsed._[0], parsed.require].flat(),
|
|
6
|
+
tsx: parsed => parsed._.filter(p => p !== 'watch'),
|
|
7
|
+
default: parsed => [parsed.require].flat(),
|
|
8
|
+
};
|
|
9
|
+
export const resolve = (binary, args, { cwd }) => {
|
|
10
|
+
const parsed = parseArgs(args, { string: ['r'], alias: { require: ['r', 'loader'] } });
|
|
11
|
+
const resolver = argResolvers[binary] ?? argResolvers.default;
|
|
12
|
+
const resolve = resolver(parsed);
|
|
13
|
+
return [binary, ...tryResolveFilePaths(cwd, resolve)];
|
|
14
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
import { isInNodeModules, join } from '../../util/path.js';
|
|
3
|
+
import { _tryResolve } from '../../util/require.js';
|
|
4
|
+
const tryResolveFilePath = (cwd, specifier, fallback) => {
|
|
5
|
+
if (specifier) {
|
|
6
|
+
const filePath = join(cwd, specifier);
|
|
7
|
+
if (!isInNodeModules(filePath)) {
|
|
8
|
+
const resolvedFilePath = _tryResolve(filePath, cwd);
|
|
9
|
+
if (resolvedFilePath)
|
|
10
|
+
return [resolvedFilePath];
|
|
11
|
+
}
|
|
12
|
+
return fallback ? [fallback] : [];
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
};
|
|
16
|
+
export const tryResolveFilePaths = (cwd, specifiers) => specifiers.flatMap(specifier => tryResolveFilePath(cwd, specifier, specifier));
|
|
17
|
+
export const resolve = (binary, args, { cwd }) => {
|
|
18
|
+
const parsed = parseArgs(args, { string: ['r'], alias: { require: ['r', 'loader', 'experimental-loader'] } });
|
|
19
|
+
return [...tryResolveFilePath(cwd, parsed._[0]), ...tryResolveFilePaths(cwd, [parsed.require].flat())];
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
export const resolve = (binary, args, { fromArgs }) => {
|
|
3
|
+
const parsed = parseArgs(args, { '--': true, stopEarly: true, boolean: ['yes', 'no'], alias: { yes: 'y', no: 'n' } });
|
|
4
|
+
return [...(parsed.yes ? [] : fromArgs(parsed._)), ...(parsed['--'] ? fromArgs(parsed['--']) : [])];
|
|
5
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
const commands = [
|
|
3
|
+
'add',
|
|
4
|
+
'dlx',
|
|
5
|
+
'run',
|
|
6
|
+
'i',
|
|
7
|
+
'install',
|
|
8
|
+
'up',
|
|
9
|
+
'update',
|
|
10
|
+
'upgrade',
|
|
11
|
+
'remove',
|
|
12
|
+
'rm',
|
|
13
|
+
'uninstall',
|
|
14
|
+
'un',
|
|
15
|
+
'link',
|
|
16
|
+
'ln',
|
|
17
|
+
'unlink',
|
|
18
|
+
'import',
|
|
19
|
+
'rebuild',
|
|
20
|
+
'rb',
|
|
21
|
+
'prune',
|
|
22
|
+
'fetch',
|
|
23
|
+
'install-test',
|
|
24
|
+
'it',
|
|
25
|
+
'patch',
|
|
26
|
+
'patch-commit',
|
|
27
|
+
'audit',
|
|
28
|
+
'list',
|
|
29
|
+
'ls',
|
|
30
|
+
'outdated',
|
|
31
|
+
'why',
|
|
32
|
+
'test',
|
|
33
|
+
't',
|
|
34
|
+
'tst',
|
|
35
|
+
];
|
|
36
|
+
export const resolve = (binary, args, { manifest }) => {
|
|
37
|
+
const scripts = manifest.scripts ? Object.keys(manifest.scripts) : [];
|
|
38
|
+
const parsed = parseArgs(args, {});
|
|
39
|
+
const [command, result] = parsed._;
|
|
40
|
+
if (scripts.includes(command) || commands.includes(command))
|
|
41
|
+
return [];
|
|
42
|
+
if (command === 'exec')
|
|
43
|
+
return [result];
|
|
44
|
+
return command ? [command] : [];
|
|
45
|
+
};
|