Electron-packager: Add option to apply applicable options to package.json

Created on 20 Feb 2017  Â·  5Comments  Â·  Source: electron/electron-packager

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

For instance, setting the app-version option would not only change the "ProductVersion metadata property on Windows, and CFBundleShortVersionString on OS X", but would also change version in the packaged app's package.json. This way, accessing app.version from Electron will return the version passed to electron-packager, and not the original version.

As far as I can tell, this would only apply to the version and name options. I think name should modify productName in package.json.

IMHO, this should eventually be made the default behavior, but that would require a major version change.

If this sounds good, I might go ahead and work on a PR for this.

enhancement wontfix

Most helpful comment

I'm not inclined to add this functionality to Electron Packager, partly because I don't see a broader use case for it, and partly because I think it will make the code base messier than it already is.

However, you can implement it for your app by using an afterCopy hook with the packager API:

const packager = require('electron-packager');

const packagerOptions = {
  // ...
  afterCopy: (buildPath, electronVersion, platform, arch, callback) => {
    // read package.json from buildPath
    // modify deserialized package.json
    // write new package.json contents
    callback();
  }
  // ...
};

packager(packagerOptions, (err, appPaths) => { /* ... */ });

All 5 comments

Just so I'm clear about the feature you're requesting, you could like Electron Packager to update the version field of the Electron app's package.json if, for example, --app-version=1.2.3 is specified on the command line? If this is accurate, what is the use case for this feature?

Yes, but it would only update the version of package.json located in the temp directory for packaging. The main source code would be unchanged.

My use case for this feature is to have a script that uses electron-packager to make a test version of the app. The electron-packager name option would include the word "test". The packaged test app would then be able to check for the word test and modify its behavior as discussed here.

I'm not inclined to add this functionality to Electron Packager, partly because I don't see a broader use case for it, and partly because I think it will make the code base messier than it already is.

However, you can implement it for your app by using an afterCopy hook with the packager API:

const packager = require('electron-packager');

const packagerOptions = {
  // ...
  afterCopy: (buildPath, electronVersion, platform, arch, callback) => {
    // read package.json from buildPath
    // modify deserialized package.json
    // write new package.json contents
    callback();
  }
  // ...
};

packager(packagerOptions, (err, appPaths) => { /* ... */ });

OK, thanks for reminding me about afterCopy. That should do nicely.

electron-builder for such use case supports --extraMetadata — ability to inject/modify package.json (e.g. https://github.com/electron-userland/electron-builder/issues/639#issuecomment-237545651). Because in general such options should be inferred from package.json, not vice versa.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Orrison picture Orrison  Â·  3Comments

kdawg1406 picture kdawg1406  Â·  4Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  Â·  4Comments

ghost picture ghost  Â·  3Comments

quadrophobiac picture quadrophobiac  Â·  4Comments