Проблемы установки шоколадных пакетов с NodeJS - PullRequest
2 голосов
/ 02 ноября 2019

Я написал приложение Electron с пользовательским интерфейсом React, в котором используется рендер и основной процесс. Как часть требований, я создал список пользовательского интерфейса с шоколадными пакетами, которые можно установить. У меня есть модуль сценария powershell, который выполняет команды. Я успешно установил менеджер пакетов, но у меня были проблемы с установкой пакетов при использовании модуля сценариев powershell. Это сводит меня с ума. Установка работает нормально, когда я выполняю в терминале. Я не уверен точно, что я делаю неправильно, но некоторая помощь очень ценится.

Вот часть кода, которая выполняет команду терминала.

Электрон получил команду

ipc.on(Actions.INSTALL_CHOCO_PACKAGE, (event, args) => {   
    logger.info(`[INSTALL_CHOCO_PACKAGGE] - powershell Install-Package -Item ${args}'`);
    execInstallPackage(`powershell Install-Package -Item ${args}`, event);

});

Узел выполняет команду



    async function execInstallPackage(argument, event){
            logger.info(`Executing command ${argument}`)
             childProcess =  exec(
            argument,
        ( error, stdout, stderr ) =>
                some output is performed

Вот функция в модуле скриптов Powershell

    function Install-Package {
       [CmdletBinding()]
        param(
            [string[]]$Item,

        )

        if($Item.count -gt 1){
            forEach($package in $Item){
                Start-Process cmd -Verb RunAs -ArgumentList '/c choco install $($package) -dfvy'
                #cmd /c "choco install $($package) -dfvy"
            }   
        }
        else {
            Write-Output "--Executing $($Item)" 

            Set-ExecutionPolicy Bypass -Scope Process -Force 
            choco install $Item -dfvy
        }
    }

Я пробовал использовать два разных метода и получаю ту же ошибку:

*2019-11-01 10:19:58,107 14332 [INFO ] - 
Firefox v70.0.1 (forced) [Approved]
2019-11-01 10:19:58,116 14332 [INFO ] - firefox package files install completed. Performing other installation steps.
2019-11-01 10:19:58,281 14332 [ERROR] - firefox not installed. An error occurred during installation:
 Item has already been added. Key in dictionary: 'Path'  Key being added: 'PATH'
2019-11-01 10:19:58,290 14332 [WARN ] - 
Chocolatey installed 0/0 packages. 
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2019-11-01 10:19:58,292 14332 [WARN ] - 
Did you know the proceeds of Pro (and some proceeds from other
 licensed editions) go into bettering the community infrastructure?
 Your support ensures an active community, keeps Chocolatey tip top,
 plus it nets you some awesome features!
 https://chocolatey.org/compare
2019-11-01 10:19:58,293 14332 [DEBUG] - Sending message 'PostRunMessage' out if there are subscribers...
2019-11-01 10:19:58,302 14332 [ERROR] - The process cannot access the file 'C:\ProgramData\chocolatey\lib\Firefox\.chocolateyPending' because it is being used by another process.
2019-11-01 10:19:58,305 14332 [ERROR] - More Details: System.IO.IOException: The process cannot access the file 'C:\ProgramData\chocolatey\lib\Firefox\.chocolateyPending' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at chocolatey.infrastructure.filesystem.DotNetFileSystem.get_file_encoding(String filePath)
   at chocolatey.infrastructure.filesystem.DotNetFileSystem.write_file(String filePath, String fileText)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.set_pending(PackageResult packageResult, ChocolateyConfiguration config)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName)
   at chocolatey.infrastructure.app.services.NugetService.install_run(ChocolateyConfiguration config, Action`1 continueAction)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.perform_source_runner_function[T](ChocolateyConfiguration config, Func`2 function)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.install_run(ChocolateyConfiguration config)
   at chocolatey.infrastructure.app.runners.GenericRunner.run(ChocolateyConfiguration config, Container container, Boolean isConsole, Action`1 parseArgs)
   at chocolatey.infrastructure.app.runners.ConsoleApplication.run(String[] args, ChocolateyConfiguration config, Container container)
   at chocolatey.console.Program.Main(String[] args)
2019-11-01 10:19:58,306 14332 [DEBUG] - Exiting with 1
2019-11-01 13:43:28,540 17184 [DEBUG] - XmlConfiguration is now operational
2019-11-01 13:43:28,572 17184 [INFO ] - ============================================================*
...