Please describe your issue:
I want to exclude some folders from electron-forge package compilation. The /dist/ folder is mostly empty, followed the instruction https://www.electron.build/file-patterns i want to exclude empty folder /dist/, another not empty folders and some files as follows:
"electronPackagerConfig": {
"packageManager": "npm",
"afterExtract": [
"crv/build-scripts/afterExtract.js"
],
"asar": true,
"overwrite": true,
"ignore": [
"/apps/",
"/dist${/*}",
"/libs/",
"/out/",
"/out-tsc/",
"/scripts/",
"/styles/",
"/themes/",
"/angular.json",
"/package-lock.json",
"/tsconfig.json",
"/tslint.json",
"/.editorconfig",
"/.gitignore",
"/README.md"
]
},
The compiler throws an error:
Console output when you run electron-forge with the environment variable DEBUG=electron-forge:*. (Instructions on how to do so here). Please include the stack trace if one exists.
> [email protected] electron-package-debug-win C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA
> set DEBUG=electron-forge:* & electron-forge package
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Checking your system +0ms
electron-forge:lifecycle Process Succeeded: Checking your system +2s
electron-forge:runtime-config setting key: verbose to value: false +0ms
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Preparing to Package Application for arch: x64 +0ms
electron-forge:project-resolver searching for project in: C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA +0ms
electron-forge:project-resolver electron-forge compatible package.json found in C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\package.json +6ms
An unhandled rejection has occurred inside Forge:
Invalid or unexpected token
SyntaxError: Invalid or unexpected token
at Function (<anonymous>)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:1089:12
at apply (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:74:25)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:1126:12
at apply (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:76:25)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:317:12
at template (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\lodash.template\index.js:1088:16)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:142:46
at Array.forEach (<anonymous>)
at template (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:138:32)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:140:11
at Array.forEach (<anonymous>)
at template (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:138:32)
at C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:140:11
at Array.forEach (<anonymous>)
at template (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-forge\dist\util\forge-config.js:138:32)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] electron-package-debug-win: `set DEBUG=electron-forge:* & electron-forge package`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] electron-package-debug-win script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Krzysztof\AppData\Roaming\npm-cache\_logs\2019-06-04T14_20_33_012Z-debug.log
What command line arguments are you passing?
Put the arguments here
What does your config.forge data in package.json look like?
"config": {
"forge": {
"make_targets": {
"win32": [
"squirrel"
],
"darwin": [
"zip"
],
"linux": [
"deb",
"rpm"
]
},
"electronPackagerConfig": {
"packageManager": "npm",
"afterExtract": [
"crv/build-scripts/afterExtract.js"
],
"asar": true,
"overwrite": true,
"ignore": [
"/apps/",
"/dist${/*}",
"/libs/",
"/out/",
"/out-tsc/",
"/scripts/",
"/styles/",
"/themes/",
"/angular.json",
"/package-lock.json",
"/tsconfig.json",
"/tslint.json",
"/.editorconfig",
"/.gitignore",
"/README.md"
]
},
"electronWinstallerConfig": {
"name": "crv"
},
"electronInstallerDebian": {},
"electronInstallerRedhat": {},
"github_repository": {
"owner": "",
"name": ""
},
"windowsStoreConfig": {
"packageName": "",
"name": "crv"
}
}
},
Please provide either a failing minimal testcase (with a link to the code) or detailed steps to
reproduce your problem. Using electron-forge init is a good starting point, if that is not the
source of your problem.
When I change the /dist${/*} part to /dist/** in the config as follow:
"ignore": [
"/apps/",
"/dist/**",
"/libs/",
"/out/",
"/out-tsc/",
"/scripts/",
"/styles/",
"/themes/",
"/angular.json",
"/package-lock.json",
"/tsconfig.json",
"/tslint.json",
"/.editorconfig",
"/.gitignore",
"/README.md"
]
},
compiler throws the error:
> set DEBUG=electron-forge:* & electron-forge package
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Checking your system +0ms
electron-forge:lifecycle Process Succeeded: Checking your system +2s
electron-forge:runtime-config setting key: verbose to value: false +0ms
WARNING: DEBUG environment variable detected. Progress indicators will be sent over electron-forge:lifecycle
electron-forge:lifecycle Process Started: Preparing to Package Application for arch: x64 +0ms
electron-forge:project-resolver searching for project in: C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA +0ms
electron-forge:project-resolver electron-forge compatible package.json found in C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\package.json +6ms
electron-forge:require-search searching [ 'crv/build-scripts/afterExtract.js',
'C:\\ZNF_SandBox2\\Mvc\\StorkCMS\\Stork.SPA\\crv\\build-scripts\\afterExtract.js',
'C:\\ZNF_SandBox2\\Mvc\\StorkCMS\\Stork.SPA\\node_modules\\crv\\build-scripts\\afterExtract.js' ] relative to C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA +0ms
electron-forge:require-search testing crv/build-scripts/afterExtract.js +4ms
electron-forge:require-search testing C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\crv\build-scripts\afterExtract.js +2ms
electron-forge:hook could not find hook: generateAssets +0ms
electron-forge:hook could not find hook: prePackage +1ms
electron-forge:packager packaging with options { asar: true,
overwrite: true,
packageManager: 'npm',
afterExtract: [ [Function] ],
ignore:
[ '/apps/',
'/dist/**',
'/libs/',
'/out/',
'/out-tsc/',
'/scripts/',
'/styles/',
'/themes/',
'/angular.json',
'/package-lock.json',
'/tsconfig.json',
'/tslint.json',
'/.editorconfig',
'/.gitignore',
'/README.md' ],
afterCopy: [ [Function] ],
afterPrune: [ [Function] ],
dir: 'C:\\ZNF_SandBox2\\Mvc\\StorkCMS\\Stork.SPA',
arch: 'x64',
platform: 'win32',
out: 'C:\\ZNF_SandBox2\\Mvc\\StorkCMS\\Stork.SPA\\out',
electronVersion: '4.0.0',
quiet: true } +0ms
Database successfully copied!
An unhandled rejection has occurred inside Forge:
Invalid regular expression: //dist/**/: Nothing to repeat
SyntaxError: Invalid regular expression: //dist/**/: Nothing to repeat
at String.match (<anonymous>)
at ignore.some.regex (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\ignore.js:65:41)
at Array.some (<anonymous>)
at filterByRegexes (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\ignore.js:65:22)
at Object.filter (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\ignore.js:83:12)
at handleFilter (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\node_modules\fs-extra\lib\copy\copy.js:60:24)
at Object.copy (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\node_modules\fs-extra\lib\copy\copy.js:38:27)
at Promise (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\universalify\index.js:13:12)
at new Promise (<anonymous>)
at Object.copy (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\universalify\index.js:7:14)
at WindowsApp.copyTemplate (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\platform.js:102:15)
at fs.move.then (C:\ZNF_SandBox2\Mvc\StorkCMS\Stork.SPA\node_modules\electron-packager\platform.js:90:24)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] electron-package-debug-win: `set DEBUG=electron-forge:* & electron-forge package`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] electron-package-debug-win script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Krzysztof\AppData\Roaming\npm-cache\_logs\2019-06-04T14_33_31_882Z-debug.log
How to exclude empty folders?
followed the instruction https://www.electron.build/file-patterns
First off, that website is for electron-builder, not Electron Forge.
Secondly, per the Electron Packager API docs, ignore takes RegExps, not globs.
Do you have an idea how to use RegExp in package.json? No example found in the provided link
"ignore": [
want to exclude empty folder(s)
]
Thank you!
Since ignore also works for the Electron Packager CLI, Strings which are regular expressions are accepted.
I can find the folder name with regular expression, but when the folder is empty exception is thrown:
SyntaxError: Invalid regular expression: //dist/**/: Nothing to repeat
Is there another way to exclude empty folders? Thanks.
A couple of things:
/, that's only for RegExp literals./dist/** is not a regular expression, it's a glob pattern. You want /dist/ which checks for the dist folder name. If that doesn't work, replace the last / with a $. For more information on JavaScript regular expressions, check out the MDN web docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExpThank you very much for your help. My final solution looks as follow:
"ignore": [
"^(\/apps$)",
"^(\/dist$)",
"^(\/libs$)",
"^(\/out$)",
"^(\/out-tsc$)",
"^(\/scripts$)",
"^(\/styles$)",
"^(\/themes$)",
".editorconfig",
".gitignore",
"angular.json",
"package-lock.json",
"^(\/README.md$)",
"Stork.SPA.njsproj",
"Stork.SPA.njsproj.user",
"tsconfig.json",
"tslint.json"
]
It's important to take only the first folder in the hierarchy, otherwise all folders with the same name in node_modules are ignored. It was the big mistake in my attempts.
Most helpful comment
Thank you very much for your help. My final solution looks as follow:
It's important to take only the first folder in the hierarchy, otherwise all folders with the same name in node_modules are ignored. It was the big mistake in my attempts.