electron / electron/forge

`@electron-forge/maker-zip` should have `keyResolver` for `macUpdateManifestBaseUrl` file URLs

Open
#3,379 0 comments 0 reactions 0 assignees View on GitHub
maker/zip
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] I have searched the issue tracker for a feature request that matches the one I want to file, without success.

### Problem description

I'm using `@electron-forge/publisher-s3` and have `keyResolver` set in `forge.config.ts`:
```ts
publishers: [
{
// https://www.electronforge.io/config/publishers/s3
name: "@electron-forge/publisher-s3",
config: {
endpoint: `https://${process.env.PUBLISH_S3_URL}`,
bucket: process.env.PUBLISH_S3_BUCKET,
region: "us-east-1",
public: true,
keyResolver: (fileName: string, platform: string, arch: string) =>
getS3FilePath(
platform,
arch,
pkg.version,
fileName.split(".").pop()!,
),
},
},
]
```

`getS3FilePath` results in something like:
```
https://my-bucket.s3.amazonaws.com/releases/darwin/arm64/my-electron-app-1.0.0.zip
```

Now, we want to use `@electron-forge/maker-zip` with the `macUpdateManifestBaseUrl` but it will use the default path that `@electron-forge/publisher-s3` would use.

In `forge.config.ts`:
```ts
makers: [
new MakerZIP((arch) => ({
macUpdateManifestBaseUrl: `https://my-bucket.s3.amazonaws.com/releases/darwin/${arch}`
]
```

This results in the following `RELEASES.json` file:
```
{
"currentRelease": "1.0.0",
"releases": [
{
"version": "1.0.0",
"updateTo": {
"name": "My Electron App v1.0.0",
"version": "1.0.0",
"pub_date": "2023-10-10T18:00:07.611Z",
"url": "https://my-bucket.s3.amazonaws.com/releases/darwin/arm64/My%20Electron%20App-darwin-arm64-1.0.0.zip",
"notes": ""
}
}
]
}

```

This doesn't match up with where the bundle is actually uploaded to S3 using `@electron-forge/publisher-s3`.

### Proposed solution

Allow passing a function as `urlKeyResolver` like `keyResolver` in `@electron-forge/publisher-s3`

The `platform` parameter isn't needed since it will always be `darwin`, the `arch` parameter isn't needed since that's passed in via the maker options.

`fileName` will be the name of the file being written.

```ts
makers: [
new MakerZIP((arch) => ({
macUpdateManifestBaseUrl: `https://my-bucket.s3.amazonaws.com/releases/darwin/${arch}`,
urlKeyResolver: (fileName: string) =>
getS3FilePath(
"darwin",
arch,
pkg.version,
fileName.split(".").pop()!,
)
]
```

Then, when writing the `url` into `RELEASES.json`, it will go through that instead.

### Alternatives considered

Removing `keyResolver` from `@electron-forge/publisher-s3` will cause the two to match up, but we'd like more control over the file names.

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.