Skip to content

Commit 77feecc

Browse files
committed
fix(docs): jsdoc-compatible CancellablePromise typedef for NodeUtils
jsdoc cannot parse TypeScript intersection types - the "Promise<void> & {cancel...}" return annotations broke the API docs generator. Replaced with a CancellablePromise typedef.
1 parent 9434252 commit 77feecc

2 files changed

Lines changed: 45 additions & 34 deletions

File tree

docs/API-Reference/utils/NodeUtils.md

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,34 @@ This is only available in the native app.
5656
| url | <code>string</code> |
5757
| browserName | <code>string</code> |
5858

59+
<a name="_npmInstallInFolder"></a>
60+
61+
## \_npmInstallInFolder(moduleNativeDir) ⇒ [<code>CancellablePromise</code>](#CancellablePromise)
62+
Runs the bundled npm install in the given folder. Rejects if an install is already in
63+
progress there (two npm processes on one node_modules corrupt each other).
64+
65+
The returned promise carries a `cancel()` method - cancellation is only meaningful for
66+
the specific install you started, so it lives on the handle rather than as a module API.
67+
Cancelling kills the npm process; the promise then rejects with a "cancelled" error.
68+
69+
**Kind**: global function
70+
71+
| Param | Type | Description |
72+
| --- | --- | --- |
73+
| moduleNativeDir | <code>string</code> | platform path of the folder holding package.json |
74+
5975
<a name="downloadFile"></a>
6076

61-
## downloadFile(url, destFile, [options]) ⇒ <code>Promise.&lt;void&gt;</code>
77+
## downloadFile(url, destFile, [options]) ⇒ [<code>CancellablePromise</code>](#CancellablePromise)
6278
Downloads a URL to a file on disk, fully node-side (native fetch, streamed to disk).
6379
When an expected sha256 is given, a mismatch deletes the file and rejects - a resolved
6480
promise means the file holds exactly the pinned bytes.
6581
This is only available in the native app.
6682

6783
**Kind**: global function
84+
**Returns**: [<code>CancellablePromise</code>](#CancellablePromise) - the returned promise carries a `cancel()` method that aborts
85+
the download mid-stream - the promise then rejects with a "cancelled" error and the
86+
partial file is deleted
6887

6988
| Param | Type | Description |
7089
| --- | --- | --- |
@@ -73,35 +92,6 @@ This is only available in the native app.
7392
| [options] | <code>Object</code> | |
7493
| [options.sha256] | <code>string</code> | expected hex digest of the downloaded bytes |
7594
| [options.progress] | <code>function</code> | called with (transferredBytes, totalBytes) as the download advances; totalBytes is 0 if the server sent no length |
76-
| [options.cancelId] | <code>string</code> | registers the download so cancelDownload(cancelId) can abort it mid-stream; the partial file is deleted and the rejection error message contains "cancelled" |
77-
78-
<a name="cancelDownload"></a>
79-
80-
## cancelDownload(cancelId) ⇒ <code>Promise.&lt;void&gt;</code>
81-
Cancels an in-flight downloadFile run by the cancelId it was started with. Idempotent -
82-
unknown ids are a no-op. The cancelled download's promise rejects (message contains
83-
"cancelled") and its partial file is deleted.
84-
This is only available in the native app.
85-
86-
**Kind**: global function
87-
88-
| Param | Type | Description |
89-
| --- | --- | --- |
90-
| cancelId | <code>string</code> | cancelId passed to downloadFile |
91-
92-
<a name="_cancelNpmInstall"></a>
93-
94-
## \_cancelNpmInstall(moduleNativeDir) ⇒ <code>Promise.&lt;void&gt;</code>
95-
Kills an in-flight _npmInstallInFolder run by the moduleNativeDir it was started with.
96-
Idempotent - unknown dirs are a no-op. The killed install's promise rejects (message
97-
contains "cancelled").
98-
This is only available in the native app.
99-
100-
**Kind**: global function
101-
102-
| Param | Type | Description |
103-
| --- | --- | --- |
104-
| moduleNativeDir | <code>string</code> | dir passed to _npmInstallInFolder |
10595

10696
<a name="extractZipFile"></a>
10797

@@ -268,3 +258,16 @@ Retrieves the directory path for system settings. This method is applicable to n
268258

269259
- <code>Error</code> If the method is called in browser app.
270260

261+
<a name="CancellablePromise"></a>
262+
263+
## CancellablePromise : <code>Promise</code>
264+
A Promise that additionally carries a `cancel()` method aborting the underlying
265+
operation - the promise then rejects with a "cancelled" error.
266+
267+
**Kind**: global typedef
268+
**Properties**
269+
270+
| Name | Type | Description |
271+
| --- | --- | --- |
272+
| cancel | <code>function</code> | aborts the in-flight operation |
273+

src/utils/NodeUtils.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ define(function (require, exports, module) {
121121
return utilsConnector.execPeer("_loadNodeExtensionModule", {moduleNativeDir});
122122
}
123123

124+
/**
125+
* A Promise that additionally carries a `cancel()` method aborting the underlying
126+
* operation - the promise then rejects with a "cancelled" error.
127+
*
128+
* @typedef {Promise} CancellablePromise
129+
* @property {function(): Promise<void>} cancel - aborts the in-flight operation
130+
*/
131+
124132
/**
125133
* Runs the bundled npm install in the given folder. Rejects if an install is already in
126134
* progress there (two npm processes on one node_modules corrupt each other).
@@ -130,7 +138,7 @@ define(function (require, exports, module) {
130138
* Cancelling kills the npm process; the promise then rejects with a "cancelled" error.
131139
*
132140
* @param {string} moduleNativeDir - platform path of the folder holding package.json
133-
* @return {Promise<void> & {cancel: function(): Promise<void>}}
141+
* @return {CancellablePromise}
134142
*/
135143
function _npmInstallInFolder(moduleNativeDir) {
136144
if(!Phoenix.isNativeApp) {
@@ -158,9 +166,9 @@ define(function (require, exports, module) {
158166
* @param {string} [options.sha256] - expected hex digest of the downloaded bytes
159167
* @param {function(number, number)} [options.progress] - called with (transferredBytes,
160168
* totalBytes) as the download advances; totalBytes is 0 if the server sent no length
161-
* @return {Promise<void> & {cancel: function(): Promise<void>}} the returned promise carries
162-
* a `cancel()` method that aborts the download mid-stream - the promise then rejects
163-
* with a "cancelled" error and the partial file is deleted
169+
* @return {CancellablePromise} the returned promise carries a `cancel()` method that aborts
170+
* the download mid-stream - the promise then rejects with a "cancelled" error and the
171+
* partial file is deleted
164172
*/
165173
function downloadFile(url, destFile, options) {
166174
if(!Phoenix.isNativeApp) {

0 commit comments

Comments
 (0)