diff --git a/bun.lockb b/bun.lockb index ef55315d0..4237d2352 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/knip/.gitignore b/packages/knip/.gitignore index dc65baea2..e5fb1bd66 100644 --- a/packages/knip/.gitignore +++ b/packages/knip/.gitignore @@ -3,3 +3,4 @@ /tmp /node_modules !/fixtures/** +.cache diff --git a/packages/knip/package.json b/packages/knip/package.json index 03c776217..2387f493b 100644 --- a/packages/knip/package.json +++ b/packages/knip/package.json @@ -66,7 +66,7 @@ "easy-table": "1.2.0", "enhanced-resolve": "^5.17.1", "fast-glob": "^3.3.2", - "jiti": "^1.21.6", + "jiti": "^2.0.0", "js-yaml": "^4.1.0", "minimist": "^1.2.8", "picocolors": "^1.0.0", diff --git a/packages/knip/src/util/jiti.ts b/packages/knip/src/util/jiti.ts index c955a9ff3..26667703a 100644 --- a/packages/knip/src/util/jiti.ts +++ b/packages/knip/src/util/jiti.ts @@ -1,5 +1,5 @@ import { fileURLToPath } from 'node:url'; -import createJITI, { type JITIOptions } from 'jiti'; +import { type JitiOptions, createJiti } from 'jiti'; import { DEFAULT_EXTENSIONS } from '../constants.js'; import { join } from './path.js'; @@ -15,9 +15,6 @@ const options = { }, }; -// @ts-expect-error Our package.json has type=module (for globby, picocolors, etc), but here it confuses TypeScript -const createLoader = (options: JITIOptions) => createJITI(process.cwd(), options); +const createLoader = (options: JitiOptions) => createJiti(process.cwd(), options); -export const jitiCJS = createLoader(options); - -export const jitiESM = createLoader({ ...options, esmResolve: true }); +export const jiti = createLoader(options); diff --git a/packages/knip/src/util/loader.ts b/packages/knip/src/util/loader.ts index 94231e716..0578a88d9 100644 --- a/packages/knip/src/util/loader.ts +++ b/packages/knip/src/util/loader.ts @@ -3,7 +3,7 @@ import { timerify } from './Performance.js'; import { LoaderError } from './errors.js'; import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js'; import { isTypeModule } from './fs.js'; -import { jitiCJS, jitiESM } from './jiti.js'; +import { jiti } from './jiti.js'; import { extname, isInternal } from './path.js'; const load = async (filePath: string) => { @@ -45,11 +45,7 @@ const load = async (filePath: string) => { return imported.default ?? imported; } - if (ext === '.mts' || ((ext === '.ts' || ext === '.tsx') && isTypeModule(filePath))) { - return await jitiESM(filePath); - } - - return await jitiCJS(filePath); + return await jiti(filePath); } catch (error) { throw new LoaderError(`Error loading ${filePath}`, { cause: error }); } diff --git a/packages/knip/test/util/find-and-parse-gitignores.test.ts b/packages/knip/test/util/find-and-parse-gitignores.test.ts index 4de2f80c8..604a49c6a 100644 --- a/packages/knip/test/util/find-and-parse-gitignores.test.ts +++ b/packages/knip/test/util/find-and-parse-gitignores.test.ts @@ -9,6 +9,8 @@ test('findAndParseGitignores', async () => { assert.deepEqual(gitignore, { gitignoreFiles: ['../../.gitignore', '../../../../.gitignore', '.gitignore', 'a/.gitignore', 'a/b/.gitignore'], ignores: new Set([ + '**/.cache', + '**/.cache/**', '**/.idea', '**/.idea/**', '.git', @@ -34,6 +36,8 @@ test('findAndParseGitignores (/a)', async () => { '.yarn', '**/b/c', '**/b/c/**', + '**/.cache', + '**/.cache/**', '**/.idea', '**/.idea/**', ]), @@ -59,6 +63,8 @@ test('findAndParseGitignores (/a/b', async () => { '.yarn', '**/c', '**/c/**', + '**/.cache', + '**/.cache/**', '**/.idea', '**/.idea/**', ]),