knip 5.42.2 → 5.42.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.
@@ -171,7 +171,7 @@ export class WorkspaceWorker {
171
171
  const inputsFromManifest = _getInputsFromScripts(Object.values(developmentScripts), baseOptions);
172
172
  const productionInputsFromManifest = _getInputsFromScripts(Object.values(productionScripts), baseOptions);
173
173
  const hasProductionInput = (input) => productionInputsFromManifest.find(d => d.specifier === input.specifier && d.type === input.type);
174
- const getInputsFromScripts = (scripts, options) => _getInputsFromScripts(scripts, { ...baseScriptOptions, ...options });
174
+ const createGetInputsFromScripts = (containingFilePath) => (scripts, options) => _getInputsFromScripts(scripts, { ...baseOptions, ...options, containingFilePath });
175
175
  const inputs = [];
176
176
  const configFiles = new Map();
177
177
  const remainingPlugins = new Set(this.enabledPlugins);
@@ -217,12 +217,13 @@ export class WorkspaceWorker {
217
217
  configFilePath: containingFilePath,
218
218
  configFileDir: cwd,
219
219
  configFileName: '',
220
- getInputsFromScripts,
220
+ getInputsFromScripts: createGetInputsFromScripts(containingFilePath),
221
221
  };
222
222
  const configEntryPaths = [];
223
223
  for (const configFilePath of remainingConfigFilePaths) {
224
224
  const opts = {
225
225
  ...options,
226
+ getInputsFromScripts: createGetInputsFromScripts(configFilePath),
226
227
  configFilePath,
227
228
  configFileDir: dirname(configFilePath),
228
229
  configFileName: basename(configFilePath),
@@ -3,6 +3,8 @@ import { Plugins, pluginArgsMap } from '../plugins.js';
3
3
  import { debugLogObject } from '../util/debug.js';
4
4
  import { toBinary, toDeferResolve } from '../util/input.js';
5
5
  import { extractBinary } from '../util/modules.js';
6
+ import { relative } from '../util/path.js';
7
+ import { truncate } from '../util/string.js';
6
8
  import { resolve as fallbackResolve } from './fallback.js';
7
9
  import PackageManagerResolvers from './package-manager/index.js';
8
10
  import { resolve as resolverFromPlugins } from './plugins.js';
@@ -85,7 +87,8 @@ export const getDependenciesFromScript = (script, options) => {
85
87
  return parsed?.commands ? getDependenciesFromNodes(parsed.commands) : [];
86
88
  }
87
89
  catch (error) {
88
- debugLogObject('*', 'Bash parser error', error);
90
+ const msg = `Warning: failed to parse and ignoring script in ${relative(options.containingFilePath)} (${truncate(script, 30)})`;
91
+ debugLogObject('*', msg, error);
89
92
  return [];
90
93
  }
91
94
  };
package/dist/index.js CHANGED
@@ -252,18 +252,18 @@ export const main = async (unresolvedConfiguration) => {
252
252
  if (scripts && scripts.size > 0) {
253
253
  const dependencies = deputy.getDependencies(workspace.name);
254
254
  const manifestScriptNames = new Set(Object.keys(chief.getManifestForWorkspace(workspace.name)?.scripts ?? {}));
255
- const rootCwd = cwd;
255
+ const dir = dirname(filePath);
256
256
  const options = {
257
- cwd: dirname(filePath),
258
- rootCwd,
257
+ cwd: dir,
258
+ rootCwd: cwd,
259
259
  containingFilePath: filePath,
260
260
  dependencies,
261
261
  manifestScriptNames,
262
262
  };
263
263
  const inputs = _getInputsFromScripts(scripts, options);
264
264
  for (const input of inputs) {
265
- input.containingFilePath = filePath;
266
- input.dir = cwd;
265
+ input.containingFilePath ??= filePath;
266
+ input.dir ??= dir;
267
267
  const specifierFilePath = getReferencedInternalFilePath(input, workspace);
268
268
  if (specifierFilePath)
269
269
  analyzeSourceFile(specifierFilePath, principal);
@@ -29,7 +29,8 @@ const resolveConfig = async (localConfig) => {
29
29
  ? [`@storybook/builder-${builder}`, `@storybook/manager-${builder}`]
30
30
  : [builder]
31
31
  : [];
32
- const frameworks = localConfig.framework?.name ? [localConfig.framework.name] : [];
32
+ const framework = typeof localConfig.framework === 'string' ? localConfig.framework : localConfig.framework?.name;
33
+ const frameworks = framework ? [framework] : [];
33
34
  return [
34
35
  ...addons.map(toDeferResolve),
35
36
  ...builderPackages.map(id => toDependency(id)),
@@ -13,7 +13,7 @@ export type StorybookConfig = {
13
13
  name?: string;
14
14
  };
15
15
  };
16
- framework?: {
16
+ framework?: string | {
17
17
  name?: string;
18
18
  };
19
19
  };
@@ -30,5 +30,6 @@ const builtInReporters = [
30
30
  export const getExternalReporters = (reporters) => reporters
31
31
  ? [reporters]
32
32
  .flat()
33
+ .map(reporter => (Array.isArray(reporter) ? reporter[0] : reporter))
33
34
  .filter((reporter) => typeof reporter === 'string' && !builtInReporters.includes(reporter))
34
35
  : [];
@@ -8,7 +8,7 @@ interface VitestConfig {
8
8
  root?: string;
9
9
  environment?: string;
10
10
  globalSetup?: string | string[];
11
- reporters?: (string | unknown)[];
11
+ reporters?: (string | [string, unknown] | unknown)[];
12
12
  setupFiles?: string | string[];
13
13
  };
14
14
  }
@@ -2,11 +2,11 @@ import EasyTable from 'easy-table';
2
2
  import picocolors from 'picocolors';
3
3
  import { ROOT_WORKSPACE_NAME } from '../constants.js';
4
4
  import { relative, toRelative } from '../util/path.js';
5
+ import { truncate } from '../util/string.js';
5
6
  import { getTitle, identity, logTitle } from './util.js';
6
7
  const dim = picocolors.gray;
7
8
  const bright = picocolors.whiteBright;
8
9
  const TRUNCATE_WIDTH = 40;
9
- const truncate = (text) => (text.length > TRUNCATE_WIDTH ? `${text.slice(0, TRUNCATE_WIDTH - 3)}...` : text);
10
10
  const truncateStart = (text, width) => (text.length > width ? `...${text.slice(-(width - 3))}` : text);
11
11
  const sortByPos = (a, b) => {
12
12
  const [f, r, c] = a.filePath.split(':');
@@ -28,7 +28,8 @@ const logIssueRecord = (issues) => {
28
28
  const table = new EasyTable();
29
29
  for (const issue of issues) {
30
30
  const print = issue.isFixed || issue.severity === 'warn' ? dim : identity;
31
- table.cell('symbol', print(issue.symbols ? truncate(issue.symbols.map(s => s.symbol).join(', ')) : hl(issue)));
31
+ const symbols = issue.symbols;
32
+ table.cell('symbol', print(symbols ? truncate(symbols.map(s => s.symbol).join(', '), TRUNCATE_WIDTH) : hl(issue)));
32
33
  issue.parentSymbol && table.cell('parentSymbol', print(issue.parentSymbol));
33
34
  issue.symbolType && table.cell('symbolType', print(issue.symbolType));
34
35
  const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
@@ -0,0 +1 @@
1
+ export declare const truncate: (text: string, width: number) => string;
@@ -0,0 +1 @@
1
+ export const truncate = (text, width) => text.length > width ? `${text.slice(0, width - 3)}...` : text;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.42.2";
1
+ export declare const version = "5.42.3";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.42.2';
1
+ export const version = '5.42.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.42.2",
3
+ "version": "5.42.3",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {