Skip to content

fix: remove interopDefault to use jiti's default #19697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
sethamus committed May 16, 2025
commit 535f39322698edd1f0d007143542d63f4ec7de1a
32 changes: 12 additions & 20 deletions lib/config/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,13 @@ function isNativeTypeScriptSupportEnabled() {
* @since 9.24.0
*/
async function loadTypeScriptConfigFileWithJiti(filePath, fileURL, mtime) {
// eslint-disable-next-line no-use-before-define -- `ConfigLoader.loadJiti` can be overwritten for testing
const { createJiti } = await ConfigLoader.loadJiti().catch(() => {
throw new Error(
"The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.",
);
});
const { createJiti, version: jitiVersion } =
// eslint-disable-next-line no-use-before-define -- `ConfigLoader.loadJiti` can be overwritten for testing
await ConfigLoader.loadJiti().catch(() => {
throw new Error(
"The 'jiti' library is required for loading TypeScript configuration files. Make sure to install it.",
);
});

// `createJiti` was added in jiti v2.
if (typeof createJiti !== "function") {
Expand All @@ -159,8 +160,6 @@ async function loadTypeScriptConfigFileWithJiti(filePath, fileURL, mtime) {
moduleCache: false,
};

// eslint-disable-next-line no-use-before-define -- `ConfigLoader.getJitiVersion` can be overwritten for testing
const jitiVersion = ConfigLoader.getJitiVersion();
if (jitiVersion.startsWith("2.1.")) {
jitiOptions.interopDefault = false;
}
Expand Down Expand Up @@ -500,19 +499,12 @@ class ConfigLoader {

/**
* Used to import the jiti dependency. This method is exposed internally for testing purposes.
* @returns {Promise<Record<string, unknown>>} A promise that fulfills with a module object
* or rejects with an error if jiti is not found.
*/
static loadJiti() {
return import("jiti");
}

/**
* Used to get the jiti version. This method is exposed internally for testing purposes.
* @returns {string} The version of jiti.
* @returns {Promise<{createJiti: Function, version: string}>} A promise that fulfills with an object containing the jiti module's createJiti function and version.
*/
static getJitiVersion() {
return require("jiti/package.json").version;
static async loadJiti() {
const { createJiti } = await import("jiti");
const version = require("jiti/package.json").version;
return { createJiti, version };
}

/**
Expand Down
36 changes: 16 additions & 20 deletions tests/lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1422,16 +1422,14 @@ describe("ESLint", () => {
JITI_VERSIONS.forEach(jitiVersion => {
describe(`Loading TypeScript config files with ${jitiVersion}`, () => {
beforeEach(() => {
sinon
.stub(ConfigLoader, "loadJiti")
.callsFake(() => import(jitiVersion));
sinon
.stub(ConfigLoader, "getJitiVersion")
.callsFake(
() =>
require(`${jitiVersion}/package.json`)
.version,
);
sinon.stub(ConfigLoader, "loadJiti").callsFake(() =>
Promise.resolve({
createJiti: require(jitiVersion).createJiti,
version: require(
`${jitiVersion}/package.json`,
).version,
}),
);
});

afterEach(() => {
Expand Down Expand Up @@ -6349,16 +6347,14 @@ describe("ESLint", () => {
JITI_VERSIONS.forEach(jitiVersion => {
describe(`Loading TypeScript config files with ${jitiVersion}`, () => {
beforeEach(() => {
sinon
.stub(ConfigLoader, "loadJiti")
.callsFake(() => import(jitiVersion));
sinon
.stub(ConfigLoader, "getJitiVersion")
.callsFake(
() =>
require(`${jitiVersion}/package.json`)
.version,
);
sinon.stub(ConfigLoader, "loadJiti").callsFake(() =>
Promise.resolve({
createJiti: require(jitiVersion).createJiti,
version: require(
`${jitiVersion}/package.json`,
).version,
}),
);
});

afterEach(() => {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy