Skip to content

Commit bb9b69f

Browse files
Transpile to ES6
Add support for ES6 transpilation. Change dependency injection in order to match the `class` and `constructor` keywords. Update istanbul to latest version as its previous versions do not support ES6. Remove bluebird.d.ts as it conflicts with Promises from TypeScript's ES6 d.ts. Remove bluebird as dependency - we will use native Promises from now on. Add support for Node.js 4 and 5 - both versions have limited support for ES6 features, so in order to support them we have to: - pass --harmony flag to Node.js - do not use some features like default values of method arguments. - do not use spread operator - it's implementation in Node.js 4 is limited only to arrays. Even this implementation has issues. So use `.apply` instead of using spread operator. Remove all other usages of spread operator (for objects). Add tests scripts for istanbul and mocha, as they both will need the `--harmony` flag as well, so we cannot execute them directly with Node.js 4 and 5. Instead we'll execute a custom script, that will start a new node process. Introduce `test-scripts` directory with JavaScript executables to start the tests. Set them in package.json. They are required as when Node 4 or Node 5 is used, the tests will need `--harmony` flag as well. Exclude `test-scripts` directory from npm package (add it to `.npmignore`) - users do not need these files. Exclude `.vscode/launch.json` from `.gitignore` and add predefined launch configurations. They can be used for debugging CLI process and unit tests.
1 parent c960701 commit bb9b69f

20 files changed

+246
-50
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ results
2929
scratch/
3030
.idea/
3131
.settings/
32-
.vscode/
32+
.vscode/**
33+
!.vscode/launch.json
3334
test-reports.xml
3435

3536
npm-debug.log
3637
node_modules
37-
docs/html
38+
docs/html
39+
40+
!test-scripts/*.js

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ lib/**/*.ts
2121
lib/**/*.js.map
2222

2323
test/
24+
test-scripts/
2425
.vscode
2526
lib/common/test/
2627
coverage/
2728
scratch/
2829
*.suo
2930
.travis.yml
3031
docs/html/
31-
dev/
32+
dev/

.vscode/launch.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Launch Program (Node 6+)",
11+
"program": "${workspaceRoot}/lib/nativescript-cli.js",
12+
"cwd": "${workspaceRoot}",
13+
"sourceMaps": true,
14+
// define the arguments that you would like to pass to CLI, for example
15+
// "args": [ "build", "android", "--justlaunch" ]
16+
"args": [
17+
18+
]
19+
},
20+
21+
{
22+
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
23+
"type": "node",
24+
"request": "launch",
25+
"name": "Launch Tests (Node 6+)",
26+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
27+
"cwd": "${workspaceRoot}",
28+
"sourceMaps": true
29+
},
30+
31+
{
32+
"type": "node",
33+
"runtimeArgs": [
34+
"--harmony"
35+
],
36+
"request": "launch",
37+
"name": "Launch Program (Node 4, Node 5)",
38+
"program": "${workspaceRoot}/lib/nativescript-cli.js",
39+
"cwd": "${workspaceRoot}",
40+
"sourceMaps": true,
41+
// define the arguments that you would like to pass to CLI, for example
42+
// "args": [ "build", "android", "--justlaunch" ]
43+
"args": [
44+
45+
]
46+
},
47+
48+
{
49+
// in case you want to debug a single test, modify it's code to be `it.only(...` instead of `it(...`
50+
"type": "node",
51+
"runtimeArgs": [
52+
"--harmony"
53+
],
54+
"request": "launch",
55+
"name": "Launch Tests (Node 4, Node 5)",
56+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
57+
"cwd": "${workspaceRoot}",
58+
"sourceMaps": true
59+
},
60+
61+
{
62+
"type": "node",
63+
"request": "attach",
64+
"name": "Attach to Process",
65+
"port": 5858,
66+
"sourceMaps": true
67+
}
68+
69+
]
70+
}

