electron / electron/windows-installer

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

Open
#503 3 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.6k
Forks
267
Avg merge
5h 38m
Merged PRs (30d)
1

Description

## 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: https://github.com/electron/windows-installer/blob/598aa70da25b4446dd816d0bd97fa7786bdfe79f/src/index.ts#L148

I believe this is the issue, specifically because of the following behavior which occurs with path.join().
```js
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.