electron-updater 4.3.8 → 4.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +22 -0
  2. package/out/AppAdapter.js +19 -28
  3. package/out/AppAdapter.js.map +1 -1
  4. package/out/AppImageUpdater.js +103 -195
  5. package/out/AppImageUpdater.js.map +1 -1
  6. package/out/AppUpdater.d.ts +1 -1
  7. package/out/AppUpdater.js +517 -771
  8. package/out/AppUpdater.js.map +1 -1
  9. package/out/BaseUpdater.js +79 -103
  10. package/out/BaseUpdater.js.map +1 -1
  11. package/out/DownloadedUpdateHelper.js +150 -223
  12. package/out/DownloadedUpdateHelper.js.map +1 -1
  13. package/out/ElectronAppAdapter.js +35 -63
  14. package/out/ElectronAppAdapter.js.map +1 -1
  15. package/out/MacUpdater.js +132 -201
  16. package/out/MacUpdater.js.map +1 -1
  17. package/out/NoOpLogger.d.ts +6 -0
  18. package/out/NoOpLogger.js +19 -0
  19. package/out/NoOpLogger.js.map +1 -0
  20. package/out/NsisUpdater.js +199 -345
  21. package/out/NsisUpdater.js.map +1 -1
  22. package/out/differentialDownloader/DataSplitter.js +180 -252
  23. package/out/differentialDownloader/DataSplitter.js.map +1 -1
  24. package/out/differentialDownloader/DifferentialDownloader.d.ts +1 -1
  25. package/out/differentialDownloader/DifferentialDownloader.js +242 -355
  26. package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
  27. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
  28. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
  29. package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
  30. package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
  31. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +79 -107
  32. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -1
  33. package/out/differentialDownloader/downloadPlanBuilder.js +99 -123
  34. package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
  35. package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
  36. package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
  37. package/out/electronHttpExecutor.js +73 -106
  38. package/out/electronHttpExecutor.js.map +1 -1
  39. package/out/event.d.ts +35 -0
  40. package/out/event.js +39 -0
  41. package/out/event.js.map +1 -0
  42. package/out/log.d.ts +11 -0
  43. package/out/log.js +19 -0
  44. package/out/log.js.map +1 -0
  45. package/out/main.d.ts +1 -3
  46. package/out/main.js +60 -196
  47. package/out/main.js.map +1 -1
  48. package/out/providerFactory.js +49 -105
  49. package/out/providerFactory.js.map +1 -1
  50. package/out/providers/BintrayProvider.d.ts +2 -2
  51. package/out/providers/BintrayProvider.js +40 -95
  52. package/out/providers/BintrayProvider.js.map +1 -1
  53. package/out/providers/GenericProvider.d.ts +2 -2
  54. package/out/providers/GenericProvider.js +46 -80
  55. package/out/providers/GenericProvider.js.map +1 -1
  56. package/out/providers/GitHubProvider.d.ts +2 -2
  57. package/out/providers/GitHubProvider.js +122 -201
  58. package/out/providers/GitHubProvider.js.map +1 -1
  59. package/out/providers/PrivateGitHubProvider.js +87 -165
  60. package/out/providers/PrivateGitHubProvider.js.map +1 -1
  61. package/out/providers/Provider.js +122 -173
  62. package/out/providers/Provider.js.map +1 -1
  63. package/out/util.d.ts +5 -0
  64. package/out/util.js +42 -0
  65. package/out/util.js.map +1 -0
  66. package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
  67. package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
  68. package/package.json +33 -31
@@ -1,220 +1,141 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.computeReleaseNotes = computeReleaseNotes;
7
- exports.GitHubProvider = exports.BaseGitHubProvider = void 0;
8
-
9
- function _builderUtilRuntime() {
10
- const data = require("builder-util-runtime");
11
-
12
- _builderUtilRuntime = function () {
13
- return data;
14
- };
15
-
16
- return data;
17
- }
18
-
19
- function semver() {
20
- const data = _interopRequireWildcard(require("semver"));
21
-
22
- semver = function () {
23
- return data;
24
- };
25
-
26
- return data;
27
- }
28
-
29
- function _url() {
30
- const data = require("url");
31
-
32
- _url = function () {
33
- return data;
34
- };
35
-
36
- return data;
37
- }
38
-
39
- function _main() {
40
- const data = require("../main");
41
-
42
- _main = function () {
43
- return data;
44
- };
45
-
46
- return data;
47
- }
48
-
49
- function _Provider() {
50
- const data = require("./Provider");
51
-
52
- _Provider = function () {
53
- return data;
54
- };
55
-
56
- return data;
57
- }
58
-
59
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
60
-
61
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
62
-
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeReleaseNotes = exports.GitHubProvider = exports.BaseGitHubProvider = void 0;
4
+ const builder_util_runtime_1 = require("builder-util-runtime");
5
+ const semver = require("semver");
6
+ const url_1 = require("url");
7
+ const util_1 = require("../util");
8
+ const Provider_1 = require("./Provider");
63
9
  const hrefRegExp = /\/tag\/v?([^/]+)$/;
