Open
Description
If the working directory of Web Test Runner and its parent directories do not contain a package.json file the getPackageType
function will loop forever.
This happens because path.resolve('/', '..')
will return /
without throwing any errors, hence the currentPath
variable will keep the same value and the loop will never exit.
Suggested Fix
Add a check that the path has changed when the parent path is resolved.
async function getPackageType(basedir) {
let currentPath = basedir;
try {
while (await fileExists(currentPath)) {
const pkgJsonPath = path.join(currentPath, 'package.json');
if (await fileExists(pkgJsonPath)) {
const pkgJsonString = await fs.readFile(pkgJsonPath, { encoding: 'utf-8' });
const pkgJson = JSON.parse(pkgJsonString);
return pkgJson.type || 'commonjs';
}
const oldPath = currentPath;
currentPath = path.resolve(oldPath, '..');
if (currentPath === oldPath) {
return 'commonjs';
}
}
} catch (e) {
// don't log any error
}
return 'commonjs';
}
Metadata
Metadata
Assignees
Labels
No labels