knip 2.41.0 → 2.41.1
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/eslint/helpers.d.ts +0 -2
- package/dist/plugins/eslint/helpers.js +8 -5
- package/dist/plugins/vitest/index.js +10 -4
- package/dist/util/fs.d.ts +1 -0
- package/dist/util/fs.js +24 -2
- package/dist/util/loader.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -4,6 +4,4 @@ type GetDependenciesDeep = (configFilePath: string, options: {
|
|
|
4
4
|
manifest: PackageJsonWithPlugins;
|
|
5
5
|
}, dependencies?: Set<string>) => Promise<Set<string>>;
|
|
6
6
|
export declare const getDependenciesDeep: GetDependenciesDeep;
|
|
7
|
-
export declare const resolvePluginSpecifier: (specifier: string) => string;
|
|
8
|
-
export declare const resolveExtendSpecifier: (specifier: string) => string | undefined;
|
|
9
7
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
+
import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
|
|
2
3
|
import { isInternal, dirname, toAbsolute } from '../../util/path.js';
|
|
3
4
|
import { load } from '../../util/plugin.js';
|
|
4
5
|
import { _resolve } from '../../util/require.js';
|
|
@@ -54,15 +55,17 @@ const resolveSpecifier = (namespace, rawSpecifier) => {
|
|
|
54
55
|
const specifier = rawSpecifier.replace(/(^plugin:|:.+$)/, '');
|
|
55
56
|
if (isQualifiedSpecifier(specifier))
|
|
56
57
|
return specifier;
|
|
57
|
-
if (!specifier.startsWith('@'))
|
|
58
|
-
|
|
58
|
+
if (!specifier.startsWith('@')) {
|
|
59
|
+
const id = rawSpecifier.startsWith('plugin:') ? getPackageNameFromModuleSpecifier(specifier) : specifier;
|
|
60
|
+
return `${namespace}-${id}`;
|
|
61
|
+
}
|
|
59
62
|
const [scope, name, ...rest] = specifier.split('/');
|
|
60
63
|
if (rawSpecifier.startsWith('plugin:') && rest.length === 0)
|
|
61
|
-
return [scope, namespace
|
|
64
|
+
return [scope, namespace].join('/');
|
|
62
65
|
return [scope, name ? `${namespace}-${name}` : namespace, ...rest].join('/');
|
|
63
66
|
};
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
const resolvePluginSpecifier = (specifier) => resolveSpecifier('eslint-plugin', specifier);
|
|
68
|
+
const resolveExtendSpecifier = (specifier) => {
|
|
66
69
|
if (isInternal(specifier))
|
|
67
70
|
return;
|
|
68
71
|
if (/^next(\/.+)?$/.test(specifier))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
-
import { dirname, join } from '../../util/path.js';
|
|
2
|
+
import { dirname, join, relative } from '../../util/path.js';
|
|
3
3
|
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load, tryResolve } from '../../util/plugin.js';
|
|
5
5
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
@@ -9,6 +9,13 @@ export const ENABLERS = ['vitest'];
|
|
|
9
9
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
10
10
|
export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,projects}.{ts,js,json}'];
|
|
11
11
|
export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
|
|
12
|
+
const resolveEntry = (containingFilePath, specifier) => {
|
|
13
|
+
const dir = dirname(containingFilePath);
|
|
14
|
+
const resolvedPath = tryResolve(join(dir, specifier), containingFilePath);
|
|
15
|
+
if (resolvedPath)
|
|
16
|
+
return toEntryPattern(relative(dir, resolvedPath));
|
|
17
|
+
return specifier;
|
|
18
|
+
};
|
|
12
19
|
const findConfigDependencies = (configFilePath, localConfig, options) => {
|
|
13
20
|
const { isProduction, config } = options;
|
|
14
21
|
const testConfig = localConfig.test;
|
|
@@ -18,9 +25,8 @@ const findConfigDependencies = (configFilePath, localConfig, options) => {
|
|
|
18
25
|
const environments = testConfig.environment ? [getEnvPackageName(testConfig.environment)] : [];
|
|
19
26
|
const reporters = getExternalReporters(testConfig.reporters);
|
|
20
27
|
const coverage = testConfig.coverage ? [`@vitest/coverage-${testConfig.coverage.provider ?? 'v8'}`] : [];
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const globalSetup = (testConfig.globalSetup ? [testConfig.globalSetup].flat() : []).map(toPath);
|
|
28
|
+
const setupFiles = [testConfig.setupFiles ?? []].flat().map(v => resolveEntry(configFilePath, v));
|
|
29
|
+
const globalSetup = [testConfig.globalSetup ?? []].flat().map(v => resolveEntry(configFilePath, v));
|
|
24
30
|
return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
|
|
25
31
|
};
|
|
26
32
|
export const findVitestDependencies = async (configFilePath, localConfig, options) => {
|
package/dist/util/fs.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare const loadJSON: (filePath: string) => Promise<any>;
|
|
|
5
5
|
export declare const loadYAML: (filePath: string) => Promise<unknown>;
|
|
6
6
|
export declare const parseJSON: (filePath: string, contents: string) => Promise<any>;
|
|
7
7
|
export declare const parseYAML: (contents: string) => Promise<unknown>;
|
|
8
|
+
export declare function isTypeModule(filePath: string): boolean;
|
package/dist/util/fs.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { statSync } from 'node:fs';
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import yaml from 'js-yaml';
|
|
4
4
|
import stripJsonComments from 'strip-json-comments';
|
|
5
5
|
import { LoaderError } from './errors.js';
|
|
6
|
-
import { join } from './path.js';
|
|
6
|
+
import { dirname, join } from './path.js';
|
|
7
7
|
export const isFile = (filePath) => {
|
|
8
8
|
const stat = statSync(filePath, { throwIfNoEntry: false });
|
|
9
9
|
return stat !== undefined && stat.isFile();
|
|
@@ -40,3 +40,25 @@ export const parseJSON = async (filePath, contents) => {
|
|
|
40
40
|
export const parseYAML = async (contents) => {
|
|
41
41
|
return yaml.load(contents);
|
|
42
42
|
};
|
|
43
|
+
export function isTypeModule(filePath) {
|
|
44
|
+
if (!filePath.endsWith('.js'))
|
|
45
|
+
return false;
|
|
46
|
+
try {
|
|
47
|
+
let currentDir = dirname(filePath);
|
|
48
|
+
while (true) {
|
|
49
|
+
const packagePath = join(currentDir, 'package.json');
|
|
50
|
+
try {
|
|
51
|
+
const data = JSON.parse(readFileSync(packagePath, 'utf-8'));
|
|
52
|
+
return data.type === 'module';
|
|
53
|
+
}
|
|
54
|
+
catch { }
|
|
55
|
+
const parentDir = dirname(currentDir);
|
|
56
|
+
if (parentDir === currentDir)
|
|
57
|
+
return false;
|
|
58
|
+
currentDir = parentDir;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
package/dist/util/loader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
2
|
import { LoaderError } from './errors.js';
|
|
3
3
|
import { loadJSON, loadYAML, loadFile, parseJSON, parseYAML } from './fs.js';
|
|
4
|
+
import { isTypeModule } from './fs.js';
|
|
4
5
|
import { extname } from './path.js';
|
|
5
6
|
import { timerify } from './Performance.js';
|
|
6
7
|
import { jiti } from './register.js';
|
|
@@ -20,7 +21,7 @@ const load = async (filePath) => {
|
|
|
20
21
|
if (ext === '.yaml' || ext === '.yml') {
|
|
21
22
|
return loadYAML(filePath);
|
|
22
23
|
}
|
|
23
|
-
if (ext === '.mjs') {
|
|
24
|
+
if (ext === '.mjs' || (ext === '.js' && isTypeModule(filePath))) {
|
|
24
25
|
const fileUrl = pathToFileURL(filePath);
|
|
25
26
|
const imported = await import(fileUrl.href);
|
|
26
27
|
return imported.default ?? imported;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.41.
|
|
1
|
+
export declare const version = "2.41.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.41.
|
|
1
|
+
export const version = '2.41.1';
|
package/package.json
CHANGED