Skip to content
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

createWindowsInstaller Fails Writing to temp/*.nuspec File When "/" in Package Name #503

Open
brandonegg opened this issue Mar 11, 2024 · 0 comments

Comments

@brandonegg
Copy link

brandonegg commented Mar 11, 2024

Background

I don't use this package directly, however I encountered this issue with the @electron-forge/maker-squirrel package. After some investigation I believe the issue resides within this package. The error in question is the following:

No dice: ENOENT: no such file or directory, open 'C:\Users\brand\AppData\Local\Temp\si-2024211-6524-qimd4y.k3l7a\@demo\electron-app.nuspec'

This step occurs when windows-installer is attempting to write the *.nuspec file to the temp directory.

Reproduce

Environment

Windows 11: 23H2
Node: v18.19.1
Npm: 10.2.4

I have created a repository which uses the base electron webpack template and includes steps for reproducing: https://github.com/brandonegg/electron-winstaller-demo?tab=readme-ov-file#environment

The variable which appears to be linked to the error is the "name" key inside of package.json. When the name contains a "/" character the createWindowsInstaller function fails with the message included above. If the forward slash is removed from the name, the function produces no errors.

Analysis

I found this line:

const targetNuspecPath = path.join(nugetOutput, metadata.name + '.nuspec');

I believe this is the issue, specifically because of the following behavior which occurs with path.join().

console.log(path.join(__dirname, '@demo/electron-app-win32-x64'));
# output: C:\Users\brand\Documents\my-new-app\@demo\electron-app-win32-x64

node's path.join() is trying to be clever when joining the path and replaces the "/" with a "\". When this path is used by fs.writeFile() on line 150 it is trying to write to a directory that does not exist.

Proposed Solution

As someone who is not very familiar with the low-level interworkings of native node-api's I wanted to present this issue to the maintainers prior to developing my own solution. A simple approach would be a regex to match & replace any of these known troublesome characters with a "-" (I see squirrel doesn't like this) or "_". This appears to be how electron-forge package is producing its artifacts. The output directory is named @demo-electron-app-{platform}-{arch}, aka they replaced "/" with "-". I would be happy to create a PR for this if this sounds like a good work around. I would assume since this is only a temp output directory the naming convention isn't too important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant