Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install-app-deps: Configuring yargs through package.json is deprecated #3751

Closed
ivancuric opened this issue Mar 13, 2019 · 13 comments
Closed

Comments

@ivancuric
Copy link

  • Version: 20.39.0

  • Target: 4.0.8 on platform=win32 arch=x64

I have a few local native modules linked via file: in package.json.

> electron-builder install-app-deps

Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.
  • electron-builder version=20.39.0
  • loaded configuration file=package.json ("build" field)
  • rebuilding native production dependencies platform=win32 arch=x64

What are the yargs errors about?

@nathanlesage
Copy link

I just discovered them myself. It appears that this pertains to the command line arguments. For instance, what I've been doing in my package.json for the last year was put these commands in the scripts section:

...
"scripts": {
        "postinstall": "electron-builder install-app-deps",
        "start": "electron .",
        "build:quick": "electron-builder --dir",
        "release:this": "electron-builder",
        "release:mac": "electron-builder --mac",
        "release:win": "electron-builder --win",
        "release:linux": "electron-builder --linux"
    },

And yargs is basically a JavaScript package that parses command line arguments.

So I'm pretty sure these warnings mean: "Please don't use --dir, --mac etc. anymore, but use the Javascript API directly!"

I.e.: Run electron-builder from within a node.js-script.

@ivancuric
Copy link
Author

https://www.electron.build/api/electron-builder
I don't see any way to run it using the provided API.

@nathanlesage
Copy link

@ivancuric It's just weirdly documented.

As it says in the API docs:

image

Raw Options refer to the CLI options and there you'll find this:

image

So CLI equals API arguments, i.e. you'd have to pass the command line arguments into the package.jsons build-property and hope you place them at the right position in the tree.


Downside of this is obviously that you'd need several different scripts to pass data to the builder so that it does not always trigger a full chain-rebuild if you just want to drop a testing app into the release directory, so you'd have to do something like this to avoid this:

// Some script file, i.e. build.js
const builder = require('electron-builder')

// ... Some logic that builds up the build field, e.g.:
let options = {
  "win": {
    "target": [
      {
        "target": "nsis",
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  }

builder.build(options).then((sth) => {
  // I have literally no idea what would be passed
  // during a successful call, maybe just dump it
  // to the console
  console.log(sth)
}).catch((e) => {
  // Some error handling
  console.error(e)
})

@ivancuric
Copy link
Author

Ah, thanks!

@mubaidr
Copy link

mubaidr commented Mar 19, 2019

Thanks @nathanlesage

By the way on successful build it returns paths to all the packages built.

@nathanlesage
Copy link

You're welcome! 🎉

And @mubaidr: classic.

@mubaidr
Copy link

mubaidr commented Mar 20, 2019

Working build script:

const builder = require('electron-builder')
const Platform = builder.Platform

const config = {
  "win": {
    "target": [
      {
        target: ['nsis', 'zip', 'portable'],
        "arch": [
          "x64",
          "ia32"
        ]
      }
    ]
  }

builder
  .build({
    targets: Platform.WINDOWS.createTarget(),
    config,
  })
  .then(m => {
    console.log(m)
  })
  .catch(e => {
    console.error(e)
  })

@jgierer12
Copy link

This occurs for me even if I'm running electron-builder from the terminal, with and without options and even with things like --help and --version which are supposed to be run from the CLI.

@stvenyin
Copy link

configure "scripts": {
"postinstall": "electron-builder install-app-deps",
"start": "electron .",
"build:quick": "electron-builder --dir",
"release:this": "electron-builder",
"release:mac": "electron-builder --mac",
"release:win": "electron-builder --win",
"release:linux": "electron-builder --linux"
},
https://www.electron.build/api/electron-builder
Thanks!

@stvenyin
Copy link

image

@Faksprod
Copy link

Faksprod commented Apr 3, 2019

Same problem here when I tried to run code containing in my package.json file from the CLI (Terminal) on MacOS Mojave (was working well 3 months ago before my yesterday Electron update).

  • Electron: 4.1.3
  • Electron-builder: 20.39.0

package.json

{
    "scripts": {
        "start": "electron .",
        "build": "electron-builder",
        "build-mac": "electron-builder --mac"
    },
    "build": {
        "appId": "com.myCompany.myApp",
        "productName": "myAppName",
        "copyright": "Copyright © 2019 myCompany",
        "mac":{
            "target":"mas",
            "type":"distribution",
            "provisioningProfile":"myApp.provisionprofile",
            "identity": "MyCompany (idNumber)",
        },
        "directories": {
            "output": "build"
        }
    }
}

When I try to run npm run build-mac it gives me this error message Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.

Thanks to @nathanlesage I finally found the solution. It wasn't really clear for me about where I should put the build.js file et how to execute it (I'm not a Node JS pro). If someone is in my case, here are more detailed steps:

  • Create a new JS file in the folder containing the package.json file.
  • You can give any name to this new JS file (eg: myCustomScript.js).
  • In this myCustomScript.js file you will use the electron-builder JS API to run your build instead of using the CLI command electron-builder --mac.
  • Put this script (from the electron-builder doc).
  • Change the targets property if needed and custom the config property.
  • In the config property you just have to copy paste the object contained in the "build" tree of your package.json. Then you can remove the "build" part from your package.json tree cause you don't need here anymore.
  • Finally, to call and execute your myCustomScript.js you can add a line in the scripts property of your package.json like this:
"scripts": {
    "myCustomScript": "node myCustomScript.js"
}
  • Then you can call it from the Terminal like this npm run myCustomScript

So now, my files looks like below and it works like a charm!

package.json (new)

{
    "scripts": {
        "start": "electron .",
        "build": "electron-builder",
        "myCustomScript": "node myCustomScript.js"
    }
}

myCustomScript.js

"use strict";

const builder = require("electron-builder");
const Platform = builder.Platform;

builder.build({
    targets: Platform.MAC.createTarget(),
    config: {
        
        "directories": {
            "output": "build"
        },
        "appId": "com.myCompany.myApp",
        "productName": "myAppName",
        "copyright": "Copyright © 2019 myCompany",

        "mac":{
            "target":"mas",
            "type":"distribution",
            "provisioningProfile":"myApp.provisionprofile",
            "identity": "MyCompany (idNumber)"
        }
    }
})
.then(() => {
    // handle result
    console.log('Build OK!');
})
.catch((error) => {
    // handle error
    console.log(error);
})

@mb8z
Copy link

mb8z commented Apr 15, 2019

How about the --publish option? How should I apply this?

dscalzi added a commit to dscalzi/HeliosLauncher that referenced this issue Apr 23, 2019
It seems that the package-json based configuration is deprecated.
See electron-userland/electron-builder#3751
firede added a commit to firede/electron-builder that referenced this issue Apr 24, 2019
…ecated electron-userland#3751

1. remove `yargs` field from `package.json`.
2. upgrade `@types/yargs` for better type definitions.
3. move `parserConfiguration` to the entry point for every "bin".
@firede
Copy link
Contributor

firede commented Apr 24, 2019

Configuring yargs through package.json is deprecated and will be removed in the next major release, please use the JS API instead.

This warning is from yargs, not electron-builder, so it’s great to keep using the CLI.
I created a PR to fix this internal error: #3852

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants