knip 5.57.2 → 5.58.0

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.
@@ -269,6 +269,8 @@ export class WorkspaceWorker {
269
269
  const cache = {};
270
270
  const key = `${wsName}:${pluginName}`;
271
271
  if (plugin.resolveConfig && !seen.get(key)?.has(configFilePath)) {
272
+ if (typeof plugin.setup === 'function')
273
+ await plugin.setup(resolveOpts);
272
274
  const localConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
273
275
  if (localConfig) {
274
276
  const inputs = await plugin.resolveConfig(localConfig, resolveOpts);
@@ -276,6 +278,8 @@ export class WorkspaceWorker {
276
278
  addInput(input, configFilePath);
277
279
  cache.resolveConfig = inputs;
278
280
  }
281
+ if (typeof plugin.teardown === 'function')
282
+ await plugin.teardown(resolveOpts);
279
283
  }
280
284
  if (plugin.resolveFromAST) {
281
285
  const sourceFile = this.getSourceFile(configFilePath);
@@ -420,6 +420,7 @@ export declare const Plugins: {
420
420
  isEnabled: import("../types/config.js").IsPluginEnabled;
421
421
  config: string[];
422
422
  production: string[];
423
+ setup: () => Promise<void>;
423
424
  resolveConfig: import("../types/config.js").ResolveConfig<import("./nuxt/types.js").NuxtConfig>;
424
425
  };
425
426
  nx: {
@@ -9,6 +9,7 @@ declare const _default: {
9
9
  isEnabled: IsPluginEnabled;
10
10
  config: string[];
11
11
  production: string[];
12
+ setup: () => Promise<void>;
12
13
  resolveConfig: ResolveConfig<NuxtConfig>;
13
14
  };
14
15
  export default _default;
@@ -3,12 +3,7 @@ import { join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  const title = 'Nuxt';
5
5
  const enablers = ['nuxt'];
6
- const isEnabled = ({ dependencies }) => {
7
- const isEnabled = hasDependency(dependencies, enablers);
8
- if (isEnabled && !('defineNuxtConfig' in globalThis))
9
- globalThis.defineNuxtConfig = (c) => c;
10
- return isEnabled;
11
- };
6
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
12
7
  const config = ['nuxt.config.{js,mjs,ts}'];
13
8
  const production = [
14
9
  'app.{vue,jsx,tsx}',
@@ -21,6 +16,11 @@ const production = [
21
16
  'server/middleware/**/*.ts',
22
17
  'server/plugins/**/*.ts',
23
18
  ];
19
+ const setup = async () => {
20
+ if (globalThis && !('defineNuxtConfig' in globalThis)) {
21
+ Object.defineProperty(globalThis, 'defineNuxtConfig', { value: (id) => id });
22
+ }
23
+ };
24
24
  const resolveConfig = async (localConfig) => {
25
25
  const srcDir = localConfig.srcDir ?? '.';
26
26
  const patterns = [
@@ -45,5 +45,6 @@ export default {
45
45
  isEnabled,
46
46
  config,
47
47
  production,
48
+ setup,
48
49
  resolveConfig,
49
50
  };
@@ -1,3 +1,4 @@
1
+ import { DEFAULT_EXTENSIONS } from '../../constants.js';
1
2
  import { toAlias, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
2
3
  import { join, toPosix } from '../../util/path.js';
3
4
  import { hasDependency } from '../../util/plugin.js';
@@ -98,6 +99,12 @@ export const resolveConfig = async (localConfig, options) => {
98
99
  }
99
100
  if (cfg.resolve?.alias)
100
101
  addAliases(cfg.resolve.alias);
102
+ if (cfg.resolve?.extensions) {
103
+ const customExtensions = cfg.resolve.extensions.filter(ext => ext.startsWith('.') && !DEFAULT_EXTENSIONS.includes(ext));
104
+ for (const ext of customExtensions) {
105
+ inputs.add(toEntry(`src/**/*${ext}`));
106
+ }
107
+ }
101
108
  for (const dependency of findConfigDependencies(cfg, options))
102
109
  inputs.add(dependency);
103
110
  const _entry = cfg.build?.lib?.entry ?? [];
@@ -37,6 +37,7 @@ export interface ViteConfig extends VitestConfig {
37
37
  };
38
38
  resolve?: {
39
39
  alias?: AliasOptions;
40
+ extensions?: string[];
40
41
  };
41
42
  }
42
43
  export type COMMAND = 'dev' | 'serve' | 'build';
@@ -109,9 +109,9 @@ export const findWebpackDependenciesFromConfig = async (config, options) => {
109
109
  inputs.add(toDeferResolve(entry));
110
110
  }
111
111
  }
112
- if (opts.resolve?.alias) {
112
+ const processAlias = (aliases) => {
113
113
  const addStar = (value) => (value.endsWith('*') ? value : join(value, '*').replace(/\/\*\*$/, '/*'));
114
- for (const [alias, value] of Object.entries(opts.resolve.alias)) {
114
+ for (const [alias, value] of Object.entries(aliases)) {
115
115
  if (!value)
116
116
  continue;
117
117
  const prefixes = Array.isArray(value) ? value : [value];
@@ -126,6 +126,12 @@ export const findWebpackDependenciesFromConfig = async (config, options) => {
126
126
  }
127
127
  }
128
128
  }
129
+ };
130
+ if (opts.resolve?.alias) {
131
+ processAlias(opts.resolve.alias);
132
+ }
133
+ if (opts.resolveLoader?.alias) {
134
+ processAlias(opts.resolveLoader.alias);
129
135
  }
130
136
  }
131
137
  }
@@ -90,6 +90,8 @@ export interface PluginOptions extends BaseOptions {
90
90
  enabledPlugins: string[];
91
91
  getInputsFromScripts: GetInputsFromScriptsPartial;
92
92
  }
93
+ type PluginSetup = (options: PluginOptions) => Promise<void> | void;
94
+ type PluginTeardown = (options: PluginOptions) => Promise<void> | void;
93
95
  export type ResolveConfig<T = any> = (config: T, options: PluginOptions) => Promise<Input[]> | Input[];
94
96
  export type Resolve = (options: PluginOptions) => Promise<Input[]> | Input[];
95
97
  export type GetSourceFile = (filePath: string) => ts.SourceFile | undefined;
@@ -109,6 +111,8 @@ export interface Plugin {
109
111
  entry?: string[];
110
112
  production?: string[];
111
113
  project?: string[];
114
+ setup?: PluginSetup;
115
+ teardown?: PluginTeardown;
112
116
  resolveConfig?: ResolveConfig;
113
117
  resolve?: Resolve;
114
118
  resolveFromAST?: ResolveFromAST;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.57.2";
1
+ export declare const version = "5.58.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.57.2';
1
+ export const version = '5.58.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.57.2",
3
+ "version": "5.58.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {