From 77b86bfc8c4ae64d6ea90a1cc3ebe2f8cf492d68 Mon Sep 17 00:00:00 2001 From: Artem Egorov Date: Mon, 23 Jul 2018 12:40:04 +0300 Subject: [PATCH] Fixed error while stop expo packager (#753) --- src/common/packager.ts | 58 +++++++++++++++++------- src/extension/exponent/exponentHelper.ts | 47 ++++++++++--------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/common/packager.ts b/src/common/packager.ts index f110c8868..86efd4880 100644 --- a/src/common/packager.ts +++ b/src/common/packager.ts @@ -73,21 +73,29 @@ export class Packager { args = args.concat("--resetCache"); } - // Arguments below using for Expo apps - args.push("--root", path.relative(this.projectPath, path.resolve(this.workspacePath, ".vscode"))); let helper = new ExponentHelper(this.workspacePath, this.projectPath); - return helper.getExpPackagerOptions() - .then((options: ExpConfigPackager) => { - Object.keys(options).forEach(key => { - args = args.concat([`--${key}`, options[key]]); - }); + return helper.isExpoApp(false) + .then((isExpo) => { + if (isExpo) { + // Arguments below using for Expo apps + args.push("--root", path.relative(this.projectPath, path.resolve(this.workspacePath, ".vscode"))); + return helper.getExpPackagerOptions() + .then((options: ExpConfigPackager) => { + Object.keys(options).forEach(key => { + args = args.concat([`--${key}`, options[key]]); + }); + + return args; + }) + .catch(() => { + this.logger.warning("Couldn't read packager's options from exp.json, continue..."); + return args; + }); + } else { return args; - }) - .catch(() => { - this.logger.warning("Couldn't read packager's options from exp.json, continue..."); - return args; - }); + } + }); }) .then((args) => { const projectRoot = SettingsHelper.getReactNativeProjectRoot(this.workspacePath); @@ -293,11 +301,27 @@ export class Packager { this.logger.info("Stopping Packager"); return new CommandExecutor(this.projectPath, this.logger).killReactPackager(this.packagerProcess).then(() => { this.packagerProcess = undefined; - this.logger.debug("Stopping Exponent"); - return XDL.stopAll(this.projectPath) - .then(() => - this.logger.debug("Exponent Stopped") - ); + + let helper = new ExponentHelper(this.workspacePath, this.projectPath); + + return helper.isExpoApp(false) + .then((isExpo) => { + if (isExpo) { + this.logger.debug("Stopping Exponent"); + return XDL.stopAll(this.projectPath) + .then(() => { + this.logger.debug("Exponent Stopped"); + }) + .catch((err) => { + if (err.code === "NOT_LOGGED_IN") { + return void(0); + } + throw err; + }); + } else { + return void(0); + } + }); }); } diff --git a/src/extension/exponent/exponentHelper.ts b/src/extension/exponent/exponentHelper.ts index 4a1af8b7b..f2e34ab13 100644 --- a/src/extension/exponent/exponentHelper.ts +++ b/src/extension/exponent/exponentHelper.ts @@ -25,7 +25,7 @@ const DBL_SLASHES = /\\/g; export class ExponentHelper { private workspaceRootPath: string; private projectRootPath: string; - private fs: FileSystem; + private fs: FileSystem = new FileSystem(); private hasInitialized: boolean; private logger: OutputChannelLogger = OutputChannelLogger.getMainChannel(); @@ -42,6 +42,7 @@ export class ExponentHelper { public configureExponentEnvironment(): Q.Promise { this.lazilyInitialize(); this.logger.info("Making sure your project uses the correct dependencies for exponent. This may take a while..."); + this.logger.logStream("Checking if this is Expo app."); return this.isExpoApp(true) .then(isExpo => { this.logger.logStream(".\n"); @@ -85,6 +86,27 @@ export class ExponentHelper { .then(opts => opts || {}); } + public isExpoApp(showProgress: boolean = false): Q.Promise { + if (showProgress) { + this.logger.logStream("..."); + } + + const packageJsonPath = this.pathToFileInWorkspace("package.json"); + return this.fs.readFile(packageJsonPath) + .then(content => { + const packageJson = JSON.parse(content); + const isExp = packageJson.dependencies && !!packageJson.dependencies.expo || false; + if (showProgress) this.logger.logStream("."); + return isExp; + }).catch(() => { + if (showProgress) { + this.logger.logStream("."); + } + // Not in a react-native project + return false; + }); + } + /** * Path to a given file inside the .vscode directory */ @@ -258,35 +280,12 @@ AppRegistry.registerRunnable('main', function(appParameters) { return path.join(this.projectRootPath, filename).replace(DBL_SLASHES, "/"); } - private isExpoApp(showProgress: boolean = false): Q.Promise { - this.logger.logStream("Checking if this is Expo app."); - if (showProgress) { - this.logger.logStream("..."); - } - - const packageJsonPath = this.pathToFileInWorkspace("package.json"); - return this.fs.readFile(packageJsonPath) - .then(content => { - const packageJson = JSON.parse(content); - const isExp = packageJson.dependencies && !!packageJson.dependencies.expo || false; - if (showProgress) this.logger.logStream("."); - return isExp; - }).catch(() => { - if (showProgress) { - this.logger.logStream("."); - } - // Not in a react-native project - return false; - }); - } - /** * Works as a constructor but only initiliazes when it's actually needed. */ private lazilyInitialize(): void { if (!this.hasInitialized) { this.hasInitialized = true; - this.fs = new FileSystem(); XDL.configReactNativeVersionWargnings(); XDL.attachLoggerStream(this.projectRootPath, {