Skip to content

Commit aeef64a

Browse files
TsvetanMilanovrosen-vladimirov
authored andcommitted
Fix iOS device log filter (#2617)
We need to pass the project directory only for the ios-log-filter in the NS CLI. That's why we can use the projectData instead of adding it as a parameter.
1 parent 8cd5d13 commit aeef64a

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

lib/bootstrap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,5 @@ $injector.require("iOSLogFilter", "./services/ios-log-filter");
124124
$injector.require("projectChangesService", "./services/project-changes-service");
125125

126126
$injector.require("emulatorPlatformService", "./services/emulator-platform-service");
127+
128+
$injector.require("staticConfig", "./config");

lib/nativescript-cli-lib-bootstrap.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ $injector.requirePublic("companionAppsService", "./common/appbuilder/services/li
99
$injector.requirePublicClass("deviceEmitter", "./common/appbuilder/device-emitter");
1010
$injector.requirePublicClass("deviceLogProvider", "./common/appbuilder/device-log-provider");
1111
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
12+
$injector.require("iOSLogFilter", "./common/mobile/ios/ios-log-filter");
13+
14+
// We need this because some services check if (!$options.justLaunch) to start the device log after some operation.
15+
// We don't want this behaviour when the CLI is required as library.
16+
$injector.resolve("options").justLaunch = true;

lib/services/ios-log-filter.ts

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
let sourcemap = require("source-map");
22
import * as path from "path";
3+
import { cache } from "../common/decorators";
34

45
export class IOSLogFilter implements Mobile.IPlatformLogFilter {
56

67
private partialLine: string = null;
78

8-
constructor(private $fs: IFileSystem) {
9-
}
10-
11-
public filterData(data: string, logLevel: string, projectDir: string, pid?: string): string {
9+
constructor(private $fs: IFileSystem,
10+
private $projectData: IProjectData) { }
1211

12+
public filterData(data: string, logLevel: string, pid?: string): string {
1313
if (pid && data && data.indexOf(`[${pid}]`) === -1) {
1414
return null;
1515
}
@@ -40,15 +40,15 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
4040
let pidIndex = line.indexOf(searchString);
4141
if (pidIndex > 0) {
4242
line = line.substring(pidIndex + searchString.length, line.length);
43-
this.getOriginalFileLocation(line, projectDir);
44-
result += this.getOriginalFileLocation(line, projectDir) + "\n";
43+
this.getOriginalFileLocation(line);
44+
result += this.getOriginalFileLocation(line) + "\n";
4545
continue;
4646
}
4747
}
4848
if (skipLastLine && i === lines.length - 1) {
4949
this.partialLine = line;
5050
} else {
51-
result += this.getOriginalFileLocation(line, projectDir) + "\n";
51+
result += this.getOriginalFileLocation(line) + "\n";
5252
}
5353
}
5454
return result;
@@ -57,11 +57,12 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
5757
return data;
5858
}
5959

60-
private getOriginalFileLocation(data: string, projectDir: string): string {
61-
let fileString = "file:///";
62-
let fileIndex = data.indexOf(fileString);
60+
private getOriginalFileLocation(data: string): string {
61+
const fileString = "file:///";
62+
const fileIndex = data.indexOf(fileString);
63+
const projectDir = this.getProjectDir();
6364

64-
if (fileIndex >= 0) {
65+
if (fileIndex >= 0 && projectDir) {
6566
let parts = data.substring(fileIndex + fileString.length).split(":");
6667
if (parts.length >= 4) {
6768
let file = parts[0];
@@ -87,5 +88,16 @@ export class IOSLogFilter implements Mobile.IPlatformLogFilter {
8788

8889
return data;
8990
}
91+
92+
@cache()
93+
private getProjectDir(): string {
94+
try {
95+
this.$projectData.initializeProjectData();
96+
return this.$projectData.projectDir;
97+
} catch (err) {
98+
return null;
99+
}
100+
}
90101
}
102+
91103
$injector.register("iOSLogFilter", IOSLogFilter);

0 commit comments

Comments
 (0)