knip 2.0.0-beta.0 → 2.0.0-beta.2
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 +168 -132
- package/dist/binaries/index.js +1 -0
- package/dist/binaries/resolvers/fallback.js +6 -5
- package/dist/binaries/resolvers/index.d.ts +1 -0
- package/dist/binaries/resolvers/index.js +1 -0
- package/dist/binaries/resolvers/node.d.ts +0 -1
- package/dist/binaries/resolvers/node.js +1 -15
- package/dist/binaries/resolvers/rollup.js +10 -0
- package/dist/binaries/resolvers/util.d.ts +2 -0
- package/dist/binaries/resolvers/util.js +15 -0
- package/dist/cli.js +0 -0
- package/dist/configuration-chief.js +3 -5
- package/dist/configuration-validator.d.ts +400 -8
- package/dist/configuration-validator.js +7 -0
- package/dist/constants.js +1 -1
- package/dist/index.js +12 -11
- package/dist/plugins/commitizen/index.d.ts +6 -0
- package/dist/plugins/commitizen/index.js +14 -0
- package/dist/plugins/commitizen/types.d.ts +3 -0
- package/dist/plugins/eslint/helpers.js +9 -9
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/project-principal.js +0 -2
- package/dist/types/ast.d.ts +1 -1
- package/dist/types/issues.d.ts +9 -1
- package/dist/types/issues.js +10 -1
- package/dist/typescript/ast-walker.js +29 -23
- package/dist/typescript/resolveModuleNames.js +0 -4
- package/dist/util/cli-arguments.d.ts +1 -2
- package/dist/util/cli-arguments.js +1 -3
- package/dist/util/compilers.d.ts +72 -2
- package/dist/util/performance.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspace-worker.d.ts +1 -1
- package/package.json +5 -3
- package/schema.json +4 -0
- package/dist/commonjs.test.js +0 -29
- package/dist/compilers.test.d.ts +0 -1
- package/dist/compilers.test.js +0 -18
- package/dist/definitely-typed.test.d.ts +0 -1
- package/dist/definitely-typed.test.js +0 -35
- package/dist/dependencies.test.d.ts +0 -1
- package/dist/dependencies.test.js +0 -76
- package/dist/entry-js.test.d.ts +0 -1
- package/dist/entry-js.test.js +0 -38
- package/dist/exports.test.d.ts +0 -1
- package/dist/exports.test.js +0 -48
- package/dist/fixtures/binaries/dir/index.d.ts +0 -1
- package/dist/fixtures/binaries/dir/index.js +0 -1
- package/dist/fixtures/binaries/main.d.ts +0 -1
- package/dist/fixtures/binaries/main.js +0 -1
- package/dist/fixtures/binaries/require.d.ts +0 -1
- package/dist/fixtures/binaries/require.js +0 -1
- package/dist/fixtures/binaries/script.d.ts +0 -1
- package/dist/fixtures/binaries/script.js +0 -1
- package/dist/fixtures/commonjs/dir/mod.d.ts +0 -1
- package/dist/fixtures/commonjs/dir/mod.js +0 -5
- package/dist/fixtures/commonjs/dir/mod1.d.ts +0 -7
- package/dist/fixtures/commonjs/dir/mod1.js +0 -5
- package/dist/fixtures/commonjs/dir/mod2.d.ts +0 -4
- package/dist/fixtures/commonjs/dir/mod2.js +0 -4
- package/dist/fixtures/commonjs/dir/mod3.d.ts +0 -2
- package/dist/fixtures/commonjs/dir/mod3.js +0 -4
- package/dist/fixtures/commonjs/export-is.d.ts +0 -2
- package/dist/fixtures/commonjs/export-is.js +0 -2
- package/dist/fixtures/commonjs/index.d.ts +0 -1
- package/dist/fixtures/commonjs/index.js +0 -31
- package/dist/fixtures/commonjs/odd.d.ts +0 -1
- package/dist/fixtures/commonjs/odd.js +0 -7
- package/dist/fixtures/compilers/component.d.ts +0 -2
- package/dist/fixtures/compilers/component.jsx +0 -1
- package/dist/fixtures/compilers/index.d.ts +0 -1
- package/dist/fixtures/compilers/index.js +0 -1
- package/dist/fixtures/compilers/knip.d.ts +0 -0
- package/dist/fixtures/compilers/knip.js +0 -7
- package/dist/fixtures/definitely-typed/index.d.ts +0 -1
- package/dist/fixtures/definitely-typed/index.js +0 -1
- package/dist/fixtures/dependencies/entry.d.ts +0 -1
- package/dist/fixtures/dependencies/entry.js +0 -6
- package/dist/fixtures/dependencies/my-module.d.ts +0 -3
- package/dist/fixtures/dependencies/my-module.js +0 -6
- package/dist/fixtures/dependencies/unused-module.d.ts +0 -1
- package/dist/fixtures/dependencies/unused-module.js +0 -6
- package/dist/fixtures/entry-js/dangling.d.ts +0 -1
- package/dist/fixtures/entry-js/dangling.js +0 -1
- package/dist/fixtures/entry-js/index.d.ts +0 -1
- package/dist/fixtures/entry-js/index.js +0 -2
- package/dist/fixtures/entry-js/my-module.d.ts +0 -4
- package/dist/fixtures/entry-js/my-module.js +0 -6
- package/dist/fixtures/entry-js/my-namespace.d.ts +0 -5
- package/dist/fixtures/entry-js/my-namespace.js +0 -3
- package/dist/fixtures/exports/dangling.d.ts +0 -1
- package/dist/fixtures/exports/dangling.js +0 -1
- package/dist/fixtures/exports/default-arrow-function.d.ts +0 -2
- package/dist/fixtures/exports/default-arrow-function.js +0 -1
- package/dist/fixtures/exports/default-class.d.ts +0 -2
- package/dist/fixtures/exports/default-class.js +0 -2
- package/dist/fixtures/exports/default-function.d.ts +0 -1
- package/dist/fixtures/exports/default-function.js +0 -1
- package/dist/fixtures/exports/default-generator-function.d.ts +0 -1
- package/dist/fixtures/exports/default-generator-function.js +0 -1
- package/dist/fixtures/exports/default-named-class.d.ts +0 -2
- package/dist/fixtures/exports/default-named-class.js +0 -2
- package/dist/fixtures/exports/default-named-function.d.ts +0 -1
- package/dist/fixtures/exports/default-named-function.js +0 -1
- package/dist/fixtures/exports/default-named-generator-function.d.ts +0 -1
- package/dist/fixtures/exports/default-named-generator-function.js +0 -1
- package/dist/fixtures/exports/default.d.ts +0 -3
- package/dist/fixtures/exports/default.js +0 -2
- package/dist/fixtures/exports/dynamic-import.d.ts +0 -4
- package/dist/fixtures/exports/dynamic-import.js +0 -3
- package/dist/fixtures/exports/index.d.ts +0 -2
- package/dist/fixtures/exports/index.js +0 -6
- package/dist/fixtures/exports/my-module.d.ts +0 -5
- package/dist/fixtures/exports/my-module.js +0 -7
- package/dist/fixtures/exports/my-namespace.d.ts +0 -5
- package/dist/fixtures/exports/my-namespace.js +0 -3
- package/dist/fixtures/exports/named.d.ts +0 -11
- package/dist/fixtures/exports/named.js +0 -11
- package/dist/fixtures/exports/types.d.ts +0 -9
- package/dist/fixtures/exports/types.js +0 -3
- package/dist/fixtures/gitignore/packages/a/build/dist.d.ts +0 -2
- package/dist/fixtures/gitignore/packages/a/build/dist.js +0 -1
- package/dist/fixtures/gitignore/packages/a/dist.d.ts +0 -1
- package/dist/fixtures/gitignore/packages/a/dist.js +0 -1
- package/dist/fixtures/gitignore/packages/a/index.d.ts +0 -1
- package/dist/fixtures/gitignore/packages/a/index.js +0 -1
- package/dist/fixtures/imports/dir/import-b.d.ts +0 -2
- package/dist/fixtures/imports/dir/import-b.js +0 -1
- package/dist/fixtures/imports/dir/mod.d.ts +0 -1
- package/dist/fixtures/imports/dir/mod.js +0 -1
- package/dist/fixtures/imports/index.d.ts +0 -1
- package/dist/fixtures/imports/index.js +0 -35
- package/dist/fixtures/js-only/dangling.d.ts +0 -1
- package/dist/fixtures/js-only/dangling.js +0 -1
- package/dist/fixtures/js-only/index.d.ts +0 -1
- package/dist/fixtures/js-only/index.js +0 -2
- package/dist/fixtures/js-only/my-namespace.d.ts +0 -3
- package/dist/fixtures/js-only/my-namespace.js +0 -3
- package/dist/fixtures/jsdoc/index.d.ts +0 -4
- package/dist/fixtures/jsdoc/index.js +0 -8
- package/dist/fixtures/members/index.d.ts +0 -1
- package/dist/fixtures/members/index.js +0 -16
- package/dist/fixtures/members/members.d.ts +0 -23
- package/dist/fixtures/members/members.js +0 -38
- package/dist/fixtures/namespace/index.d.ts +0 -1
- package/dist/fixtures/namespace/index.js +0 -5
- package/dist/fixtures/namespace/namespace.d.ts +0 -3
- package/dist/fixtures/namespace/namespace.js +0 -3
- package/dist/fixtures/namespace/re-exported-module.d.ts +0 -2
- package/dist/fixtures/namespace/re-exported-module.js +0 -2
- package/dist/fixtures/pathless/src/dir/module-a.d.ts +0 -2
- package/dist/fixtures/pathless/src/dir/module-a.js +0 -1
- package/dist/fixtures/pathless/src/index.d.ts +0 -2
- package/dist/fixtures/pathless/src/index.js +0 -2
- package/dist/fixtures/pathless/src/same.d.ts +0 -2
- package/dist/fixtures/pathless/src/same.js +0 -1
- package/dist/fixtures/paths-knip-config/abc/main.d.ts +0 -0
- package/dist/fixtures/paths-knip-config/abc/main.js +0 -1
- package/dist/fixtures/paths-knip-config/index.d.ts +0 -1
- package/dist/fixtures/paths-knip-config/index.js +0 -1
- package/dist/fixtures/paths-knip-config/knip.d.ts +0 -3
- package/dist/fixtures/paths-knip-config/knip.js +0 -9
- package/dist/fixtures/paths-knip-config/lib/fn.d.ts +0 -2
- package/dist/fixtures/paths-knip-config/lib/fn.js +0 -1
- package/dist/fixtures/paths-knip-config/lib/index.d.ts +0 -2
- package/dist/fixtures/paths-knip-config/lib/index.js +0 -1
- package/dist/fixtures/paths-knip-config/my-module.d.ts +0 -2
- package/dist/fixtures/paths-knip-config/my-module.js +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/index.d.ts +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/index.js +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/lib/fn.d.ts +0 -2
- package/dist/fixtures/paths-knip-config-workspaces/lib/fn.js +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/lib/index.d.ts +0 -2
- package/dist/fixtures/paths-knip-config-workspaces/lib/index.js +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/my-module.d.ts +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/my-module.js +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/ws/index.d.ts +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/ws/index.js +0 -1
- 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 +0 -1
- package/dist/fixtures/paths-knip-config-workspaces/ws/util/lang.d.ts +0 -2
- package/dist/fixtures/paths-knip-config-workspaces/ws/util/lang.js +0 -1
- package/dist/fixtures/peer-dependencies/index.d.ts +0 -1
- package/dist/fixtures/peer-dependencies/index.js +0 -1
- package/dist/fixtures/plugins/ava/ava.config.d.mts +0 -13
- package/dist/fixtures/plugins/ava/ava.config.mjs +0 -13
- package/dist/fixtures/plugins/babel/babel.config.d.ts +0 -14
- package/dist/fixtures/plugins/babel/babel.config.js +0 -47
- package/dist/fixtures/plugins/capacitor/capacitor.config.d.ts +0 -3
- package/dist/fixtures/plugins/capacitor/capacitor.config.js +0 -15
- package/dist/fixtures/plugins/commitlint/commitlint.config.d.ts +0 -2
- package/dist/fixtures/plugins/commitlint/commitlint.config.js +0 -2
- package/dist/fixtures/plugins/cypress/cypress/support/commands.d.ts +0 -1
- package/dist/fixtures/plugins/cypress/cypress/support/commands.js +0 -5
- package/dist/fixtures/plugins/cypress/cypress/support/e2e.d.ts +0 -2
- package/dist/fixtures/plugins/cypress/cypress/support/e2e.js +0 -2
- package/dist/fixtures/plugins/cypress/cypress.config.d.ts +0 -2
- package/dist/fixtures/plugins/cypress/cypress.config.js +0 -9
- package/dist/fixtures/plugins/eslint/eslint.config.d.ts +0 -7
- package/dist/fixtures/plugins/eslint/eslint.config.js +0 -11
- package/dist/fixtures/plugins/eslint/index.d.ts +0 -1
- package/dist/fixtures/plugins/eslint/index.js +0 -1
- package/dist/fixtures/plugins/gatsby/gatsby-config.d.ts +0 -17
- package/dist/fixtures/plugins/gatsby/gatsby-config.js +0 -40
- package/dist/fixtures/plugins/gatsby/gatsby-node.d.ts +0 -3
- package/dist/fixtures/plugins/gatsby/gatsby-node.js +0 -15
- package/dist/fixtures/plugins/github-actions/comment.d.ts +0 -0
- package/dist/fixtures/plugins/github-actions/comment.js +0 -1
- package/dist/fixtures/plugins/github-actions/scripts/check-dependencies.d.ts +0 -0
- package/dist/fixtures/plugins/github-actions/scripts/check-dependencies.js +0 -1
- package/dist/fixtures/plugins/jest/jest.config.d.ts +0 -2
- package/dist/fixtures/plugins/jest/jest.config.js +0 -7
- package/dist/fixtures/plugins/jest/jest.config.shared.d.ts +0 -2
- package/dist/fixtures/plugins/jest/jest.config.shared.js +0 -15
- package/dist/fixtures/plugins/jest/jest.setup.d.ts +0 -1
- package/dist/fixtures/plugins/jest/jest.setup.js +0 -1
- package/dist/fixtures/plugins/jest/jest.transform.d.ts +0 -1
- package/dist/fixtures/plugins/jest/jest.transform.js +0 -2
- package/dist/fixtures/plugins/lefthook/example.d.mts +0 -2
- package/dist/fixtures/plugins/lefthook/example.mjs +0 -1
- package/dist/fixtures/plugins/next/next.config.d.ts +0 -2
- package/dist/fixtures/plugins/next/next.config.js +0 -9
- package/dist/fixtures/plugins/next/pages/[[...route]].d.ts +0 -3
- package/dist/fixtures/plugins/next/pages/[[...route]].jsx +0 -3
- package/dist/fixtures/plugins/next/pages/page.d.ts +0 -3
- package/dist/fixtures/plugins/next/pages/page.jsx +0 -3
- package/dist/fixtures/plugins/playwright/playwright.config.d.ts +0 -3
- package/dist/fixtures/plugins/playwright/playwright.config.js +0 -10
- package/dist/fixtures/plugins/playwright/test/some.spec.d.ts +0 -1
- package/dist/fixtures/plugins/playwright/test/some.spec.js +0 -6
- package/dist/fixtures/plugins/postcss/postcss.config.d.ts +0 -1
- package/dist/fixtures/plugins/postcss/postcss.config.js +0 -4
- package/dist/fixtures/plugins/remix/app/entry.client.d.ts +0 -1
- package/dist/fixtures/plugins/remix/app/entry.client.jsx +0 -11
- package/dist/fixtures/plugins/remix/app/entry.server.jsx +0 -3
- package/dist/fixtures/plugins/remix/app/root.d.ts +0 -5
- package/dist/fixtures/plugins/remix/app/root.jsx +0 -31
- package/dist/fixtures/plugins/remix/app/routes/index.d.ts +0 -1
- package/dist/fixtures/plugins/remix/app/routes/index.jsx +0 -8
- package/dist/fixtures/plugins/remix/app/utils.d.ts +0 -1
- package/dist/fixtures/plugins/remix/app/utils.js +0 -1
- package/dist/fixtures/plugins/remix/remix.config.d.ts +0 -2
- package/dist/fixtures/plugins/remix/remix.config.js +0 -5
- package/dist/fixtures/plugins/remix/remix.init/index.d.ts +0 -4
- package/dist/fixtures/plugins/remix/remix.init/index.js +0 -4
- package/dist/fixtures/plugins/remix/server.d.ts +0 -0
- package/dist/fixtures/plugins/remix/server.js +0 -1
- package/dist/fixtures/plugins/rollup/rollup.config.d.ts +0 -16
- package/dist/fixtures/plugins/rollup/rollup.config.js +0 -26
- package/dist/fixtures/plugins/sentry/sentry.client.config.d.ts +0 -1
- package/dist/fixtures/plugins/sentry/sentry.client.config.js +0 -6
- package/dist/fixtures/plugins/sentry/sentry.server.config.d.ts +0 -1
- package/dist/fixtures/plugins/sentry/sentry.server.config.js +0 -1
- package/dist/fixtures/plugins/storybook/addon/register.d.ts +0 -0
- package/dist/fixtures/plugins/storybook/addon/register.js +0 -1
- package/dist/fixtures/plugins/storybook/main.d.ts +0 -10
- package/dist/fixtures/plugins/storybook/main.js +0 -38
- package/dist/fixtures/plugins/storybook/preview.d.ts +0 -13
- package/dist/fixtures/plugins/storybook/preview.js +0 -14
- package/dist/fixtures/plugins/stryker/stryker.conf.cjs +0 -6
- package/dist/fixtures/plugins/stryker/stryker.conf.d.cts +0 -3
- package/dist/fixtures/plugins/stryker/stryker.conf.d.mts +0 -6
- package/dist/fixtures/plugins/stryker/stryker.conf.mjs +0 -6
- package/dist/fixtures/plugins/svelte/knip.d.ts +0 -11
- package/dist/fixtures/plugins/svelte/knip.js +0 -10
- package/dist/fixtures/plugins/svelte/src/routes/+page.d.ts +0 -1
- package/dist/fixtures/plugins/svelte/src/routes/+page.js +0 -1
- package/dist/fixtures/plugins/svelte/svelte.config.d.ts +0 -2
- package/dist/fixtures/plugins/svelte/svelte.config.js +0 -9
- package/dist/fixtures/plugins/svelte/vite.config.d.ts +0 -2
- package/dist/fixtures/plugins/svelte/vite.config.js +0 -5
- package/dist/fixtures/plugins/vitest/test/basic.spec.d.ts +0 -1
- package/dist/fixtures/plugins/vitest/test/basic.spec.js +0 -8
- package/dist/fixtures/plugins/vitest/vite.config.d.ts +0 -2
- package/dist/fixtures/plugins/vitest/vite.config.js +0 -10
- package/dist/fixtures/plugins/vitest/vitest.config.d.ts +0 -2
- package/dist/fixtures/plugins/vitest/vitest.config.js +0 -10
- package/dist/fixtures/plugins/webpack/merge.d.ts +0 -2
- package/dist/fixtures/plugins/webpack/merge.js +0 -9
- package/dist/fixtures/plugins/webpack/src/app-dep.d.ts +0 -2
- package/dist/fixtures/plugins/webpack/src/app-dep.js +0 -1
- package/dist/fixtures/plugins/webpack/src/app.d.ts +0 -1
- package/dist/fixtures/plugins/webpack/src/app.js +0 -1
- package/dist/fixtures/plugins/webpack/src/entry.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/entry.js +0 -1
- package/dist/fixtures/plugins/webpack/src/unused.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/unused.js +0 -1
- package/dist/fixtures/plugins/webpack/src/vendor.d.ts +0 -0
- package/dist/fixtures/plugins/webpack/src/vendor.js +0 -1
- package/dist/fixtures/plugins/webpack/webpack.common.d.ts +0 -65
- package/dist/fixtures/plugins/webpack/webpack.common.js +0 -81
- package/dist/fixtures/plugins/webpack/webpack.config.d.ts +0 -2
- package/dist/fixtures/plugins/webpack/webpack.config.js +0 -4
- package/dist/fixtures/plugins/webpack/webpack.dev.d.ts +0 -2
- package/dist/fixtures/plugins/webpack/webpack.dev.js +0 -19
- package/dist/fixtures/plugins/webpack/webpack.prod.d.ts +0 -2
- package/dist/fixtures/plugins/webpack/webpack.prod.js +0 -16
- package/dist/fixtures/re-exports/barrel.d.ts +0 -1
- package/dist/fixtures/re-exports/barrel.js +0 -1
- package/dist/fixtures/re-exports/entry.d.ts +0 -1
- package/dist/fixtures/re-exports/entry.js +0 -2
- package/dist/fixtures/re-exports/my-module.d.ts +0 -4
- package/dist/fixtures/re-exports/my-module.js +0 -6
- package/dist/fixtures/react/App.d.ts +0 -1
- package/dist/fixtures/react/App.jsx +0 -7
- package/dist/fixtures/react/Component.d.ts +0 -1
- package/dist/fixtures/react/Component.jsx +0 -4
- package/dist/fixtures/self-reference/entry.d.ts +0 -1
- package/dist/fixtures/self-reference/entry.js +0 -8
- package/dist/fixtures/self-reference/lib/module.d.ts +0 -2
- package/dist/fixtures/self-reference/lib/module.js +0 -1
- package/dist/fixtures/self-reference/out/entry.d.ts +0 -1
- package/dist/fixtures/self-reference/out/entry.js +0 -11
- package/dist/fixtures/self-reference/out/lib/module.d.mts +0 -3
- package/dist/fixtures/self-reference/out/lib/module.mjs +0 -4
- package/dist/fixtures/self-reference-from-plugin/entry.d.ts +0 -0
- package/dist/fixtures/self-reference-from-plugin/entry.js +0 -2
- package/dist/fixtures/self-reference-from-plugin/file.d.ts +0 -2
- package/dist/fixtures/self-reference-from-plugin/file.js +0 -1
- package/dist/fixtures/tsconfig-paths/aliased-dir/a.d.ts +0 -1
- package/dist/fixtures/tsconfig-paths/aliased-dir/a.js +0 -1
- package/dist/fixtures/tsconfig-paths/index.d.ts +0 -1
- package/dist/fixtures/tsconfig-paths/index.js +0 -6
- package/dist/fixtures/tsconfig-paths/internal-package/index.d.ts +0 -2
- package/dist/fixtures/tsconfig-paths/internal-package/index.js +0 -2
- package/dist/fixtures/tsconfig-paths/unprefixed/module.d.ts +0 -2
- package/dist/fixtures/tsconfig-paths/unprefixed/module.js +0 -2
- package/dist/fixtures/tsconfig-paths-extends/src/cli.d.ts +0 -1
- package/dist/fixtures/tsconfig-paths-extends/src/cli.js +0 -3
- package/dist/fixtures/tsconfig-paths-extends/src/index.d.ts +0 -3
- package/dist/fixtures/tsconfig-paths-extends/src/index.js +0 -3
- package/dist/fixtures/tsconfig-paths-extends/src/lib/main.d.ts +0 -2
- package/dist/fixtures/tsconfig-paths-extends/src/lib/main.js +0 -1
- package/dist/fixtures/tsconfig-paths-extends/src/util/index.d.ts +0 -2
- package/dist/fixtures/tsconfig-paths-extends/src/util/index.js +0 -1
- package/dist/fixtures/tsconfig-paths-implicit/src/hello/world.d.ts +0 -1
- package/dist/fixtures/tsconfig-paths-implicit/src/hello/world.js +0 -1
- package/dist/fixtures/tsconfig-paths-implicit/src/index.d.ts +0 -1
- package/dist/fixtures/tsconfig-paths-implicit/src/index.js +0 -2
- package/dist/fixtures/workspaces/apps/a/index.d.ts +0 -1
- package/dist/fixtures/workspaces/apps/a/index.js +0 -6
- package/dist/fixtures/workspaces/apps/b/index.d.ts +0 -1
- package/dist/fixtures/workspaces/apps/b/index.js +0 -4
- package/dist/fixtures/workspaces/docs/dangling.d.ts +0 -1
- package/dist/fixtures/workspaces/docs/dangling.js +0 -1
- package/dist/fixtures/workspaces/packages/lib-a/index.d.ts +0 -4
- package/dist/fixtures/workspaces/packages/lib-a/index.js +0 -3
- package/dist/fixtures/workspaces/packages/lib-b/ignored/index.d.ts +0 -0
- package/dist/fixtures/workspaces/packages/lib-b/ignored/index.js +0 -1
- package/dist/fixtures/workspaces/packages/lib-b/index.d.ts +0 -3
- package/dist/fixtures/workspaces/packages/lib-b/index.js +0 -2
- package/dist/fixtures/workspaces-nested/level-1-1/index.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/index.js +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/index.spec.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/index.spec.js +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.js +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.spec.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/index.spec.js +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.js +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.spec.d.ts +0 -1
- package/dist/fixtures/workspaces-nested/level-1-1/level-1-2/level-1-3/index.spec.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/dir/module-a.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/dir/module-a.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/index.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/index.js +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/same.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-a/src/same.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/dir/module-b.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/dir/module-b.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/index.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-b/src/index.js +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/dir/module.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/dir/module.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/index.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-c/src/index.js +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/dir/module.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/dir/module.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/index.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-d/src/index.js +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/dir/module-e.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/dir/module-e.js +0 -1
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/index.d.ts +0 -2
- package/dist/fixtures/workspaces-paths/packages/lib-e/src/index.js +0 -2
- package/dist/fixtures/workspaces-pnpm/apps/a/index.d.ts +0 -1
- package/dist/fixtures/workspaces-pnpm/apps/a/index.js +0 -6
- package/dist/fixtures/workspaces-pnpm/apps/b/index.d.ts +0 -1
- package/dist/fixtures/workspaces-pnpm/apps/b/index.js +0 -4
- package/dist/fixtures/workspaces-pnpm/docs/dangling.d.ts +0 -1
- package/dist/fixtures/workspaces-pnpm/docs/dangling.js +0 -1
- package/dist/fixtures/workspaces-pnpm/packages/lib-a/index.d.ts +0 -4
- package/dist/fixtures/workspaces-pnpm/packages/lib-a/index.js +0 -3
- package/dist/fixtures/workspaces-pnpm/packages/lib-b/index.d.ts +0 -3
- package/dist/fixtures/workspaces-pnpm/packages/lib-b/index.js +0 -2
- package/dist/fixtures/workspaces-self-reference/packages/self-reference/entry.d.ts +0 -1
- package/dist/fixtures/workspaces-self-reference/packages/self-reference/entry.js +0 -4
- 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 +0 -2
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/file.d.ts +0 -2
- package/dist/fixtures/workspaces-self-reference/packages/self-reference-from-plugin/file.js +0 -1
- package/dist/fixtures/zero-config/exclude.d.ts +0 -1
- package/dist/fixtures/zero-config/exclude.js +0 -1
- package/dist/fixtures/zero-config/index.d.ts +0 -1
- package/dist/fixtures/zero-config/index.js +0 -2
- package/dist/fixtures/zero-config/my-module.d.ts +0 -4
- package/dist/fixtures/zero-config/my-module.js +0 -6
- package/dist/fixtures/zero-config/my-namespace.d.ts +0 -5
- package/dist/fixtures/zero-config/my-namespace.js +0 -3
- package/dist/gitignore.test.d.ts +0 -1
- package/dist/gitignore.test.js +0 -22
- package/dist/helpers/baseArguments.d.ts +0 -8
- package/dist/helpers/baseArguments.js +0 -8
- package/dist/helpers/baseCounters.d.ts +0 -17
- package/dist/helpers/baseCounters.js +0 -7
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/index.js +0 -4
- package/dist/imports.test.d.ts +0 -1
- package/dist/imports.test.js +0 -39
- package/dist/js-only.test.d.ts +0 -1
- package/dist/js-only.test.js +0 -26
- package/dist/jsdoc.test.d.ts +0 -1
- package/dist/jsdoc.test.js +0 -21
- package/dist/members.test.d.ts +0 -1
- package/dist/members.test.js +0 -28
- package/dist/namespace.test.d.ts +0 -1
- package/dist/namespace.test.js +0 -18
- package/dist/npm-scripts.test.d.ts +0 -1
- package/dist/npm-scripts.test.js +0 -78
- package/dist/pathless.test.d.ts +0 -1
- package/dist/pathless.test.js +0 -14
- package/dist/paths-knip-config-workspaces.test.d.ts +0 -1
- package/dist/paths-knip-config-workspaces.test.js +0 -18
- package/dist/paths-knip-config.test.d.ts +0 -1
- package/dist/paths-knip-config.test.js +0 -18
- package/dist/peer-dependencies.test.d.ts +0 -1
- package/dist/peer-dependencies.test.js +0 -20
- package/dist/plugins/_template.test.d.ts +0 -1
- package/dist/plugins/_template.test.js +0 -12
- package/dist/plugins/ava.test.d.ts +0 -1
- package/dist/plugins/ava.test.js +0 -18
- package/dist/plugins/babel.test.d.ts +0 -1
- package/dist/plugins/babel.test.js +0 -62
- package/dist/plugins/capacitor.test.d.ts +0 -1
- package/dist/plugins/capacitor.test.js +0 -31
- package/dist/plugins/changesets.test.d.ts +0 -1
- package/dist/plugins/changesets.test.js +0 -12
- package/dist/plugins/commitlint.test.d.ts +0 -1
- package/dist/plugins/commitlint.test.js +0 -22
- package/dist/plugins/cspell.test.d.ts +0 -1
- package/dist/plugins/cspell.test.js +0 -10
- package/dist/plugins/cypress.test.d.ts +0 -1
- package/dist/plugins/cypress.test.js +0 -23
- package/dist/plugins/eslint.test.d.ts +0 -1
- package/dist/plugins/eslint.test.js +0 -43
- package/dist/plugins/gatsby.test.d.ts +0 -1
- package/dist/plugins/gatsby.test.js +0 -31
- package/dist/plugins/github-actions.test.d.ts +0 -1
- package/dist/plugins/github-actions.test.js +0 -25
- package/dist/plugins/husky.test.d.ts +0 -1
- package/dist/plugins/husky.test.js +0 -32
- package/dist/plugins/jest.test.d.ts +0 -1
- package/dist/plugins/jest.test.js +0 -18
- package/dist/plugins/lefthook.test.d.ts +0 -1
- package/dist/plugins/lefthook.test.js +0 -16
- package/dist/plugins/lint-staged.test.d.ts +0 -1
- package/dist/plugins/lint-staged.test.js +0 -18
- package/dist/plugins/markdownlint.test.d.ts +0 -1
- package/dist/plugins/markdownlint.test.js +0 -12
- package/dist/plugins/mocha.test.d.ts +0 -1
- package/dist/plugins/mocha.test.js +0 -22
- package/dist/plugins/next.test.d.ts +0 -1
- package/dist/plugins/next.test.js +0 -24
- package/dist/plugins/npm-package-json-lint.test.d.ts +0 -1
- package/dist/plugins/npm-package-json-lint.test.js +0 -12
- package/dist/plugins/nx.test.d.ts +0 -1
- package/dist/plugins/nx.test.js +0 -15
- package/dist/plugins/nyc.test.d.ts +0 -1
- package/dist/plugins/nyc.test.js +0 -10
- package/dist/plugins/playwright.test.d.ts +0 -1
- package/dist/plugins/playwright.test.js +0 -20
- package/dist/plugins/postcss.test.d.ts +0 -1
- package/dist/plugins/postcss.test.js +0 -33
- package/dist/plugins/prettier.test.d.ts +0 -1
- package/dist/plugins/prettier.test.js +0 -10
- package/dist/plugins/release-it.test.d.ts +0 -1
- package/dist/plugins/release-it.test.js +0 -10
- package/dist/plugins/remark.test.d.ts +0 -1
- package/dist/plugins/remark.test.js +0 -12
- package/dist/plugins/remix.test.d.ts +0 -1
- package/dist/plugins/remix.test.js +0 -39
- package/dist/plugins/rollup.test.d.ts +0 -1
- package/dist/plugins/rollup.test.js +0 -24
- package/dist/plugins/semantic-release.test.d.ts +0 -1
- package/dist/plugins/semantic-release.test.js +0 -31
- package/dist/plugins/sentry.test.d.ts +0 -1
- package/dist/plugins/sentry.test.js +0 -14
- package/dist/plugins/storybook.test.d.ts +0 -1
- package/dist/plugins/storybook.test.js +0 -18
- package/dist/plugins/stryker.test.d.ts +0 -1
- package/dist/plugins/stryker.test.js +0 -44
- package/dist/plugins/svelte.test.d.ts +0 -1
- package/dist/plugins/svelte.test.js +0 -21
- package/dist/plugins/typedoc.test.d.ts +0 -1
- package/dist/plugins/typedoc.test.js +0 -14
- package/dist/plugins/vitest.test.d.ts +0 -1
- package/dist/plugins/vitest.test.js +0 -17
- package/dist/plugins/webpack.test.d.ts +0 -1
- package/dist/plugins/webpack.test.js +0 -56
- package/dist/re-exports.test.d.ts +0 -1
- package/dist/re-exports.test.js +0 -18
- package/dist/react.test.d.ts +0 -1
- package/dist/react.test.js +0 -19
- package/dist/self-reference-from-plugin.test.d.ts +0 -1
- package/dist/self-reference-from-plugin.test.js +0 -47
- package/dist/self-reference.test.d.ts +0 -1
- package/dist/self-reference.test.js +0 -46
- package/dist/source-lab.d.ts +0 -21
- package/dist/source-lab.js +0 -135
- package/dist/tsconfig-paths-extends.test.d.ts +0 -1
- package/dist/tsconfig-paths-extends.test.js +0 -18
- package/dist/tsconfig-paths-implicit.test.d.ts +0 -1
- package/dist/tsconfig-paths-implicit.test.js +0 -18
- package/dist/tsconfig-paths.test.d.ts +0 -1
- package/dist/tsconfig-paths.test.js +0 -26
- package/dist/util/binaries/bash-parser.d.ts +0 -6
- package/dist/util/binaries/bash-parser.js +0 -57
- package/dist/util/binaries/index.d.ts +0 -2
- package/dist/util/binaries/index.js +0 -27
- package/dist/util/binaries/resolvers/fallback.js +0 -14
- package/dist/util/binaries/resolvers/index.d.ts +0 -4
- package/dist/util/binaries/resolvers/index.js +0 -4
- package/dist/util/binaries/resolvers/node.d.ts +0 -3
- package/dist/util/binaries/resolvers/node.js +0 -20
- package/dist/util/binaries/resolvers/npx.d.ts +0 -2
- package/dist/util/binaries/resolvers/npx.js +0 -5
- package/dist/util/binaries/resolvers/pnpm.d.ts +0 -2
- package/dist/util/binaries/resolvers/pnpm.js +0 -45
- package/dist/util/binaries/resolvers/yarn.d.ts +0 -2
- package/dist/util/binaries/resolvers/yarn.js +0 -46
- package/dist/util/binaries/types.d.ts +0 -18
- package/dist/util/binaries/types.js +0 -1
- package/dist/util/find-import-specifiers.d.ts +0 -5
- package/dist/util/find-import-specifiers.js +0 -48
- package/dist/util/get-included-issue-types.test.d.ts +0 -1
- package/dist/util/get-included-issue-types.test.js +0 -70
- package/dist/util/getReferencesFromScripts.test.d.ts +0 -1
- package/dist/util/getReferencesFromScripts.test.js +0 -126
- package/dist/util/log.d.ts +0 -7
- package/dist/util/log.js +0 -21
- package/dist/util/members.d.ts +0 -3
- package/dist/util/members.js +0 -25
- package/dist/util/module.test.d.ts +0 -1
- package/dist/util/module.test.js +0 -12
- package/dist/util/os.d.ts +0 -1
- package/dist/util/os.js +0 -1
- package/dist/util/project.d.ts +0 -13
- package/dist/util/project.js +0 -48
- package/dist/util/resolve-included-issue-types.d.ts +0 -16
- package/dist/util/resolve-included-issue-types.js +0 -30
- package/dist/util/type.d.ts +0 -2
- package/dist/util/type.js +0 -9
- package/dist/util/workspace.test.d.ts +0 -1
- package/dist/util/workspace.test.js +0 -13
- package/dist/workspaces-nested.test.d.ts +0 -1
- package/dist/workspaces-nested.test.js +0 -44
- package/dist/workspaces-paths.test.d.ts +0 -1
- package/dist/workspaces-paths.test.js +0 -21
- package/dist/workspaces-pnpm.test.d.ts +0 -1
- package/dist/workspaces-pnpm.test.js +0 -21
- package/dist/workspaces.test.d.ts +0 -1
- package/dist/workspaces.test.js +0 -56
- package/dist/zero-config.test.d.ts +0 -1
- package/dist/zero-config.test.js +0 -37
- /package/dist/{util/binaries/resolvers/fallback.d.ts → binaries/resolvers/rollup.d.ts} +0 -0
- /package/dist/{commonjs.test.d.ts → plugins/commitizen/types.js} +0 -0
package/README.md
CHANGED
|
@@ -7,23 +7,23 @@ dependencies leads to improved performance, less maintenance and easier refactor
|
|
|
7
7
|
export const myVar = true;
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
ESLint handles files in isolation, so it does not know whether `myVar` is
|
|
11
|
-
project as a whole, and finds unused exports, files and dependencies.
|
|
10
|
+
This is where ESLint stops: it handles files in isolation, so it does not know whether `myVar` is used somewhere else.
|
|
11
|
+
This is where Knip starts: it lints the project as a whole, and finds unused exports, files and dependencies.
|
|
12
12
|
|
|
13
|
-
It's only human to forget removing things that you no longer use. But how do you find out? Where
|
|
13
|
+
It's only human to forget removing things that you no longer use. But how do you find out? Where do you start finding
|
|
14
14
|
things that can be removed?
|
|
15
15
|
|
|
16
16
|
The dots don't connect themselves. This is where Knip comes in:
|
|
17
17
|
|
|
18
18
|
- [x] Finds **unused files, dependencies and exports**
|
|
19
19
|
- [x] Finds used dependencies not listed in `package.json`
|
|
20
|
-
- [x]
|
|
21
|
-
- [x] Finds unused members of classes and enums
|
|
22
|
-
- [x] Built-in support for [monorepos/workspaces][1]
|
|
20
|
+
- [x] Built-in support for [workspaces (monorepos)][1]
|
|
23
21
|
- [x] Growing list of [built-in plugins][2]
|
|
24
|
-
- [x] Use [compilers][3] to include other file types (e.g.
|
|
22
|
+
- [x] Use [compilers][3] to include other file types (e.g. `.mdx`, `.vue`, `.svelte`)
|
|
25
23
|
- [x] Checks npm scripts for used and unlisted dependencies
|
|
26
|
-
- [x]
|
|
24
|
+
- [x] Finds unused members of classes and enums
|
|
25
|
+
- [x] Finds duplicate exports
|
|
26
|
+
- [x] Supports any combination of JavaScript and TypeScript
|
|
27
27
|
- [x] Features multiple [reporters][4] and supports [custom reporters][5]
|
|
28
28
|
- [x] Run Knip as part of your CI environment to detect issues and prevent regressions
|
|
29
29
|
|
|
@@ -34,16 +34,8 @@ with OpenAI_</sup>
|
|
|
34
34
|
|
|
35
35
|
## Migrating to v2.0.0
|
|
36
36
|
|
|
37
|
-
Migrating from v1 to v2 requires no changes in configuration.
|
|
38
|
-
for
|
|
39
|
-
|
|
40
|
-
## Issues
|
|
41
|
-
|
|
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 `tests/fixtures`.
|
|
44
|
-
Correctness and bug fixes have priority over performance and new features.
|
|
45
|
-
|
|
46
|
-
Also see the [FAQ][10].
|
|
37
|
+
Migrating from v1 to v2 requires no changes in configuration. Mostly it's just a whole lot faster! The [release notes
|
|
38
|
+
for v2][8] provide more details.
|
|
47
39
|
|
|
48
40
|
## Installation
|
|
49
41
|
|
|
@@ -51,21 +43,23 @@ Also see the [FAQ][10].
|
|
|
51
43
|
|
|
52
44
|
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6. Knip is _cutting edge!_
|
|
53
45
|
|
|
54
|
-
##
|
|
46
|
+
## Configuration
|
|
55
47
|
|
|
56
|
-
Knip has good defaults and you can run it without any configuration
|
|
57
|
-
with a configuration file (or a `knip` property in `package.json`). Here's a `knip.json` with the default values:
|
|
48
|
+
Knip has good defaults and you can run it without any configuration. Here's the default:
|
|
58
49
|
|
|
59
50
|
```json
|
|
60
51
|
{
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"project": ["**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}"]
|
|
52
|
+
"entry": ["index.{js,ts}", "src/index.{js,ts}"],
|
|
53
|
+
"project": ["**/*.{js,ts}"]
|
|
64
54
|
}
|
|
65
55
|
```
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
_Actually_, here's the full list of default extensions: `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`.
|
|
58
|
+
|
|
59
|
+
If this matches your project, you don't need any configuration. Not even a `knip.json` file.
|
|
60
|
+
|
|
61
|
+
Larger projects tend to have more things customized, and therefore probably get more out of Knip with a configuration
|
|
62
|
+
file. Let's say you are using `.ts` files excusively and have all source files only in the `src` directory:
|
|
69
63
|
|
|
70
64
|
```json
|
|
71
65
|
{
|
|
@@ -78,7 +72,16 @@ have all source files only in the `src` directory:
|
|
|
78
72
|
The `entry` files target the starting point(s) to resolve the rest of the imported code. The `project` files should
|
|
79
73
|
contain all files to match against the files resolved from the entry files, including potentially unused files.
|
|
80
74
|
|
|
81
|
-
|
|
75
|
+
Places where Knip looks for configuration:
|
|
76
|
+
|
|
77
|
+
- `knip.json`
|
|
78
|
+
- `knip.jsonc`
|
|
79
|
+
- `.knip.json`
|
|
80
|
+
- `.knip.jsonc`
|
|
81
|
+
- `knip.js`
|
|
82
|
+
- `knip.ts`
|
|
83
|
+
|
|
84
|
+
So you can use a dynamic `knip.ts` with TypeScript if you prefer:
|
|
82
85
|
|
|
83
86
|
```ts
|
|
84
87
|
import type { KnipConfig } from 'knip';
|
|
@@ -91,8 +94,6 @@ const config: KnipConfig = {
|
|
|
91
94
|
export default config;
|
|
92
95
|
```
|
|
93
96
|
|
|
94
|
-
Please see [workspaces & monorepos][1] for more details about configuring them.
|
|
95
|
-
|
|
96
97
|
Then run the checks with `npx knip`. Or first add this script to `package.json`:
|
|
97
98
|
|
|
98
99
|
```json
|
|
@@ -106,6 +107,8 @@ Then run the checks with `npx knip`. Or first add this script to `package.json`:
|
|
|
106
107
|
Use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine with
|
|
107
108
|
`yarn` or `pnpm` as well.
|
|
108
109
|
|
|
110
|
+
Using workspaces in a monorepo? Please see [workspaces][1] for more details about configuring them.
|
|
111
|
+
|
|
109
112
|
## Command-line options
|
|
110
113
|
|
|
111
114
|
$ npx knip --help
|
|
@@ -119,11 +122,10 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
|
|
|
119
122
|
--production Analyze only production source files (e.g. no tests, devDependencies, exported types)
|
|
120
123
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
121
124
|
--workspace Analyze a single workspace (default: analyze all configured workspaces)
|
|
122
|
-
--ignore Ignore files matching this glob pattern, can be repeated
|
|
123
125
|
--no-gitignore Don't use .gitignore
|
|
124
126
|
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
125
127
|
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
126
|
-
--dependencies Shortcut for --include dependencies,unlisted
|
|
128
|
+
--dependencies Shortcut for --include dependencies,unlisted,unresolved
|
|
127
129
|
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
128
130
|
--no-progress Don't show dynamic progress updates
|
|
129
131
|
--reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
|
|
@@ -153,7 +155,7 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
|
|
|
153
155
|
|
|
154
156
|
Here's an example run using the default reporter:
|
|
155
157
|
|
|
156
|
-
<img src="./assets/screenshot-
|
|
158
|
+
<img src="./assets/screenshot-exports.png" alt="example output of exported values and types" width="578">
|
|
157
159
|
|
|
158
160
|
This example shows more output related to unused and unlisted dependencies:
|
|
159
161
|
|
|
@@ -196,8 +198,8 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
196
198
|
|
|
197
199
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
198
200
|
|
|
199
|
-
Still not happy with the results? Getting too much output/false positives? The [FAQ][
|
|
200
|
-
|
|
201
|
+
Still not happy with the results? Getting too much output/false positives? The [FAQ][9] may be useful. Feel free to open
|
|
202
|
+
an issue and I'm happy to look into it. Also see the next section on how to [ignore][10] certain false positives:
|
|
201
203
|
|
|
202
204
|
## Ignore
|
|
203
205
|
|
|
@@ -212,7 +214,7 @@ There are a few ways to tell Knip to ignore certain packages, binaries, dependen
|
|
|
212
214
|
}
|
|
213
215
|
```
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
These can also be configured per workspace (except for `ignoreWorkspaces`).
|
|
216
218
|
|
|
217
219
|
## Now what?
|
|
218
220
|
|
|
@@ -230,18 +232,18 @@ As always, make sure to backup files or use Git before deleting files or making
|
|
|
230
232
|
|
|
231
233
|
🔁 Repeat the process to reveal new unused files and exports. Sometimes it's so liberating to remove things!
|
|
232
234
|
|
|
233
|
-
## Workspaces
|
|
235
|
+
## Workspaces (monorepos)
|
|
234
236
|
|
|
235
|
-
Workspaces and monorepos are handled out-of-the-box by Knip. Every workspace
|
|
236
|
-
|
|
237
|
+
Workspaces and monorepos are handled out-of-the-box by Knip. Every workspace is part of the analysis.
|
|
238
|
+
|
|
239
|
+
Here's an example configuration with some custom `entry` and `project` patterns:
|
|
237
240
|
|
|
238
241
|
```jsonc
|
|
239
242
|
{
|
|
240
|
-
"ignoreWorkspaces": ["packages/ignore-me"],
|
|
241
243
|
"workspaces": {
|
|
242
244
|
".": {
|
|
243
|
-
"entry": "
|
|
244
|
-
"project": "
|
|
245
|
+
"entry": "scripts/*.js",
|
|
246
|
+
"project": "scripts/**/*.js"
|
|
245
247
|
},
|
|
246
248
|
"packages/*": {
|
|
247
249
|
"entry": "{index,cli}.ts",
|
|
@@ -254,19 +256,19 @@ be part of the analysis. Here's an example:
|
|
|
254
256
|
}
|
|
255
257
|
```
|
|
256
258
|
|
|
257
|
-
It might be useful to run Knip first with no or little configuration to see where it needs
|
|
258
|
-
project files. The default configuration of each workspace is the same as
|
|
259
|
+
It might be useful to run Knip first with no or little configuration to see where it needs custom `entry` and/or
|
|
260
|
+
`project` files. The default configuration of each workspace is the same as for a regular project.
|
|
259
261
|
|
|
260
262
|
Workspaces are sometimes also referred to as packages in a monorepo. Knip uses the term workspaces exclusively to
|
|
261
263
|
indicate the directories that have a `package.json`.
|
|
262
264
|
|
|
263
|
-
Root workspaces must be
|
|
265
|
+
Root workspaces must be named `"."` under `workspaces` (like in the example).
|
|
264
266
|
|
|
265
267
|
Knip supports workspaces as defined in three possible locations:
|
|
266
268
|
|
|
267
|
-
- In the `workspaces` array in `package.json
|
|
268
|
-
- In the `workspaces.packages` array in `package.json
|
|
269
|
-
- In the `packages` array in `pnpm-workspace.yaml
|
|
269
|
+
- In the `workspaces` array in `package.json` (npm, Yarn, Lerna).
|
|
270
|
+
- In the `workspaces.packages` array in `package.json` (legacy).
|
|
271
|
+
- In the `packages` array in `pnpm-workspace.yaml` (pnpm).
|
|
270
272
|
|
|
271
273
|
Extra "workspaces" not configured as a workspace in the root `package.json` can be configured as well, Knip is happy to
|
|
272
274
|
analyze unused dependencies and exports from any directory with a `package.json`.
|
|
@@ -279,12 +281,29 @@ Use `--debug` to get more verbose output.
|
|
|
279
281
|
|
|
280
282
|
## Plugins
|
|
281
283
|
|
|
284
|
+
Plugins tell Knip where to look for configuration and entry files, and if necessary have a custom dependency finder.
|
|
285
|
+
Knip plugins are automatically activated, you don't need to install or configure anything.
|
|
286
|
+
|
|
287
|
+
To explain what they do, here's a quick example from a `.eslintrc.json` configuration file (for ESLint):
|
|
288
|
+
|
|
289
|
+
```json
|
|
290
|
+
{
|
|
291
|
+
"extends": ["airbnb"],
|
|
292
|
+
"plugins": ["prettier"]
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Knip's ESLint plugin reads `.eslintrc.json` and will return `eslint-config-airbnb` and `eslint-plugin-prettier` from
|
|
297
|
+
this example to Knip, so it can tell you whether `package.json` is out of sync. In a nutshell, this is how plugins work.
|
|
298
|
+
This is especially useful over time when such configuration files change (and they will)!
|
|
299
|
+
|
|
282
300
|
Knip contains a growing list of plugins:
|
|
283
301
|
|
|
284
302
|
- [Ava][plugin-ava]
|
|
285
303
|
- [Babel][plugin-babel]
|
|
286
304
|
- [Capacitor][plugin-capacitor]
|
|
287
305
|
- [Changesets][plugin-changesets]
|
|
306
|
+
- [Commitizen][plugin-commitizen]
|
|
288
307
|
- [commitlint][plugin-commitlint]
|
|
289
308
|
- [cspell][plugin-cspell]
|
|
290
309
|
- [Cypress][plugin-cypress]
|
|
@@ -319,26 +338,53 @@ Knip contains a growing list of plugins:
|
|
|
319
338
|
- [Webpack][plugin-webpack]
|
|
320
339
|
|
|
321
340
|
Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
|
|
322
|
-
whether one
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
Most plugins use one or both of the following file types:
|
|
341
|
+
whether one of a few dependencies are listed in `package.json`. Once enabled, they add a set of `config` files for
|
|
342
|
+
itself and/or `entry` files for Knip to analyze.
|
|
326
343
|
|
|
327
|
-
- `config`
|
|
328
|
-
- `entry`
|
|
344
|
+
- `config` files are given to the plugin's dependency finder
|
|
345
|
+
- `entry` files are given to Knip to include with the analysis of the rest of the source code
|
|
329
346
|
|
|
330
347
|
See each plugin's documentation for its default values.
|
|
331
348
|
|
|
332
349
|
### `config`
|
|
333
350
|
|
|
334
|
-
Plugins
|
|
335
|
-
|
|
336
|
-
|
|
351
|
+
Plugins usually include `config` files. They are handled by the plugin's custom dependency finder, which returns all
|
|
352
|
+
dependencies referenced in the files it is given. Knip handles the rest to determine which of those dependencies are
|
|
353
|
+
unused or missing.
|
|
337
354
|
|
|
338
355
|
### `entry`
|
|
339
356
|
|
|
340
|
-
Other configuration files use `require` or `import` statements to use dependencies, so they
|
|
341
|
-
|
|
357
|
+
Other configuration files use `require` or `import` statements to use dependencies, so they don't need special handing
|
|
358
|
+
and can be analyzed like any other source file. That's why these configuration files are also used as `entry` files.
|
|
359
|
+
|
|
360
|
+
### Override plugin configuration
|
|
361
|
+
|
|
362
|
+
Usually no custom configuration is required for plugins, but if your project uses custom file locations then Knip allows
|
|
363
|
+
to override any defaults. Let's take Cypress for example. By default it uses `cypress.config.js`, but your project uses
|
|
364
|
+
`config/cypress.js`. Also, the default pattern for test files is `cypress/e2e/**/*.cy.js`, but your project has them at
|
|
365
|
+
`e2e-tests/*.spec.ts`. Here's how to configure this:
|
|
366
|
+
|
|
367
|
+
```json
|
|
368
|
+
{
|
|
369
|
+
"cypress": {
|
|
370
|
+
"entry": ["config/cypress.js", "e2e-tests/*.spec.js"]
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Multi-project repositories
|
|
376
|
+
|
|
377
|
+
Some repositories have a single `package.json`, but consist of multiple projects with potentially lots of configuration
|
|
378
|
+
files (such as the [Nx "intregrated repo" style][11]). Let's assume some of these projects are apps and have their own
|
|
379
|
+
Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
|
|
380
|
+
|
|
381
|
+
```json
|
|
382
|
+
{
|
|
383
|
+
"cypress": {
|
|
384
|
+
"entry": ["apps/**/cypress.config.ts", "apps/**/cypress/e2e/*.spec.ts"]
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
342
388
|
|
|
343
389
|
### Disable a plugin
|
|
344
390
|
|
|
@@ -346,7 +392,7 @@ In case a plugin causes issues, it can be disabled by using `false` as its value
|
|
|
346
392
|
|
|
347
393
|
### Create a new plugin
|
|
348
394
|
|
|
349
|
-
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][
|
|
395
|
+
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][12]. This
|
|
350
396
|
guide also contains more details if you want to learn more about plugins and why they are useful.
|
|
351
397
|
|
|
352
398
|
## Compilers
|
|
@@ -356,7 +402,8 @@ finding unused or missing dependencies. For instance, `.mdx`, `.vue` and `.svelt
|
|
|
356
402
|
|
|
357
403
|
Currently this is only supported by using `knip.js` or `knip.ts`. Provide a `compilers` object in the configuration
|
|
358
404
|
where each key represents the extension and the value is a function that takes the contents of these files as input and
|
|
359
|
-
returns JavaScript or TypeScript as output.
|
|
405
|
+
returns JavaScript or TypeScript as output. Here is an example that compiles `.mdx` files to JavaScript so these files
|
|
406
|
+
and their imports and exports become part of the analyis:
|
|
360
407
|
|
|
361
408
|
```js
|
|
362
409
|
import { compileSync } from 'mdx-js/mdx';
|
|
@@ -368,7 +415,7 @@ export default {
|
|
|
368
415
|
};
|
|
369
416
|
```
|
|
370
417
|
|
|
371
|
-
Read [Compilers][
|
|
418
|
+
Read [Compilers][13] for more details and examples.
|
|
372
419
|
|
|
373
420
|
## Production Mode
|
|
374
421
|
|
|
@@ -439,32 +486,14 @@ Knip provides the following built-in reporters:
|
|
|
439
486
|
- json
|
|
440
487
|
- symbol
|
|
441
488
|
|
|
442
|
-
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
443
|
-
|
|
444
|
-
<img src="./assets/screenshot-basic-compact.png" alt="example output of dependencies" width="578">
|
|
445
|
-
|
|
446
489
|
### Custom Reporters
|
|
447
490
|
|
|
448
491
|
When the provided built-in reporters are not sufficient, a custom reporter can be implemented.
|
|
449
492
|
|
|
450
|
-
Pass `--reporter ./my-reporter
|
|
451
|
-
|
|
452
|
-
```ts
|
|
453
|
-
type Reporter = (options: ReporterOptions) => void;
|
|
454
|
-
|
|
455
|
-
type ReporterOptions = {
|
|
456
|
-
report: Report;
|
|
457
|
-
issues: Issues;
|
|
458
|
-
cwd: string;
|
|
459
|
-
workingDir: string;
|
|
460
|
-
isProduction: boolean;
|
|
461
|
-
options: string;
|
|
462
|
-
};
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
493
|
+
Pass `--reporter ./my-reporter` from the command-line. The data can then be used to write issues to `stdout`, a JSON or
|
|
494
|
+
CSV file, or sent to a service.
|
|
466
495
|
|
|
467
|
-
Find more details and ideas in [custom reporters][
|
|
496
|
+
Find more details and ideas in [custom reporters][14].
|
|
468
497
|
|
|
469
498
|
## Public exports
|
|
470
499
|
|
|
@@ -493,17 +522,6 @@ I love the Unix philosophy ("do one thing well"). But in this case I believe it'
|
|
|
493
522
|
in a single tool. When building a dependency graph of the project, an abstract syntax tree for each file, and traversing
|
|
494
523
|
all of this, why not collect the various issues in one go?
|
|
495
524
|
|
|
496
|
-
### Why so much configuration?
|
|
497
|
-
|
|
498
|
-
The structure and configuration of projects and their dependencies vary wildly, and no matter how well-balanced,
|
|
499
|
-
defaults only get you so far. Some implementations and some tools out there have smart or unconventional ways to import
|
|
500
|
-
code, making things more complicated. That's why Knip tends to require more configuration in larger projects, based on
|
|
501
|
-
how many dependencies are used and how much the configuration in the project diverges from the defaults.
|
|
502
|
-
|
|
503
|
-
One important goal of Knip is to minimize the amount of configuration necessary. When you false positives are reported
|
|
504
|
-
and you think there are feasible ways to infer things automatically, reducing the amount of configuration, please open
|
|
505
|
-
an issue.
|
|
506
|
-
|
|
507
525
|
### How do I handle too many output/false positives?
|
|
508
526
|
|
|
509
527
|
#### Too many unused files
|
|
@@ -521,7 +539,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
|
|
|
521
539
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
522
540
|
to match the custom location(s).
|
|
523
541
|
|
|
524
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
542
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][15].
|
|
525
543
|
|
|
526
544
|
#### Too many unused exports
|
|
527
545
|
|
|
@@ -529,7 +547,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
529
547
|
|
|
530
548
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
531
549
|
add the containing file to the `entry` array in the configuration.
|
|
532
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
550
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][16]
|
|
533
551
|
|
|
534
552
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
535
553
|
|
|
@@ -539,9 +557,8 @@ help:
|
|
|
539
557
|
|
|
540
558
|
- Use `--no-exit-code` for exit code 0 in CI.
|
|
541
559
|
- Use `--include` (or `--exclude`) to report only the issue types that have little or no errors.
|
|
542
|
-
- Use
|
|
543
|
-
- Use
|
|
544
|
-
- Limit the number of workspaces configured to analyze in `knip.json`.
|
|
560
|
+
- Use separate Knip commands to analyze e.g. unused `--dependencies` and/or `--exports`.
|
|
561
|
+
- Use [ignore patterns][10] to filter out the most problematic areas.
|
|
545
562
|
|
|
546
563
|
All of this is hiding problems, so please make sure to plan for fixing them and/or open issues here for false positives.
|
|
547
564
|
|
|
@@ -549,23 +566,23 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
549
566
|
|
|
550
567
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
551
568
|
|
|
552
|
-
| Feature
|
|
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
|
|
568
|
-
| ESLint plugin available
|
|
569
|
+
| Feature | **knip** | [depcheck][17] | [unimported][18] | [ts-unused-exports][19] | [ts-prune][20] |
|
|
570
|
+
| :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
571
|
+
| Unused files | ✅ | - | ✅ | - | - |
|
|
572
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
573
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - |
|
|
574
|
+
| [Plugins][2] | ✅ | ✅ | ❌ | - | - |
|
|
575
|
+
| [Compilers][3] | ✅ | - | - | - | - |
|
|
576
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ |
|
|
577
|
+
| Unused class members | ✅ | - | - | - | - |
|
|
578
|
+
| Unused enum members | ✅ | - | - | - | - |
|
|
579
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ |
|
|
580
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ |
|
|
581
|
+
| Custom reporters | ✅ | - | - | - | - |
|
|
582
|
+
| JavaScript support | ✅ | ✅ | ✅ | - | - |
|
|
583
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
584
|
+
| [Support workspaces][1] | ✅ | ❌ | ❌ | - | - |
|
|
585
|
+
| ESLint plugin available | - | - | - | ✅ | - |
|
|
569
586
|
|
|
570
587
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
571
588
|
|
|
@@ -585,7 +602,7 @@ The following commands are similar:
|
|
|
585
602
|
unimported
|
|
586
603
|
knip --production --dependencies --include files
|
|
587
604
|
|
|
588
|
-
Also see [production mode][
|
|
605
|
+
Also see [production mode][21].
|
|
589
606
|
|
|
590
607
|
### ts-unused-exports
|
|
591
608
|
|
|
@@ -603,37 +620,56 @@ The following commands are similar:
|
|
|
603
620
|
knip --include exports,types
|
|
604
621
|
knip --exports # Adds unused exports/types in namespaces and unused enum/class members
|
|
605
622
|
|
|
623
|
+
## Projects using Knip
|
|
624
|
+
|
|
625
|
+
Many thanks to some of the early adopters of Knip:
|
|
626
|
+
|
|
627
|
+
- [Block Protocol][22]
|
|
628
|
+
- [DeepmergeTS][23]
|
|
629
|
+
- [eslint-plugin-functional][24]
|
|
630
|
+
- [freeCodeCamp.org][25]
|
|
631
|
+
- [is-immutable-type][26]
|
|
632
|
+
- [release-it][27]
|
|
633
|
+
- [Template TypeScript Node Package][28]
|
|
634
|
+
|
|
606
635
|
## Knip?!
|
|
607
636
|
|
|
608
637
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
609
638
|
for the job. I'm motivated to make knip perfectly suited for the job of cutting projects to perfection! ✂️
|
|
610
639
|
|
|
611
|
-
[1]: #workspaces
|
|
640
|
+
[1]: #workspaces-monorepos
|
|
612
641
|
[2]: #plugins
|
|
613
642
|
[3]: #compilers
|
|
614
643
|
[4]: #reporters
|
|
615
644
|
[5]: #custom-reporters
|
|
616
645
|
[6]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
617
646
|
[7]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
618
|
-
[8]:
|
|
619
|
-
[9]:
|
|
620
|
-
[10]: #
|
|
621
|
-
[11]:
|
|
622
|
-
[12]:
|
|
623
|
-
[13]: ./docs/
|
|
624
|
-
[14]: ./docs/
|
|
625
|
-
[15]:
|
|
626
|
-
[16]: #
|
|
627
|
-
[17]:
|
|
628
|
-
[18]: https://github.com/
|
|
629
|
-
[19]: https://github.com/
|
|
630
|
-
[20]: https://github.com/
|
|
631
|
-
[21]:
|
|
632
|
-
[22]:
|
|
647
|
+
[8]: ./docs/release-notes-v2.md
|
|
648
|
+
[9]: #faq
|
|
649
|
+
[10]: #ignore
|
|
650
|
+
[11]: https://nx.dev/concepts/integrated-vs-package-based
|
|
651
|
+
[12]: ./docs/writing-a-plugin.md
|
|
652
|
+
[13]: ./docs/compilers.md
|
|
653
|
+
[14]: ./docs/custom-reporters.md
|
|
654
|
+
[15]: #create-a-new-plugin
|
|
655
|
+
[16]: #public-exports
|
|
656
|
+
[17]: https://github.com/depcheck/depcheck
|
|
657
|
+
[18]: https://github.com/smeijer/unimported
|
|
658
|
+
[19]: https://github.com/pzavolinsky/ts-unused-exports
|
|
659
|
+
[20]: https://github.com/nadeesha/ts-prune
|
|
660
|
+
[21]: #production-mode
|
|
661
|
+
[22]: https://github.com/blockprotocol/blockprotocol
|
|
662
|
+
[23]: https://github.com/RebeccaStevens/deepmerge-ts
|
|
663
|
+
[24]: https://github.com/eslint-functional/eslint-plugin-functional
|
|
664
|
+
[25]: https://github.com/freeCodeCamp/freeCodeCamp
|
|
665
|
+
[26]: https://github.com/RebeccaStevens/is-immutable-type
|
|
666
|
+
[27]: https://github.com/release-it/release-it
|
|
667
|
+
[28]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
|
|
633
668
|
[plugin-ava]: ./src/plugins/ava
|
|
634
669
|
[plugin-babel]: ./src/plugins/babel
|
|
635
670
|
[plugin-capacitor]: ./src/plugins/capacitor
|
|
636
671
|
[plugin-changesets]: ./src/plugins/changesets
|
|
672
|
+
[plugin-commitizen]: ./src/plugins/commitizen
|
|
637
673
|
[plugin-commitlint]: ./src/plugins/commitlint
|
|
638
674
|
[plugin-cspell]: ./src/plugins/cspell
|
|
639
675
|
[plugin-cypress]: ./src/plugins/cypress
|
package/dist/binaries/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const getReferencesFromScripts = (npmScripts, options = {}) => {
|
|
|
16
16
|
binaries: binaries
|
|
17
17
|
.map(stripBinary)
|
|
18
18
|
.map(getPackageNameFromModuleSpecifier)
|
|
19
|
+
.filter(binaryName => !binaryName.startsWith('.'))
|
|
19
20
|
.filter(binaryName => !IGNORED_GLOBAL_BINARIES.includes(binaryName) && !ignore.includes(binaryName)),
|
|
20
21
|
};
|
|
21
22
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import parseArgs from 'minimist';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { compact } from '../../util/array.js';
|
|
3
|
+
import { tryResolveFilePaths } from './util.js';
|
|
4
|
+
const argFilters = {
|
|
4
5
|
'babel-node': parsed => [parsed._[0], parsed.require].flat(),
|
|
5
6
|
'ts-node': parsed => [parsed._[0], parsed.require].flat(),
|
|
6
7
|
tsx: parsed => parsed._.filter(p => p !== 'watch'),
|
|
@@ -8,7 +9,7 @@ const argResolvers = {
|
|
|
8
9
|
};
|
|
9
10
|
export const resolve = (binary, args, { cwd }) => {
|
|
10
11
|
const parsed = parseArgs(args, { string: ['r'], alias: { require: ['r', 'loader'] } });
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
return [binary, ...tryResolveFilePaths(cwd,
|
|
12
|
+
const argFilter = argFilters[binary] ?? argFilters.default;
|
|
13
|
+
const filteredArgs = compact(argFilter(parsed));
|
|
14
|
+
return [binary, ...tryResolveFilePaths(cwd, filteredArgs)];
|
|
14
15
|
};
|
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
import parseArgs from 'minimist';
|
|
2
|
-
import {
|
|
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));
|
|
2
|
+
import { tryResolveFilePath, tryResolveFilePaths } from './util.js';
|
|
17
3
|
export const resolve = (binary, args, { cwd }) => {
|
|
18
4
|
const parsed = parseArgs(args, { string: ['r'], alias: { require: ['r', 'loader', 'experimental-loader'] } });
|
|
19
5
|
return [...tryResolveFilePath(cwd, parsed._[0]), ...tryResolveFilePaths(cwd, [parsed.require].flat())];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import parseArgs from 'minimist';
|
|
2
|
+
import { tryResolveFilePaths } from './util.js';
|
|
3
|
+
export const resolve = (binary, args, { cwd, fromArgs }) => {
|
|
4
|
+
const safeArgs = args.filter(arg => arg !== '--watch');
|
|
5
|
+
const parsed = parseArgs(safeArgs, { alias: { plugin: 'p' } });
|
|
6
|
+
const watchers = parsed.watch ? fromArgs(Object.values(parsed.watch)) : [];
|
|
7
|
+
const plugins = parsed.plugin ? tryResolveFilePaths(cwd, [parsed.plugin].flat()) : [];
|
|
8
|
+
const configPlugins = parsed.configPlugin ? tryResolveFilePaths(cwd, [parsed.configPlugin].flat()) : [];
|
|
9
|
+
return [binary, ...watchers, ...plugins, ...configPlugins];
|
|
10
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isInNodeModules, join } from '../../util/path.js';
|
|
2
|
+
import { _tryResolve } from '../../util/require.js';
|
|
3
|
+
export const tryResolveFilePath = (cwd, specifier, fallback) => {
|
|
4
|
+
if (specifier) {
|
|
5
|
+
const filePath = join(cwd, specifier);
|
|
6
|
+
if (!isInNodeModules(filePath)) {
|
|
7
|
+
const resolvedFilePath = _tryResolve(filePath, cwd);
|
|
8
|
+
if (resolvedFilePath)
|
|
9
|
+
return [resolvedFilePath];
|
|
10
|
+
}
|
|
11
|
+
return fallback ? [fallback] : [];
|
|
12
|
+
}
|
|
13
|
+
return [];
|
|
14
|
+
};
|
|
15
|
+
export const tryResolveFilePaths = (cwd, specifiers) => specifiers.flatMap(specifier => tryResolveFilePath(cwd, specifier, specifier));
|
package/dist/cli.js
CHANGED
|
File without changes
|