in src/cordova.ts [273:340]
function updatePluginTypeDefinitions(cordovaProjectRoot: string): void {
// We don't need to install typings for Ionic2 and newer since it has own TS
// wrapper around core plugins. We also won't try to manage typings
// in typescript projects as it might break compilation due to conflicts
// between typings we install and user-installed ones.
const ionicMajorVersion = CordovaProjectHelper.determineIonicMajorVersion(cordovaProjectRoot);
if (CordovaProjectHelper.isTypescriptProject(cordovaProjectRoot) || ionicMajorVersion > 1) {
return;
}
let installedPlugins: string[] = CordovaProjectHelper.getInstalledPlugins(cordovaProjectRoot);
const nodeModulesDir = path.resolve(cordovaProjectRoot, "node_modules");
if (semver.gte(vscode.version, "1.7.2-insider") && fs.existsSync(nodeModulesDir)) {
// Read installed node modules and filter out plugins that have been already installed in node_modules
// This happens if user has used '--fetch' option to install plugin. In this case VSCode will provide
// own intellisense for these plugins using ATA (automatic typings acquisition)
let installedNpmModules: string[] = [];
try {
installedNpmModules = fs.readdirSync(nodeModulesDir);
} catch (e) { }
const pluginTypingsJson = getPluginTypingsJson() || {};
installedPlugins = installedPlugins.filter(pluginId => {
// plugins with `forceInstallTypings` flag don't have typings on NPM yet,
// so we still need to install these even if they present in 'node_modules'
const forceInstallTypings = pluginTypingsJson[pluginId] &&
pluginTypingsJson[pluginId].forceInstallTypings;
return forceInstallTypings || installedNpmModules.indexOf(pluginId) === -1;
});
}
let newTypeDefs = getNewTypeDefinitions(installedPlugins);
let cordovaPluginTypesFolder = CordovaProjectHelper.getCordovaPluginTypeDefsPath(cordovaProjectRoot);
let ionicPluginTypesFolder = CordovaProjectHelper.getIonicPluginTypeDefsPath(cordovaProjectRoot);
if (!CordovaProjectHelper.existsSync(cordovaPluginTypesFolder)) {
addPluginTypeDefinitions(cordovaProjectRoot, installedPlugins, []);
return;
}
let currentTypeDefs: string[] = [];
// Now read the type definitions of Cordova plugins
fs.readdir(cordovaPluginTypesFolder, (err: Error, cordovaTypeDefs: string[]) => {
if (err) {
// ignore
}
if (cordovaTypeDefs) {
currentTypeDefs = cordovaTypeDefs.map(typeDef => getRelativeTypeDefinitionFilePath(cordovaProjectRoot, cordovaPluginTypesFolder, typeDef));
}
// Now read the type definitions of Ionic plugins
fs.readdir(ionicPluginTypesFolder, (err: Error, ionicTypeDefs: string[]) => {
if (err) {
// ignore
}
if (ionicTypeDefs) {
currentTypeDefs.concat(ionicTypeDefs.map(typeDef => getRelativeTypeDefinitionFilePath(cordovaProjectRoot, ionicPluginTypesFolder, typeDef)));
}
addPluginTypeDefinitions(cordovaProjectRoot, installedPlugins, currentTypeDefs);
removePluginTypeDefinitions(cordovaProjectRoot, currentTypeDefs, newTypeDefs);
});
});
}