Gruntfile.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,7 @@ module.exports = function(grunt) {
2828

2929
pkg: grunt.file.readJSON("package.json"),
3030
ts: {
31-
options: {
32-
target: 'es5',
33-
module: 'commonjs',
34-
sourceMap: true,
35-
declaration: false,
36-
removeComments: false,
37-
noImplicitAny: true,
38-
experimentalDecorators: true
39-
},
31+
options: grunt.file.readJSON("tsconfig.json").compilerOptions,
4032

4133
devlib: {
4234
src: ["lib/**/*.ts", "!lib/common/node_modules/**/*.ts"],
@@ -131,7 +123,18 @@ module.exports = function(grunt) {
131123
},
132124

133125
clean: {
134-
src: ["test/**/*.js*", "lib/**/*.js*", "!lib/common/vendor/*.js", "!lib/common/**/*.json", "!lib/common/Gruntfile.js", "!lib/common/node_modules/**/*", "!lib/common/hooks/**/*.js", "!lib/common/bin/*.js", "*.tgz"]
126+
src: ["test/**/*.js*",
127+
"lib/**/*.js*",
128+
"!test-scripts/**/*",
129+
"!lib/common/vendor/*.js",
130+
"!lib/common/**/*.json",
131+
"!lib/common/Gruntfile.js",
132+
"!lib/common/node_modules/**/*",
133+
"!lib/common/hooks/**/*.js",
134+
"!lib/common/bin/*.js",
135+
"!lib/common/test-scripts/**/*",
136+
"!lib/common/scripts/**/*",
137+
"*.tgz"]
135138
}
136139
});
137140

bin/nativescript

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
#!/bin/sh
22

33
AB_DIR="`dirname \"$0\"`"
4-
node "$AB_DIR/nativescript.js" "$@"
4+
NODE_VERSION=`node --version`
5+
NODE4_VERSION_PREFIX="v4."
6+
NODE5_VERSION_PREFIX="v5."
7+
8+
# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
9+
# so we have to pass --harmony flag for them in order to enable spread opearator usage
10+
# Use POSIX substring parameter expansion, so the code will work on all shells.
11+
12+
if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
13+
then
14+
# Node is 4.x.x or 5.x.x
15+
node --harmony "$AB_DIR/nativescript.js" "$@"
16+
else
17+
# Node is NOT 4.x.x or 5.x.x
18+
node "$AB_DIR/nativescript.js" "$@"
19+
fi

bin/nativescript.cmd

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
@node %~dp0\nativescript.js %*
1+
@for /F "delims=" %%i IN ('@node --version') DO @set node_ver=%%i
2+
3+
@echo %node_ver% | @findstr /b /c:"v4."
4+
@set is_node_4=%errorlevel%
5+
6+
@echo %node_ver% | @findstr /b /c:"v5."
7+
@set is_node_5=%errorlevel%
8+
9+
@set use_harmony_flag=0
10+
11+
@if %is_node_4% == 0 @set use_harmony_flag=1
12+
@if %is_node_5% == 0 @set use_harmony_flag=1
13+
14+
@if %use_harmony_flag% == 1 (
15+
return @node --harmony %~dp0\nativescript.js %*
16+
) else (
17+
@node %~dp0\nativescript.js %*
18+
)

bin/tns

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
#!/bin/sh
22

33
AB_DIR="`dirname \"$0\"`"
4-
node "$AB_DIR/nativescript.js" "$@"
4+
NODE_VERSION=`node --version`
5+
NODE4_VERSION_PREFIX="v4."
6+
NODE5_VERSION_PREFIX="v5."
7+
8+
# check if Node.js version is 4.x.x or 5.x.x - both of them do not support some of required features
9+
# so we have to pass --harmony flag for them in order to enable spread opearator usage
10+
# Use POSIX substring parameter expansion, so the code will work on all shells.
11+
12+
if [ "${NODE_VERSION#$NODE4_VERSION_PREFIX*}" != "$NODE_VERSION" -o "${NODE_VERSION#$NODE5_VERSION_PREFIX*}" != "$NODE_VERSION" ]
13+
then
14+
# Node is 4.x.x or 5.x.x
15+
node --harmony "$AB_DIR/nativescript.js" "$@"
16+
else
17+
# Node is NOT 4.x.x or 5.x.x
18+
node "$AB_DIR/nativescript.js" "$@"
19+
fi

bin/tns.cmd

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
@node %~dp0\nativescript.js %*
1+
@for /F "delims=" %%i IN ('@node --version') DO @set node_ver=%%i
2+
3+
@echo %node_ver% | @findstr /b /c:"v4."
4+
@set is_node_4=%errorlevel%
5+
6+
@echo %node_ver% | @findstr /b /c:"v5."
7+
@set is_node_5=%errorlevel%
8+
9+
@set use_harmony_flag=0
10+
11+
@if %is_node_4% == 0 @set use_harmony_flag=1
12+
@if %is_node_5% == 0 @set use_harmony_flag=1
13+
14+
@if %use_harmony_flag% == 1 (
15+
return @node --harmony %~dp0\nativescript.js %*
16+
) else (
17+
@node %~dp0\nativescript.js %*
18+
)

lib/device-sockets/ios/socket-request-executor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
1313
return (() => {
1414
let npc = new iOSProxyServices.NotificationProxyClient(device, this.$injector);
1515

16-
let [alreadyConnected, readyForAttach, attachAvailable] = [this.$iOSNotification.alreadyConnected, this.$iOSNotification.readyForAttach, this.$iOSNotification.attachAvailable]
17-
.map((notification) => this.$iOSNotificationService.awaitNotification(npc, notification, timeout));
16+
let data = [this.$iOSNotification.alreadyConnected, this.$iOSNotification.readyForAttach, this.$iOSNotification.attachAvailable]
17+
.map((notification) => this.$iOSNotificationService.awaitNotification(npc, notification, timeout)),
18+
alreadyConnected = data[0],
19+
readyForAttach = data[1],
20+
attachAvailable = data[2];
1821

1922
npc.postNotificationAndAttachForData(this.$iOSNotification.attachAvailabilityQuery);
2023

0 commit comments

Comments
 (0)