knip 2.41.1 → 2.41.2

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.
@@ -4,7 +4,7 @@ import { findVitestDependencies } from '../vitest/index.js';
4
4
  export const NAME = 'Vite';
5
5
  export const ENABLERS = ['vite'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const CONFIG_FILE_PATTERNS = ['vite.config.{js,ts}'];
7
+ export const CONFIG_FILE_PATTERNS = ['vite.config.{js,mjs,ts,cjs,mts,cts}'];
8
8
  const findViteDependencies = async (configFilePath, options) => {
9
9
  const localConfig = await load(configFilePath);
10
10
  if (!localConfig)
package/dist/util/fs.d.ts CHANGED
@@ -5,4 +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;
8
+ export declare function isTypeModule(path: string): boolean;
package/dist/util/fs.js CHANGED
@@ -40,25 +40,18 @@ 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');
43
+ export function isTypeModule(path) {
44
+ while (path && path !== '.' && path !== '/') {
45
+ path = dirname(path);
46
+ try {
47
+ const pkg = readFileSync(join(path, 'package.json'), 'utf-8');
50
48
  try {
51
- const data = JSON.parse(readFileSync(packagePath, 'utf-8'));
52
- return data.type === 'module';
49
+ return JSON.parse(pkg).type === 'module';
53
50
  }
54
51
  catch { }
55
- const parentDir = dirname(currentDir);
56
- if (parentDir === currentDir)
57
- return false;
58
- currentDir = parentDir;
52
+ break;
59
53
  }
54
+ catch { }
60
55
  }
61
- catch (error) {
62
- return false;
63
- }
56
+ return false;
64
57
  }
@@ -4,7 +4,7 @@ import { loadJSON, loadYAML, loadFile, parseJSON, parseYAML } from './fs.js';
4
4
  import { isTypeModule } from './fs.js';
5
5
  import { extname } from './path.js';
6
6
  import { timerify } from './Performance.js';
7
- import { jiti } from './register.js';
7
+ import { jitiCJS, jitiESM } from './register.js';
8
8
  export const FAKE_PATH = '__FAKE__';
9
9
  const load = async (filePath) => {
10
10
  if (filePath === FAKE_PATH)
@@ -26,7 +26,12 @@ const load = async (filePath) => {
26
26
  const imported = await import(fileUrl.href);
27
27
  return imported.default ?? imported;
28
28
  }
29
- return await jiti(filePath);
29
+ if (isTypeModule(filePath)) {
30
+ return await jitiESM(filePath);
31
+ }
32
+ else {
33
+ return await jitiCJS(filePath);
34
+ }
30
35
  }
31
36
  catch (error) {
32
37
  throw new LoaderError(`Error loading ${filePath}`, { cause: error });
@@ -1 +1,2 @@
1
- export declare const jiti: any;
1
+ export declare const jitiCJS: any;
2
+ export declare const jitiESM: any;
@@ -1,14 +1,10 @@
1
- import module from 'node:module';
2
- import createJITI from 'jiti';
3
- import { IGNORED_FILE_EXTENSIONS, DEFAULT_EXTENSIONS } from '../constants.js';
4
- const _extensions = module.Module._extensions;
5
- export const jiti = createJITI(process.cwd(), { interopDefault: true, extensions: DEFAULT_EXTENSIONS });
6
- if (!('.ts' in _extensions)) {
7
- jiti.register();
8
- }
9
- const exportFilePath = (module, filePath) => {
10
- module.exports = filePath;
1
+ import createJITI, {} from 'jiti';
2
+ import { DEFAULT_EXTENSIONS } from '../constants.js';
3
+ const options = {
4
+ interopDefault: true,
5
+ extensions: DEFAULT_EXTENSIONS,
6
+ esmResolve: false,
11
7
  };
12
- IGNORED_FILE_EXTENSIONS.forEach(ext => {
13
- _extensions[ext] = exportFilePath;
14
- });
8
+ const createLoader = (options) => createJITI(process.cwd(), options);
9
+ export const jitiCJS = createLoader(options);
10
+ export const jitiESM = createLoader({ ...options, esmResolve: true });
@@ -5,11 +5,11 @@ import { debugLog } from './debug.js';
5
5
  import { getPackageNameFromModuleSpecifier } from './modules.js';
6
6
  import { cwd, toPosix, join } from './path.js';
7
7
  import { timerify } from './Performance.js';
8
- import { jiti } from './register.js';
8
+ import { jitiCJS } from './register.js';
9
9
  const createRequire = (path) => nodeCreateRequire(pathToFileURL(path ?? cwd));
10
10
  const require = createRequire();
11
11
  export const _require = timerify(require);
12
- const resolve = (specifier) => toPosix(jiti.resolve(specifier));
12
+ const resolve = (specifier) => toPosix(jitiCJS.resolve(specifier));
13
13
  const tryResolve = (specifier, from) => {
14
14
  try {
15
15
  return resolve(specifier);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.41.1";
1
+ export declare const version = "2.41.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.41.1';
1
+ export const version = '2.41.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.41.1",
3
+ "version": "2.41.2",
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",