Skip to content

Commit 551fa25

Browse files
committed
fix: support internal Android runtime ts files during debug
1 parent 8e999cf commit 551fa25

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/debug-adapter/nativeScriptPathTransformer.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
2222
return;
2323
}
2424

25+
const isAndroid = this.targetPlatform === 'android';
26+
2527
if (_.startsWith(scriptUrl, 'mdha:')) {
2628
scriptUrl = _.trimStart(scriptUrl, 'mdha:');
2729
}
@@ -37,7 +39,7 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
3739
let relativePath = scriptUrl;
3840

3941
if (matches) {
40-
relativePath = this.targetPlatform === 'android' ? matches[3] : matches[2];
42+
relativePath = isAndroid ? matches[3] : matches[2];
4143
}
4244

4345
const nodePath = path.join('..', 'node_modules');
@@ -48,22 +50,41 @@ export class NativeScriptPathTransformer extends UrlPathTransformer {
4850
relativePath = relativePath.replace('app', this.appDirPath);
4951
}
5052

51-
const absolutePath = path.resolve(path.join(webRoot, relativePath));
53+
let absolutePath = path.resolve(path.join(webRoot, relativePath));
54+
let platformSpecificPath = this.getPlatformSpecificPath(absolutePath);
5255

53-
if (fs.existsSync(absolutePath)) {
54-
return Promise.resolve(absolutePath);
56+
if (platformSpecificPath) {
57+
return Promise.resolve(platformSpecificPath);
5558
}
5659

57-
const fileExtension = path.extname(absolutePath);
60+
if (isAndroid) {
61+
// handle files like /data/data/internal/ts_helpers.ts
62+
absolutePath = path.resolve(path.join(webRoot, 'platforms', this.targetPlatform.toLowerCase(), 'app', 'src', 'main', 'assets', relativePath));
63+
platformSpecificPath = this.getPlatformSpecificPath(absolutePath);
64+
65+
if (platformSpecificPath) {
66+
return Promise.resolve(platformSpecificPath);
67+
}
68+
}
69+
70+
return Promise.resolve(scriptUrl);
71+
}
72+
73+
private getPlatformSpecificPath(rawPath: string): string {
74+
if (fs.existsSync(rawPath)) {
75+
return rawPath;
76+
}
77+
78+
const fileExtension = path.extname(rawPath);
5879

5980
if (fileExtension) {
60-
const platformSpecificPath = absolutePath.replace(fileExtension, `.${this.targetPlatform}${fileExtension}`);
81+
const platformSpecificPath = rawPath.replace(fileExtension, `.${this.targetPlatform}${fileExtension}`);
6182

6283
if (fs.existsSync(platformSpecificPath)) {
63-
return Promise.resolve(platformSpecificPath);
84+
return platformSpecificPath;
6485
}
6586
}
6687

67-
return Promise.resolve(scriptUrl);
88+
return null;
6889
}
6990
}

0 commit comments

Comments
 (0)