knip 4.0.2 → 4.0.4

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.
@@ -132,7 +132,7 @@ export class DependencyDeputy {
132
132
  return false;
133
133
  }
134
134
  maybeAddReferencedBinary(workspace, binaryName) {
135
- if (IGNORED_GLOBAL_BINARIES.includes(binaryName))
135
+ if (IGNORED_GLOBAL_BINARIES.has(binaryName))
136
136
  return true;
137
137
  this.addReferencedBinary(workspace.name, binaryName);
138
138
  const workspaceNames = this.isStrict ? [workspace.name] : [workspace.name, ...[...workspace.ancestors].reverse()];
@@ -269,7 +269,7 @@ export class DependencyDeputy {
269
269
  const peerDependencies = this.getPeerDependencies(workspaceName);
270
270
  ignoreDependencies
271
271
  .filter(packageName => {
272
- if (hasMatchInArray(IGNORED_DEPENDENCIES, packageName))
272
+ if (hasMatchInSet(IGNORED_DEPENDENCIES, packageName))
273
273
  return true;
274
274
  if (this.ignoreDependencies.includes(packageName))
275
275
  return true;
@@ -282,7 +282,7 @@ export class DependencyDeputy {
282
282
  });
283
283
  ignoreBinaries
284
284
  .filter(binaryName => {
285
- if (hasMatchInArray(IGNORED_GLOBAL_BINARIES, binaryName))
285
+ if (hasMatchInSet(IGNORED_GLOBAL_BINARIES, binaryName))
286
286
  return true;
287
287
  if (this.ignoreBinaries.includes(binaryName))
288
288
  return true;
@@ -300,7 +300,7 @@ export class DependencyDeputy {
300
300
  const peerDependencies = this.getPeerDependencies(ROOT_WORKSPACE_NAME);
301
301
  Array.from(rootIgnoreDependencies.keys())
302
302
  .filter(packageName => {
303
- if (hasMatchInArray(IGNORED_DEPENDENCIES, packageName))
303
+ if (hasMatchInSet(IGNORED_DEPENDENCIES, packageName))
304
304
  return true;
305
305
  const isReferenced = rootIgnoreDependencies.get(packageName) !== 0;
306
306
  const isListed = hasMatchInArray(dependencies, packageName) && !hasMatchInArray(peerDependencies, packageName);
@@ -309,7 +309,7 @@ export class DependencyDeputy {
309
309
  .forEach(identifier => configurationHints.add({ workspaceName: ROOT_WORKSPACE_NAME, identifier, type: 'ignoreDependencies' }));
310
310
  Array.from(rootIgnoreBinaries.keys())
311
311
  .filter(binaryName => {
312
- if (hasMatchInArray(IGNORED_GLOBAL_BINARIES, binaryName))
312
+ if (hasMatchInSet(IGNORED_GLOBAL_BINARIES, binaryName))
313
313
  return true;
314
314
  const isReferenced = rootIgnoreBinaries.get(binaryName) !== 0;
315
315
  const isInstalled = hasMatchInArray(Array.from(installedBinaries?.keys() ?? []), binaryName);
@@ -3,8 +3,8 @@ export declare const ROOT_WORKSPACE_NAME = ".";
3
3
  export declare const KNIP_CONFIG_LOCATIONS: string[];
4
4
  export declare const DEFAULT_EXTENSIONS: string[];
5
5
  export declare const GLOBAL_IGNORE_PATTERNS: string[];
6
- export declare const IGNORED_GLOBAL_BINARIES: string[];
7
- export declare const IGNORED_DEPENDENCIES: string[];
6
+ export declare const IGNORED_GLOBAL_BINARIES: Set<string>;
7
+ export declare const IGNORED_DEPENDENCIES: Set<string>;
8
8
  export declare const DUMMY_VIRTUAL_FILE_EXTENSIONS: Set<string>;
9
9
  export declare const IGNORED_FILE_EXTENSIONS: Set<string>;
10
10
  export declare const IGNORE_DEFINITELY_TYPED: string[];
package/dist/constants.js CHANGED
@@ -11,7 +11,7 @@ export const KNIP_CONFIG_LOCATIONS = [
11
11
  ];
12
12
  export const DEFAULT_EXTENSIONS = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts'];
13
13
  export const GLOBAL_IGNORE_PATTERNS = ['**/node_modules/**', '.yarn'];
14
- export const IGNORED_GLOBAL_BINARIES = [
14
+ export const IGNORED_GLOBAL_BINARIES = new Set([
15
15
  'bash',
16
16
  'bun',
17
17
  'bunx',
@@ -45,8 +45,8 @@ export const IGNORED_GLOBAL_BINARIES = [
45
45
  'true',
46
46
  'yarn',
47
47
  'xargs',
48
- ];
49
- export const IGNORED_DEPENDENCIES = ['knip', 'typescript'];
48
+ ]);
49
+ export const IGNORED_DEPENDENCIES = new Set(['knip', 'typescript']);
50
50
  export const DUMMY_VIRTUAL_FILE_EXTENSIONS = new Set(['.html', '.jpeg', '.jpg', '.png', '.svg', '.webp']);
51
51
  export const IGNORED_FILE_EXTENSIONS = new Set([
52
52
  '.avif',
@@ -0,0 +1,139 @@
1
+ import type { EleventyConfig } from './types.js';
2
+ export declare class DummyEleventyConfig {
3
+ constructor();
4
+ _getUniqueId(): void;
5
+ reset(): void;
6
+ versionCheck(): void;
7
+ on(): void;
8
+ emit(): void;
9
+ _enablePluginExecution(): void;
10
+ addMarkdownHighlighter(): void;
11
+ addLiquidTag(): void;
12
+ addLiquidFilter(): void;
13
+ addNunjucksAsyncFilter(): void;
14
+ addNunjucksFilter(): void;
15
+ addHandlebarsHelper(): void;
16
+ addFilter(): void;
17
+ addAsyncFilter(): void;
18
+ getFilter(): void;
19
+ addNunjucksTag(): void;
20
+ addGlobalData(): void;
21
+ addNunjucksGlobal(): void;
22
+ addTransform(): void;
23
+ addLinter(): void;
24
+ addLayoutAlias(): void;
25
+ setLayoutResolution(): void;
26
+ enableLayoutResolution(): void;
27
+ getCollections(): void;
28
+ addCollection(): void;
29
+ addPlugin(): void;
30
+ _getPluginName(): void;
31
+ _executePlugin(): void;
32
+ getNamespacedName(): void;
33
+ namespace(): void;
34
+ addPassthroughCopy(input: string | Record<string, string>): void;
35
+ _normalizeTemplateFormats(): void;
36
+ setTemplateFormats(): void;
37
+ addTemplateFormats(): void;
38
+ setLibrary(): void;
39
+ amendLibrary(): void;
40
+ setPugOptions(): void;
41
+ setLiquidOptions(): void;
42
+ setNunjucksEnvironmentOptions(): void;
43
+ setNunjucksPrecompiledTemplates(): void;
44
+ setEjsOptions(): void;
45
+ setDynamicPermalinks(): void;
46
+ setUseGitIgnore(): void;
47
+ addShortcode(): void;
48
+ addAsyncShortcode(): void;
49
+ addNunjucksAsyncShortcode(): void;
50
+ addNunjucksShortcode(): void;
51
+ addLiquidShortcode(): void;
52
+ addHandlebarsShortcode(): void;
53
+ addPairedShortcode(): void;
54
+ addPairedAsyncShortcode(): void;
55
+ addPairedNunjucksAsyncShortcode(): void;
56
+ addPairedNunjucksShortcode(): void;
57
+ addPairedLiquidShortcode(): void;
58
+ addPairedHandlebarsShortcode(): void;
59
+ addJavaScriptFunction(): void;
60
+ setDataDeepMerge(): void;
61
+ isDataDeepMergeModified(): void;
62
+ addWatchTarget(): void;
63
+ setWatchJavaScriptDependencies(): void;
64
+ setServerOptions(): void;
65
+ setBrowserSyncConfig(): void;
66
+ setChokidarConfig(): void;
67
+ setWatchThrottleWaitTime(): void;
68
+ setFrontMatterParsingOptions(): void;
69
+ setQuietMode(): void;
70
+ addExtension(): void;
71
+ addDataExtension(): void;
72
+ setUseTemplateCache(): void;
73
+ setPrecompiledCollections(): void;
74
+ setServerPassthroughCopyBehavior(): void;
75
+ addUrlTransform(): void;
76
+ setDataFileSuffixes(): void;
77
+ setDataFileBaseName(): void;
78
+ getMergingConfigObject(): void;
79
+ _uniqueId: {};
80
+ events: {};
81
+ benchmarkManager: {};
82
+ benchmarks: {};
83
+ collections: {};
84
+ precompiledCollections: {};
85
+ templateFormats: {};
86
+ liquidOptions: {};
87
+ liquidTags: {};
88
+ liquidFilters: {};
89
+ liquidShortcodes: {};
90
+ liquidPairedShortcodes: {};
91
+ nunjucksEnvironmentOptions: {};
92
+ nunjucksPrecompiledTemplates: {};
93
+ nunjucksFilters: {};
94
+ nunjucksAsyncFilters: {};
95
+ nunjucksTags: {};
96
+ nunjucksGlobals: {};
97
+ nunjucksShortcodes: {};
98
+ nunjucksAsyncShortcodes: {};
99
+ nunjucksPairedShortcodes: {};
100
+ nunjucksAsyncPairedShortcodes: {};
101
+ javascriptFunctions: {};
102
+ markdownHighlighter: null;
103
+ libraryOverrides: {};
104
+ passthroughCopies: Record<string, Record<never, never>>;
105
+ layoutAliases: {};
106
+ layoutResolution: boolean;
107
+ linters: {};
108
+ transforms: {};
109
+ activeNamespace: string;
110
+ DateTime: {};
111
+ dynamicPermalinks: boolean;
112
+ useGitIgnore: boolean;
113
+ ignores: Set<unknown>;
114
+ watchIgnores: Set<unknown>;
115
+ dataDeepMerge: boolean;
116
+ extensionMap: Set<unknown>;
117
+ watchJavaScriptDependencies: boolean;
118
+ additionalWatchTargets: never[];
119
+ serverOptions: {};
120
+ globalData: {};
121
+ chokidarConfig: {};
122
+ watchThrottleWaitTime: number;
123
+ dataExtensions: Map<any, any>;
124
+ quietMode: boolean;
125
+ plugins: never[];
126
+ _pluginExecution: boolean;
127
+ useTemplateCache: boolean;
128
+ dataFilterSelectors: Set<unknown>;
129
+ libraryAmendments: {};
130
+ serverPassthroughCopyBehavior: string;
131
+ urlTransforms: never[];
132
+ dataFileSuffixesOverride: boolean;
133
+ dataFileDirBaseNameOverride: boolean;
134
+ frontMatterParsingOptions: {
135
+ engines: {};
136
+ };
137
+ templateFormatsAdded: {};
138
+ }
139
+ export declare const defaultEleventyConfig: EleventyConfig;
@@ -0,0 +1,156 @@
1
+ export class DummyEleventyConfig {
2
+ constructor() { }
3
+ _getUniqueId() { }
4
+ reset() { }
5
+ versionCheck() { }
6
+ on() { }
7
+ emit() { }
8
+ _enablePluginExecution() { }
9
+ addMarkdownHighlighter() { }
10
+ addLiquidTag() { }
11
+ addLiquidFilter() { }
12
+ addNunjucksAsyncFilter() { }
13
+ addNunjucksFilter() { }
14
+ addHandlebarsHelper() { }
15
+ addFilter() { }
16
+ addAsyncFilter() { }
17
+ getFilter() { }
18
+ addNunjucksTag() { }
19
+ addGlobalData() { }
20
+ addNunjucksGlobal() { }
21
+ addTransform() { }
22
+ addLinter() { }
23
+ addLayoutAlias() { }
24
+ setLayoutResolution() { }
25
+ enableLayoutResolution() { }
26
+ getCollections() { }
27
+ addCollection() { }
28
+ addPlugin() { }
29
+ _getPluginName() { }
30
+ _executePlugin() { }
31
+ getNamespacedName() { }
32
+ namespace() { }
33
+ addPassthroughCopy(input) {
34
+ if (typeof input === 'string') {
35
+ this.passthroughCopies[input] = {};
36
+ }
37
+ else {
38
+ for (let [inputPath] of Object.entries(input)) {
39
+ this.passthroughCopies[inputPath] = {};
40
+ }
41
+ }
42
+ }
43
+ _normalizeTemplateFormats() { }
44
+ setTemplateFormats() { }
45
+ addTemplateFormats() { }
46
+ setLibrary() { }
47
+ amendLibrary() { }
48
+ setPugOptions() { }
49
+ setLiquidOptions() { }
50
+ setNunjucksEnvironmentOptions() { }
51
+ setNunjucksPrecompiledTemplates() { }
52
+ setEjsOptions() { }
53
+ setDynamicPermalinks() { }
54
+ setUseGitIgnore() { }
55
+ addShortcode() { }
56
+ addAsyncShortcode() { }
57
+ addNunjucksAsyncShortcode() { }
58
+ addNunjucksShortcode() { }
59
+ addLiquidShortcode() { }
60
+ addHandlebarsShortcode() { }
61
+ addPairedShortcode() { }
62
+ addPairedAsyncShortcode() { }
63
+ addPairedNunjucksAsyncShortcode() { }
64
+ addPairedNunjucksShortcode() { }
65
+ addPairedLiquidShortcode() { }
66
+ addPairedHandlebarsShortcode() { }
67
+ addJavaScriptFunction() { }
68
+ setDataDeepMerge() { }
69
+ isDataDeepMergeModified() { }
70
+ addWatchTarget() { }
71
+ setWatchJavaScriptDependencies() { }
72
+ setServerOptions() { }
73
+ setBrowserSyncConfig() { }
74
+ setChokidarConfig() { }
75
+ setWatchThrottleWaitTime() { }
76
+ setFrontMatterParsingOptions() { }
77
+ setQuietMode() { }
78
+ addExtension() { }
79
+ addDataExtension() { }
80
+ setUseTemplateCache() { }
81
+ setPrecompiledCollections() { }
82
+ setServerPassthroughCopyBehavior() { }
83
+ addUrlTransform() { }
84
+ setDataFileSuffixes() { }
85
+ setDataFileBaseName() { }
86
+ getMergingConfigObject() { }
87
+ _uniqueId = {};
88
+ events = {};
89
+ benchmarkManager = {};
90
+ benchmarks = {};
91
+ collections = {};
92
+ precompiledCollections = {};
93
+ templateFormats = {};
94
+ liquidOptions = {};
95
+ liquidTags = {};
96
+ liquidFilters = {};
97
+ liquidShortcodes = {};
98
+ liquidPairedShortcodes = {};
99
+ nunjucksEnvironmentOptions = {};
100
+ nunjucksPrecompiledTemplates = {};
101
+ nunjucksFilters = {};
102
+ nunjucksAsyncFilters = {};
103
+ nunjucksTags = {};
104
+ nunjucksGlobals = {};
105
+ nunjucksShortcodes = {};
106
+ nunjucksAsyncShortcodes = {};
107
+ nunjucksPairedShortcodes = {};
108
+ nunjucksAsyncPairedShortcodes = {};
109
+ javascriptFunctions = {};
110
+ markdownHighlighter = null;
111
+ libraryOverrides = {};
112
+ passthroughCopies = {};
113
+ layoutAliases = {};
114
+ layoutResolution = true;
115
+ linters = {};
116
+ transforms = {};
117
+ activeNamespace = '';
118
+ DateTime = {};
119
+ dynamicPermalinks = true;
120
+ useGitIgnore = true;
121
+ ignores = new Set();
122
+ watchIgnores = new Set();
123
+ dataDeepMerge = true;
124
+ extensionMap = new Set();
125
+ watchJavaScriptDependencies = true;
126
+ additionalWatchTargets = [];
127
+ serverOptions = {};
128
+ globalData = {};
129
+ chokidarConfig = {};
130
+ watchThrottleWaitTime = 0;
131
+ dataExtensions = new Map();
132
+ quietMode = false;
133
+ plugins = [];
134
+ _pluginExecution = false;
135
+ useTemplateCache = true;
136
+ dataFilterSelectors = new Set();
137
+ libraryAmendments = {};
138
+ serverPassthroughCopyBehavior = '';
139
+ urlTransforms = [];
140
+ dataFileSuffixesOverride = false;
141
+ dataFileDirBaseNameOverride = false;
142
+ frontMatterParsingOptions = {
143
+ engines: {},
144
+ };
145
+ templateFormatsAdded = {};
146
+ }
147
+ export const defaultEleventyConfig = {
148
+ dir: {
149
+ input: '.',
150
+ output: '_site',
151
+ includes: '_includes',
152
+ layouts: '_includes',
153
+ data: '_data',
154
+ },
155
+ templateFormats: '11ty.js',
156
+ };
@@ -3,8 +3,10 @@ declare const _default: {
3
3
  NAME: string;
4
4
  ENABLERS: string[];
5
5
  isEnabled: IsPluginEnabledCallback;
6
+ CONFIG_FILE_PATTERNS: string[];
6
7
  ENTRY_FILE_PATTERNS: string[];
7
8
  PRODUCTION_ENTRY_FILE_PATTERNS: string[];
9
+ PROJECT_FILE_PATTERNS: string[];
8
10
  findDependencies: GenericPluginCallback;
9
11
  };
10
12
  export default _default;
@@ -1,23 +1,63 @@
1
+ import { DEFAULT_EXTENSIONS } from '../../constants.js';
2
+ import { isDirectory } from '../../util/fs.js';
3
+ import { dirname, isInternal, join } from '../../util/path.js';
1
4
  import { timerify } from '../../util/Performance.js';
2
- import { hasDependency } from '../../util/plugin.js';
3
- import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
5
+ import { hasDependency, load } from '../../util/plugin.js';
6
+ import { toProductionEntryPattern } from '../../util/protocols.js';
7
+ import { DummyEleventyConfig, defaultEleventyConfig } from './helpers.js';
4
8
  const NAME = 'Eleventy';
5
9
  const ENABLERS = ['@11ty/eleventy'];
6
10
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- const ENTRY_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}'];
11
+ const CONFIG_FILE_PATTERNS = ['.eleventy.js', 'eleventy.config.{js,cjs}'];
12
+ const ENTRY_FILE_PATTERNS = [];
8
13
  const PRODUCTION_ENTRY_FILE_PATTERNS = ['posts/**/*.11tydata.js', '_data/**/*.{js,cjs,mjs}'];
14
+ const PROJECT_FILE_PATTERNS = [];
9
15
  const findEleventyDependencies = async (configFilePath, options) => {
10
16
  const { config } = options;
11
- return config.entry
12
- ? config.entry.map(toProductionEntryPattern)
13
- : [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
17
+ let localConfig = (await load(configFilePath));
18
+ if (!localConfig)
19
+ return config.entry
20
+ ? config.entry.map(toProductionEntryPattern)
21
+ : PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
22
+ const dummyUserConfig = new DummyEleventyConfig();
23
+ if (typeof localConfig === 'function')
24
+ localConfig = await localConfig(dummyUserConfig);
25
+ const inputDir = localConfig?.dir?.input || defaultEleventyConfig.dir.input;
26
+ const dataDir = localConfig?.dir?.data || defaultEleventyConfig.dir.data;
27
+ const templateFormats = localConfig.templateFormats || defaultEleventyConfig.templateFormats;
28
+ const exts = DEFAULT_EXTENSIONS.map(extname => extname.slice(1)).join(',');
29
+ const copiedPackages = new Set();
30
+ const copiedEntries = new Set();
31
+ for (const path of Object.keys(dummyUserConfig.passthroughCopies)) {
32
+ const isDir = !path.includes('*') && isDirectory(join(dirname(configFilePath), path));
33
+ if (isDir) {
34
+ copiedEntries.add(join(path, `**/*.{${exts}}`));
35
+ }
36
+ else if (isInternal(path)) {
37
+ copiedEntries.add(path);
38
+ }
39
+ else {
40
+ copiedPackages.add(path);
41
+ }
42
+ }
43
+ return [
44
+ ...(config?.entry ?? [
45
+ join(inputDir, dataDir, '**/*.js'),
46
+ join(inputDir, `**/*.{${typeof templateFormats === 'string' ? templateFormats : templateFormats.join(',')}}`),
47
+ join(inputDir, '**/*.11tydata.js'),
48
+ ...copiedEntries,
49
+ ]).map(toProductionEntryPattern),
50
+ ...copiedPackages,
51
+ ];
14
52
  };
15
53
  const findDependencies = timerify(findEleventyDependencies);
16
54
  export default {
17
55
  NAME,
18
56
  ENABLERS,
19
57
  isEnabled,
58
+ CONFIG_FILE_PATTERNS,
20
59
  ENTRY_FILE_PATTERNS,
21
60
  PRODUCTION_ENTRY_FILE_PATTERNS,
61
+ PROJECT_FILE_PATTERNS,
22
62
  findDependencies,
23
63
  };
@@ -0,0 +1,10 @@
1
+ export type EleventyConfig = {
2
+ dir: {
3
+ input: string;
4
+ output: string;
5
+ includes: string;
6
+ layouts: string;
7
+ data: string;
8
+ };
9
+ templateFormats: string | string[];
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@ import { basename } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  const NAME = 'PostCSS';
5
- const ENABLERS = ['postcss', 'next'];
5
+ const ENABLERS = ['postcss', 'postcss-cli', 'next'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  const CONFIG_FILE_PATTERNS = ['postcss.config.{cjs,js}', 'postcss.config.json', 'package.json'];
8
8
  const findPostCSSDependencies = async (configFilePath, options) => {
@@ -5,6 +5,12 @@ const NAME = 'Stylelint';
5
5
  const ENABLERS = ['stylelint'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  const CONFIG_FILE_PATTERNS = ['.stylelintrc', '.stylelintrc.{cjs,js,json,yaml,yml}', 'stylelint.config.{cjs,mjs,js}'];
8
+ const findDependenciesInConfig = (config) => {
9
+ const extend = config.extends ? [config.extends].flat().filter(id => !isInternal(id)) : [];
10
+ const plugins = config.plugins ? [config.plugins].flat().filter(id => !isInternal(id)) : [];
11
+ const overrideConfigs = 'overrides' in config ? config.overrides.flatMap(findDependenciesInConfig) : [];
12
+ return [...extend, ...plugins, ...overrideConfigs];
13
+ };
8
14
  const findPluginDependencies = async (configFilePath, options) => {
9
15
  const { manifest, isProduction } = options;
10
16
  if (isProduction)
@@ -12,9 +18,7 @@ const findPluginDependencies = async (configFilePath, options) => {
12
18
  const localConfig = basename(configFilePath) === 'package.json' ? manifest.stylelint : await load(configFilePath);
13
19
  if (!localConfig)
14
20
  return [];
15
- const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
16
- const plugins = localConfig.plugins ? [localConfig.plugins].flat().filter(plugin => !isInternal(plugin)) : [];
17
- return [...extend, ...plugins];
21
+ return findDependenciesInConfig(localConfig);
18
22
  };
19
23
  const findDependencies = timerify(findPluginDependencies);
20
24
  export default {
@@ -1,4 +1,7 @@
1
- export type PluginConfig = {
1
+ export type BaseStyleLintConfig = {
2
2
  extends?: string | string[];
3
3
  plugins?: string[];
4
4
  };
5
+ export type StyleLintConfig = BaseStyleLintConfig & {
6
+ overrides: BaseStyleLintConfig[];
7
+ };
@@ -1,5 +1,5 @@
1
1
  import { compact } from '../../util/array.js';
2
- import { join, relative } from '../../util/path.js';
2
+ import { isInternal, join, relative } from '../../util/path.js';
3
3
  import { timerify } from '../../util/Performance.js';
4
4
  import { hasDependency, load } from '../../util/plugin.js';
5
5
  import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
@@ -23,16 +23,16 @@ const resolveRuleSetDependencies = (rule) => {
23
23
  let useItem = rule.use ?? rule.loader ?? rule;
24
24
  if (typeof useItem === 'function')
25
25
  useItem = useItem(info);
26
- return [useItem].flat().flatMap((useItem) => {
27
- if (!useItem)
26
+ if (typeof useItem === 'string' && hasBabelOptions(rule)) {
27
+ return [useItem, ...getDependenciesFromConfig(rule.options)];
28
+ }
29
+ return [useItem].flat().flatMap((item) => {
30
+ if (!item)
28
31
  return [];
29
- if (hasBabelOptions(useItem)) {
30
- return [
31
- ...resolveUseItem(useItem),
32
- ...getDependenciesFromConfig(useItem.options),
33
- ];
32
+ if (hasBabelOptions(item)) {
33
+ return [...resolveUseItem(item), ...getDependenciesFromConfig(item.options)];
34
34
  }
35
- return resolveUseItem(useItem);
35
+ return resolveUseItem(item);
36
36
  });
37
37
  };
38
38
  const resolveUseItem = (use) => {
@@ -74,9 +74,14 @@ export const findWebpackDependenciesFromConfig = async ({ config, cwd }) => {
74
74
  });
75
75
  }
76
76
  entries.forEach(entry => {
77
- const item = relative(cwd, join(options.context ? options.context : cwd, entry));
78
- const value = options.mode === 'development' ? toEntryPattern(item) : toProductionEntryPattern(item);
79
- entryPatterns.add(value);
77
+ if (!isInternal(entry)) {
78
+ dependencies.add(entry);
79
+ }
80
+ else {
81
+ const item = relative(cwd, join(options.context ? options.context : cwd, entry));
82
+ const value = options.mode === 'development' ? toEntryPattern(item) : toProductionEntryPattern(item);
83
+ entryPatterns.add(value);
84
+ }
80
85
  });
81
86
  }
82
87
  }
@@ -7,7 +7,7 @@ const getImportSpecifiers = (node) => {
7
7
  const importClause = node.argument;
8
8
  if (ts.isLiteralTypeNode(importClause) && ts.isStringLiteral(importClause.literal)) {
9
9
  const identifier = node.qualifier && ts.isIdentifier(node.qualifier) ? String(node.qualifier.escapedText) : 'default';
10
- imports.push({ specifier: importClause.literal.text, identifier, pos: undefined });
10
+ imports.push({ specifier: importClause.literal.text, identifier, pos: importClause.literal.pos });
11
11
  }
12
12
  }
13
13
  ts.forEachChild(node, visit);
@@ -26,11 +26,11 @@ export default visit(isJS, (node, { isFixExports }) => {
26
26
  if (ts.isObjectLiteralExpression(expr) && expr.properties.every(ts.isShorthandPropertyAssignment)) {
27
27
  return expr.properties.map(node => {
28
28
  const fix = isFixExports ? [node.getStart(), node.getEnd()] : undefined;
29
- return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.pos, fix };
29
+ return { node, identifier: node.getText(), type: SymbolType.UNKNOWN, pos: node.getStart(), fix };
30
30
  });
31
31
  }
32
32
  else {
33
- return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos, fix: undefined };
33
+ return { node, identifier: 'default', type: SymbolType.UNKNOWN, pos: expr.pos + 1, fix: undefined };
34
34
  }
35
35
  }
36
36
  }
@@ -118,10 +118,7 @@ export async function globby(patterns, options) {
118
118
  ignore.push(...i.ignores);
119
119
  }
120
120
  const { dir, ...fastGlobOptions } = { ...options, ignore };
121
- debugLogObject(relative(options.cwd, options.dir) || ROOT_WORKSPACE_NAME, `Glob options`, {
122
- patterns,
123
- ...fastGlobOptions,
124
- });
121
+ debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, `Glob options`, { patterns, ...options });
125
122
  return fastGlob(patterns, fastGlobOptions);
126
123
  }
127
124
  export async function isGitIgnoredFn(options) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "4.0.2";
1
+ export declare const version = "4.0.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '4.0.2';
1
+ export const version = '4.0.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {