diff --git a/bun.lockb b/bun.lockb index 71dc64226..cb0a5f8ac 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/knip/package.json b/packages/knip/package.json index 84f1e3c9e..e22c76f43 100644 --- a/packages/knip/package.json +++ b/packages/knip/package.json @@ -65,7 +65,7 @@ "@snyk/github-codeowners": "1.1.0", "easy-table": "1.2.0", "fast-glob": "^3.3.2", - "jiti": "^1.21.6", + "jiti": "2.0.0-beta.3", "js-yaml": "^4.1.0", "minimist": "^1.2.8", "picocolors": "^1.0.0", diff --git a/packages/knip/src/util/loader.ts b/packages/knip/src/util/loader.ts index d9e9430f4..89280b9f5 100644 --- a/packages/knip/src/util/loader.ts +++ b/packages/knip/src/util/loader.ts @@ -4,7 +4,7 @@ import { LoaderError } from './errors.js'; import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js'; import { isTypeModule } from './fs.js'; import { extname, isInternal } from './path.js'; -import { jitiCJS, jitiESM } from './register.js'; +import { jiti } from './register.js'; const load = async (filePath: string) => { try { @@ -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/src/util/register.ts b/packages/knip/src/util/register.ts index c955a9ff3..b7140ecfc 100644 --- a/packages/knip/src/util/register.ts +++ b/packages/knip/src/util/register.ts @@ -1,5 +1,6 @@ import { fileURLToPath } from 'node:url'; -import createJITI, { type JITIOptions } from 'jiti'; +// @ts-expect-error ts(2614) +import { type JitiOptions, createJiti } from 'jiti'; import { DEFAULT_EXTENSIONS } from '../constants.js'; import { join } from './path.js'; @@ -15,9 +16,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/require.ts b/packages/knip/src/util/require.ts index bace7cf11..0a9a80b5f 100644 --- a/packages/knip/src/util/require.ts +++ b/packages/knip/src/util/require.ts @@ -5,7 +5,7 @@ import { timerify } from './Performance.js'; import { debugLog } from './debug.js'; import { getPackageNameFromModuleSpecifier } from './modules.js'; import { cwd, join, toPosix } from './path.js'; -import { jitiCJS } from './register.js'; +import { jiti as _jiti } from './register.js'; /* * package.json#exports + self-referencing not supported in `resolve` package nor Bun: @@ -18,7 +18,7 @@ const createRequire = (path?: string) => nodeCreateRequire(pathToFileURL(path ?? const require = createRequire(); export const _require = timerify(require); -const resolve = (specifier: string) => toPosix(jitiCJS.resolve(specifier)); +const resolve = (specifier: string) => toPosix(_jiti.resolve(specifier)); const tryResolve = (specifier: string, from: string) => { try {