64
-
65
- class BaseGitHubProvider extends _main().Provider {
66
- constructor(options, defaultHost, runtimeOptions) {
67
- super({ ...runtimeOptions,
68
-
69
- /* because GitHib uses S3 */
70
- isUseMultipleRangeRequest: false
71
- });
72
- this.options = options;
73
- this.baseUrl = (0, _main().newBaseUrl)((0, _builderUtilRuntime().githubUrl)(options, defaultHost));
74
- const apiHost = defaultHost === "github.com" ? "api.github.com" : defaultHost;
75
- this.baseApiUrl = (0, _main().newBaseUrl)((0, _builderUtilRuntime().githubUrl)(options, apiHost));
76
- }
77
-
78
- computeGithubBasePath(result) {
79
- // https://github.com/electron-userland/electron-builder/issues/1903#issuecomment-320881211
80
- const host = this.options.host;
81
- return host != null && host !== "github.com" && host !== "api.github.com" ? `/api/v3${result}` : result;
82
- }
83
-
10
+ class BaseGitHubProvider extends Provider_1.Provider {
11
+ constructor(options, defaultHost, runtimeOptions) {
12
+ super({
13
+ ...runtimeOptions,
14
+ /* because GitHib uses S3 */
15
+ isUseMultipleRangeRequest: false,
16
+ });
17
+ this.options = options;
18
+ this.baseUrl = util_1.newBaseUrl(builder_util_runtime_1.githubUrl(options, defaultHost));
19
+ const apiHost = defaultHost === "github.com" ? "api.github.com" : defaultHost;
20
+ this.baseApiUrl = util_1.newBaseUrl(builder_util_runtime_1.githubUrl(options, apiHost));
21
+ }
22
+ computeGithubBasePath(result) {
23
+ // https://github.com/electron-userland/electron-builder/issues/1903#issuecomment-320881211
24
+ const host = this.options.host;
25
+ return host != null && host !== "github.com" && host !== "api.github.com" ? `/api/v3${result}` : result;
26
+ }
84
27
  }
85
-
86
28
  exports.BaseGitHubProvider = BaseGitHubProvider;
87
-
88
29
  class GitHubProvider extends BaseGitHubProvider {
89
- constructor(options, updater, runtimeOptions) {
90
- super(options, "github.com", runtimeOptions);
91
- this.options = options;
92
- this.updater = updater;
93
- }
94
-
95
- async getLatestVersion() {
96
- const cancellationToken = new (_builderUtilRuntime().CancellationToken)();
97
- const feedXml = await this.httpRequest((0, _main().newUrlFromBase)(`${this.basePath}.atom`, this.baseUrl), {
98
- accept: "application/xml, application/atom+xml, text/xml, */*"
99
- }, cancellationToken);
100
- const feed = (0, _builderUtilRuntime().parseXml)(feedXml);
101
- let latestRelease = feed.element("entry", false, `No published versions on GitHub`);
102
- let version;
103
-
104
- try {
105
- if (this.updater.allowPrerelease) {
30
+ constructor(options, updater, runtimeOptions) {
31
+ super(options, "github.com", runtimeOptions);
32
+ this.options = options;
33
+ this.updater = updater;
34
+ }
35
+ async getLatestVersion() {
36
+ const cancellationToken = new builder_util_runtime_1.CancellationToken();
37
+ const feedXml = (await this.httpRequest(util_1.newUrlFromBase(`${this.basePath}.atom`, this.baseUrl), {
38
+ accept: "application/xml, application/atom+xml, text/xml, */*",
39
+ }, cancellationToken));
40
+ const feed = builder_util_runtime_1.parseXml(feedXml);
106
41
  // noinspection TypeScriptValidateJSTypes
107
- version = latestRelease.element("link").attribute("href").match(hrefRegExp)[1];
108
- } else {
109
- version = await this.getLatestVersionString(cancellationToken);
110
-
111
- for (const element of feed.getElements("entry")) {
112
- if (element.element("link").attribute("href").match(hrefRegExp)[1] === version) {
113
- latestRelease = element;
114
- break;
115
- }
42
+ let latestRelease = feed.element("entry", false, `No published versions on GitHub`);
43
+ let version;
44
+ try {
45
+ if (this.updater.allowPrerelease) {
46
+ // noinspection TypeScriptValidateJSTypes
47
+ version = hrefRegExp.exec(latestRelease.element("link").attribute("href"))[1];
48
+ }
49
+ else {
50
+ version = await this.getLatestVersionString(cancellationToken);
51
+ for (const element of feed.getElements("entry")) {
52
+ // noinspection TypeScriptValidateJSTypes
53
+ if (hrefRegExp.exec(element.element("link").attribute("href"))[1] === version) {
54
+ latestRelease = element;
55
+ break;
56
+ }
57
+ }
58
+ }
116
59
  }
117
- }
118
- } catch (e) {
119
- throw (0, _builderUtilRuntime().newError)(`Cannot parse releases feed: ${e.stack || e.message},\nXML:\n${feedXml}`, "ERR_UPDATER_INVALID_RELEASE_FEED");
120
- }
121
-
122
- if (version == null) {
123
- throw (0, _builderUtilRuntime().newError)(`No published versions on GitHub`, "ERR_UPDATER_NO_PUBLISHED_VERSIONS");
60
+ catch (e) {
61
+ throw builder_util_runtime_1.newError(`Cannot parse releases feed: ${e.stack || e.message},\nXML:\n${feedXml}`, "ERR_UPDATER_INVALID_RELEASE_FEED");
62
+ }
63
+ if (version == null) {
64
+ throw builder_util_runtime_1.newError(`No published versions on GitHub`, "ERR_UPDATER_NO_PUBLISHED_VERSIONS");
65
+ }
66
+ const channelFile = util_1.getChannelFilename(this.getDefaultChannelName());
67
+ const channelFileUrl = util_1.newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl);
68
+ const requestOptions = this.createRequestOptions(channelFileUrl);
69
+ let rawData;
70
+ try {
71
+ rawData = (await this.executor.request(requestOptions, cancellationToken));
72
+ }
73
+ catch (e) {
74
+ if (!this.updater.allowPrerelease && e instanceof builder_util_runtime_1.HttpError && e.statusCode === 404) {
75
+ throw builder_util_runtime_1.newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND");
76
+ }
77
+ throw e;
78
+ }
79
+ const result = Provider_1.parseUpdateInfo(rawData, channelFile, channelFileUrl);
80
+ if (result.releaseName == null) {
81
+ result.releaseName = latestRelease.elementValueOrEmpty("title");
82
+ }
83
+ if (result.releaseNotes == null) {
84
+ result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease);
85
+ }
86
+ return result;
124
87
  }
125
-
126
- const channelFile = (0, _main().getChannelFilename)(this.getDefaultChannelName());
127
- const channelFileUrl = (0, _main().newUrlFromBase)(this.getBaseDownloadPath(version, channelFile), this.baseUrl);
128
- const requestOptions = this.createRequestOptions(channelFileUrl);
129
- let rawData;
130
-
131
- try {
132
- rawData = await this.executor.request(requestOptions, cancellationToken);
133
- } catch (e) {
134
- if (!this.updater.allowPrerelease && e instanceof _builderUtilRuntime().HttpError && e.statusCode === 404) {
135
- throw (0, _builderUtilRuntime().newError)(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, "ERR_UPDATER_CHANNEL_FILE_NOT_FOUND");
136
- }
137
-
138
- throw e;
88
+ async getLatestVersionString(cancellationToken) {
89
+ const options = this.options;
90
+ // do not use API for GitHub to avoid limit, only for custom host or GitHub Enterprise
91
+ const url = options.host == null || options.host === "github.com"
92
+ ? util_1.newUrlFromBase(`${this.basePath}/latest`, this.baseUrl)
93
+ : new url_1.URL(`${this.computeGithubBasePath(`/repos/${options.owner}/${options.repo}/releases`)}/latest`, this.baseApiUrl);
94
+ try {
95
+ const rawData = await this.httpRequest(url, { Accept: "application/json" }, cancellationToken);
96
+ if (rawData == null) {
97
+ return null;
98
+ }
99
+ const releaseInfo = JSON.parse(rawData);
100
+ return releaseInfo.tag_name.startsWith("v") ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name;
101
+ }
102
+ catch (e) {
103
+ throw builder_util_runtime_1.newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND");
104
+ }
139
105
  }
140
-
141
- const result = (0, _Provider().parseUpdateInfo)(rawData, channelFile, channelFileUrl);
142
-
143
- if (result.releaseName == null) {
144
- result.releaseName = latestRelease.elementValueOrEmpty("title");
106
+ get basePath() {
107
+ return `/${this.options.owner}/${this.options.repo}/releases`;
145
108
  }
146
-
147
- if (result.releaseNotes == null) {
148
- result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease);
109
+ resolveFiles(updateInfo) {
110
+ // still replace space to - due to backward compatibility
111
+ return Provider_1.resolveFiles(updateInfo, this.baseUrl, p => this.getBaseDownloadPath(updateInfo.version, p.replace(/ /g, "-")));
149
112
  }
150
-
151
- return result;
152
- }
153
-
154
- async getLatestVersionString(cancellationToken) {
155
- const options = this.options; // do not use API for GitHub to avoid limit, only for custom host or GitHub Enterprise
156
-
157
- const url = options.host == null || options.host === "github.com" ? (0, _main().newUrlFromBase)(`${this.basePath}/latest`, this.baseUrl) : new (_url().URL)(`${this.computeGithubBasePath(`/repos/${options.owner}/${options.repo}/releases`)}/latest`, this.baseApiUrl);
158
-
159
- try {
160
- const rawData = await this.httpRequest(url, {
161
- Accept: "application/json"
162
- }, cancellationToken);
163
-
164
- if (rawData == null) {
165
- return null;
166
- }
167
-
168
- const releaseInfo = JSON.parse(rawData);
169
- return releaseInfo.tag_name.startsWith("v") ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name;
170
- } catch (e) {
171
- throw (0, _builderUtilRuntime().newError)(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, "ERR_UPDATER_LATEST_VERSION_NOT_FOUND");
113
+ getBaseDownloadPath(version, fileName) {
114
+ return `${this.basePath}/download/${this.options.vPrefixedTagName === false ? "" : "v"}${version}/${fileName}`;
172
115
  }
173
- }
174
-
175
- get basePath() {
176
- return `/${this.options.owner}/${this.options.repo}/releases`;
177
- }
178
-
179
- resolveFiles(updateInfo) {
180
- // still replace space to - due to backward compatibility
181
- return (0, _Provider().resolveFiles)(updateInfo, this.baseUrl, p => this.getBaseDownloadPath(updateInfo.version, p.replace(/ /g, "-")));
182
- }
183
-
184
- getBaseDownloadPath(version, fileName) {
185
- return `${this.basePath}/download/${this.options.vPrefixedTagName === false ? "" : "v"}${version}/${fileName}`;
186
- }
187
-
188
116
  }
189
-
190
117
  exports.GitHubProvider = GitHubProvider;
191
-
192
118
  function getNoteValue(parent) {
193
- const result = parent.elementValueOrEmpty("content"); // GitHub reports empty notes as <content>No content.</content>
194
-
195
- return result === "No content." ? "" : result;
119
+ const result = parent.elementValueOrEmpty("content");
120
+ // GitHub reports empty notes as <content>No content.</content>
121
+ return result === "No content." ? "" : result;
196
122
  }
197
-
198
123
  function computeReleaseNotes(currentVersion, isFullChangelog, feed, latestRelease) {
199
- if (!isFullChangelog) {
200
- return getNoteValue(latestRelease);
201
- }
202
-
203
- const releaseNotes = [];
204
-
205
- for (const release of feed.getElements("entry")) {
206
- // noinspection TypeScriptValidateJSTypes
207
- const versionRelease = release.element("link").attribute("href").match(/\/tag\/v?([^/]+)$/)[1];
208
-
209
- if (semver().lt(currentVersion, versionRelease)) {
210
- releaseNotes.push({
211
- version: versionRelease,
212
- note: getNoteValue(release)
213
- });
124
+ if (!isFullChangelog) {
125
+ return getNoteValue(latestRelease);
214
126
  }
215
- }
216
-
217
- return releaseNotes.sort((a, b) => semver().rcompare(a.version, b.version));
218
- }
219
- // __ts-babel@6.0.4
127
+ const releaseNotes = [];
128
+ for (const release of feed.getElements("entry")) {
129
+ // noinspection TypeScriptValidateJSTypes
130
+ const versionRelease = /\/tag\/v?([^/]+)$/.exec(release.element("link").attribute("href"))[1];
131
+ if (semver.lt(currentVersion, versionRelease)) {
132
+ releaseNotes.push({
133
+ version: versionRelease,
134
+ note: getNoteValue(release),
135
+ });
136
+ }
137
+ }
138
+ return releaseNotes.sort((a, b) => semver.rcompare(a.version, b.version));
139
+ }
140
+ exports.computeReleaseNotes = computeReleaseNotes;
220
141
  //# sourceMappingURL=GitHubProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/providers/GitHubProvider.ts"],"names":[],"mappings":";;;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;;;;;AAEA,MAAM,UAAU,GAAG,mBAAnB;;AAEM,MAAgB,kBAAhB,SAAiE,gBAAjE,CAA4E;AAKhF,EAAA,WAAA,CAAyC,OAAzC,EAAiE,WAAjE,EAAsF,cAAtF,EAA4H;AAC1H,UAAM,EACJ,GAAG,cADC;;AAEJ;AACA,MAAA,yBAAyB,EAAE;AAHvB,KAAN;AADuC,SAAA,OAAA,GAAA,OAAA;AAOvC,SAAK,OAAL,GAAe,wBAAW,qCAAU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AhB,EAAwB,SAAxB,CAAkC,MAAlC,EAA0C,KAA1C,CAAgD,mBAAhD,EAAsE,CAAtE,CAAvB;;AACA,QAAI,MAAM,GAAC,EAAP,CAAU,cAAV,EAA0B,cAA1B,CAAJ,EAA+C;AAC7C,MAAA,YAAY,CAAC,IAAb,CAAkB;AAChB,QAAA,OAAO,EAAE,cADO;AAEhB,QAAA,IAAI,EAAE,YAAY,CAAC,OAAD;AAFF,OAAlB;AAID;AACF;;AACD,SAAO,YAAY,CAChB,IADI,CACC,CAAC,CAAD,EAAI,CAAJ,KAAU,MAAM,GAAC,QAAP,CAAgB,CAAC,CAAC,OAAlB,EAA2B,CAAC,CAAC,OAA7B,CADX,CAAP;AAED,C","sourcesContent":["import { CancellationToken, GithubOptions, githubUrl, HttpError, newError, parseXml, ReleaseNoteInfo, UpdateInfo, XElement } from \"builder-util-runtime\"\nimport * as semver from \"semver\"\nimport { URL } from \"url\"\nimport { AppUpdater } from \"../AppUpdater\"\nimport { getChannelFilename, newBaseUrl, newUrlFromBase, Provider, ResolvedUpdateFileInfo } from \"../main\"\nimport { parseUpdateInfo, ProviderRuntimeOptions, resolveFiles } from \"./Provider\"\n\nconst hrefRegExp = /\\/tag\\/v?([^/]+)$/\n\nexport abstract class BaseGitHubProvider<T extends UpdateInfo> extends Provider<T> {\n // so, we don't need to parse port (because node http doesn't support host as url does)\n protected readonly baseUrl: URL\n protected readonly baseApiUrl: URL\n\n protected constructor(protected readonly options: GithubOptions, defaultHost: string, runtimeOptions: ProviderRuntimeOptions) {\n super({\n ...runtimeOptions,\n /* because GitHib uses S3 */\n isUseMultipleRangeRequest: false,\n })\n\n this.baseUrl = newBaseUrl(githubUrl(options, defaultHost))\n const apiHost = defaultHost === \"github.com\" ? \"api.github.com\" : defaultHost\n this.baseApiUrl = newBaseUrl(githubUrl(options, apiHost))\n }\n\n protected computeGithubBasePath(result: string): string {\n // https://github.com/electron-userland/electron-builder/issues/1903#issuecomment-320881211\n const host = this.options.host\n return host != null && host !== \"github.com\" && host !== \"api.github.com\" ? `/api/v3${result}` : result\n }\n}\n\nexport class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {\n constructor(protected readonly options: GithubOptions, private readonly updater: AppUpdater, runtimeOptions: ProviderRuntimeOptions) {\n super(options, \"github.com\", runtimeOptions)\n }\n\n async getLatestVersion(): Promise<UpdateInfo> {\n const cancellationToken = new CancellationToken()\n\n const feedXml: string = (await this.httpRequest(newUrlFromBase(`${this.basePath}.atom`, this.baseUrl), {\n accept: \"application/xml, application/atom+xml, text/xml, */*\",\n }, cancellationToken))!\n\n const feed = parseXml(feedXml)\n let latestRelease = feed.element(\"entry\", false, `No published versions on GitHub`)\n let version: string | null\n try {\n if (this.updater.allowPrerelease) {\n // noinspection TypeScriptValidateJSTypes\n version = latestRelease.element(\"link\").attribute(\"href\").match(hrefRegExp)!![1]\n }\n else {\n version = await this.getLatestVersionString(cancellationToken)\n for (const element of feed.getElements(\"entry\")) {\n if (element.element(\"link\").attribute(\"href\").match(hrefRegExp)!![1] === version) {\n latestRelease = element\n break\n }\n }\n }\n }\n catch (e) {\n throw newError(`Cannot parse releases feed: ${e.stack || e.message},\\nXML:\\n${feedXml}`, \"ERR_UPDATER_INVALID_RELEASE_FEED\")\n }\n\n if (version == null) {\n throw newError(`No published versions on GitHub`, \"ERR_UPDATER_NO_PUBLISHED_VERSIONS\")\n }\n\n const channelFile = getChannelFilename(this.getDefaultChannelName())\n const channelFileUrl = newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl)\n const requestOptions = this.createRequestOptions(channelFileUrl)\n let rawData: string\n try {\n rawData = (await this.executor.request(requestOptions, cancellationToken))!!\n }\n catch (e) {\n if (!this.updater.allowPrerelease && e instanceof HttpError && e.statusCode === 404) {\n throw newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, \"ERR_UPDATER_CHANNEL_FILE_NOT_FOUND\")\n }\n throw e\n }\n\n const result = parseUpdateInfo(rawData, channelFile, channelFileUrl)\n if (result.releaseName == null) {\n result.releaseName = latestRelease.elementValueOrEmpty(\"title\")\n }\n\n if (result.releaseNotes == null) {\n result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease)\n }\n return result\n }\n\n private async getLatestVersionString(cancellationToken: CancellationToken): Promise<string | null> {\n const options = this.options\n // do not use API for GitHub to avoid limit, only for custom host or GitHub Enterprise\n const url = (options.host == null || options.host === \"github.com\") ?\n newUrlFromBase(`${this.basePath}/latest`, this.baseUrl) :\n new URL(`${this.computeGithubBasePath(`/repos/${options.owner}/${options.repo}/releases`)}/latest`, this.baseApiUrl)\n try {\n const rawData = await this.httpRequest(url, {Accept: \"application/json\"}, cancellationToken)\n if (rawData == null) {\n return null\n }\n\n const releaseInfo: GithubReleaseInfo = JSON.parse(rawData)\n return (releaseInfo.tag_name.startsWith(\"v\")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name\n }\n catch (e) {\n throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, \"ERR_UPDATER_LATEST_VERSION_NOT_FOUND\")\n }\n }\n\n private get basePath(): string {\n return `/${this.options.owner}/${this.options.repo}/releases`\n }\n\n resolveFiles(updateInfo: UpdateInfo): Array<ResolvedUpdateFileInfo> {\n // still replace space to - due to backward compatibility\n return resolveFiles(updateInfo, this.baseUrl, p => this.getBaseDownloadPath(updateInfo.version, p.replace(/ /g, \"-\")))\n }\n\n private getBaseDownloadPath(version: string, fileName: string): string {\n return `${this.basePath}/download/${this.options.vPrefixedTagName === false ? \"\" : \"v\"}${version}/${fileName}`\n }\n}\n\ninterface GithubReleaseInfo {\n readonly tag_name: string\n}\n\nfunction getNoteValue(parent: XElement): string {\n const result = parent.elementValueOrEmpty(\"content\")\n // GitHub reports empty notes as <content>No content.</content>\n return result === \"No content.\" ? \"\" : result\n}\n\nexport function computeReleaseNotes(currentVersion: semver.SemVer, isFullChangelog: boolean, feed: XElement, latestRelease: any): string | Array<ReleaseNoteInfo> | null {\n if (!isFullChangelog) {\n return getNoteValue(latestRelease)\n }\n\n const releaseNotes: Array<ReleaseNoteInfo> = []\n for (const release of feed.getElements(\"entry\")) {\n // noinspection TypeScriptValidateJSTypes\n const versionRelease = release.element(\"link\").attribute(\"href\").match(/\\/tag\\/v?([^/]+)$/)![1]\n if (semver.lt(currentVersion, versionRelease)) {\n releaseNotes.push({\n version: versionRelease,\n note: getNoteValue(release)\n })\n }\n }\n return releaseNotes\n .sort((a, b) => semver.rcompare(a.version, b.version))\n}\n"],"sourceRoot":""}
1
+ {"version":3,"file":"GitHubProvider.js","sourceRoot":"","sources":["../../src/providers/GitHubProvider.ts"],"names":[],"mappings":";;;AAAA,+DAAwJ;AACxJ,iCAAgC;AAChC,6BAAyB;AAGzB,kCAAwE;AACxE,yCAA4F;AAE5F,MAAM,UAAU,GAAG,mBAAmB,CAAA;AAEtC,MAAsB,kBAAyC,SAAQ,mBAAW;IAKhF,YAAyC,OAAsB,EAAE,WAAmB,EAAE,cAAsC;QAC1H,KAAK,CAAC;YACJ,GAAG,cAAc;YACjB,4BAA4B;YAC5B,yBAAyB,EAAE,KAAK;SACjC,CAAC,CAAA;QALqC,YAAO,GAAP,OAAO,CAAe;QAO7D,IAAI,CAAC,OAAO,GAAG,iBAAU,CAAC,gCAAS,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAA;QAC1D,MAAM,OAAO,GAAG,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW,CAAA;QAC7E,IAAI,CAAC,UAAU,GAAG,iBAAU,CAAC,gCAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAC3D,CAAC;IAES,qBAAqB,CAAC,MAAc;QAC5C,2FAA2F;QAC3F,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;QAC9B,OAAO,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,YAAY,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EAAE,CAAA;IAC/C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;QAC/C,yCAAyC;QACzC,MAAM,cAAc,GAAG,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAE,CAAC,CAAC,CAAC,CAAA;QAC9F,IAAI,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE;YAC7C,YAAY,CAAC,IAAI,CAAC;gBAChB,OAAO,EAAE,cAAc;gBACvB,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC;aAC5B,CAAC,CAAA;SACH;KACF;IACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAA;AAC3E,CAAC;AAjBD,kDAiBC","sourcesContent":["import { CancellationToken, GithubOptions, githubUrl, HttpError, newError, parseXml, ReleaseNoteInfo, UpdateInfo, XElement } from \"builder-util-runtime\"\nimport * as semver from \"semver\"\nimport { URL } from \"url\"\nimport { AppUpdater } from \"../AppUpdater\"\nimport { ResolvedUpdateFileInfo } from \"../main\"\nimport { getChannelFilename, newBaseUrl, newUrlFromBase } from \"../util\"\nimport { parseUpdateInfo, Provider, ProviderRuntimeOptions, resolveFiles } from \"./Provider\"\n\nconst hrefRegExp = /\\/tag\\/v?([^/]+)$/\n\nexport abstract class BaseGitHubProvider<T extends UpdateInfo> extends Provider<T> {\n // so, we don't need to parse port (because node http doesn't support host as url does)\n protected readonly baseUrl: URL\n protected readonly baseApiUrl: URL\n\n protected constructor(protected readonly options: GithubOptions, defaultHost: string, runtimeOptions: ProviderRuntimeOptions) {\n super({\n ...runtimeOptions,\n /* because GitHib uses S3 */\n isUseMultipleRangeRequest: false,\n })\n\n this.baseUrl = newBaseUrl(githubUrl(options, defaultHost))\n const apiHost = defaultHost === \"github.com\" ? \"api.github.com\" : defaultHost\n this.baseApiUrl = newBaseUrl(githubUrl(options, apiHost))\n }\n\n protected computeGithubBasePath(result: string): string {\n // https://github.com/electron-userland/electron-builder/issues/1903#issuecomment-320881211\n const host = this.options.host\n return host != null && host !== \"github.com\" && host !== \"api.github.com\" ? `/api/v3${result}` : result\n }\n}\n\nexport class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {\n constructor(protected readonly options: GithubOptions, private readonly updater: AppUpdater, runtimeOptions: ProviderRuntimeOptions) {\n super(options, \"github.com\", runtimeOptions)\n }\n\n async getLatestVersion(): Promise<UpdateInfo> {\n const cancellationToken = new CancellationToken()\n\n const feedXml: string = (await this.httpRequest(\n newUrlFromBase(`${this.basePath}.atom`, this.baseUrl),\n {\n accept: \"application/xml, application/atom+xml, text/xml, */*\",\n },\n cancellationToken\n ))!\n\n const feed = parseXml(feedXml)\n // noinspection TypeScriptValidateJSTypes\n let latestRelease = feed.element(\"entry\", false, `No published versions on GitHub`)\n let version: string | null\n try {\n if (this.updater.allowPrerelease) {\n // noinspection TypeScriptValidateJSTypes\n version = hrefRegExp.exec(latestRelease.element(\"link\").attribute(\"href\"))![1]\n } else {\n version = await this.getLatestVersionString(cancellationToken)\n for (const element of feed.getElements(\"entry\")) {\n // noinspection TypeScriptValidateJSTypes\n if (hrefRegExp.exec(element.element(\"link\").attribute(\"href\"))![1] === version) {\n latestRelease = element\n break\n }\n }\n }\n } catch (e) {\n throw newError(`Cannot parse releases feed: ${e.stack || e.message},\\nXML:\\n${feedXml}`, \"ERR_UPDATER_INVALID_RELEASE_FEED\")\n }\n\n if (version == null) {\n throw newError(`No published versions on GitHub`, \"ERR_UPDATER_NO_PUBLISHED_VERSIONS\")\n }\n\n const channelFile = getChannelFilename(this.getDefaultChannelName())\n const channelFileUrl = newUrlFromBase(this.getBaseDownloadPath(version, channelFile), this.baseUrl)\n const requestOptions = this.createRequestOptions(channelFileUrl)\n let rawData: string\n try {\n rawData = (await this.executor.request(requestOptions, cancellationToken))!\n } catch (e) {\n if (!this.updater.allowPrerelease && e instanceof HttpError && e.statusCode === 404) {\n throw newError(`Cannot find ${channelFile} in the latest release artifacts (${channelFileUrl}): ${e.stack || e.message}`, \"ERR_UPDATER_CHANNEL_FILE_NOT_FOUND\")\n }\n throw e\n }\n\n const result = parseUpdateInfo(rawData, channelFile, channelFileUrl)\n if (result.releaseName == null) {\n result.releaseName = latestRelease.elementValueOrEmpty(\"title\")\n }\n\n if (result.releaseNotes == null) {\n result.releaseNotes = computeReleaseNotes(this.updater.currentVersion, this.updater.fullChangelog, feed, latestRelease)\n }\n return result\n }\n\n private async getLatestVersionString(cancellationToken: CancellationToken): Promise<string | null> {\n const options = this.options\n // do not use API for GitHub to avoid limit, only for custom host or GitHub Enterprise\n const url =\n options.host == null || options.host === \"github.com\"\n ? newUrlFromBase(`${this.basePath}/latest`, this.baseUrl)\n : new URL(`${this.computeGithubBasePath(`/repos/${options.owner}/${options.repo}/releases`)}/latest`, this.baseApiUrl)\n try {\n const rawData = await this.httpRequest(url, { Accept: \"application/json\" }, cancellationToken)\n if (rawData == null) {\n return null\n }\n\n const releaseInfo: GithubReleaseInfo = JSON.parse(rawData)\n return releaseInfo.tag_name.startsWith(\"v\") ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name\n } catch (e) {\n throw newError(`Unable to find latest version on GitHub (${url}), please ensure a production release exists: ${e.stack || e.message}`, \"ERR_UPDATER_LATEST_VERSION_NOT_FOUND\")\n }\n }\n\n private get basePath(): string {\n return `/${this.options.owner}/${this.options.repo}/releases`\n }\n\n resolveFiles(updateInfo: UpdateInfo): Array<ResolvedUpdateFileInfo> {\n // still replace space to - due to backward compatibility\n return resolveFiles(updateInfo, this.baseUrl, p => this.getBaseDownloadPath(updateInfo.version, p.replace(/ /g, \"-\")))\n }\n\n private getBaseDownloadPath(version: string, fileName: string): string {\n return `${this.basePath}/download/${this.options.vPrefixedTagName === false ? \"\" : \"v\"}${version}/${fileName}`\n }\n}\n\ninterface GithubReleaseInfo {\n readonly tag_name: string\n}\n\nfunction getNoteValue(parent: XElement): string {\n const result = parent.elementValueOrEmpty(\"content\")\n // GitHub reports empty notes as <content>No content.</content>\n return result === \"No content.\" ? \"\" : result\n}\n\nexport function computeReleaseNotes(currentVersion: semver.SemVer, isFullChangelog: boolean, feed: XElement, latestRelease: any): string | Array<ReleaseNoteInfo> | null {\n if (!isFullChangelog) {\n return getNoteValue(latestRelease)\n }\n\n const releaseNotes: Array<ReleaseNoteInfo> = []\n for (const release of feed.getElements(\"entry\")) {\n // noinspection TypeScriptValidateJSTypes\n const versionRelease = /\\/tag\\/v?([^/]+)$/.exec(release.element(\"link\").attribute(\"href\"))![1]\n if (semver.lt(currentVersion, versionRelease)) {\n releaseNotes.push({\n version: versionRelease,\n note: getNoteValue(release),\n })\n }\n }\n return releaseNotes.sort((a, b) => semver.rcompare(a.version, b.version))\n}\n"]}