-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add support for an include option (in addition to ignore) #972
Comments
👋 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. |
I think we need more detail around this feature before we decide whether to add it to the code:
Using existing NPM config is probably a bad idea, given the myriad different ways that users structure their code repositories. |
Sorry, I might have been too terse. I can answer these from my POV:
Augment. Makes no sense to break current use-cases.
Whitelist is checked first, a subset of files is returned, then ignore settings are applied on top of that subset.
Not that I see. Whitelisting doesn't apply to the "node_modules" folder.
My suggestion is simply that electron-packager respects the
The API is the Additionally, if really really needed, electron-packager could have some Let me know if there's more. |
I forgot to say that this has little to do with npm, and everything to do with package.json . The fact that |
Any news here? Please give me an example to exclude everything except one folder i.e. "dist". |
@LordMidi did you find a solution for the regex? |
@HaimBendanan No - but I use a package script instead. This removes everything that should not be included. See all options: https://github.com/electron/electron-packager/blob/master/docs/api.md const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const packager = require('electron-packager');
const packagerOptions = {
dir: '.',
out: 'dist_electron',
platform: 'win32',
overwrite: true,
asar: true,
afterCopy: [
cleanSources
]
};
packager(packagerOptions).then(outPath => {
console.log(`build path: ${outPath}`);
});
// remove folders & files not to be included in the app
function cleanSources(buildPath, electronVersion, platform, arch, callback) {
// folders & files to be included in the app
const appItems = [
'dist',
'electron',
'main.js',
'node_modules'
];
fs.readdirSync(buildPath).filter((item) => {
return appItems.indexOf(item) === -1
}).forEach((item) => {
rimraf.sync(path.join(buildPath, item));
});
console.log('removed folders & files not to be included in the app');
callback();
} |
I ended up using electron-builder, which support a 'files' attribute for added dependencies- but thanks anyway :) |
I made an attempt to implement this over the US holiday weekend. The simple case works fine (top-level files/folders), but once you start trying to handle complex globs, the amount of code that would need to be written on the Electron Packager side in order for it to work with The alternative is to use the |
That would require effectively reimplementing recursive copy, which I don't want to write or maintain. |
Why would it be recursive? fast-glob would give you a flat array of paths like:
... I might be missing something, as I'm not familiar with this project's code. |
It's recursive because you have to also ensure that the directories are created with the same metadata as the original, macOS/Linux permissions for example. In your example, the Turns out |
I looked at
This is different from the |
So using |
That has the same problem as #972 (comment):
It would be much cleaner to use |
Oh, I thought that copying Anyway, hopefully a solution will be found soon, because blacklisting is far from ideal. |
I believe the perceived problem stems from the horrible Electron convention to mix distributable source files (e.g. A better convention is to put your distributable source files in a separate directory, e.g. (Also, if you really want a whitelist, note that |
👋 I was able to get the regex to work using |
That works great! However I'm a little confused as to what's happening because in the docs it says it's matched against the absolute path. Maybe I'm not understanding something or the docs are simply wrong. |
Preflight Checklist
Problem Description
AFAICS (apologies if I missed smth) electron-packager has a way to ignore paths from getting copied to the output artifact, but blacklisting is a risky way to decide what goes in. Add a file with sensitive info to the repo, forget to add it to ignore, and BAM!
A whitelist is stable and does answer directly the question: what goes into the artifact?
Proposed Solution
In the best of worlds, you should just follow
npm pack
, meaning respect thefiles
section inpackage.json
, and if none - respect the.npmignore
(or just stick to the current--ignore
flag).The text was updated successfully, but these errors were encountered: