knip 5.46.1 → 5.46.3

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.
@@ -22,14 +22,16 @@ export class PrincipalFactory {
22
22
  options.compilerOptions = mergePaths(cwd, compilerOptions, paths);
23
23
  if (isFile && compilerOptions.module !== ts.ModuleKind.CommonJS)
24
24
  compilerOptions.moduleResolution ??= ts.ModuleResolutionKind.Bundler;
25
- const principal = this.findReusablePrincipal(compilerOptions);
25
+ const principal = this.findReusablePrincipal(cwd, compilerOptions);
26
26
  if (!isIsolateWorkspaces && principal) {
27
27
  this.linkPrincipal(principal, cwd, compilerOptions, pkgName, compilers);
28
28
  return principal.principal;
29
29
  }
30
30
  return this.addNewPrincipal(options);
31
31
  }
32
- findReusablePrincipal(compilerOptions) {
32
+ findReusablePrincipal(cwd, compilerOptions) {
33
+ if (compilerOptions.rootDir && cwd !== compilerOptions.rootDir)
34
+ return;
33
35
  const workspacePaths = compilerOptions?.paths ? Object.keys(compilerOptions.paths) : [];
34
36
  const principal = Array.from(this.principals).find(principal => {
35
37
  if (compilerOptions.pathsBasePath && principal.principal.compilerOptions.pathsBasePath)
@@ -5,6 +5,7 @@ const commands = [
5
5
  'add',
6
6
  'audit',
7
7
  'bin',
8
+ 'cache',
8
9
  'config',
9
10
  'dedupe',
10
11
  'deploy',
@@ -39,7 +39,7 @@ export const resolve = (binary, _args, options) => {
39
39
  if (id.includes('node_modules/.bin/'))
40
40
  positionals.push(toBinary(extractBinary(id)));
41
41
  else
42
- positionals.push(toDeferResolveEntry(id));
42
+ positionals.push(toDeferResolveEntry(id, { optional: true }));
43
43
  }
44
44
  }
45
45
  const mapToParsedKey = (id) => parsed[id];
@@ -109,7 +109,8 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
109
109
  productionEntryFilePatterns.add(resolvedFilePath);
110
110
  }
111
111
  else if (isDeferResolveEntry(input)) {
112
- entryFilePatterns.add(resolvedFilePath);
112
+ if (!isProduction || !input.optional)
113
+ entryFilePatterns.add(resolvedFilePath);
113
114
  }
114
115
  else {
115
116
  principal.addEntryPath(resolvedFilePath, { skipExportsAnalysis: true });
@@ -1,15 +1,16 @@
1
- import { toEntry } from '../../util/input.js';
1
+ import { toEntry, toProductionEntry } from '../../util/input.js';
2
2
  const title = 'Node.js';
3
3
  const isEnabled = () => true;
4
4
  const config = ['package.json'];
5
5
  const packageJsonPath = (id) => id;
6
6
  const resolveEntryPaths = localConfig => {
7
7
  const scripts = localConfig.scripts;
8
- const entry = ['server.js'];
8
+ const entries = [toProductionEntry('server.js')];
9
9
  if (scripts && Object.keys(scripts).some(script => /(?<=^|\s)node\s(.*)--test/.test(scripts[script]))) {
10
- entry.push(...['**/*{.,-,_}test.?(c|m)js', '**/test-*.?(c|m)js', '**/test.?(c|m)js', '**/test/**/*.?(c|m)js']);
10
+ const patterns = ['**/*{.,-,_}test.?(c|m)js', '**/test-*.?(c|m)js', '**/test.?(c|m)js', '**/test/**/*.?(c|m)js'];
11
+ entries.push(...patterns.map(toEntry));
11
12
  }
12
- return entry.map(toEntry);
13
+ return entries;
13
14
  };
14
15
  const args = {
15
16
  positional: true,
@@ -60,6 +60,17 @@ export const findWebpackDependenciesFromConfig = async ({ config, cwd }) => {
60
60
  for (const loader of options.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []) {
61
61
  inputs.add(toDeferResolve(loader.replace(/\?.*/, '')));
62
62
  }
63
+ for (const plugin of options?.plugins ?? []) {
64
+ if (plugin && plugin.constructor.name === 'ProvidePlugin') {
65
+ const providePluginInstance = plugin;
66
+ if (providePluginInstance.definitions) {
67
+ for (const values of Object.values(providePluginInstance.definitions)) {
68
+ const specifier = typeof values === 'string' ? values : values[0];
69
+ inputs.add(toDeferResolve(specifier));
70
+ }
71
+ }
72
+ }
73
+ }
63
74
  if (typeof options.entry === 'string')
64
75
  entries.push(options.entry);
65
76
  else if (Array.isArray(options.entry))
@@ -1,4 +1,4 @@
1
- import type { Configuration } from 'webpack';
1
+ import type { Configuration, ProvidePlugin } from 'webpack';
2
2
  type Mode = 'none' | 'development' | 'production';
3
3
  export type Env = {
4
4
  production: boolean;
@@ -7,6 +7,6 @@ export type Env = {
7
7
  export type Argv = {
8
8
  mode: Mode;
9
9
  };
10
+ export type { ProvidePlugin };
10
11
  type Configurations = Configuration | Configuration[];
11
12
  export type WebpackConfig = Configurations | ((env: Env, argv: Argv) => Configurations) | (() => Promise<Configuration>);
12
- export {};
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.46.1";
1
+ export declare const version = "5.46.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.46.1';
1
+ export const version = '5.46.3';
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.46.1",
3
+ "version": "5.46.3",
4
4
  "description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/webpro-nl/knip",
8
+ "url": "git+https://github.com/webpro-nl/knip.git",
9
9
  "directory": "packages/knip"
10
10
  },
11
11
  "bugs": "https://github.com/webpro-nl/knip/issues",
@@ -91,7 +91,7 @@
91
91
  "@wdio/types": "^9.5.0",
92
92
  "codeclimate-types": "^0.3.1",
93
93
  "glob": "^10.4.2",
94
- "release-it": "^19.0.0-next.1",
94
+ "release-it": "^19.0.0-next.2",
95
95
  "type-fest": "^4.31.0",
96
96
  "typescript": "^5.5.2"
97
97
  },