From 9cff42c4724af19e92fb4e049634acbb21daaa48 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Tue, 15 Jan 2019 14:03:52 +0200 Subject: [PATCH 1/6] fix: error is raised when DevTools are closed while sending message In case you open Chrome DevTools and close them while the iOS runtime still sends messages, an error is raised in CLI: ``` Error: WebSocket is not open: readyState 2 (CLOSING) ``` The problem is that we are using Transform stream between the communication and close event of the socket is not raised until the stream flushes its current state. Fix it by skipping the write operation in case the socket is not in OPEN state. --- lib/device-sockets/ios/app-debug-socket-proxy-factory.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts index 10cebd65ea..0079ac2cf1 100644 --- a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts +++ b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts @@ -138,7 +138,12 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu appDebugSocket.pipe(packets); packets.on("data", (buffer: Buffer) => { - webSocket.send(buffer.toString(encoding)); + const message = buffer.toString(encoding); + if (webSocket.readyState === webSocket.OPEN) { + webSocket.send(message); + } else { + this.$logger.trace(`Received message ${message}, but unable to send it to webSocket as its state is: ${webSocket.readyState}`); + } }); webSocket.on("error", err => { From 6bb7f8b5d5d86539e4bcbcb949917e5d6ec37126 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Tue, 15 Jan 2019 14:11:22 +0200 Subject: [PATCH 2/6] chore: update ios-device-lib to 0.5.0 Update ios-device-lib to 0.5.0, so we can use the new fixes and features: https://github.com/telerik/ios-device-lib/releases/tag/v0.5.0 --- npm-shrinkwrap.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index fd6b5c244f..d62842ad09 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3893,9 +3893,9 @@ "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" }, "ios-device-lib": { - "version": "0.4.15", - "resolved": "https://registry.npmjs.org/ios-device-lib/-/ios-device-lib-0.4.15.tgz", - "integrity": "sha512-OzyKbLxrmpTB87hPelpAsvtmPYeucSP53IaLb2QHaIDW6ZqHjJV4XCHMpwtLGvLOcMNb2WVUHxoirQ+rwC21dQ==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/ios-device-lib/-/ios-device-lib-0.5.0.tgz", + "integrity": "sha512-EKSXHYvOhjB+R/8EaWX9Iha7AIk1U26rxvxq7Hpg/19zOXqsnjuakyJ3fDKh5BXnU7CzBpkz1V2lwi8JPvD5fw==", "requires": { "bufferpack": "0.0.6", "node-uuid": "1.4.7" diff --git a/package.json b/package.json index b3c6e2f907..af05dac8f2 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "gaze": "1.1.0", "iconv-lite": "0.4.11", "inquirer": "6.2.0", - "ios-device-lib": "0.4.15", + "ios-device-lib": "0.5.0", "ios-mobileprovision-finder": "1.0.10", "ios-sim-portable": "4.0.6", "istextorbinary": "2.2.1", From 19acf2e8494d5c1558f0f2426d4cedd1362828d2 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Tue, 15 Jan 2019 14:20:21 +0200 Subject: [PATCH 3/6] fix: Chrome debug messages from iOS Runtime are not parsed correctly During debug operation, iOS Runtime "talks" to Chrome DevTools. CLI stands as proxy between them and translates the messages. Due to Node.js socket implementation, some messages may come on chunks. The format of each message is: - first 4 bytes contain the lenght of the message (in Big-Endian) - the next bytes are the actual message Currently, the following behavior is observed: - when a full message is received, CLI sends it correctly to Chrome DevTools - when more than one message is received in the data, CLI sends only the first message to Chrome DevTools and disregards the other part - in case a split message is received, when the first part is only part of the first 4 bytes (part of the length), CLI fails with `Index out of Range` or `ERR_BUFFER_OUT_OF_BOUNDS` error (based on the inner state of the variables). To fix this behavior, remove CLI's parsing and reuse the one from `ios-device-lib`. --- .../ios/app-debug-socket-proxy-factory.ts | 4 +-- lib/device-sockets/ios/packet-stream.ts | 33 ------------------- 2 files changed, 2 insertions(+), 35 deletions(-) delete mode 100644 lib/device-sockets/ios/packet-stream.ts diff --git a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts index 0079ac2cf1..5f015aca8d 100644 --- a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts +++ b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts @@ -1,9 +1,9 @@ import { EventEmitter } from "events"; import { CONNECTION_ERROR_EVENT_NAME } from "../../constants"; -import { PacketStream } from "./packet-stream"; import * as net from "net"; import * as ws from "ws"; import temp = require("temp"); +import { MessageUnpackStream } from "ios-device-lib"; export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebugSocketProxyFactory { private deviceWebServers: IDictionary = {}; @@ -134,7 +134,7 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu const encoding = "utf16le"; const appDebugSocket: net.Socket = (req)["__deviceSocket"]; - const packets = new PacketStream(); + const packets = new MessageUnpackStream(); appDebugSocket.pipe(packets); packets.on("data", (buffer: Buffer) => { diff --git a/lib/device-sockets/ios/packet-stream.ts b/lib/device-sockets/ios/packet-stream.ts deleted file mode 100644 index 220d525dd5..0000000000 --- a/lib/device-sockets/ios/packet-stream.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as stream from "stream"; - -export class PacketStream extends stream.Transform { - private buffer: Buffer; - private offset: number; - - constructor(opts?: stream.TransformOptions) { - super(opts); - } - - public _transform(packet: any, encoding: string, done: Function): void { - while (packet.length > 0) { - if (!this.buffer) { - // read length - const length = packet.readInt32BE(0); - this.buffer = Buffer.allocUnsafe(length); - this.offset = 0; - packet = packet.slice(4); - } - - packet.copy(this.buffer, this.offset); - const copied = Math.min(this.buffer.length - this.offset, packet.length); - this.offset += copied; - packet = packet.slice(copied); - - if (this.offset === this.buffer.length) { - this.push(this.buffer); - this.buffer = undefined; - } - } - done(); - } -} From 6ebf4ec8805ced8ddcecdf7ac498d63f77009fa4 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 16 Jan 2019 09:55:17 +0200 Subject: [PATCH 4/6] fix: trying to stop app on simulator may kill CLI In case you use `tns run ios --path --device `, CLI will try to stop the application, but may kill CLI instead. The problem is in ios-sim-portable, which incorrectly searches for application PID. Update the package to 4.0.7 where the issue is fixed. --- npm-shrinkwrap.json | 16 ++++++++-------- package.json | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index d62842ad09..f841d26466 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3981,9 +3981,9 @@ } }, "ios-sim-portable": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/ios-sim-portable/-/ios-sim-portable-4.0.6.tgz", - "integrity": "sha512-V4f5aiQDnikC/ERM+RD9Kj5gRPoIaXv8zt9Zq6hoe8amQa7PP3lY4zSzvVAp8H+Cfts6rtrAaSKLtGpVzoZRPw==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/ios-sim-portable/-/ios-sim-portable-4.0.7.tgz", + "integrity": "sha512-8tbgbyOTLn4PVdv/40C8tWeaKriZ+w7yOof8xC6qFlAUGpkKopHJ954akekG2sqVUnfTI3ibaXgF5tkxGtrhGA==", "requires": { "bplist-parser": "https://github.com/telerik/node-bplist-parser/tarball/master", "colors": "0.6.2", @@ -4009,7 +4009,7 @@ }, "lodash": { "version": "3.2.0", - "resolved": "http://registry.npmjs.org/lodash/-/lodash-3.2.0.tgz", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.2.0.tgz", "integrity": "sha1-S/UKMkP5rrC6xBpV09WZBnWkYvs=" }, "set-blocking": { @@ -4019,7 +4019,7 @@ }, "shelljs": { "version": "0.7.0", - "resolved": "http://registry.npmjs.org/shelljs/-/shelljs-0.7.0.tgz", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.0.tgz", "integrity": "sha1-P28uSWXOxWX2X/OGHWRPh5KBpXY=", "requires": { "glob": "^7.0.0", @@ -4029,7 +4029,7 @@ }, "string-width": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "requires": { "code-point-at": "^1.0.0", @@ -4039,7 +4039,7 @@ }, "yargs": { "version": "4.7.1", - "resolved": "http://registry.npmjs.org/yargs/-/yargs-4.7.1.tgz", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-4.7.1.tgz", "integrity": "sha1-5gQyZYozh/8mnAKOrN5KUS5Djf8=", "requires": { "camelcase": "^3.0.0", @@ -4059,7 +4059,7 @@ }, "yargs-parser": { "version": "2.4.1", - "resolved": "http://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", "integrity": "sha1-hVaN488VD/SfpRgl8DqMiA3cxcQ=", "requires": { "camelcase": "^3.0.0", diff --git a/package.json b/package.json index af05dac8f2..77a567086d 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "inquirer": "6.2.0", "ios-device-lib": "0.5.0", "ios-mobileprovision-finder": "1.0.10", - "ios-sim-portable": "4.0.6", + "ios-sim-portable": "4.0.7", "istextorbinary": "2.2.1", "jimp": "0.2.28", "lockfile": "1.0.3", From a0a85f81f0ef13d395719dd8f8903a3c3ee2344a Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 17 Jan 2019 08:26:56 +0200 Subject: [PATCH 5/6] fix: error may be raised during restart of app on ios Sim On slower mac machines, an error may be raised during restart of app on iOS Simulator. The problem is that we stop the application and try to start it after that. However, the stop method may be resolved before the application is actually killed. Trying to start it after that leads to undefined behavior and errors in some cases. To fix this, update ios-sim-portable to 4.0.8 where a possible fix is applied. --- npm-shrinkwrap.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f841d26466..ba073197ac 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3981,9 +3981,9 @@ } }, "ios-sim-portable": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/ios-sim-portable/-/ios-sim-portable-4.0.7.tgz", - "integrity": "sha512-8tbgbyOTLn4PVdv/40C8tWeaKriZ+w7yOof8xC6qFlAUGpkKopHJ954akekG2sqVUnfTI3ibaXgF5tkxGtrhGA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/ios-sim-portable/-/ios-sim-portable-4.0.8.tgz", + "integrity": "sha512-/yk204on3c1qFux7h3u3rS6z051yB6OzVTLoGry210JizaqKYmkPJr6KKfLSeZIyZxF4GsBZI2KMzlFbavjUhA==", "requires": { "bplist-parser": "https://github.com/telerik/node-bplist-parser/tarball/master", "colors": "0.6.2", diff --git a/package.json b/package.json index 77a567086d..6a4d96ee21 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "inquirer": "6.2.0", "ios-device-lib": "0.5.0", "ios-mobileprovision-finder": "1.0.10", - "ios-sim-portable": "4.0.7", + "ios-sim-portable": "4.0.8", "istextorbinary": "2.2.1", "jimp": "0.2.28", "lockfile": "1.0.3", From 45774c09040cb3fb1a03e8b73b4536a40b98d85e Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Thu, 17 Jan 2019 18:15:57 +0200 Subject: [PATCH 6/6] docs: update CHANGELOG for 5.1.1 --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1797cd2e57..d968a248d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,29 @@ NativeScript CLI Changelog ================ +5.1.1 (2019, January 17) +== + +### Fixed +* [Fixed #4024](https://github.com/NativeScript/nativescript-cli/issues/4024): LiveSync is not working in Preview app when Angular's lazy loading is used +* [Fixed #4197](https://github.com/NativeScript/nativescript-cli/issues/4197): Not able to change IPHONEOS_DEPLOYMENT_TARGET due to CLI overwriting ARCHS and VALID_ARCHS +* [Fixed #4222](https://github.com/NativeScript/nativescript-cli/issues/4222): Sidekick restarts DevTools during debug when change in .xml/.css/.html file is applied +* [Fixed #4218](https://github.com/NativeScript/nativescript-cli/issues/4218): Cannot run app after debug-brk fail +* [Fixed #4228](https://github.com/NativeScript/nativescript-cli/issues/4228): `tns update` command doesn't work with yarn +* [Fixed #4230](https://github.com/NativeScript/nativescript-cli/issues/4230): Debugging with HMR is not working for iOS +* [Fixed #4234](https://github.com/NativeScript/nativescript-cli/issues/4234): Creating project hangs on Windows when yarn is set as package manager +* [Fixed #4236](https://github.com/NativeScript/nativescript-cli/issues/4236): Chrome DevTools(iOS): Debugger does not attach after reloading the page +* [Fixed #4238](https://github.com/NativeScript/nativescript-cli/issues/4238): Fresh project build error on ios +* [Fixed #4251](https://github.com/NativeScript/nativescript-cli/pull/4251): Unhandled promise rejection error from sidekick when livesync to preview app with bundle +* [Fixed #4260](https://github.com/NativeScript/nativescript-cli/issues/4260): CLI crashes when attaching to a non running iOS app +* [Fixed #4261](https://github.com/NativeScript/nativescript-cli/issues/4261): The CLI requires developer disk image not only in debug +* [Fixed #4272](https://github.com/NativeScript/nativescript-cli/issues/4272): Generation of splash screen fails for new templates +* [Fixed #4273](https://github.com/NativeScript/nativescript-cli/issues/4273): `tns debug ios --hmr` If you have two open tabs and close one, breakpoints stop working +* [Fixed #4291](https://github.com/NativeScript/nativescript-cli/issues/4291): Error during debug on iOS: WebSocket is not open: readyState 2 (CLOSING) +* [Fixed #4292](https://github.com/NativeScript/nativescript-cli/issues/4292): Error during debug on iOS: RangeError: Index out of range +* [Fixed #4293](https://github.com/NativeScript/nativescript-cli/issues/4293): Error during debug on iOS: RangeError [ERR_BUFFER_OUT_OF_BOUNDS] + + 5.1.0 (2018, December 11) ==