From fb15f961d90a98acb272a400242c2f0de195e099 Mon Sep 17 00:00:00 2001 From: Johannah Sprinz Date: Sun, 11 Sep 2022 13:05:33 +0200 Subject: [PATCH 1/4] fix copyright headers --- src/adb.js | 3 ++- src/adb.spec.js | 3 ++- src/cancelable-promise.js | 3 ++- src/common.js | 3 ++- src/common.spec.js | 3 ++- src/fastboot.js | 3 ++- src/fastboot.spec.js | 3 ++- src/heimdall.js | 3 ++- src/heimdall.spec.js | 3 ++- src/module.js | 3 ++- src/module.spec.js | 3 ++- src/tool.js | 3 ++- src/tool.spec.js | 3 ++- 13 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/adb.js b/src/adb.js index 0712242..5b520b3 100644 --- a/src/adb.js +++ b/src/adb.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2020 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/adb.spec.js b/src/adb.spec.js index d619d09..5f96f28 100644 --- a/src/adb.spec.js +++ b/src/adb.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2021 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/cancelable-promise.js b/src/cancelable-promise.js index bcee752..abbc2f8 100644 --- a/src/cancelable-promise.js +++ b/src/cancelable-promise.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2020 UBports Foundation + * Copyright (C) 2020-2022 UBports Foundation + * Copyright (C) 2020-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/common.js b/src/common.js index 4908214..8f81216 100644 --- a/src/common.js +++ b/src/common.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2020 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/common.spec.js b/src/common.spec.js index f6b1978..a54c0c8 100644 --- a/src/common.spec.js +++ b/src/common.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2021 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/fastboot.js b/src/fastboot.js index 28b9070..5ae7f2a 100644 --- a/src/fastboot.js +++ b/src/fastboot.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2020 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/fastboot.spec.js b/src/fastboot.spec.js index 61ab9c5..f2a816c 100644 --- a/src/fastboot.spec.js +++ b/src/fastboot.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2021 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/heimdall.js b/src/heimdall.js index 3fa5ee1..fa4f03d 100644 --- a/src/heimdall.js +++ b/src/heimdall.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2019-2020 UBports Foundation + * Copyright (C) 2019-2022 UBports Foundation + * Copyright (C) 2019-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/heimdall.spec.js b/src/heimdall.spec.js index 1a611f3..1e2f85a 100644 --- a/src/heimdall.spec.js +++ b/src/heimdall.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2019-2021 UBports Foundation + * Copyright (C) 2019-2022 UBports Foundation + * Copyright (C) 2019-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/module.js b/src/module.js index 429060a..66e3549 100644 --- a/src/module.js +++ b/src/module.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2020 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/module.spec.js b/src/module.spec.js index 9e03867..9681be4 100644 --- a/src/module.spec.js +++ b/src/module.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2021 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/tool.js b/src/tool.js index 0f85ece..2c747d1 100644 --- a/src/tool.js +++ b/src/tool.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2017-2020 UBports Foundation + * Copyright (C) 2017-2022 UBports Foundation + * Copyright (C) 2017-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/tool.spec.js b/src/tool.spec.js index f757c93..4f641ee 100644 --- a/src/tool.spec.js +++ b/src/tool.spec.js @@ -1,7 +1,8 @@ "use strict"; /* - * Copyright (C) 2019-2021 UBports Foundation + * Copyright (C) 2019-2022 UBports Foundation + * Copyright (C) 2019-2022 Johannah Sprinz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by From f4ee5ff25c1011170a834ae2f2e0702823de54a5 Mon Sep 17 00:00:00 2001 From: Johannah Sprinz Date: Sun, 11 Sep 2022 13:13:02 +0200 Subject: [PATCH 2/4] introduce a setPath option for tools pass {setPath: true} when instantiating a tool to automatically add the bundled binaries to the PATH environment variable. This ensures the bundled binaries are used, rather than the system ones. --- src/adb.spec.js | 3 ++- src/cancelable-promise.spec.js | 37 ++++++++++++++++++++++++++++++++++ src/fastboot.spec.js | 7 ++++--- src/tool.js | 9 ++++++++- src/tool.spec.js | 4 ++-- 5 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/cancelable-promise.spec.js diff --git a/src/adb.spec.js b/src/adb.spec.js index 5f96f28..c83bf3b 100644 --- a/src/adb.spec.js +++ b/src/adb.spec.js @@ -354,7 +354,7 @@ describe("Adb module", function () { expect(child_process.spawn).toHaveBeenCalledWith( adb.executable, [...adb.extra, "sideload", "tests/test-data/test_file"], - { env: { ADB_TRACE: "rwx" } } + { env: expect.objectContaining({ ADB_TRACE: "rwx" }) } ); }); }); @@ -1018,6 +1018,7 @@ describe("Adb module", function () { it("should restore full backup", function () { stubExec(1, "should not be called"); jest.useFakeTimers(); + jest.setSystemTime(); fs.readJSON = jest.fn().mockReturnValue({ codename: "codename", comment: "Ubuntu Touch backup created on 1970-01-01T00:00:00.000Z", diff --git a/src/cancelable-promise.spec.js b/src/cancelable-promise.spec.js new file mode 100644 index 0000000..94a5954 --- /dev/null +++ b/src/cancelable-promise.spec.js @@ -0,0 +1,37 @@ +"use strict"; + +/* + * Copyright (C) 2022 UBports Foundation + * Copyright (C) 2022 Johannah Sprinz + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import { jest, expect } from "@jest/globals"; + +import cp from "cancelable-promise"; + +describe("CancelablePromise", function () { + it("should export tool when packaged", function () { + cp.CancelablePromise = null; + return import("./cancelable-promise.js").then(cp => + expect(cp).toBeTruthy() + ); + }); + it("should export tool when native", function () { + return import("./cancelable-promise.js").then(cp => + expect(cp).toBeTruthy() + ); + }); +}); diff --git a/src/fastboot.spec.js b/src/fastboot.spec.js index f2a816c..f62529d 100644 --- a/src/fastboot.spec.js +++ b/src/fastboot.spec.js @@ -82,6 +82,7 @@ describe("Fastboot module", function () { on: jest.fn((_, cb) => { if (i++ === 0) { cb("Sending 'boot'"); + cb("OKAY"); setTimeout(() => cb("Writing 'boot'"), 1); setTimeout(() => cb("Finished 'boot'"), 2); } else { @@ -119,7 +120,7 @@ describe("Fastboot module", function () { expect(child_process.spawn).toHaveBeenCalledWith( fastboot.executable, ["flash", "boot", "/path/to/boot.img"], - { env: { ADB_TRACE: "rwx" } } + { env: expect.objectContaining({ ADB_TRACE: "rwx" }) } ); expect(child_process.spawn).toHaveBeenCalledWith( fastboot.executable, @@ -130,7 +131,7 @@ describe("Fastboot module", function () { "--disable-verity", "/path/to/recovery.img" ], - { env: { ADB_TRACE: "rwx" } } + { env: expect.objectContaining({ ADB_TRACE: "rwx" }) } ); expect(progress).toHaveBeenCalledWith(0); expect(progress).toHaveBeenCalledWith(0.15); @@ -180,7 +181,7 @@ describe("Fastboot module", function () { expect(child_process.spawn).toHaveBeenCalledWith( fastboot.executable, ["flash", "boot", "/path/to/image"], - { env: { ADB_TRACE: "rwx" } } + { env: expect.objectContaining({ ADB_TRACE: "rwx" }) } ); done(); }); diff --git a/src/tool.js b/src/tool.js index 2c747d1..47b5305 100644 --- a/src/tool.js +++ b/src/tool.js @@ -19,7 +19,7 @@ */ import child_process from "child_process"; -import { getAndroidToolPath } from "android-tools-bin"; +import { getAndroidToolPath, getAndroidToolBaseDir } from "android-tools-bin"; import EventEmitter from "events"; import { removeFalsy } from "./common.js"; import { CancelablePromise } from "./cancelable-promise.js"; @@ -39,6 +39,12 @@ export class Tool extends EventEmitter { this.extra = options?.extra || []; this.execOptions = options?.execOptions || {}; this.processes = []; + if ( + options.setPath && + process.env.PATH && + !process.env.PATH.includes(getAndroidToolBaseDir()) + ) + process.env.PATH = `${getAndroidToolBaseDir()}:${process.env.PATH}`; } /** @@ -117,6 +123,7 @@ export class Tool extends EventEmitter { [...this.extra, ...args].flat(), { env: { + ...process.env, ADB_TRACE: "rwx" } } diff --git a/src/tool.spec.js b/src/tool.spec.js index 4f641ee..ddbe86b 100644 --- a/src/tool.spec.js +++ b/src/tool.spec.js @@ -41,7 +41,7 @@ describe("Tool module", function () { describe("constructor()", function () { ["adb", "fastboot", "heimdall"].forEach(t => { it(`should create generic ${t}`, function () { - const tool = new Tool({ tool: t }); + const tool = new Tool({ tool: t, setPath: true }); expect(tool).toExist; expect(tool.tool).toEqual(t); expect(tool.executable).toMatch(t); @@ -218,7 +218,7 @@ describe("Tool module", function () { expect(child_process.spawn).toHaveBeenCalledWith( tool.executable, [...tool.extra, ...args], - { env: { ADB_TRACE: "rwx" } } + { env: expect.objectContaining({ ADB_TRACE: "rwx" }) } ); expect(spawnStartListenerStub).toHaveBeenCalledWith({ cmd: [tool.tool, ...tool.extra, ...args] From 8e33705d6f68f653f4c2c9145654be226c27939c Mon Sep 17 00:00:00 2001 From: Johannah Sprinz Date: Sun, 11 Sep 2022 13:16:04 +0200 Subject: [PATCH 3/4] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f35edcc..cedb31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ promise-android-tools versioning started at 1.0.0, but this changelog was not ad ## [Unreleased] +### Added + +- Introduce a setPath option for tools ([#72](https://github.com/ubports/promise-android-tools/pull/72)) + ## [4.0.13] - 2022-09-07 ### Changed From be0b1246fc4b27b9aae3711898715bcba1dc44b2 Mon Sep 17 00:00:00 2001 From: Johannah Sprinz Date: Sun, 11 Sep 2022 13:16:20 +0200 Subject: [PATCH 4/4] Bump Version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index def1294..f7aabfd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "promise-android-tools", - "version": "4.0.13", + "version": "4.0.14", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "promise-android-tools", - "version": "4.0.13", + "version": "4.0.14", "license": "GPL-3.0", "dependencies": { "android-tools-bin": "^1.0.7", diff --git a/package.json b/package.json index a5803a5..40d5571 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "promise-android-tools", - "version": "4.0.13", + "version": "4.0.14", "description": "A wrapper for adb, fastboot, and heimdall that returns convenient promises.", "main": "./lib/module.cjs", "type": "module",