diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index 18f6de430e..0164509b5f 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -124,3 +124,5 @@ $injector.require("iOSLogFilter", "./services/ios-log-filter"); $injector.require("projectChangesService", "./services/project-changes-service"); $injector.require("emulatorPlatformService", "./services/emulator-platform-service"); + +$injector.require("staticConfig", "./config"); diff --git a/lib/common b/lib/common index 340713d7c9..5e861259be 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 340713d7c92e03ed8032261691b25ad91d5d2214 +Subproject commit 5e861259bef7783f71262b5aec8a6711f487c189 diff --git a/lib/nativescript-cli-lib-bootstrap.ts b/lib/nativescript-cli-lib-bootstrap.ts index ed4d033ded..1648db0a4e 100644 --- a/lib/nativescript-cli-lib-bootstrap.ts +++ b/lib/nativescript-cli-lib-bootstrap.ts @@ -9,3 +9,8 @@ $injector.requirePublic("companionAppsService", "./common/appbuilder/services/li $injector.requirePublicClass("deviceEmitter", "./common/appbuilder/device-emitter"); $injector.requirePublicClass("deviceLogProvider", "./common/appbuilder/device-log-provider"); $injector.requirePublicClass("localBuildService", "./services/local-build-service"); +$injector.require("iOSLogFilter", "./common/mobile/ios/ios-log-filter"); + +// We need this because some services check if (!$options.justLaunch) to start the device log after some operation. +// We don't want this behaviour when the CLI is required as library. +$injector.resolve("options").justLaunch = true; diff --git a/lib/services/ios-log-filter.ts b/lib/services/ios-log-filter.ts index a263252c41..94fb7db600 100644 --- a/lib/services/ios-log-filter.ts +++ b/lib/services/ios-log-filter.ts @@ -1,15 +1,15 @@ let sourcemap = require("source-map"); import * as path from "path"; +import { cache } from "../common/decorators"; export class IOSLogFilter implements Mobile.IPlatformLogFilter { private partialLine: string = null; - constructor(private $fs: IFileSystem) { - } - - public filterData(data: string, logLevel: string, projectDir: string, pid?: string): string { + constructor(private $fs: IFileSystem, + private $projectData: IProjectData) { } + public filterData(data: string, logLevel: string, pid?: string): string { if (pid && data && data.indexOf(`[${pid}]`) === -1) { return null; } @@ -40,15 +40,15 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter { let pidIndex = line.indexOf(searchString); if (pidIndex > 0) { line = line.substring(pidIndex + searchString.length, line.length); - this.getOriginalFileLocation(line, projectDir); - result += this.getOriginalFileLocation(line, projectDir) + "\n"; + this.getOriginalFileLocation(line); + result += this.getOriginalFileLocation(line) + "\n"; continue; } } if (skipLastLine && i === lines.length - 1) { this.partialLine = line; } else { - result += this.getOriginalFileLocation(line, projectDir) + "\n"; + result += this.getOriginalFileLocation(line) + "\n"; } } return result; @@ -57,11 +57,12 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter { return data; } - private getOriginalFileLocation(data: string, projectDir: string): string { - let fileString = "file:///"; - let fileIndex = data.indexOf(fileString); + private getOriginalFileLocation(data: string): string { + const fileString = "file:///"; + const fileIndex = data.indexOf(fileString); + const projectDir = this.getProjectDir(); - if (fileIndex >= 0) { + if (fileIndex >= 0 && projectDir) { let parts = data.substring(fileIndex + fileString.length).split(":"); if (parts.length >= 4) { let file = parts[0]; @@ -87,5 +88,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter { return data; } + + @cache() + private getProjectDir(): string { + try { + this.$projectData.initializeProjectData(); + return this.$projectData.projectDir; + } catch (err) { + return null; + } + } } + $injector.register("iOSLogFilter", IOSLogFilter);