electron/packager

Provide an option to preserve the state of the node_modules when packaging

JasonYeMSFT opened this issue · 2 comments

Preflight Checklist

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

Problem Description

Our observation indicates that during packaging, electron-packager will check the state of "node_modules/" with the "dependencies" field in the package.json. If the "node_modules/" directory doesn't have a module listed in the dependencies, electron-packager will report an error and fail the packaging. If the "node_modules/" directory contains a module that is not listed in the dependencies, electron-packager will not copy that module to the packaged app. And it seems like electron-packager only checks the top-level dependencies. It doesn't care about sub-dependencies.

Proposed Solution

Add an option in electron-packager to skip checking the dependencies in the package.json and preserve the state of the "node_modules/" directory when packaging the app.

Alternatives Considered

We currently workaround the issue by modifying the dependencies field in package.json prior to packaging, adding the missing ones and removing the bundled ones.

Additional Information

My team ships an electron app that includes a mixture of JavaScript and node native modules. We want to minimize the binary footage of the artifacts we ship so we decided to bundle our JavaScript. We have an algorithm that parses our dependency graph to decide which files are necessary at runtime so we can delete the rest. This results in a mismatch of the state of the "node_modules/" directory and the package.json. We don't want to simply put these packages in devDependencies because we still want to use the two fields to separate packages that are shipped vs. packages that ara only used for development. Allowing the electron-packager to skip the dependency check will save us from doing the package.json manipulation.

👋 Thanks for opening your first issue here! If you have a question about using Electron Packager, read the support docs. If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. Development and issue triage is community-driven, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We have an algorithm that parses our dependency graph to decide which files are necessary at runtime so we can delete the rest. This results in a mismatch of the state of the "node_modules/" directory and the package.json. We don't want to simply put these packages in devDependencies because we still want to use the two fields to separate packages that are shipped vs. packages that ara only used for development. Allowing the electron-packager to skip the dependency check will save us from doing the package.json manipulation.

You can either do what you're asking and disable pruning prune: false in packager options. Or change your logic to be more Correct ™️ similar to what forge does which is ignore things via the packager ignore config instead of deleting things before packager gets a go at things.