knip 2.33.1 → 2.33.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.
@@ -182,8 +182,13 @@ export class WorkspaceWorker {
182
182
  const configFilePaths = allConfigFilePaths.filter(filePath => !filePath.endsWith('package.json') ||
183
183
  get(this.manifest, 'PACKAGE_JSON_PATH' in plugin ? plugin.PACKAGE_JSON_PATH : pluginName));
184
184
  debugLogArray(`Found ${plugin.NAME} config file paths`, configFilePaths);
185
- if (patterns.length > 0 && configFilePaths.length === 0)
186
- continue;
185
+ if (patterns.length > 0 && configFilePaths.length === 0) {
186
+ if (typeof pluginConfig !== 'boolean' && pluginConfig.entry !== null && pluginConfig.entry.length > 0) {
187
+ }
188
+ else {
189
+ continue;
190
+ }
191
+ }
187
192
  if (patterns.length === 0)
188
193
  configFilePaths.push(FAKE_PATH);
189
194
  const pluginDependencies = new Set();
@@ -1,6 +1,7 @@
1
+ import { IGNORED_FILE_EXTENSIONS } from '../constants.js';
1
2
  import { compact } from '../util/array.js';
2
3
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
3
- import { isInternal } from '../util/path.js';
4
+ import { extname, isInternal } from '../util/path.js';
4
5
  import { timerify } from '../util/Performance.js';
5
6
  import { isBinary } from '../util/protocols.js';
6
7
  import { getBinariesFromScript } from './bash-parser.js';
@@ -10,8 +11,14 @@ const getDependenciesFromScripts = (npmScripts, options = {}) => {
10
11
  const scripts = typeof npmScripts === 'string' ? [npmScripts] : [...npmScripts];
11
12
  const results = scripts.flatMap(script => getBinariesFromScript(script, { cwd, manifest, knownGlobalsOnly }));
12
13
  return compact(results.map(identifier => {
13
- if (isBinary(identifier) || isInternal(identifier))
14
+ if (isBinary(identifier))
14
15
  return identifier;
16
+ if (isInternal(identifier)) {
17
+ const ext = extname(identifier);
18
+ if (ext && IGNORED_FILE_EXTENSIONS.includes(ext))
19
+ return;
20
+ return identifier;
21
+ }
15
22
  return getPackageNameFromModuleSpecifier(identifier);
16
23
  }));
17
24
  };
package/dist/constants.js CHANGED
@@ -45,6 +45,7 @@ export const IGNORED_FILE_EXTENSIONS = [
45
45
  '.sass',
46
46
  '.scss',
47
47
  '.svg',
48
+ '.sh',
48
49
  '.ttf',
49
50
  '.webp',
50
51
  '.woff',
@@ -14,12 +14,14 @@ export const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
14
14
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
15
15
  return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
16
16
  };
17
- const findPlaywrightDependencies = async (configFilePath, { cwd }) => {
18
- const config = await load(configFilePath);
19
- const projects = config.projects ? [config, ...config.projects] : [config];
20
- const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
21
- if (patterns.length > 0)
22
- return patterns;
23
- return toEntryPatterns(ENTRY_FILE_PATTERNS, cwd, configFilePath, config);
17
+ const findPlaywrightDependencies = async (configFilePath, { cwd, config }) => {
18
+ const cfg = await load(configFilePath);
19
+ if (cfg) {
20
+ const projects = cfg.projects ? [cfg, ...cfg.projects] : [cfg];
21
+ const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
22
+ if (patterns.length > 0)
23
+ return patterns;
24
+ }
25
+ return toEntryPatterns(config?.entry ?? ENTRY_FILE_PATTERNS, cwd, configFilePath, cfg ?? {});
24
26
  };
25
27
  export const findDependencies = timerify(findPlaywrightDependencies);
@@ -3,6 +3,7 @@ export declare const NAME = "Storybook";
3
3
  export declare const ENABLERS: (string | RegExp)[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const STORIES_FILE_PATTERNS: string[];
6
7
  export declare const ENTRY_FILE_PATTERNS: string[];
7
8
  export declare const PROJECT_FILE_PATTERNS: string[];
8
9
  export declare const findDependencies: GenericPluginCallback;
@@ -1,23 +1,27 @@
1
+ import { dirname, join, relative } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  import { toEntryPattern } from '../../util/protocols.js';
4
5
  export const NAME = 'Storybook';
5
6
  export const ENABLERS = [/^@storybook\//, '@nrwl/storybook'];
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const CONFIG_FILE_PATTERNS = ['.storybook/{main,manager,test-runner}.{js,ts}'];
8
- export const ENTRY_FILE_PATTERNS = ['.storybook/preview.{js,jsx,ts,tsx}', '**/*.stories.{js,jsx,ts,tsx}'];
8
+ export const CONFIG_FILE_PATTERNS = ['.storybook/{main,test-runner}.{js,ts}'];
9
+ export const STORIES_FILE_PATTERNS = ['**/*.stories.{js,jsx,ts,tsx}'];
10
+ export const ENTRY_FILE_PATTERNS = ['.storybook/{manager,preview}.{js,jsx,ts,tsx}', ...STORIES_FILE_PATTERNS];
9
11
  export const PROJECT_FILE_PATTERNS = ['.storybook/**/*.{js,jsx,ts,tsx}'];
10
- const findStorybookDependencies = async (configFilePath, { isProduction }) => {
11
- const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
12
+ const findStorybookDependencies = async (configFilePath, { isProduction, config }) => {
13
+ const cfg = await load(configFilePath);
14
+ const stories = (typeof cfg.stories === 'function' ? await cfg.stories(STORIES_FILE_PATTERNS) : cfg.stories)?.map(pattern => relative(join(dirname(configFilePath), pattern)));
15
+ const cfgPatterns = [...(config?.entry ?? []), ...(stories ?? [])];
16
+ const entryPatterns = (cfgPatterns.length > 0 ? cfgPatterns : ENTRY_FILE_PATTERNS).map(toEntryPattern);
12
17
  if (isProduction)
13
18
  return entryPatterns;
14
- const config = await load(configFilePath);
15
- if (!config)
19
+ if (!cfg)
16
20
  return [];
17
- const addons = config.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
18
- const builder = config?.core?.builder;
21
+ const addons = cfg.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
22
+ const builder = cfg?.core?.builder;
19
23
  const builderPackages = builder && /webpack/.test(builder) ? [`@storybook/builder-${builder}`, `@storybook/manager-${builder}`] : [];
20
- const frameworks = config.framework?.name ? [config.framework.name] : [];
24
+ const frameworks = cfg.framework?.name ? [cfg.framework.name] : [];
21
25
  return [...entryPatterns, ...addons, ...builderPackages, ...frameworks];
22
26
  };
23
27
  export const findDependencies = timerify(findStorybookDependencies);
@@ -1,4 +1,5 @@
1
1
  export type StorybookConfig = {
2
+ stories?: string[] | ((patterns: string[]) => Promise<string[]>);
2
3
  addons?: (string | {
3
4
  name: string;
4
5
  })[];
@@ -53,16 +53,16 @@ const findWebpackDependencies = async (configFilePath, { manifest, isProduction
53
53
  const dependencies = passes.flatMap(isProduction => {
54
54
  const env = { production: isProduction };
55
55
  const argv = { mode: isProduction ? 'production' : 'development' };
56
- const cfg = typeof config === 'function' ? config(env, argv) : config;
57
- return [cfg].flat().flatMap(config => {
58
- const dependencies = (config.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
56
+ const resolvedConfig = typeof config === 'function' ? config(env, argv) : config;
57
+ return [resolvedConfig].flat().flatMap(options => {
58
+ const dependencies = (options.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
59
59
  const entries = [];
60
- if (typeof cfg.entry === 'string')
61
- entries.push(cfg.entry);
62
- else if (Array.isArray(cfg.entry))
63
- entries.push(...cfg.entry);
64
- else if (typeof cfg.entry === 'object') {
65
- Object.values(cfg.entry).map(entry => {
60
+ if (typeof options.entry === 'string')
61
+ entries.push(options.entry);
62
+ else if (Array.isArray(options.entry))
63
+ entries.push(...options.entry);
64
+ else if (typeof options.entry === 'object') {
65
+ Object.values(options.entry).map(entry => {
66
66
  if (typeof entry === 'string')
67
67
  entries.push(entry);
68
68
  else if (Array.isArray(entry))
@@ -73,7 +73,7 @@ const findWebpackDependencies = async (configFilePath, { manifest, isProduction
73
73
  entries.push(entry['filename']);
74
74
  });
75
75
  }
76
- return [...dependencies, ...entries.map(entry => (config.context ? join(config.context, entry) : entry))];
76
+ return [...dependencies, ...entries.map(entry => (options.context ? join(options.context, entry) : entry))];
77
77
  });
78
78
  });
79
79
  const scripts = Object.values(manifest.scripts ?? {});
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.33.1";
1
+ export declare const version = "2.33.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.33.1';
1
+ export const version = '2.33.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.33.1",
3
+ "version": "2.33.2",
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",
@@ -69,8 +69,8 @@
69
69
  "@release-it/bumper": "5.1.0",
70
70
  "@swc/cli": "0.1.62",
71
71
  "@swc/core": "1.3.92",
72
- "@types/eslint": "8.44.3",
73
- "@types/js-yaml": "4.0.6",
72
+ "@types/eslint": "8.44.4",
73
+ "@types/js-yaml": "4.0.7",
74
74
  "@types/micromatch": "4.0.3",
75
75
  "@types/minimist": "1.2.3",
76
76
  "@types/node": "20.8.4",
@@ -83,8 +83,8 @@
83
83
  "eslint": "8.51.0",
84
84
  "eslint-import-resolver-typescript": "3.6.1",
85
85
  "eslint-plugin-import": "2.28.1",
86
- "eslint-plugin-n": "16.1.0",
87
- "playwright": "1.38.1",
86
+ "eslint-plugin-n": "16.2.0",
87
+ "playwright": "1.39.0",
88
88
  "prettier": "3.0.3",
89
89
  "release-it": "16.2.1",
90
90
  "remark-cli": "12.0.0",