in src/extension/simulate.ts [133:191]
public getPackage(): Promise<typeof CordovaSimulate> {
if (this.simulatePackage) {
return Promise.resolve(this.simulatePackage);
}
// Don't do the require if we don't actually need it
try {
const simulate = customRequire(this.CORDOVA_SIMULATE_PACKAGE) as typeof CordovaSimulate;
this.simulatePackage = simulate;
return Promise.resolve(this.simulatePackage);
} catch (e) {
if (e.code === "MODULE_NOT_FOUND") {
OutputChannelLogger.getMainChannel().log(localize("CordovaSimulateDepNotPresent", "cordova-simulate dependency not present. Installing it..."));
} else {
throw e;
}
}
return new Promise((resolve, reject) => {
if (!this.packageInstallProc) {
this.packageInstallProc = cp.spawn(process.platform === "win32" ? "npm.cmd" : "npm",
["install", this.CORDOVA_SIMULATE_PACKAGE, "--verbose", "--no-save"],
{ cwd: path.dirname(findFileInFolderHierarchy(__dirname, "package.json")) });
this.packageInstallProc.once("exit", (code: number) => {
if (code === 0) {
this.simulatePackage = customRequire(this.CORDOVA_SIMULATE_PACKAGE);
resolve(this.simulatePackage);
} else {
OutputChannelLogger.getMainChannel().log(localize("ErrorWhileInstallingCordovaSimulateDep", "Error while installing cordova-simulate dependency to the extension"));
reject(localize("ErrorWhileInstallingCordovaSimulateDep", "Error while installing cordova-simulate dependency to the extension"));
}
});
let lastDotTime = 0;
const printDot = () => {
const now = Date.now();
if (now - lastDotTime > 1500) {
lastDotTime = now;
OutputChannelLogger.getMainChannel().append(".");
}
};
this.packageInstallProc.stdout.on("data", () => {
printDot();
});
this.packageInstallProc.stderr.on("data", (data: Buffer) => {
printDot();
});
} else {
const packageCheck = setInterval(() => {
if (this.simulatePackage) {
clearInterval(packageCheck);
resolve(this.simulatePackage);
}
}, 1000);
}
});
}