Skip to content

Commit

Permalink
Do not install typings for plugins installed with '--fetch' option
Browse files Browse the repository at this point in the history
Note that we still need to install typings for plugins which don’t have typings available on NPM
  • Loading branch information
Vladimir Kotikov committed Nov 30, 2016
1 parent c9c156d commit a6afb25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pluginTypings.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@
"typingFile": "cordova/plugins/WebSQL.d.ts"
},
"cordova-plugin-x-toast": {
"typingFile": "cordova/plugins/Toast.d.ts"
"typingFile": "cordova/plugins/Toast.d.ts",
"forceInstallTypings": true
},
"ionic-plugin-keyboard": {
"typingFile": "cordova-ionic/plugins/keyboard.d.ts"
"typingFile": "cordova-ionic/plugins/keyboard.d.ts",
"forceInstallTypings": true
},
"phonegap-plugin-barcodescanner": {
"typingFile": "cordova/plugins/BarcodeScanner.d.ts"
},
"phonegap-plugin-push": {
"typingFile": "cordova/plugins/Push.d.ts"
}
}
}
19 changes: 19 additions & 0 deletions src/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {CordovaProjectHelper} from './utils/cordovaProjectHelper';
import {CordovaCommandHelper} from './utils/cordovaCommandHelper';
import {ExtensionServer} from './extension/extensionServer';
import * as Q from "q";
import * as semver from 'semver';
import {PluginSimulator} from "./extension/simulate";
import {Telemetry} from './utils/telemetry';
import {TelemetryHelper} from './utils/telemetryHelper';
Expand Down Expand Up @@ -213,6 +214,24 @@ function getRelativeTypeDefinitionFilePath(projectRoot: string, parentPath: stri

function updatePluginTypeDefinitions(cordovaProjectRoot: string): void {
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)
try {
const installedNpmModules: string[] = fs.readdirSync(nodeModulesDir);
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'
return getPluginTypingsJson()[pluginId].forceInstallTypings ||
installedNpmModules.indexOf(pluginId) === -1;
});
} catch (e) { }
}

let newTypeDefs = getNewTypeDefinitions(installedPlugins);
let cordovaPluginTypesFolder = CordovaProjectHelper.getCordovaPluginTypeDefsPath(cordovaProjectRoot);
let ionicPluginTypesFolder = CordovaProjectHelper.getIonicPluginTypeDefsPath(cordovaProjectRoot);
Expand Down

0 comments on commit a6afb25

Please sign in to comment.