From ac94426a15505531391236d7249996879534cf8c Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Fri, 19 Jan 2024 14:58:26 -0500 Subject: [PATCH 1/2] Support overriding various package upload form data --- package-lock.json | 30 ++++++++++++++++++++---------- src/RokuDeploy.spec.ts | 31 +++++++++++++++++++++++++++++++ src/RokuDeploy.ts | 18 +++++++++++++++--- src/RokuDeployOptions.ts | 16 ++++++++++++++++ 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2aaf6d6..3ed364f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1297,14 +1297,24 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001271", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001271.tgz", - "integrity": "sha512-BBruZFWmt3HFdVPS8kceTBIguKxu4f99n5JNp06OlPD/luoAMIaIK5ieV5YjnBLH3Nysai9sxj9rpJj4ZisXOA==", + "version": "1.0.30001579", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz", + "integrity": "sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA==", "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ] }, "node_modules/caseless": { "version": "0.12.0", @@ -5844,9 +5854,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001271", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001271.tgz", - "integrity": "sha512-BBruZFWmt3HFdVPS8kceTBIguKxu4f99n5JNp06OlPD/luoAMIaIK5ieV5YjnBLH3Nysai9sxj9rpJj4ZisXOA==", + "version": "1.0.30001579", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001579.tgz", + "integrity": "sha512-u5AUVkixruKHJjw/pj9wISlcMpgFWzSrczLZbrqBSxukQixmg0SJ5sZTpvaFvxU0HoQKd4yoyAogyrAz9pzJnA==", "dev": true }, "caseless": { diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index d93702f..83a98db 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -919,6 +919,34 @@ describe('index', () => { } catch (e) { } }); + it('uses overridden route', async () => { + const stub = mockDoPostRequest(); + await rokuDeploy.publish({ + ...options, + packageUploadOverrides: { + route: 'alt_path' + } + }); + expect(stub.getCall(0).args[0].url).to.eql('http://0.0.0.0:80/alt_path'); + }); + + it('overrides formData', async () => { + const stub = mockDoPostRequest(); + await rokuDeploy.publish({ + ...options, + remoteDebug: true, + packageUploadOverrides: { + formData: { + remotedebug: null, + newfield: 'here' + } + } + }); + expect(stub.getCall(0).args[0].formData).to.include({ + newfield: 'here' + }).and.to.not.haveOwnProperty('remotedebug'); + }); + it('does not delete the archive by default', async () => { let zipPath = `${options.outDir}/${options.outFile}`; @@ -2161,6 +2189,9 @@ describe('index', () => { it('rejects the promise when an error occurs', async () => { //zip path doesn't exist await assertThrowsAsync(async () => { + sinon.stub(fsExtra, 'outputFile').callsFake(() => { + throw new Error(); + }); await rokuDeploy.zipFolder('source', '.tmp/some/zip/path/that/does/not/exist'); }); }); diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 3a04b2e..6295b3b 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -142,7 +142,7 @@ export class RokuDeploy { if (options.incrementBuildNumber) { let timestamp = dateformat(new Date(), 'yymmddHHMM'); parsedManifest.build_version = timestamp; //eslint-disable-line camelcase - await this.fsExtra.writeFile(manifestPath, this.stringifyManifest(parsedManifest)); + await this.fsExtra.outputFile(manifestPath, this.stringifyManifest(parsedManifest)); } if (beforeZipCallback) { @@ -433,7 +433,9 @@ export class RokuDeploy { readStream.on('open', resolve); }); - let requestOptions = this.generateBaseRequestOptions('plugin_install', options, { + const route = options.packageUploadOverrides?.route ?? 'plugin_install'; + + let requestOptions = this.generateBaseRequestOptions(route, options, { mysubmit: 'Replace', archive: readStream }); @@ -449,6 +451,16 @@ export class RokuDeploy { requestOptions.formData.remotedebug_connect_early = '1'; } + //apply any supplied formData overrides + for (const key in options.packageUploadOverrides?.formData ?? {}) { + const value = options.packageUploadOverrides.formData[key]; + if (value === undefined || value === null) { + delete requestOptions.formData[key]; + } else { + requestOptions.formData[key] = value; + } + } + //try to "replace" the channel first since that usually works. let response: HttpResponse; try { @@ -1151,7 +1163,7 @@ export class RokuDeploy { await Promise.all(promises); // level 2 compression seems to be the best balance between speed and file size. Speed matters more since most will be calling squashfs afterwards. const content = await zip.generateAsync({ type: 'nodebuffer', compressionOptions: { level: 2 } }); - return this.fsExtra.writeFile(zipFilePath, content); + return this.fsExtra.outputFile(zipFilePath, content); } } diff --git a/src/RokuDeployOptions.ts b/src/RokuDeployOptions.ts index 75e4378..8b44f99 100644 --- a/src/RokuDeployOptions.ts +++ b/src/RokuDeployOptions.ts @@ -158,6 +158,22 @@ export interface RokuDeployOptions { * If true, the previously installed dev channel will be deleted before installing the new one */ deleteInstalledChannel?: boolean; + + /** + * Overrides for values used during the zip upload process. You probably don't need to change these... + */ + packageUploadOverrides?: { + /** + * The route to use for uploading to the Roku device. Defaults to 'plugin_install' + * @default 'plugin_install' + */ + route?: string; + + /** + * A dictionary of form fields to be included in the package upload request. Set a value to null to delete from the form + */ + formData?: Record; + }; } export type FileEntry = (string | { src: string | string[]; dest?: string }); From d474400db40e23c033e3b5c34022418ccc24fda0 Mon Sep 17 00:00:00 2001 From: George Cook Date: Fri, 16 Feb 2024 17:31:15 +0000 Subject: [PATCH 2/2] adds support for squashfs deployments --- src/RokuDeploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 6295b3b..46a53f1 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -978,7 +978,7 @@ export class RokuDeploy { options = this.getOptions(options); let zipFileName = options.outFile; - if (!zipFileName.toLowerCase().endsWith('.zip')) { + if (!zipFileName.toLowerCase().endsWith('.zip') && !zipFileName.toLowerCase().endsWith('.squashfs')) { zipFileName += '.zip'; } let outFolderPath = path.resolve(options.outDir);