Skip to content

Commit c1bb030

Browse files
committed
change default versionjson path, modify LocalDevProvider
1 parent c693320 commit c1bb030

File tree

7 files changed

+22
-35
lines changed

7 files changed

+22
-35
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ updater.provider = new GitHubProvider({
352352
})
353353
```
354354

355-
Or use built-in `LocalDevProvider`
355+
Or use built-in `LocalDevProvider`:
356+
357+
- download update json from `{baseDir}/{versionPath}`
358+
- download update asar from `{baseDir}/{name}-{version}.asar.gz`
356359

357360
```ts
358361
const provider = new LocalDevProvider({

src/entry/updater.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { app } from 'electron'
22
import { EventEmitter } from 'node:events'
33
import fs from 'node:fs'
44

5-
import type {
6-
DownloadingInfo,
7-
IProvider,
8-
UpdateInfoWithURL,
9-
UpdateJSONWithURL,
10-
} from '../provider/types'
5+
import type { DownloadingInfo, IProvider, UpdateInfoWithURL, VersionJSON } from '../provider/types'
116
import type {
127
Logger,
138
UpdateInfoWithExtraVersion,
@@ -92,10 +87,7 @@ export class Updater<
9287
* if data is absent, download URL from provider and return it,
9388
* else if data is `UpdateJSON`, return it
9489
*/
95-
private async fetch(
96-
format: 'json',
97-
data?: UpdateJSONWithURL,
98-
): Promise<UpdateJSONWithURL | undefined>
90+
private async fetch(format: 'json', data?: VersionJSON): Promise<VersionJSON | undefined>
9991
/**
10092
* This function is used to parse download data.
10193
*
@@ -105,7 +97,7 @@ export class Updater<
10597
* @param data download URL or update json or buffer
10698
*/
10799
private async fetch(format: 'buffer', data?: Buffer): Promise<Buffer | undefined>
108-
private async fetch(format: 'json' | 'buffer', data?: Buffer | UpdateJSONWithURL): Promise<any> {
100+
private async fetch(format: 'json' | 'buffer', data?: Buffer | VersionJSON): Promise<any> {
109101
if (typeof data === 'object') {
110102
if (
111103
(format === 'json' && isUpdateJSON(data)) ||

src/provider/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DownloadingInfo, IProvider, UpdateInfoWithURL, UpdateJSONWithURL } from './types'
1+
import type { DownloadingInfo, IProvider, UpdateInfoWithURL, VersionJSON } from './types'
22

33
import { defaultVerifySignature } from '../utils/crypto'
44
import { defaultIsLowerVersion } from '../utils/version'
@@ -26,7 +26,7 @@ export abstract class BaseProvider implements IProvider {
2626
name: string,
2727
versionPath: string,
2828
signal: AbortSignal,
29-
): Promise<UpdateJSONWithURL>
29+
): Promise<VersionJSON>
3030

3131
/**
3232
* @inheritdoc

src/provider/github/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Promisable } from '@subframe7536/type-utils'
22

33
import { URL } from 'node:url'
44

5-
import type { DownloadingInfo, UpdateInfoWithURL, UpdateJSONWithURL, URLHandler } from '../types'
5+
import type { DownloadingInfo, UpdateInfoWithURL, VersionJSON, URLHandler } from '../types'
66

77
import { defaultDownloadAsar, defaultDownloadUpdateJSON } from '../../utils/download'
88
import { BaseProvider } from '../base'
@@ -63,7 +63,7 @@ export abstract class BaseGitHubProvider<
6363
name: string,
6464
versionPath: string,
6565
signal: AbortSignal,
66-
): Promise<UpdateJSONWithURL> {
66+
): Promise<VersionJSON> {
6767
const { beta, version, ...info } = await defaultDownloadUpdateJSON(
6868
await this.parseURL(await this.getVersionURL(versionPath, signal)),
6969
this.getHeaders('json'),

src/provider/local.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Buffer } from 'node:buffer'
33
import fs from 'node:fs/promises'
44
import path from 'node:path'
55

6-
import type { DownloadingInfo, UpdateInfoWithURL, UpdateJSONWithURL } from './types'
6+
import type { DownloadingInfo, UpdateInfoWithURL, VersionJSON } from './types'
77

88
import { isUpdateJSON } from '../utils'
99
import { BaseProvider } from './base'
@@ -13,17 +13,12 @@ export interface LocalDevProviderOptions {
1313
* Base directory for update files
1414
*/
1515
baseDir: string
16-
/**
17-
* App name (used for constructing file paths)
18-
*/
19-
appName?: string
2016
}
2117

2218
/**
2319
* Update Provider for local development
24-
* - check update from local file system
25-
* - download update json and get version and download url
26-
* - download update asar from local file system
20+
* - download update json from `{baseDir}/{versionPath}`
21+
* - download update asar from `{baseDir}/{name}-{version}.asar.gz`
2722
*
2823
* This provider is useful for testing updates during development without
2924
* needing to deploy to a remote server.
@@ -43,14 +38,15 @@ export class LocalDevProvider extends BaseProvider {
4338
name: string,
4439
versionPath: string,
4540
signal: AbortSignal,
46-
): Promise<UpdateJSONWithURL> {
41+
): Promise<VersionJSON> {
4742
signal.throwIfAborted()
4843

49-
const { beta, version, ...info } = await this.readJSON(versionPath)
44+
const { beta, version, ...info } = await this.readJSON(
45+
path.join(this.options.baseDir, versionPath),
46+
)
5047

51-
const getAppName = this.options.appName || name
5248
const getURL = (ver: string): string =>
53-
path.join(this.options.baseDir, `${getAppName}-${ver}.asar.gz`)
49+
path.join(this.options.baseDir, `${name}-${ver}.asar.gz`)
5450

5551
return {
5652
...info,

src/provider/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface DownloadingInfo {
3131
bps: number
3232
}
3333

34-
export type UpdateJSONWithURL = UpdateInfoWithURL & { beta: UpdateInfoWithURL }
34+
export type VersionJSON = UpdateInfoWithURL & { beta: UpdateInfoWithURL }
3535

3636
export interface IProvider {
3737
/**
@@ -44,11 +44,7 @@ export interface IProvider {
4444
* @param versionPath normalized version path in project
4545
* @param signal abort signal
4646
*/
47-
downloadJSON: (
48-
name: string,
49-
versionPath: string,
50-
signal: AbortSignal,
51-
) => Promise<UpdateJSONWithURL>
47+
downloadJSON: (name: string, versionPath: string, signal: AbortSignal) => Promise<VersionJSON>
5248
/**
5349
* Download update asar buffer
5450
* @param updateInfo existing update info

src/vite/option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export async function parseUpdaterOption(
348348
entryOutDir = 'dist-entry',
349349
electronDistPath = 'dist-electron',
350350
rendererDistPath = 'dist',
351-
versionPath = 'version.json',
351+
versionPath = 'release/version.json',
352352
} = {},
353353
keys: {
354354
privateKeyPath = 'keys/private.pem',

0 commit comments

Comments
 (0)