in tools/pkglint/lib/rules.ts [652:679]
public validate(pkg: PackageJson) {
const bundled: string[] = pkg.json.bundleDependencies || pkg.json.bundledDependencies || [];
if (bundled.length === 0) { return; }
const repoPackageJson = path.resolve(__dirname, '../../../package.json');
const nohoist: string[] = require(repoPackageJson).workspaces.nohoist; // eslint-disable-line @typescript-eslint/no-require-imports
const missing = new Array<string>();
for (const dep of bundled) {
for (const entry of [`${pkg.packageName}/${dep}`, `${pkg.packageName}/${dep}/**`]) {
if (nohoist.indexOf(entry) >= 0) { continue; }
missing.push(entry);
}
}
if (missing.length > 0) {
pkg.report({
ruleName: this.name,
message: `Repository-level 'workspaces.nohoist' directive is missing: ${missing.join(', ')}`,
fix: () => {
const packageJson = require(repoPackageJson); // eslint-disable-line @typescript-eslint/no-require-imports
packageJson.workspaces.nohoist = [...packageJson.workspaces.nohoist, ...missing].sort();
fs.writeFileSync(repoPackageJson, `${JSON.stringify(packageJson, null, 2)}\n`, { encoding: 'utf8' });
},
});
}
}