diff --git a/lib/get-config.js b/lib/get-config.js index aa119f302d..cf305867d9 100644 --- a/lib/get-config.js +++ b/lib/get-config.js @@ -1,10 +1,10 @@ -import { dirname, extname } from "node:path"; +import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; import { castArray, isNil, isPlainObject, isString, pickBy } from "lodash-es"; import { readPackageUp } from "read-pkg-up"; import { cosmiconfig } from "cosmiconfig"; -import resolveFrom from "resolve-from"; +import importFrom from "import-from-esm"; import debugConfig from "debug"; import { repoUrl } from "./git.js"; import PLUGINS_DEFINITIONS from "./definitions/plugins.js"; @@ -33,17 +33,7 @@ export default async (context, cliOptions) => { options = { ...(await castArray(extendPaths).reduce(async (eventualResult, extendPath) => { const result = await eventualResult; - const resolvedPath = resolveFrom.silent(__dirname, extendPath) || resolveFrom(cwd, extendPath); - const importAssertions = - extname(resolvedPath) === ".json" - ? { - assert: { - type: "json", - }, - } - : undefined; - - const { default: extendsOptions } = await import(resolvedPath, importAssertions); + const extendsOptions = (await importFrom.silent(__dirname, extendPath)) || (await importFrom(cwd, extendPath)); // For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path, // so those plugin will be loaded relative to the config file diff --git a/package-lock.json b/package-lock.json index 493ec6a986..e3beea1e33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "git-log-parser": "^1.2.0", "hook-std": "^3.0.0", "hosted-git-info": "^7.0.0", + "import-from-esm": "^1.2.1", "lodash-es": "^4.17.21", "marked": "^9.0.0", "marked-terminal": "^6.0.0", @@ -6003,6 +6004,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/import-from-esm": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/import-from-esm/-/import-from-esm-1.2.1.tgz", + "integrity": "sha512-Nly5Ab75rWZmOwtMa0B0NQNnHGcHOQ2zkU/bVENwK2lbPq+kamPDqNKNJ0hF7w7lR/ETD5nGgJq0XbofsZpYCA==", + "dependencies": { + "import-meta-resolve": "^4.0.0" + }, + "engines": { + "node": ">=16.20" + } + }, + "node_modules/import-meta-resolve": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.0.0.tgz", + "integrity": "sha512-okYUR7ZQPH+efeuMJGlq4f8ubUgO50kByRPyt/Cy1Io4PSRsPjxME+YlVaCOx+NIToW7hCsZNFJyTPFFKepRSA==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", diff --git a/package.json b/package.json index 3142052974..ecb30d881e 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "git-log-parser": "^1.2.0", "hook-std": "^3.0.0", "hosted-git-info": "^7.0.0", + "import-from-esm": "^1.2.1", "lodash-es": "^4.17.21", "marked": "^9.0.0", "marked-terminal": "^6.0.0",