mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
The tip "npm install ..." is not that useful when one is using another package manager instead of NPM. And also can lead to confusion.
21 lines
568 B
TypeScript
21 lines
568 B
TypeScript
import { Logger } from '../services/logger.service';
|
|
|
|
const MISSING_REQUIRED_DEPENDENCY = (name: string, reason: string) =>
|
|
`The "${name}" package is missing. Please, make sure to install it to take advantage of ${reason}.`;
|
|
|
|
const logger = new Logger('PackageLoader');
|
|
|
|
export function loadPackage(
|
|
packageName: string,
|
|
context: string,
|
|
loaderFn?: Function,
|
|
) {
|
|
try {
|
|
return loaderFn ? loaderFn() : require(packageName);
|
|
} catch (e) {
|
|
logger.error(MISSING_REQUIRED_DEPENDENCY(packageName, context));
|
|
Logger.flush();
|
|
process.exit(1);
|
|
}
|
|
}
|