knip 1.0.0-beta.6 → 1.0.0-beta.7

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 CHANGED
@@ -314,6 +314,14 @@ use the `--production` flag. Here's an example:
314
314
  }
315
315
  ```
316
316
 
317
+ Here's what's included in production mode analysis:
318
+
319
+ - Only `entry` and `project` patterns suffixed with `!`.
320
+ - Only `entry` patterns from plugins exported as `PRODUCTION_ENTRY_FILE_PATTERNS` (such as Next.js and Gatsby).
321
+ - Only the `npm start` script (e.g. not the `test` or other npm scripts in `package.json`).
322
+ - Only `exports`, `nsExports` and `classMembers` are included in the report (`types`, `nsTypes`, `enumMembers` are
323
+ ignored).
324
+
317
325
  #### Strict
318
326
 
319
327
  Additionally, the `--strict` flag can be used to:
package/dist/cli.js CHANGED
@@ -7,13 +7,13 @@ import { ConfigurationError } from './util/errors.js';
7
7
  import { measure } from './util/performance.js';
8
8
  import { main } from './index.js';
9
9
  register();
10
- const { values: { debug: isDebug = false, help, 'include-entry-exports': isIncludeEntryExports = false, 'max-issues': maxIssues = '0', 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': noProgress = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, }, } = parsedArgs;
10
+ const { values: { debug: isDebug = false, help, 'include-entry-exports': isIncludeEntryExports = false, 'max-issues': maxIssues = '0', 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, }, } = parsedArgs;
11
11
  if (help) {
12
12
  console.log(helpText);
13
13
  process.exit(0);
14
14
  }
15
15
  const cwd = process.cwd();
16
- const isShowProgress = !isDebug && noProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
16
+ const isShowProgress = !isDebug && isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
17
17
  const printReport = reporter in reporters ? reporters[reporter] : await import(path.join(cwd, reporter));
18
18
  const run = async () => {
19
19
  try {
@@ -4,7 +4,7 @@ import { ConfigurationValidator } from './configuration-validator.js';
4
4
  import type { Configuration, WorkspaceConfiguration } from './types/config.js';
5
5
  import type { PackageJson } from '@npmcli/package-json';
6
6
  type ConfigurationManagerOptions = {
7
- cwd?: string;
7
+ cwd: string;
8
8
  isProduction: boolean;
9
9
  };
10
10
  export default class ConfigurationChief {
@@ -30,14 +30,14 @@ const defaultConfig = {
30
30
  };
31
31
  const PLUGIN_NAMES = Object.keys(plugins);
32
32
  export default class ConfigurationChief {
33
- cwd = process.cwd();
33
+ cwd;
34
34
  isProduction = false;
35
35
  config;
36
36
  manifestPath;
37
37
  manifest;
38
38
  manifestWorkspaces;
39
39
  constructor({ cwd, isProduction }) {
40
- this.cwd = cwd ?? this.cwd;
40
+ this.cwd = cwd;
41
41
  this.isProduction = isProduction;
42
42
  this.config = defaultConfig;
43
43
  }
package/dist/index.js CHANGED
@@ -260,7 +260,7 @@ export const main = async (unresolvedConfiguration) => {
260
260
  if (report.dependencies) {
261
261
  const { dependencyIssues, devDependencyIssues } = deputy.settleDependencyIssues();
262
262
  dependencyIssues.forEach(issue => collector.addIssue(issue));
263
- if (!isProduction)
263
+ if (!isStrict)
264
264
  devDependencyIssues.forEach(issue => collector.addIssue(issue));
265
265
  }
266
266
  const { issues, counters } = collector.getIssues();
File without changes
File without changes
File without changes
@@ -16,8 +16,8 @@ const findManifestDependencies = async ({ rootConfig, manifest, isRoot, isProduc
16
16
  .filter(binaryName => !IGNORED_GLOBAL_BINARIES.includes(binaryName))
17
17
  .filter(binaryName => !ignoreBinaries.includes(binaryName));
18
18
  const installedBinaries = new Map();
19
- const deps = [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {})];
20
- for (const packageName of deps) {
19
+ const packageNames = [...Object.keys(manifest.dependencies ?? {}), ...Object.keys(manifest.devDependencies ?? {})];
20
+ for (const packageName of packageNames) {
21
21
  const manifest = await getPackageManifest(dir, packageName, isRoot, cwd);
22
22
  if (manifest) {
23
23
  const binaries = typeof manifest.bin === 'string' ? [packageName] : Object.keys(manifest.bin ?? {});
@@ -1,6 +1,5 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Sentry";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
- export declare const findDependencies: GenericPluginCallback;
@@ -1,11 +1,13 @@
1
- import { _load } from '../../util/loader.js';
2
- import { timerify } from '../../util/performance.js';
3
1
  export const NAME = 'Sentry';
4
- export const ENABLERS = ['@sentry/replay'];
2
+ export const ENABLERS = [
3
+ '@sentry/browser',
4
+ '@sentry/electron',
5
+ '@sentry/ember',
6
+ '@sentry/gatsby',
7
+ '@sentry/nextjs',
8
+ '@sentry/remix',
9
+ '@sentry/replay',
10
+ '@sentry/tracing',
11
+ ];
5
12
  export const isEnabled = ({ dependencies }) => ENABLERS.some(enabler => dependencies.has(enabler));
6
13
  export const ENTRY_FILE_PATTERNS = ['sentry.{client,server}.config.{js,ts}'];
7
- const findNycDependencies = async (configFilePath) => {
8
- const config = await _load(configFilePath);
9
- return [config.extends];
10
- };
11
- export const findDependencies = timerify(findNycDependencies);
@@ -4,7 +4,7 @@ import { timerify } from '../../util/performance.js';
4
4
  export const NAME = 'Webpack';
5
5
  export const ENABLERS = ['webpack'];
6
6
  export const isEnabled = ({ dependencies }) => ENABLERS.some(enabler => dependencies.has(enabler));
7
- export const CONFIG_FILE_PATTERNS = ['webpack.config*.js'];
7
+ export const CONFIG_FILE_PATTERNS = ['webpack.config*.{js,ts}'];
8
8
  const resolveRuleSetLoaders = (rule) => {
9
9
  if (!rule || typeof rule === 'string')
10
10
  return [];
@@ -24,7 +24,10 @@ const resolveUseItemLoader = (use) => {
24
24
  return [];
25
25
  };
26
26
  const findWebpackDependencies = async (configFilePath, { manifest }) => {
27
- const config = await _load(configFilePath);
27
+ let config = await _load(configFilePath);
28
+ if (typeof config === 'function') {
29
+ config = config();
30
+ }
28
31
  const loaders = (config.module?.rules?.flatMap(resolveRuleSetLoaders) ?? [])
29
32
  .map(loader => loader.replace(/\?.*/, ''))
30
33
  .filter(loader => !loader.startsWith('/'));
package/dist/util/glob.js CHANGED
@@ -16,7 +16,7 @@ export const negate = (pattern) => pattern.replace(/^!?/, '!');
16
16
  export const hasProductionSuffix = (pattern) => pattern.endsWith('!');
17
17
  export const hasNoProductionSuffix = (pattern) => !pattern.endsWith('!');
18
18
  const removeProductionSuffix = (pattern) => pattern.replace(/!$/, '');
19
- const negatedLast = (a) => (a.startsWith('!') ? 1 : -1);
19
+ const negatedLast = (pattern) => (pattern.startsWith('!') ? 1 : -1);
20
20
  const glob = async ({ cwd, workingDir = cwd, patterns, ignore = [], gitignore = true }) => {
21
21
  const cwdPosix = ensurePosixPath(cwd);
22
22
  const workingDirPosix = ensurePosixPath(workingDir);
@@ -7,7 +7,7 @@ import parsedArgs from './cli-arguments.js';
7
7
  import { loadJSON } from './fs.js';
8
8
  import { timerify } from './performance.js';
9
9
  const require = createRequire(process.cwd());
10
- const { values: { 'no-progress': noProgress = false }, } = parsedArgs;
10
+ const { values: { 'no-progress': isNoProgress = false, debug: isDebug = false }, } = parsedArgs;
11
11
  const load = async (filePath) => {
12
12
  try {
13
13
  if (path.extname(filePath) === '.json' || /rc$/.test(filePath)) {
@@ -20,7 +20,7 @@ const load = async (filePath) => {
20
20
  return imported.default ?? imported;
21
21
  }
22
22
  catch (error) {
23
- if (noProgress) {
23
+ if (isNoProgress || isDebug) {
24
24
  console.log('Failed to load ' + filePath);
25
25
  console.log(error?.toString());
26
26
  }
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { ROOT_WORKSPACE_NAME, TEST_FILE_PATTERNS } from './constants.js';
3
- import * as npm from './npm-scripts/index.js';
3
+ import * as npm from './manifest/index.js';
4
4
  import * as plugins from './plugins/index.js';
5
5
  import { debugLogFiles, debugLogIssues, debugLogObject } from './util/debug.js';
6
6
  import { _pureGlob, negate, hasProductionSuffix, hasNoProductionSuffix } from './util/glob.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",
5
5
  "keywords": [
6
6
  "find",
@@ -62,7 +62,7 @@
62
62
  "@snyk/github-codeowners": "1.1.0",
63
63
  "chalk": "5.2.0",
64
64
  "easy-table": "1.2.0",
65
- "esbuild": "0.16.12",
65
+ "esbuild": "0.16.13",
66
66
  "esbuild-register": "3.4.2",
67
67
  "eslint": "8.31.0",
68
68
  "fast-glob": "3.2.12",
@@ -87,8 +87,8 @@
87
87
  "@types/node": "18.11.18",
88
88
  "@types/npmcli__map-workspaces": "3.0.0",
89
89
  "@types/webpack": "5.28.0",
90
- "@typescript-eslint/eslint-plugin": "5.47.1",
91
- "@typescript-eslint/parser": "5.47.1",
90
+ "@typescript-eslint/eslint-plugin": "5.48.0",
91
+ "@typescript-eslint/parser": "5.48.0",
92
92
  "eslint-import-resolver-typescript": "3.5.2",
93
93
  "eslint-plugin-import": "2.26.0",
94
94
  "globstar": "1.0.0",