Skip to content

Commit 5b3a5ae

Browse files
Merge branch 'master' into etabakov/update-license-year
2 parents acf359c + ba80dd4 commit 5b3a5ae

File tree

7 files changed

+94
-34
lines changed

7 files changed

+94
-34
lines changed

package.json

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@
2525
],
2626
"license": "SEE LICENSE IN LICENSE.txt",
2727
"dependencies": {
28-
"lodash": "^4.17.10",
29-
"semver": "^5.5.0",
28+
"lodash": "4.17.11",
29+
"semver": "5.6.0",
3030
"universal-analytics": "0.4.15",
31-
"uuid": "^3.2.1",
32-
"vscode-chrome-debug-core": "^3.23.11",
33-
"vscode-debugadapter": "^1.28.0-pre.2"
31+
"uuid": "3.3.2",
32+
"vscode-chrome-debug-core": "3.23.11",
33+
"vscode-debugadapter": "1.34.0"
3434
},
3535
"devDependencies": {
36-
"@types/lodash": "^4.14.109",
37-
"@types/mocha": "^5.2.1",
36+
"@types/lodash": "4.14.121",
37+
"@types/mocha": "5.2.6",
3838
"@types/node": "6.0.46",
39-
"@types/semver": "^5.5.0",
39+
"@types/semver": "5.5.0",
4040
"@types/universal-analytics": "0.4.1",
41-
"cpx": "^1.5.0",
42-
"mocha": "^5.2.0",
43-
"sinon": "^5.0.10",
41+
"cpx": "1.5.0",
42+
"mocha": "5.2.0",
43+
"sinon": "5.1.1",
4444
"tslint": "5.10.0",
45-
"tslint-eslint-rules": "^5.3.1",
45+
"tslint-eslint-rules": "5.4.0",
4646
"typescript": "2.6.2",
4747
"vsce": "~1.36.0",
4848
"vscode": "~1.1.10",
49-
"vscode-debugprotocol": "^1.28.0-pre.1"
49+
"vscode-debugprotocol": "1.34.0"
5050
},
5151
"scripts": {
5252
"clean": "git clean -fdx",
@@ -143,6 +143,20 @@
143143
"sourceMaps": true,
144144
"watch": true
145145
},
146+
{
147+
"name": "Test on iOS",
148+
"type": "nativescript",
149+
"request": "launch",
150+
"platform": "ios",
151+
"appRoot": "${workspaceRoot}",
152+
"sourceMaps": true,
153+
"watch": false,
154+
"stopOnEntry": true,
155+
"launchTests": true,
156+
"tnsArgs": [
157+
"--justlaunch"
158+
]
159+
},
146160
{
147161
"name": "Attach on iOS",
148162
"type": "nativescript",
@@ -161,6 +175,20 @@
161175
"sourceMaps": true,
162176
"watch": true
163177
},
178+
{
179+
"name": "Test on Android",
180+
"type": "nativescript",
181+
"request": "launch",
182+
"platform": "android",
183+
"appRoot": "${workspaceRoot}",
184+
"sourceMaps": true,
185+
"watch": false,
186+
"stopOnEntry": true,
187+
"launchTests": true,
188+
"tnsArgs": [
189+
"--justlaunch"
190+
]
191+
},
164192
{
165193
"name": "Attach on Android",
166194
"type": "nativescript",
@@ -281,6 +309,11 @@
281309
"type": "object",
282310
"description": "A set of mappings for rewriting the locations of source files from what the sourcemap says, to their locations on the disk.",
283311
"default": null
312+
},
313+
"launchTests": {
314+
"type": "boolean",
315+
"description": "If true, the launch request will run the unit tests instead of the app itself.",
316+
"default": false
284317
}
285318
}
286319
},

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
}

src/project/androidProject.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ export class AndroidProject extends Project {
3131
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
3232
}
3333

