knip 2.34.1 → 2.35.0

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.
@@ -5,6 +5,9 @@ export const ENABLERS = ['astro'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content/config.ts'];
7
7
  export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx'];
8
- export const findDependencies = async () => {
9
- return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
8
+ export const findDependencies = async (configFilePath, options) => {
9
+ const { config } = options;
10
+ return config.entry
11
+ ? config.entry.map(toProductionEntryPattern)
12
+ : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
10
13
  };
@@ -13,9 +13,10 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
13
13
  'src/html.{js,jsx,ts,tsx}',
14
14
  'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
15
15
  ];
16
- const findGatsbyDependencies = async (configFilePath, { isProduction }) => {
16
+ const findGatsbyDependencies = async (configFilePath, options) => {
17
+ const { isProduction, config } = options;
17
18
  const localConfig = await load(configFilePath);
18
- const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
19
+ const entryPatterns = (config.entry ?? PRODUCTION_ENTRY_FILE_PATTERNS).map(toProductionEntryPattern);
19
20
  if (isProduction || !localConfig)
20
21
  return entryPatterns;
21
22
  if (/gatsby-config/.test(configFilePath)) {
@@ -18,6 +18,9 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
18
18
  ...productionEntryFilePatternsWithoutSrc,
19
19
  ...productionEntryFilePatternsWithoutSrc.map(pattern => `src/${pattern}`),
20
20
  ];
21
- export const findDependencies = async () => {
22
- return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
21
+ export const findDependencies = async (configFilePath, options) => {
22
+ const { config } = options;
23
+ return config.entry
24
+ ? config.entry.map(toProductionEntryPattern)
25
+ : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
23
26
  };
@@ -3,7 +3,7 @@ import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'PostCSS';
4
4
  export const ENABLERS = ['postcss', 'next'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
- export const CONFIG_FILE_PATTERNS = ['postcss.config.js', 'postcss.config.json', 'package.json'];
6
+ export const CONFIG_FILE_PATTERNS = ['postcss.config.{cjs,js}', 'postcss.config.json', 'package.json'];
7
7
  const findPostCSSDependencies = async (configFilePath, options) => {
8
8
  const { manifest, isProduction } = options;
9
9
  if (isProduction)
@@ -11,7 +11,10 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
11
11
  'app/routes/**/*.{js,ts,tsx}',
12
12
  'server.{js,ts}',
13
13
  ];
14
- const findRemixDependencies = async () => {
15
- return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
14
+ const findRemixDependencies = async (configFilePath, options) => {
15
+ const { config } = options;
16
+ return config.entry
17
+ ? config.entry.map(toProductionEntryPattern)
18
+ : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
16
19
  };
17
20
  export const findDependencies = timerify(findRemixDependencies);
@@ -9,6 +9,16 @@ const findViteDependencies = async (configFilePath, options) => {
9
9
  const localConfig = await load(configFilePath);
10
10
  if (!localConfig)
11
11
  return [];
12
+ if (typeof localConfig === 'function') {
13
+ const dependencies = new Set();
14
+ for (const command of ['dev', 'serve', 'build']) {
15
+ for (const mode of ['development', 'production']) {
16
+ const config = await localConfig({ command, mode, ssrBuild: undefined });
17
+ findVitestDeps(config, options).forEach(dependency => dependencies.add(dependency));
18
+ }
19
+ }
20
+ return Array.from(dependencies);
21
+ }
12
22
  return findVitestDeps(localConfig, options);
13
23
  };
14
24
  export const findDependencies = timerify(findViteDependencies);
@@ -1,4 +1,13 @@
1
1
  import type { VitestConfig } from '../vitest/types.js';
2
- export interface ViteConfig extends VitestConfig {
2
+ interface Config extends VitestConfig {
3
3
  plugins: unknown[];
4
4
  }
5
+ export type COMMAND = 'dev' | 'serve' | 'build';
6
+ export type MODE = 'development' | 'production';
7
+ interface Options {
8
+ command: COMMAND;
9
+ mode: MODE;
10
+ ssrBuild?: boolean | undefined;
11
+ }
12
+ export type ViteConfig = Config | ((options: Options) => Config) | ((options: Options) => Promise<Config>);
13
+ export {};
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.34.1";
1
+ export declare const version = "2.35.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.34.1';
1
+ export const version = '2.35.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.34.1",
3
+ "version": "2.35.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",