15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrebuildInstall = void 0;
const debug_1 = __importDefault(require("debug"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
const cross_spawn_promise_1 = require("@malept/cross-spawn-promise");
const _1 = require(".");
const d = (0, debug_1.default)('electron-rebuild');
class PrebuildInstall extends _1.NativeModule {
    async usesTool() {
        const dependencies = await this.packageJSONFieldWithDefault('dependencies', {});
        // eslint-disable-next-line no-prototype-builtins
        return dependencies.hasOwnProperty('prebuild-install');
    }
    async locateBinary() {
        return (0, _1.locateBinary)(this.modulePath, 'node_modules/prebuild-install/bin.js');
    }
    async run(prebuildInstallPath) {
        await (0, cross_spawn_promise_1.spawn)(process.execPath, [
            path_1.default.resolve(__dirname, '..', `prebuild-shim.js`),
            prebuildInstallPath,
            `--arch=${this.rebuilder.arch}`,
            `--platform=${this.rebuilder.platform}`,
            `--tag-prefix=${this.rebuilder.prebuildTagPrefix}`,
            ...await this.getPrebuildInstallRuntimeArgs(),
        ], {
            cwd: this.modulePath,
        });
    }
    async findPrebuiltModule() {
        var _a;
        const prebuildInstallPath = await this.locateBinary();
        if (prebuildInstallPath) {
            d(`triggering prebuild download step: ${this.moduleName}`);
            try {
                await this.run(prebuildInstallPath);
                return true;
            }
            catch (err) {
                d('failed to use prebuild-install:', err);
                if ((_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.includes('requires Node-API but Electron')) {
                    throw err;
                }
            }
        }
        else {
            d(`could not find prebuild-install relative to: ${this.modulePath}`);
        }
        return false;
    }
    /**
     * Whether a prebuild-install-based native module exists.
     */
    async prebuiltModuleExists() {
        return fs_extra_1.default.pathExists(path_1.default.resolve(this.modulePath, 'prebuilds', `${this.rebuilder.platform}-${this.rebuilder.arch}`, `electron-${this.rebuilder.ABI}.node`));
    }
    async getPrebuildInstallRuntimeArgs() {
        const moduleNapiVersions = await this.getSupportedNapiVersions();
        if (moduleNapiVersions) {
            const napiVersion = this.nodeAPI.getNapiVersion(moduleNapiVersions);
            return [
                '--runtime=napi',
                `--target=${napiVersion}`,
            ];
        }
        else {
            return [
                '--runtime=electron',
                `--target=${this.rebuilder.electronVersion}`,
            ];
        }
    }
}
exports.PrebuildInstall = PrebuildInstall;
//# sourceMappingURL=prebuild-install.js.map