Hello,
There are two problems. The first one is that the regedit module is not saved automatically in app.asar.unpacked
The second problem is that it's not really working even if I set manually the asarUnpack value.
builder.build ({
// blabla
config: {
asarUnpack: [
'**node_modules/regedit/**',
],
}
// blabla
})
The regedit module spawn/exec (I don't know exactly) wsf and vbs scripts.
In the win.asar.unpacked directory I can find this module with all files. It looks perfect...
C:\blabla\win-ia32-unpacked\resources\app.asar.unpacked\node_modules\regedit.
But when executing.. it's not working at all...
Input Error: Can not find script file "C:\blabla\win-ia32-unpacked\resources\app.asar\node_modules\regedit\vbs\regList.wsf".
Why the spawn/exec calls are not looking in the app.asar.unpacked directory? asarUnpack seems useless if it's necessary to handle manually the location for the spawns. I'm doing something wrong?
Thanks for help
Regards
'node_modules/regedit/'
Please change to '**/node_modules/regedit/**/*'
@develar It changes nothing.. same results.. it looks for app.asar instead of app.asar.unpacked.
I can create a package with electron-builder and regedit if you want to reproduce?!
@Skywalker13 Are you sure that the whole dir regedit is unpacked? According to https://github.com/ironSource/node-regedit/blob/fb00769991f28ab0c65697b6a3a52667be2e4147/index.js#L325 should be ok.
I can create a package with electron-builder and regedit if you want to reproduce?!
will be helpful
@develar
Here a complete sample in order to reproduce.. test.zip
There are only two files:
package.json
{
"name": "test",
"productName": "test",
"description": "test",
"author": "test",
"version": "0.0.1",
"main": "index.js",
"scripts": {
"pack": "build --dir",
"dist": "build"
},
"build": {
"appId": "com.test.id",
"asarUnpack": [
"**/node_modules/regedit/**/*"
]
},
"dependencies": {
"regedit": "^2.2.6"
},
"devDependencies": {
"electron": "^1.4.14",
"electron-builder": "^11.3.0"
}
}
index.js
'use strict';
const regedit = require ('regedit');
regedit.list ('HKCU\\SOFTWARE', function (err, result) {
if (err) {
console.error (err);
process.exit (1);
}
console.dir (result);
process.exit (0);
});
Outputs:
npm i
C:\Users\DevBox2\Documents\devel\test>npm i
> [email protected] postinstall C:\Users\DevBox2\Documents\devel\test\node_modules\electron
> node install.js
[email protected] C:\Users\DevBox2\Documents\devel\test
+-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | | `-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | | `-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | | +-- [email protected]
| | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | `-- [email protected]
| | | +-- [email protected]
| | | | +-- [email protected]
| | | | `-- [email protected]
| | | | +-- [email protected]
| | | | `-- [email protected]
| | | | `-- [email protected]
| | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | | +-- [email protected]
| | | | | | +-- [email protected]
| | | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | | `-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | | `-- [email protected]
| | | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | `-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| `-- [email protected]
| `-- [email protected]
| `-- [email protected]
+-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | | `-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | | `-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | | `-- [email protected]
| | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | | +-- [email protected]
| | | | | `-- [email protected]
| | | | +-- [email protected]
| | | | +-- [email protected]
| | | | `-- [email protected]
| | | | `-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| | +-- [email protected]
| | | +-- [email protected]
| | | `-- [email protected]
| | | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| +-- [email protected]
| | +-- [email protected]
| | `-- [email protected]
| | `-- [email protected]
| +-- [email protected]
| +-- [email protected]
| `-- [email protected]
| `-- [email protected]
`-- [email protected]
+-- [email protected]
| `-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
+-- [email protected]
| +-- [email protected]
| +-- [email protected]
| `-- [email protected]
`-- [email protected]
npm WARN optional Skipping failed optional dependency /7zip-bin/7zip-bin-mac:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN optional Skipping failed optional dependency /7zip-bin/7zip-bin-linux:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.
pack:
C:\Users\DevBox2\Documents\devel\test>npm run pack
> [email protected] pack C:\Users\DevBox2\Documents\devel\test
> build --dir
No native production dependencies
Packaging for win32 x64 using electron 1.4.14 to dist\win-unpacked
β οΈ Application icon is not set, default Electron icon will be used
run test.exe:
C:\Users\DevBox2\Documents\devel\test>cd dist\win-unpacked
C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked>test.exe
C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked>
Input Error: Can not find script file "C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked\resources\app.asar\node_modules\regedit\vbs\regList.wsf".
{ Error: Command failed: cscript.exe //Nologo C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked\resources\app.asar\node_modules\regedit\vbs\regList.wsf A HKCU\SOFTWARE
at ChildProcess.exithandler (child_process.js:218:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:877:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
killed: false,
code: 1,
signal: null,
cmd: 'cscript.exe //Nologo C:\\Users\\DevBox2\\Documents\\devel\\test\\dist\\win-unpacked\\resources\\app.asar\\node_modules\\regedit\\vbs\\regList.wsf A HKCU\\SOFTWARE' }
undefined
Folder content:
C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked>cd resources
C:\Users\DevBox2\Documents\devel\test\dist\win-unpacked\resources>tree /F
Folder PATH listing for volume system
Volume serial number is 688C-B0FB
C:.
β app.asar
β electron.asar
β
ββββapp.asar.unpacked
ββββnode_modules
ββββregedit
β .npmignore
β errors.js
β index.js
β LICENSE
β package.json
β
ββββlib
β cscript.js
β execFile.js
β helper.js
β
ββββvbs
β ArchitectureAgnosticRegistry.vbs
β ArchitectureSpecificRegistry.vbs
β JsonSafeTest.wsf
β regCreateKey.wsf
β regDeleteKey.wsf
β regList.wsf
β regListStream.wsf
β regPutValue.wsf
β regUtil.vbs
β util.vbs
β
ββββwinerrors
error.txt
generatedErrorObjects.js
generateErrorDeclaration.js
generateErrorsJS.js
parsed.json
parseErrors.js
run.sh
@develar Sorry, forget my last message (deleted here) if you have received this one by email, I was requiring the bad module, it works with node-notifier.
@develar now I understand why it works with notifier (for example) but not with regedit.
node electron is able to find an executable file automatically with spawn/exec by looking in asar.unpacked. But __dirname is always "wrong" (for this purpose). It points to asar every time. The "magic" seems in the node electron lib like child_process.
I've tried a stupid script like this (I've a copy of dir.exe in my test module):
'use strict';
const path = require ('path');
const {execSync} = require ('child_process');
console.log (__dirname);
const dir = path.join (__dirname, 'dir.exe');
process.stdout.write (execSync (`dir c:\\`, {shell: true}));
with:
"build": {
"appId": "com.test.id",
"asarUnpack": [
"*.exe"
]
},
dir.exe is in asar.unpacked and execFile is working fine.
In the case of regedit, the path.join () with __dirname is used as argument for the spawn of cscript.exe. Of course, cscript.exe can not find the vbs script directly with the asar file.
IMO, the bug is that when __dirname is used in path functions like path.join, the result is not pointing on the real physical file but on the virtual filesystem even when the pointed file is unpacked. Maybe it should be fixed in the node electron path module directly.
It means that asarUnpack is useful only for files passed to exec/spawn functions.
Edit
Similar problem with a PNG file in the notifier module with an ugly hack where asar is replaced by asar.unpacked. https://github.com/electron/electron/issues/6262
It seems unacceptable because it needs to modify the modules in order to be usable with asar.
@Skywalker13 Strange. I am not aware of that. Probably you can use extraResources option and add this directory to search path require('module').globalPaths.push(YOUR_PATH);
@develar thanks, it looks like a good workaround
Btw β may be you just need write custom nsis installer script instead of using regedit node module.
I'm already working with Squirrel.Windows and the app is in production. I'm changing from electron-packager + electron-winstaller to electron-builder in order to support properly macOS and Linux too. Changing for NSIS breaks the auto-update for our customers.
I'm using regedit in the squirrel script and I use a module which uses regedit too to retrieve regional settings on Windows. Then, it's not used only for installing.
@develar I've make a module in order to handle this problem with only one line of code to add in the electron project, see https://github.com/epsitec-sa/hazardous
For example, with my sample:
'use strict';
require ('hazardous');
const regedit = require ('regedit');
regedit.list ('HKCU\\SOFTWARE', function (err, result) {
if (err) {
console.error (err);
process.exit (1);
}
console.dir (result);
process.exit (0);
});
The only thing to do is to add require ('hazardous'); at the beginning of the main script of the app. Then, the functions join(), resolve() and normalize() can return the unpacked location according to some conditions; just read the README for details.
It feels like the hazardous library should be the normal behavior for these functions. Is there a reason it's not?
In our case we're exec'ing a java on the system and running a JAR file that's packaged with the app. It's convoluted but saved us development effort by not having to rewrite some functions in node.
When actually this will be fixed, so no need any shaman magic with node_modules?
Most helpful comment
@develar I've make a module in order to handle this problem with only one line of code to add in the electron project, see https://github.com/epsitec-sa/hazardous
For example, with my sample:
The only thing to do is to add
require ('hazardous');at the beginning of the main script of the app. Then, the functionsjoin(),resolve()andnormalize()can return the unpacked location according to some conditions; just read the README for details.