chore: use package.mock.json for allowing non-existing npm deps in it

This commit is contained in:
Thijs Louisse 2022-04-28 13:12:21 +02:00 committed by Thijs Louisse
parent 8ecfc31c0d
commit 2b3d2bd6a4
3 changed files with 9 additions and 3 deletions

View file

@ -49,7 +49,14 @@ function getPackageJson(rootPath) {
const fileContent = fs.readFileSync(`${rootPath}/package.json`, 'utf8'); const fileContent = fs.readFileSync(`${rootPath}/package.json`, 'utf8');
return JSON.parse(fileContent); return JSON.parse(fileContent);
} catch (_) { } catch (_) {
return undefined; try {
// For testing purposes, we allow to have a package.mock.json that contains 'fictional'
// packages (like 'exporting-ref-project') not on npm registry
const fileContent = fs.readFileSync(`${rootPath}/package.mock.json`, 'utf8');
return JSON.parse(fileContent);
} catch (__) {
return undefined;
}
} }
} }
@ -252,8 +259,7 @@ class InputDataService {
const project = { path: projectPath }; const project = { path: projectPath };
// Add project meta info // Add project meta info
try { try {
const file = pathLib.resolve(projectPath, 'package.json'); const pkgJson = getPackageJson(projectPath);
const pkgJson = JSON.parse(fs.readFileSync(file, 'utf8'));
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
project.mainEntry = this.__normalizeMainEntry(pkgJson.main || './index.js'); project.mainEntry = this.__normalizeMainEntry(pkgJson.main || './index.js');
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign