Skip to content

Commit 314e745

Browse files
authored
Merge pull request #4673 from NativeScript/kddimitrov/webpack-source-maps-log
Kddimitrov/webpack source maps log
2 parents 24dd109 + 0eccef8 commit 314e745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1058
-138
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ docs/html
4040
docs-cli
4141

4242
!test-scripts/*.js
43+
!test/files/**/*.js
4344

4445
# From previous submodule
4546
lib/common/*.js

Gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module.exports = function (grunt) {
114114

115115
clean: {
116116
src: ["test/**/*.js*",
117+
"!test/files/**/*.js*",
117118
"lib/**/*.js*",
118119
"!test-scripts/**/*",
119120
"!lib/common/vendor/*.js",

lib/bootstrap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ $injector.requireCommand("post-install-cli", "./commands/post-install");
175175
$injector.requireCommand("update", "./commands/update");
176176

177177
$injector.require("iOSLogFilter", "./services/ios-log-filter");
178+
$injector.require("logSourceMapService", "./services/log-source-map-service");
178179
$injector.require("projectChangesService", "./services/project-changes-service");
179180

180181
$injector.require("pbxprojDomXcode", "./node/pbxproj-dom-xcode");

lib/common/commands/device/run-application.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class RunApplicationOnDeviceCommand implements ICommand {
1515
this.$errors.failWithoutHelp("More than one device found. Specify device explicitly with --device option. To discover device ID, use $%s device command.", this.$staticConfig.CLIENT_NAME.toLowerCase());
1616
}
1717

18-
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication({ appId: args[0], projectName: args[1] }));
18+
await this.$devicesService.execute(async (device: Mobile.IDevice) => await device.applicationManager.startApplication({ appId: args[0], projectName: args[1], projectDir: null }));
1919
}
2020
}
2121

lib/common/commands/device/stop-application.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class StopApplicationOnDeviceCommand implements ICommand {
99
public async execute(args: string[]): Promise<void> {
1010
await this.$devicesService.initialize({ deviceId: this.$options.device, skipInferPlatform: true, platform: args[1] });
1111

12-
const action = (device: Mobile.IDevice) => device.applicationManager.stopApplication({ appId: args[0], projectName: args[2] });
12+
const action = (device: Mobile.IDevice) => device.applicationManager.stopApplication({ appId: args[0], projectName: args[2], projectDir: null });
1313
await this.$devicesService.execute(action);
1414
}
1515
}

lib/common/definitions/mobile.d.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ declare module Mobile {
106106
}
107107

