in jshint-server/src/server.ts [439:488]
async getLib(): Promise<any> {
if (this.lib) {
return this.lib;
}
const globalPath = this.getGlobalPackageManagerPath(this.packageManager || 'yarn');
let libraryPathPromise;
if (this.nodePath) {
libraryPathPromise = Files.resolve('jshint', this.nodePath, this.nodePath, () => this.trace).then(undefined, () => {
return Files.resolve('jshint', globalPath, this.workspaceRoot, () => this.trace);
});
} else {
libraryPathPromise = Files.resolve('jshint', /* nodePath */ undefined, this.workspaceRoot, () => this.trace).then(undefined, () => {
return Files.resolve('jshint', globalPath, this.workspaceRoot, () => this.trace);
});
}
let path;
try {
path = await libraryPathPromise;
} catch (e) {
this.connection.console.error('Failed to load jshint library');
throw new Error('Failed to load jshint library. Please install jshint in your workspace folder using \'npm install jshint\' or globally using \'npm install -g jshint\' and then reload.');;
}
const confirmed = await this.confirmLibraryUsage(path, globalPath);
if (!confirmed) {
throw new Error('Library is not trusted');
}
let lib;
try {
lib = require(path);
} catch (e) {
this.connection.console.error('Failed to load jshint library');
throw new Error('Failed to load jshint library. Please install jshint in your workspace folder using \'npm install jshint\' or globally using \'npm install -g jshint\' and then reload.');
}
if (!lib.JSHINT) {
const message = 'The jshint library doesn\'t export a JSHINT property.';
this.connection.console.error(message);
throw new Error(message);
}
this.connection.console.info(`jshint library loaded from ${path}`);
this.lib = lib;
return this.lib;
}