Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 9 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 9 additions & 19 deletions src/configuration/from_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Loading