This is not the usual stupid .wsf files missing in production build question.
I am using regedit 5.1.3 with an electron-forge application together with webpack and react (no typescript). I get the error
Input Error: Can not find script file "C:UsersalexDesktopprojectdirundefinedvbsregList.wsf"
I have set the custom vbs location like this:
regedit.setExternalVBSLocation(path.join(process.cwd(), "/resources/vbs/"))
I checked 100 times for the path and they are all ok.
Lets take a look at the definitioin of setExternalVBSLocation
inside the regedit library
module.exports.setExternalVBSLocation = function(newLocation) {
if (fs.existsSync(newLocation)) {
externalVBSFolderLocation = newLocation
return 'Folder found and set'
}
return 'Folder not found'
}
The function should return 'Folder found and set'
if the setting went succesfully and 'Folder not found'
if it didn’t.
I console logged the calling of the function like so:
console.log(regedit.setExternalVBSLocation(path.join(process.cwd(), "/resources/vbs/")))
An indeed i get Folder found and set
!
Now lets take a look at the definition of baseCommand
where the actual sauce is happening. This function is called everytime a modification has to be performed to the registry:
function baseCommand(cmd, arch) {
let scriptPath
// test undefined, null and empty string
if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
scriptPath = externalVBSFolderLocation
} else {
scriptPath = path.join(__dirname, 'vbs')
}
return ['//Nologo', path.join(scriptPath, cmd), arch]
}
Focus on the first if condition. According to my situation the condition should be true and it is because i can log to the console before the attribution to scriptPath
:
...
if (externalVBSFolderLocation && typeof(externalVBSFolderLocation) === 'string') {
console.log(externalVBSFolderLocation) // <-- logging works
scriptPath = externalVBSFolderLocation
console.log(scriptPath) // Logs: "C:UsersalexDesktopprojectdirresourcesvbs"
}
...
As you can see everything is normal until i console.log(scriptPath)
before the return of baseCommand
function:
...
console.log(scriptPath) // Logs some total BULL$HIT: "undefinedvbs"
return ['//Nologo', path.join(scriptPath, cmd), arch]
}
What in the WORLD is happening. Why the value of scriptPath
is different right after it has been attributed?
If I modify the baseCommand
function to:
function baseCommand(cmd, arch) {
return ['//Nologo', path.join(externalVBSFolderLocation, cmd), arch]
}
Everything works like a charm without all those conditions. The problem is that i have to modify the internal code of the package to get it to work…
I want to understand better what is going on with the scriptPath variable. This is a very strange behaviour that I have never seen in programming!