diff --git a/package-lock.json b/package-lock.json index 53afda499..5eb61c15d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,6 @@ "mkdirp": "^3.0.0", "mz": "^2.7.0", "progress": "^2.0.3", - "read-package-up": "^11.0.0", "semver": "7.7.2", "string-argv": "0.3.1", "supports-color": "^8.1.1", @@ -5890,6 +5889,7 @@ "resolved": "https://registry.npmjs.org/index-to-position/-/index-to-position-0.1.2.tgz", "integrity": "sha512-MWDKS3AS1bGCHLBA2VLImJz42f7bJh8wQsTGCzI3j519/CASStoDONUBVz2I/VID0MpiX3SGSnbOD2xUalbE5g==", "license": "MIT", + "peer": true, "engines": { "node": ">=18" }, @@ -8469,6 +8469,7 @@ "resolved": "https://registry.npmjs.org/read-package-up/-/read-package-up-11.0.0.tgz", "integrity": "sha512-MbgfoNPANMdb4oRBNg5eqLbB2t2r+o5Ua1pNt8BqGp4I0FJZhuVSOj3PaBPni4azWuSzEdNn2evevzVmEk1ohQ==", "license": "MIT", + "peer": true, "dependencies": { "find-up-simple": "^1.0.0", "read-pkg": "^9.0.0", @@ -8486,6 +8487,7 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-7.0.2.tgz", "integrity": "sha512-puUZAUKT5m8Zzvs72XWy3HtvVbTWljRE66cP60bxJzAqf2DgICo7lYTY2IHUmLnNpjYvw5bvmoHvPc0QO2a62w==", "license": "ISC", + "peer": true, "dependencies": { "lru-cache": "^10.0.1" }, @@ -8497,13 +8499,15 @@ "version": "10.4.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", - "license": "ISC" + "license": "ISC", + "peer": true }, "node_modules/read-package-up/node_modules/normalize-package-data": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-6.0.2.tgz", "integrity": "sha512-V6gygoYb/5EmNI+MEGrWkC+e6+Rr7mTmfHrxDbLzxQogBkgzo76rkok0Am6thgSF7Mv2nLOajAJj5vDJZEFn7g==", "license": "BSD-2-Clause", + "peer": true, "dependencies": { "hosted-git-info": "^7.0.0", "semver": "^7.3.5", @@ -8518,6 +8522,7 @@ "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-8.1.0.tgz", "integrity": "sha512-rum1bPifK5SSar35Z6EKZuYPJx85pkNaFrxBK3mwdfSJ1/WKbYrjoW/zTPSjRRamfmVX1ACBIdFAO0VRErW/EA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.22.13", "index-to-position": "^0.1.2", @@ -8535,6 +8540,7 @@ "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-9.0.1.tgz", "integrity": "sha512-9viLL4/n1BJUCT1NXVTdS1jtm80yDEgR5T4yCelII49Mbj0v1rZdKqj7zCiYdbB0CuCgdrvHcNogAKTFPBocFA==", "license": "MIT", + "peer": true, "dependencies": { "@types/normalize-package-data": "^2.4.3", "normalize-package-data": "^6.0.0", @@ -10283,6 +10289,7 @@ "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", "license": "MIT", + "peer": true, "engines": { "node": ">=18" }, diff --git a/package.json b/package.json index e0cfa6fad..ca80d45c3 100644 --- a/package.json +++ b/package.json @@ -250,7 +250,6 @@ "mkdirp": "^3.0.0", "mz": "^2.7.0", "progress": "^2.0.3", - "read-package-up": "^11.0.0", "semver": "7.7.2", "string-argv": "0.3.1", "supports-color": "^8.1.1", diff --git a/src/configuration/from_file.ts b/src/configuration/from_file.ts index 9629e033c..a35cedd9e 100644 --- a/src/configuration/from_file.ts +++ b/src/configuration/from_file.ts @@ -107,24 +107,20 @@ async function loadFile( break case '.js': { - const parentPackage = await readPackageJson(filePath) - if (!parentPackage) { + logger.debug( + `Loading configuration file "${file}" as JavaScript based on extension` + ) + const ambiguous = await import(pathToFileURL(filePath).toString()) + if ('module.exports' in ambiguous) { logger.debug( - `Loading configuration file "${file}" as CommonJS based on absence of a parent package` + `Treating configuration file "${file}" as CommonJS based on heuristics` ) - // eslint-disable-next-line @typescript-eslint/no-require-imports - definitions = require(filePath) - } else if (parentPackage.type === 'module') { - logger.debug( - `Loading configuration file "${file}" as ESM based on "${parentPackage.name}" package type` - ) - definitions = await import(pathToFileURL(filePath).toString()) + definitions = ambiguous['module.exports'] } else { logger.debug( - `Loading configuration file "${file}" as CommonJS based on "${parentPackage.name}" package type` + `Treating configuration file "${file}" as ESM based on heuristics` ) - // eslint-disable-next-line @typescript-eslint/no-require-imports - definitions = require(filePath) + definitions = ambiguous } } break @@ -136,9 +132,3 @@ async function loadFile( } return definitions } - -async function readPackageJson(filePath: string) { - const { readPackageUp } = await import('read-package-up') - const parentPackage = await readPackageUp({ cwd: path.dirname(filePath) }) - return parentPackage?.packageJson -}