34-
public debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult {
34+
public debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult {
3535
let args: string[] = [];
3636

3737
args.push(options.watch ? '--watch' : '--no-watch');
3838
if (options.stopOnEntry) { args.push('--debug-brk'); }
3939
args = args.concat(tnsArgs);
4040

41-
const debugProcess: ChildProcess = super.executeDebugCommand(args);
41+
const debugProcess: ChildProcess = options.launchTests ?
42+
super.executeTestCommand(args) : super.executeDebugCommand(args);
4243
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
4344
const shouldWaitAfterRestartMessage = semver.lt(semver.coerce(this.cliVersion), '5.1.0');
4445
const waitForRestartMessage = shouldWaitAfterRestartMessage || args.indexOf('--debug-brk') > -1;

src/project/iosProject.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ export class IosProject extends Project {
3232
return { tnsProcess: debugProcess, tnsOutputEventEmitter };
3333
}
3434

35-
public debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult {
35+
public debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult {
3636
let args: string[] = [];
3737

3838
args.push(options.watch ? '--watch' : '--no-watch');
3939
if (options.stopOnEntry) { args.push('--debug-brk'); }
4040
args = args.concat(tnsArgs);
41+
const debugProcess: ChildProcess = options.launchTests ?
42+
super.executeTestCommand(args) : super.executeDebugCommand(args);
4143

42-
const debugProcess: ChildProcess = super.executeDebugCommand(args);
4344
const tnsOutputEventEmitter: EventEmitter = new EventEmitter();
4445

4546
this.configureReadyEvent(debugProcess.stdout, tnsOutputEventEmitter);

src/project/project.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export abstract class Project {
2727

2828
public abstract attach(tnsArgs?: string[]): IDebugResult;
2929

30-
public abstract debug(options: { stopOnEntry: boolean, watch: boolean }, tnsArgs?: string[]): IDebugResult;
30+
public abstract debug(options: { stopOnEntry: boolean, watch: boolean, launchTests: boolean }, tnsArgs?: string[]): IDebugResult;
3131

3232
protected configureReadyEvent(readableStream: stream.Readable, eventEmitter: EventEmitter): void {
3333
new scanner.StringMatchingScanner(readableStream).onEveryMatch('TypeScript compiler failed', () => {
@@ -42,4 +42,8 @@ export abstract class Project {
4242
protected executeDebugCommand(args: string[]): ChildProcess {
4343
return this._cli.execute(['debug', this.platformName()].concat(args), this._appRoot);
4444
}
45+
46+
protected executeTestCommand(args: string[]): ChildProcess {
47+
return this._cli.execute(['test', this.platformName()].concat(args), this._appRoot);
48+
}
4549
}

src/services/buildService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ export class BuildService {
5656
}
5757
}
5858

59-
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch }, tnsArgs);
59+
cliCommand = project.debug({ stopOnEntry: args.stopOnEntry, watch: args.watch, launchTests: args.launchTests }, tnsArgs);
6060
} else if (args.request === 'attach') {
6161
cliCommand = project.attach(args.tnsArgs);
6262
}
6363

64-
return new Promise<string | number> ((res, rej) => {
64+
return new Promise<string | number>((res, rej) => {
6565
if (cliCommand.tnsProcess) {
6666
this._tnsProcess = cliCommand.tnsProcess;
6767
cliCommand.tnsProcess.stdout.on('data', (data) => { this._logger.log(data.toString()); });
@@ -109,7 +109,7 @@ export class BuildService {
109109
const teamIdArgIndex = tnsArgs.indexOf('--teamId');
110110

111111
if (teamIdArgIndex > 0 && teamIdArgIndex + 1 < tnsArgs.length) {
112-
return tnsArgs[ teamIdArgIndex + 1 ];
112+
return tnsArgs[teamIdArgIndex + 1];
113113
}
114114
}
115115

@@ -128,7 +128,7 @@ export class BuildService {
128128
const xcconfigFile = path.join(appRoot, 'App_Resources/iOS/build.xcconfig');
129129

130130
if (fs.existsSync(xcconfigFile)) {
131-
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8'});
131+
const text = fs.readFileSync(xcconfigFile, { encoding: 'utf8' });
132132
let teamId: string;
133133

134134
text.split(/\r?\n/).forEach((line) => {

src/tests/pathTransformData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tests = [
55
{ platform: 'android', scriptUrl: 'native prologue.js', expectedResult: 'native prologue.js' },
66
{ platform: 'android', scriptUrl: 'v8/gc', expectedResult: 'v8/gc' },
77
{ platform: 'android', scriptUrl: 'VM25', expectedResult: 'VM25' },
8-
{ platform: 'android', scriptUrl: '/data/data/org.nativescript.TabNavigation/files/internal/ts_helpers.js', expectedResult: '/data/data/org.nativescript.TabNavigation/files/internal/ts_helpers.js' },
8+
{ platform: 'android', scriptUrl: '/data/data/org.nativescript.TabNavigation/files/internal/ts_helpers.js', expectedResult: `C:\\projectpath\\platforms\\android\\app\\src\\main\\assets\\internal\\ts_helpers.js`, existingPath: 'C:\\projectpath\\platforms\\android\\app\\src\\main\\assets\\internal\\ts_helpers.js' },
99
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/tns_modules/nativescript-angular/platform.js', expectedResult: 'C:\\projectpath\\node_modules\\nativescript-angular\\platform.js', existingPath: 'C:\\projectpath\\node_modules\\nativescript-angular\\platform.js' },
1010
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/tns_modules/nativescript-angular/platform-common.js', expectedResult: 'C:\\projectpath\\node_modules\\nativescript-angular\\platform-common.js', existingPath: 'C:\\projectpath\\node_modules\\nativescript-angular\\platform-common.js' },
1111
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/tns_modules/@angular/common/bundles/common.umd.js', expectedResult: 'C:\\projectpath\\node_modules\\@angular\\common\\bundles\\common.umd.js', existingPath: 'C:\\projectpath\\node_modules\\@angular\\common\\bundles\\common.umd.js' },
@@ -15,9 +15,9 @@ const tests = [
1515
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/tns_modules/tns-core-modules/ui/page/page.js', expectedResult: 'C:\\projectpath\\node_modules\\tns-core-modules\\ui\\page\\page.android.js', existingPath: 'C:\\projectpath\\node_modules\\tns-core-modules\\ui\\page\\page.android.js' },
1616
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/tns_modules/tns-core-modules/ui/layouts/layout-base.js', expectedResult: 'C:\\projectpath\\node_modules\\tns-core-modules\\ui\\layouts\\layout-base.android.js', existingPath: 'C:\\projectpath\\node_modules\\tns-core-modules\\ui\\layouts\\layout-base.android.js' },
1717
{ platform: 'android', scriptUrl: 'ng:///css/0/data/data/org.nativescript.TabNavigation/files/app/tabs/tabs.component.scss.ngstyle.js', expectedResult: 'ng:///css/0/data/data/org.nativescript.TabNavigation/files/app/tabs/tabs.component.scss.ngstyle.js' },
18-
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/main.js', expectedResult: 'C:\\projectpath\\src\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\main.js' },
19-
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/app/main.js', expectedResult: 'C:\\projectpath\\src\\app\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\app\\main.js' },
20-
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.app1/files/app/app/main.js', expectedResult: 'C:\\projectpath\\src\\app\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\app\\main.js' },
18+
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/main.js', expectedResult: 'C:\\projectpath\\src\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\main.js' },
19+
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.TabNavigation/files/app/app/main.js', expectedResult: 'C:\\projectpath\\src\\app\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\app\\main.js' },
20+
{ platform: 'android', scriptUrl: 'file:///data/data/org.nativescript.app1/files/app/app/main.js', expectedResult: 'C:\\projectpath\\src\\app\\main.js', nsconfig: { appPath: 'src' }, existingPath: 'C:\\projectpath\\src\\app\\main.js' },
2121
];
2222

2323
export = tests;

0 commit comments

Comments
 (0)