knip 2.12.2 → 2.13.0-next-webpack.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.
- package/dist/plugins/next/index.d.ts +3 -2
- package/dist/plugins/next/index.js +20 -2
- package/dist/plugins/next/types.d.ts +12 -0
- package/dist/plugins/next/types.js +1 -0
- package/dist/plugins/webpack/index.d.ts +2 -0
- package/dist/plugins/webpack/index.js +17 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { IsPluginEnabledCallback } from '../../types/plugins.js';
|
|
1
|
+
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
|
|
2
2
|
export declare const NAME = "Next.js";
|
|
3
3
|
export declare const ENABLERS: string[];
|
|
4
4
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
6
6
|
export declare const PRODUCTION_ENTRY_FILE_PATTERNS: string[];
|
|
7
|
+
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { timerify } from '../../util/Performance.js';
|
|
2
|
+
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { getWebpackDependencies } from '../webpack/index.js';
|
|
2
4
|
export const NAME = 'Next.js';
|
|
3
5
|
export const ENABLERS = ['next'];
|
|
4
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
5
|
-
export const
|
|
7
|
+
export const CONFIG_FILE_PATTERNS = ['next.config.{js,ts}'];
|
|
6
8
|
export const PRODUCTION_ENTRY_FILE_PATTERNS = ['pages/**/*.{js,jsx,ts,tsx}', 'src/pages/**/*.{js,jsx,ts,tsx}'];
|
|
9
|
+
const findNextDependencies = async (configFilePath, { isProduction }) => {
|
|
10
|
+
const config = await load(configFilePath);
|
|
11
|
+
if (!config || typeof config.webpack !== 'function')
|
|
12
|
+
return [];
|
|
13
|
+
const preConfig = { module: { rules: [] } };
|
|
14
|
+
const buildId = '1';
|
|
15
|
+
const defaultLoaders = { babel: {} };
|
|
16
|
+
const nextRuntime = undefined;
|
|
17
|
+
const envPasses = isProduction === true ? [true] : [false, true];
|
|
18
|
+
const isServerPasses = [false, true];
|
|
19
|
+
return envPasses.flatMap(dev => isServerPasses.flatMap(isServer => {
|
|
20
|
+
const webpackConfig = config.webpack(preConfig, { buildId, dev, isServer, defaultLoaders, nextRuntime });
|
|
21
|
+
return getWebpackDependencies(webpackConfig, isProduction);
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
export const findDependencies = timerify(findNextDependencies);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebpackConfig } from '../webpack/types.js';
|
|
2
|
+
type Options = {
|
|
3
|
+
buildId: string;
|
|
4
|
+
dev: boolean;
|
|
5
|
+
isServer: boolean;
|
|
6
|
+
defaultLoaders: Record<string, unknown>;
|
|
7
|
+
nextRuntime: undefined | string;
|
|
8
|
+
};
|
|
9
|
+
export interface NextConfig {
|
|
10
|
+
webpack: (config: WebpackConfig, options: Options) => WebpackConfig;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { WebpackConfig } from './types.js';
|
|
1
2
|
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
|
|
2
3
|
export declare const NAME = "Webpack";
|
|
3
4
|
export declare const ENABLERS: string[];
|
|
4
5
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
6
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
7
|
+
export declare const getWebpackDependencies: (config: WebpackConfig, isProduction: boolean) => any[];
|
|
6
8
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -40,26 +40,29 @@ const resolveUseItem = (use) => {
|
|
|
40
40
|
return [use.loader];
|
|
41
41
|
return [];
|
|
42
42
|
};
|
|
43
|
+
export const getWebpackDependencies = (config, isProduction) => {
|
|
44
|
+
const env = { production: isProduction };
|
|
45
|
+
const argv = { mode: isProduction ? 'production' : 'development' };
|
|
46
|
+
const cfg = typeof config === 'function' ? config(env, argv) : config;
|
|
47
|
+
return [cfg].flat().flatMap(config => {
|
|
48
|
+
const dependencies = (config.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
|
|
49
|
+
const entries = cfg.entry
|
|
50
|
+
? typeof cfg.entry === 'string'
|
|
51
|
+
? [cfg.entry]
|
|
52
|
+
: Array.isArray(cfg.entry)
|
|
53
|
+
? cfg.entry
|
|
54
|
+
: Object.values(cfg.entry).map(entry => (typeof entry === 'string' ? entry : entry.filename))
|
|
55
|
+
: [];
|
|
56
|
+
return [...dependencies, ...entries];
|
|
57
|
+
});
|
|
58
|
+
};
|
|
43
59
|
const findWebpackDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
44
60
|
const config = await load(configFilePath);
|
|
45
61
|
if (!config)
|
|
46
62
|
return [];
|
|
47
63
|
const passes = typeof config === 'function' ? [false, true] : [isProduction];
|
|
48
64
|
const dependencies = passes.flatMap(isProduction => {
|
|
49
|
-
|
|
50
|
-
const argv = { mode: isProduction ? 'production' : 'development' };
|
|
51
|
-
const cfg = typeof config === 'function' ? config(env, argv) : config;
|
|
52
|
-
return [cfg].flat().flatMap(config => {
|
|
53
|
-
const dependencies = (config.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
|
|
54
|
-
const entries = cfg.entry
|
|
55
|
-
? typeof cfg.entry === 'string'
|
|
56
|
-
? [cfg.entry]
|
|
57
|
-
: Array.isArray(cfg.entry)
|
|
58
|
-
? cfg.entry
|
|
59
|
-
: Object.values(cfg.entry).map(entry => (typeof entry === 'string' ? entry : entry.filename))
|
|
60
|
-
: [];
|
|
61
|
-
return [...dependencies, ...entries];
|
|
62
|
-
});
|
|
65
|
+
return getWebpackDependencies(config, isProduction);
|
|
63
66
|
});
|
|
64
67
|
const scripts = Object.values(manifest.scripts ?? {});
|
|
65
68
|
const webpackCLI = scripts.some(script => script?.includes('webpack ')) ? ['webpack-cli'] : [];
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.13.0-next-webpack.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.13.0-next-webpack.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0-next-webpack.0",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://github.com/webpro/knip",
|
|
6
6
|
"repository": "github:webpro/knip",
|