Skip to content

Commit a0dc521

Browse files
fix: paths to platform specific files are not correct in logs
When CLI parses the device logs, it tries to replace the file location with the real file path location. However, this does not work for platform specific files (in non-Angular projects) as we are using a virtual file system in webpack, which "lies" the file `button.js` exists, while in fact the file is `button.<platform>.js`. So in the source maps, the location of the file is `button.js`. To resolve this, check if there's a platform specific file and use it instead. Cache the original file location, so we'll not execute multiple file operations for the same file.
1 parent a9b6083 commit a0dc521

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/services/log-source-map-service.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
2727
private getProjectData: (projectDir: string) => IProjectData;
2828
private getRuntimeVersion: (projectDir: string, platform: string) => string;
2929
private cache: IDictionary<sourcemap.SourceMapConsumer> = {};
30+
private originalFilesLocationCache: IStringDictionary = {};
3031

3132
private get $platformsDataService(): IPlatformsDataService {
3233
return this.$injector.resolve<IPlatformsDataService>("platformsDataService");
@@ -123,7 +124,18 @@ export class LogSourceMapService implements Mobile.ILogSourceMapService {
123124
}
124125

125126
sourceFile = stringReplaceAll(sourceFile, "/", path.sep);
126-
return { sourceFile, line: originalPosition.line, column: originalPosition.column };
127+
if (!this.originalFilesLocationCache[sourceFile]) {
128+
const { dir, ext, name } = path.parse(sourceFile);
129+
const platformSpecificName = `${name}.${platform.toLowerCase()}`;
130+
const platformSpecificFile = path.format({ dir, ext, name: platformSpecificName });
131+
if (this.$fs.exists(platformSpecificFile)) {
132+
this.originalFilesLocationCache[sourceFile] = platformSpecificFile;
133+
} else {
134+
this.originalFilesLocationCache[sourceFile] = sourceFile;
135+
}
136+
}
137+
138+
return { sourceFile: this.originalFilesLocationCache[sourceFile], line: originalPosition.line, column: originalPosition.column };
127139
}
128140
}
129141
}

0 commit comments

Comments
 (0)