108108
interface IiOSDevice extends IDevice {
109-
getDebugSocket(appId: string, projectName: string, ensureAppStarted?: boolean): Promise<any>;
109+
getDebugSocket(appId: string, projectName: string, projectDir: string, ensureAppStarted?: boolean): Promise<any>;
110110
destroyDebugSocket(appId: string): Promise<void>;
111111
openDeviceLogStream(options?: IiOSLogStreamOptions): Promise<void>;
112112
destroyAllSockets(): Promise<void>;
@@ -145,6 +145,7 @@ declare module Mobile {
145145
device: Mobile.IDevice;
146146
getDeviceProjectRootPath(): Promise<string>;
147147
deviceSyncZipPath?: string;
148+
projectDir: string
148149
}
149150

150151
interface ILogcatStartOptions {
@@ -192,12 +193,19 @@ declare module Mobile {
192193
* @param {string} projectName The project name of the currently running application for which we need the logs.
193194
*/
194195
setProjectNameForDevice(deviceIdentifier: string, projectName: string): void;
196+
197+
/**
198+
* Sets the project name of the application on the specified device.
199+
* @param {string} deviceIdentifier The unique identifier of the device.
200+
* @param {string} projectDir The project dir of the currently running application for which we need the logs.
201+
*/
202+
setProjectDirForDevice(deviceIdentifier: string, projectDir: string): void;
195203
}
196204

197205
/**
198206
* Describes different options for filtering device logs.
199207
*/
200-
interface IDeviceLogOptions extends IDictionary<string | boolean> {
208+
interface IDeviceLogOptions extends IDictionary<string | boolean>, Partial<IProjectDir> {
201209
/**
202210
* Process id of the application on the device.
203211
*/
@@ -212,7 +220,6 @@ declare module Mobile {
212220
* The project name.
213221
*/
214222
projectName?: string;
215-
216223
}
217224

218225
/**
@@ -247,6 +254,13 @@ declare module Mobile {
247254
filterData(platform: string, data: string, deviceLogOptions: Mobile.IDeviceLogOptions): string;
248255
}
249256

257+
/**
258+
* Replaces file paths in device log with their original location
259+
*/
260+
interface ILogSourceMapService {
261+
replaceWithOriginalFileLocations(platform: string, messageData: string, loggingOptions: Mobile.IDeviceLogOptions): string
262+
}
263+
250264
/**
251265
* Describes filtering logic for specific platform (Android, iOS).
252266
*/
@@ -266,7 +280,7 @@ declare module Mobile {
266280
full: string;
267281
}
268282

269-
interface IApplicationData {
283+
interface IApplicationData extends IProjectDir {
270284
appId: string;
271285
projectName: string;
272286
justLaunch?: boolean;
@@ -462,9 +476,9 @@ declare module Mobile {
462476
isiOSDevice(device: Mobile.IDevice): boolean;
463477
isiOSSimulator(device: Mobile.IDevice): boolean;
464478
isOnlyiOSSimultorRunning(): boolean;
465-
isAppInstalledOnDevices(deviceIdentifiers: string[], appIdentifier: string, framework: string): Promise<IAppInstalledInfo>[];
479+
isAppInstalledOnDevices(deviceIdentifiers: string[], appIdentifier: string, framework: string, projectDir: string): Promise<IAppInstalledInfo>[];
466480
setLogLevel(logLevel: string, deviceIdentifier?: string): void;
467-
deployOnDevices(deviceIdentifiers: string[], packageFile: string, packageName: string, framework: string): Promise<void>[];
481+
deployOnDevices(deviceIdentifiers: string[], packageFile: string, packageName: string, framework: string, projectDir: string): Promise<void>[];
468482
getDeviceByIdentifier(identifier: string): Mobile.IDevice;
469483
mapAbstractToTcpPort(deviceIdentifier: string, appIdentifier: string, framework: string): Promise<string>;
470484
getDebuggableApps(deviceIdentifiers: string[]): Promise<Mobile.IDeviceApplicationInformation[]>[];

lib/common/mobile/android/android-application-manager.ts

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
8787
const processIdentifier = await this.getAppProcessId(deviceIdentifier, appIdentifier);
8888
if (processIdentifier) {
8989
this.$deviceLogProvider.setApplicationPidForDevice(deviceIdentifier, processIdentifier);
90+
this.$deviceLogProvider.setProjectDirForDevice(deviceIdentifier, appData.projectDir);
9091
await this.$logcatHelper.start({
9192
deviceIdentifier: this.identifier,
9293
pid: processIdentifier
@@ -118,6 +119,7 @@ export class AndroidApplicationManager extends ApplicationManagerBase {
118119
public stopApplication(appData: Mobile.IApplicationData): Promise<void> {
119120
this.$logcatHelper.stop(this.identifier);
120121
this.$deviceLogProvider.setApplicationPidForDevice(this.identifier, null);
122+
this.$deviceLogProvider.setProjectDirForDevice(this.identifier, null);
121123
return this.adb.executeShellCommand(["am", "force-stop", `${appData.appId}`]);
122124
}
123125

lib/common/mobile/device-log-emitter.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { DEVICE_LOG_EVENT_NAME } from "../constants";
44
export class DeviceLogEmitter extends DeviceLogProviderBase {
55
constructor(protected $logFilter: Mobile.ILogFilter,
66
$logger: ILogger,
7-
private $loggingLevels: Mobile.ILoggingLevels) {
7+
private $loggingLevels: Mobile.ILoggingLevels,
8+
private $logSourceMapService: Mobile.ILogSourceMapService) {
89
super($logFilter, $logger);
910
}
1011

1112
public logData(line: string, platform: string, deviceIdentifier: string): void {
1213
this.setDefaultLogLevelForDevice(deviceIdentifier);
1314

14-
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier) || { logLevel: this.$loggingLevels.info };
15-
const data = this.$logFilter.filterData(platform, line, loggingOptions);
15+
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier) || { logLevel: this.$loggingLevels.info, projectDir: null };
16+
let data = this.$logFilter.filterData(platform, line, loggingOptions);
17+
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data, loggingOptions);
1618

1719
if (data) {
1820
this.emit('data', deviceIdentifier, data);

lib/common/mobile/device-log-provider-base.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export abstract class DeviceLogProviderBase extends EventEmitter implements Mobi
2121
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.projectName, projectName);
2222
}
2323

24+
public setProjectDirForDevice(deviceIdentifier: string, projectDir: string): void {
25+
this.setDeviceLogOptionsProperty(deviceIdentifier, (deviceLogOptions: Mobile.IDeviceLogOptions) => deviceLogOptions.projectDir, projectDir);
26+
}
27+
2428
protected setDefaultLogLevelForDevice(deviceIdentifier: string): void {
2529
const logLevel = (this.devicesLogOptions[deviceIdentifier] && this.devicesLogOptions[deviceIdentifier].logLevel) || this.$logFilter.loggingLevel;
2630
this.setLogLevel(logLevel, deviceIdentifier);

lib/common/mobile/device-log-provider.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { LoggerConfigData } from "../../constants";
44

55
export class DeviceLogProvider extends DeviceLogProviderBase {
66
constructor(protected $logFilter: Mobile.ILogFilter,
7-
protected $logger: ILogger) {
7+
protected $logger: ILogger,
8+
private $logSourceMapService: Mobile.ILogSourceMapService) {
89
super($logFilter, $logger);
910
}
1011

1112
public logData(lineText: string, platform: string, deviceIdentifier: string): void {
1213
const loggingOptions = this.getDeviceLogOptionsForDevice(deviceIdentifier);
13-
const data = this.$logFilter.filterData(platform, lineText, loggingOptions);
14+
let data = this.$logFilter.filterData(platform, lineText, loggingOptions);
15+
data = this.$logSourceMapService.replaceWithOriginalFileLocations(platform, data, loggingOptions);
1416
if (data) {
1517
this.logDataCore(data);
1618
this.emit(DEVICE_LOG_EVENT_NAME, lineText, deviceIdentifier, platform);

lib/common/mobile/ios/device/ios-application-manager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class IOSApplicationManager extends ApplicationManagerBase {
9595

9696
private async setDeviceLogData(appData: Mobile.IApplicationData): Promise<void> {
9797
this.$deviceLogProvider.setProjectNameForDevice(this.device.deviceInfo.identifier, appData.projectName);
98+
this.$deviceLogProvider.setProjectDirForDevice(this.device.deviceInfo.identifier, appData.projectDir);
9899
if (!this.$options.justlaunch) {
99100
await this.startDeviceLog();
100101
}

lib/common/mobile/ios/ios-device-base.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
1414
abstract openDeviceLogStream(options?: Mobile.IiOSLogStreamOptions): Promise<void>;
1515

1616
@performanceLog()
17-
public async getDebugSocket(appId: string, projectName: string, ensureAppStarted: boolean = false): Promise<net.Socket> {
17+
public async getDebugSocket(appId: string, projectName: string, projectDir: string, ensureAppStarted: boolean = false): Promise<net.Socket> {
1818
return this.$lockService.executeActionWithLock(
1919
async () => {
2020
if (this.cachedSockets[appId]) {
2121
return this.cachedSockets[appId];
2222
}
2323

24-
await this.attachToDebuggerFoundEvent(appId, projectName);
24+
await this.attachToDebuggerFoundEvent(appId, projectName, projectDir);
2525
if (ensureAppStarted) {
26-
await this.applicationManager.startApplication({ appId, projectName });
26+
await this.applicationManager.startApplication({ appId, projectName, projectDir });
2727
}
2828

2929
this.cachedSockets[appId] = await this.getDebugSocketCore(appId);
@@ -42,8 +42,8 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
4242

4343
protected abstract async getDebugSocketCore(appId: string): Promise<net.Socket>;
4444

45-
protected async attachToDebuggerFoundEvent(appId: string, projectName: string): Promise<void> {
46-
await this.startDeviceLogProcess(projectName);
45+
protected async attachToDebuggerFoundEvent(appId: string, projectName: string, projectDir: string): Promise<void> {
46+
await this.startDeviceLogProcess(projectName, projectDir);
4747
await this.$iOSDebuggerPortService.attachToDebuggerPortFoundEvent(appId);
4848
}
4949

@@ -78,9 +78,10 @@ export abstract class IOSDeviceBase implements Mobile.IiOSDevice {
7878
}
7979
}
8080

81-
private async startDeviceLogProcess(projectName: string): Promise<void> {
81+
private async startDeviceLogProcess(projectName: string, projectDir: string): Promise<void> {
8282
if (projectName) {
8383
this.$deviceLogProvider.setProjectNameForDevice(this.deviceInfo.identifier, projectName);
84+
this.$deviceLogProvider.setProjectDirForDevice(this.deviceInfo.identifier, projectDir);
8485
}
8586

8687
await this.openDeviceLogStream();

lib/common/mobile/ios/simulator/ios-simulator-application-manager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
109109

110110
private async setDeviceLogData(appData: Mobile.IApplicationData): Promise<void> {
111111
this.$deviceLogProvider.setProjectNameForDevice(this.device.deviceInfo.identifier, appData.projectName);
112+
this.$deviceLogProvider.setProjectDirForDevice(this.device.deviceInfo.identifier, appData.projectDir);
112113

113114
if (!this.$options.justlaunch) {
114115
await this.startDeviceLog();

lib/common/mobile/mobile-core/devices-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
189189
/* tslint:enable:no-unused-variable */
190190

191191
@exported("devicesService")
192-
public isAppInstalledOnDevices(deviceIdentifiers: string[], appId: string, projectName: string): Promise<IAppInstalledInfo>[] {
192+
public isAppInstalledOnDevices(deviceIdentifiers: string[], appId: string, projectName: string, projectDir: string): Promise<IAppInstalledInfo>[] {
193193
this.$logger.trace(`Called isInstalledOnDevices for identifiers ${deviceIdentifiers}. AppIdentifier is ${appId}.`);
194-
return _.map(deviceIdentifiers, deviceIdentifier => this.isApplicationInstalledOnDevice(deviceIdentifier, { appId, projectName }));
194+
return _.map(deviceIdentifiers, deviceIdentifier => this.isApplicationInstalledOnDevice(deviceIdentifier, { appId, projectName, projectDir }));
195195
}
196196

197197
public getDeviceInstances(): Mobile.IDevice[] {
@@ -463,7 +463,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
463463
}
464464

465465
@exported("devicesService")
466-
public deployOnDevices(deviceIdentifiers: string[], packagePath: string, appId: string | Mobile.IProjectIdentifier, projectName: string): Promise<void>[] {
466+
public deployOnDevices(deviceIdentifiers: string[], packagePath: string, appId: string | Mobile.IProjectIdentifier, projectName: string, projectDir: string): Promise<void>[] {
467467
this.$logger.trace(`Called deployOnDevices for identifiers ${deviceIdentifiers} for packageFile: ${packagePath}. Application identifier is ${appId}. Project Name is: ${projectName}`);
468468
return _.map(deviceIdentifiers, async deviceIdentifier => {
469469
const device = this.getDeviceByIdentifier(deviceIdentifier);
@@ -475,7 +475,7 @@ export class DevicesService extends EventEmitter implements Mobile.IDevicesServi
475475
identifier = appId[device.deviceInfo.platform.toLowerCase()];
476476
}
477477

478-
return this.deployOnDevice(device, { packagePath, appId: identifier, projectName });
478+
return this.deployOnDevice(device, { packagePath, appId: identifier, projectName, projectDir});
479479
});
480480
}
481481

lib/common/test/unit-tests/android-application-manager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CommonLoggerStub, LogcatHelperStub, AndroidProcessServiceStub, DeviceLo
55
const invalidIdentifier = "invalid.identifier";
66
const validDeviceIdentifier = "device.identifier";
77
const validIdentifier = "org.nativescript.testApp";
8-
const validStartOptions = { appId: validIdentifier, projectName: "" };
8+
const validStartOptions = { appId: validIdentifier, projectName: "", projectDir: "" };
99

1010
class AndroidDebugBridgeStub {
1111
public calledStopApplication = false;
@@ -155,7 +155,7 @@ describe("android-application-manager", () => {
155155
it("is calling monkey to start the application when invalid identifier is passed", async () => {
156156
setup();
157157

158-
await androidApplicationManager.startApplication({ appId: invalidIdentifier, projectName: "" });
158+
await androidApplicationManager.startApplication({ appId: invalidIdentifier, projectName: "", projectDir: "" });
159159

160160
assert.isFalse(androidDebugBridge.startedWithActivityManager);
161161
});

lib/common/test/unit-tests/android-log-filter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ describe("androidLogFilter", () => {
324324
const testInjector = new Yok();
325325
testInjector.register("loggingLevels", LoggingLevels);
326326
const androidLogFilter = <Mobile.IPlatformLogFilter>testInjector.resolve(AndroidLogFilter);
327-
const filteredData = androidLogFilter.filterData(inputData, { logLevel: _logLevel, applicationPid: _pid });
327+
const filteredData = androidLogFilter.filterData(inputData, { logLevel: _logLevel, applicationPid: _pid, projectDir: null });
328328
assert.deepEqual(filteredData, expectedOutput, `The actual result '${filteredData}' did NOT match expected output '${expectedOutput}'.`);
329329
};
330330

lib/common/test/unit-tests/appbuilder/device-log-provider.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function createTestInjector(loggingLevel: string, emptyFilteredData?: boolean) {
1515

1616
testInjector.register("logger", CommonLoggerStub);
1717
testInjector.register("loggingLevels", LoggingLevels);
18+
testInjector.register("logSourceMapService", {
19+
replaceWithOriginalFileLocations: (platform: string, message: string) => message
20+
});
1821
return testInjector;
1922
}
2023

lib/common/test/unit-tests/ios-log-filter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe("iOSLogFilter", () => {
113113
const testInjector = new Yok();
114114
testInjector.register("loggingLevels", LoggingLevels);
115115
const iOSLogFilter = <Mobile.IPlatformLogFilter>testInjector.resolve(IOSLogFilter);
116-
const filteredData = iOSLogFilter.filterData(inputData, { logLevel: _logLevel, applicationPid: _pid });
116+
const filteredData = iOSLogFilter.filterData(inputData, { logLevel: _logLevel, applicationPid: _pid, projectDir: null });
117117
assert.deepEqual(filteredData, expectedOutput, `The actual result '${filteredData}' did NOT match expected output '${expectedOutput}'.`);
118118
};
119119

lib/common/test/unit-tests/log-filter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,22 @@ describe("logFilter", () => {
6767
describe("filterData", () => {
6868
describe("when logLevel is not specified and default log level is not changed", () => {
6969
it("returns same data when platform is not correct", () => {
70-
const actualData = logFilter.filterData("invalidPlatform", testData, { logLevel });
70+
const actualData = logFilter.filterData("invalidPlatform", testData, { logLevel, projectDir: null });
7171
assert.deepEqual(actualData, testData);
7272
});
7373

7474
it("returns same data when platform is not passed", () => {
75-
const actualData = logFilter.filterData(null, testData, { logLevel });
75+
const actualData = logFilter.filterData(null, testData, { logLevel, projectDir: null });
7676
assert.deepEqual(actualData, testData);
7777
});
7878

7979
it("returns correct data when platform is android", () => {
80-
const actualData = logFilter.filterData("android", testData, { logLevel });
80+
const actualData = logFilter.filterData("android", testData, { logLevel, projectDir: null });
8181
assert.deepEqual(actualData, androidInfoTestData);
8282
});
8383

8484
it("returns correct data when platform is ios", () => {
85-
const actualData = logFilter.filterData("ios", testData, { logLevel });
85+
const actualData = logFilter.filterData("ios", testData, { logLevel, projectDir: null });
8686
assert.deepEqual(actualData, iosInfoTestData);
8787
});
8888
});

lib/common/test/unit-tests/mobile/android-device-file-system.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ function createDeviceAppData(androidVersion?: string): Mobile.IDeviceAppData {
8484
version: androidVersion || "8.1.2"
8585
}
8686
},
87-
platform: "Android"
87+
platform: "Android",
88+
projectDir: ""
8889
};
8990
}
9091

lib/common/test/unit-tests/mobile/application-manager-base.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ describe("ApplicationManagerBase", () => {
8383
let testInjector: IInjector;
8484
const applicationData = {
8585
appId: "appId",
86-
projectName: "appName"
86+
projectName: "appName",
87+
projectDir: ""
8788
};
8889

8990
beforeEach(() => {
@@ -661,7 +662,7 @@ describe("ApplicationManagerBase", () => {
661662
await applicationManager.tryStartApplication(applicationData);
662663
assert.deepEqual(passedApplicationData, applicationData);
663664

664-
const secondApplicationData = { appId: "appId2", projectName: "appName2" };
665+
const secondApplicationData = { appId: "appId2", projectName: "appName2", projectDir: "" };
665666
await applicationManager.tryStartApplication(secondApplicationData);
666667
assert.deepEqual(passedApplicationData, secondApplicationData);
667668

0 commit comments

Comments
 (0)