Skip to content

Commit

Permalink
test: force utf8 for dpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed May 31, 2017
1 parent 4a87e67 commit 5f43249
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 96 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ dist/
/packages/electron-builder/README.md
/packages/electron-builder/scheme.json

/jsdoc/out/
/jsdoc/out/

electron-builder-*.d.ts
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv": "^5.1.5",
"ajv-keywords": "^2.1.0",
"archiver": "^1.3.0",
"aws-sdk": "^2.58.0",
"aws-sdk": "^2.59.0",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down Expand Up @@ -92,7 +92,7 @@
"source-map-support": "^0.4.15",
"ts-babel": "^3.0.1",
"tslint": "^5.3.2",
"typescript": "^2.3.3",
"typescript": "^2.3.4",
"whitespace": "^2.1.0",
"xml2js": "^0.4.17"
},
Expand Down
4 changes: 0 additions & 4 deletions packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _debug from "debug"
import { EventEmitter } from "events"
import { createWriteStream } from "fs-extra-p"
import { RequestOptions } from "http"
import { safeLoad } from "js-yaml"
import { Socket } from "net"
import { Transform } from "stream"
import { parse as parseUrl } from "url"
Expand Down Expand Up @@ -134,9 +133,6 @@ export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
if (data.length === 0) {
resolve()
}
else if (pathname != null && pathname.endsWith(".yml")) {
resolve(safeLoad(data))
}
else {
resolve(isJson || (pathname != null && pathname.endsWith(".json")) ? JSON.parse(data) : data)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.3.0",
"aws-sdk": "^2.58.0",
"aws-sdk": "^2.59.0",
"mime": "^1.3.6",
"electron-publish": "~0.0.0-semantic-release",
"electron-builder-util": "~0.0.0-semantic-release"
Expand Down
13 changes: 7 additions & 6 deletions packages/electron-updater/src/GenericProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { HttpError, request } from "electron-builder-http"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { GenericServerOptions, UpdateInfo } from "electron-builder-http/out/publishOptions"
import { RequestOptions } from "http"
import { safeLoad } from "js-yaml"
import * as path from "path"
import * as url from "url"
import { FileInfo, getChannelFilename, getCurrentPlatform, getCustomChannelName, getDefaultChannelName, Provider } from "./main"
import { FileInfo, getChannelFilename, getCustomChannelName, getDefaultChannelName, isUseOldMacProvider, Provider } from "./main"

export class GenericProvider extends Provider<UpdateInfo> {
private readonly baseUrl = url.parse(this.configuration.url)
Expand All @@ -15,7 +16,7 @@ export class GenericProvider extends Provider<UpdateInfo> {
}

async getLatestVersion(): Promise<UpdateInfo> {
let result: UpdateInfo | null = null
let result: UpdateInfo
const channelFile = getChannelFilename(this.channel)
const pathname = path.posix.resolve(this.baseUrl.pathname || "/", channelFile)
try {
Expand All @@ -28,7 +29,7 @@ export class GenericProvider extends Provider<UpdateInfo> {
if (this.baseUrl.port != null) {
options.port = parseInt(this.baseUrl.port, 10)
}
result = await request<UpdateInfo>(options, new CancellationToken())
result = safeLoad(await request<string>(options, new CancellationToken()))
}
catch (e) {
if (e instanceof HttpError && e.response.statusCode === 404) {
Expand All @@ -38,14 +39,14 @@ export class GenericProvider extends Provider<UpdateInfo> {
}

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
if (isUseOldMacProvider()) {
(<any>result).releaseJsonUrl = url.format(Object.assign({}, this.baseUrl, {pathname: pathname}))
}
return result
}

async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
if (getCurrentPlatform() === "darwin") {
if (isUseOldMacProvider()) {
return <any>versionInfo
}

Expand All @@ -59,7 +60,7 @@ export class GenericProvider extends Provider<UpdateInfo> {

// sha2 is required only for windows because on macOS update is verified by Squirrel.Mac
export function validateUpdateInfo(info: UpdateInfo) {
if (getCurrentPlatform() === "darwin") {
if (isUseOldMacProvider()) {
if ((<any>info).url == null) {
throw new Error("Update info doesn't contain url")
}
Expand Down
17 changes: 9 additions & 8 deletions packages/electron-updater/src/GitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { HttpError, request } from "electron-builder-http"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { GithubOptions, githubUrl, UpdateInfo } from "electron-builder-http/out/publishOptions"
import { RequestOptions } from "http"
import { safeLoad } from "js-yaml"
import * as path from "path"
import { parse as parseUrl } from "url"
import { AppUpdater } from "./AppUpdater"
import { validateUpdateInfo } from "./GenericProvider"
import { FileInfo, formatUrl, getChannelFilename, getCurrentPlatform, getDefaultChannelName, Provider } from "./main"
import { FileInfo, formatUrl, getChannelFilename, getDefaultChannelName, isUseOldMacProvider, Provider } from "./main"

export abstract class BaseGitHubProvider<T extends UpdateInfo> extends Provider<T> {
// so, we don't need to parse port (because node http doesn't support host as url does)
Expand Down Expand Up @@ -58,11 +59,11 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {
throw new Error(`Cannot parse releases feed: ${e.stack || e.message},\nXML:\n${feedXml}`)
}

let result: any
let result: UpdateInfo
const channelFile = getChannelFilename(getDefaultChannelName())
const requestOptions = Object.assign({path: this.getBaseDownloadPath(version, channelFile), headers: this.requestHeaders || undefined}, this.baseUrl)
try {
result = await request<UpdateInfo>(requestOptions, cancellationToken)
result = safeLoad(await request<string>(requestOptions, cancellationToken))
}
catch (e) {
if (!this.updater.allowPrerelease) {
Expand All @@ -74,15 +75,15 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {
}

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
result.releaseJsonUrl = `${githubUrl(this.options)}/${requestOptions.path}`
if (isUseOldMacProvider()) {
(<any>result).releaseJsonUrl = `${githubUrl(this.options)}/${requestOptions.path}`
}

if (result.releaseName == null) {
result.releaseName = latestRelease.getElementValue("title")
(<any>result).releaseName = latestRelease.getElementValue("title")
}
if (result.releaseNotes == null) {
result.releaseNotes = latestRelease.getElementValue("content")
(<any>result).releaseNotes = latestRelease.getElementValue("content")
}
return result
}
Expand All @@ -107,7 +108,7 @@ export class GitHubProvider extends BaseGitHubProvider<UpdateInfo> {
}

async getUpdateFile(versionInfo: UpdateInfo): Promise<FileInfo> {
if (getCurrentPlatform() === "darwin") {
if (isUseOldMacProvider()) {
return <any>versionInfo
}

Expand Down
31 changes: 30 additions & 1 deletion packages/electron-updater/src/MacUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import BluebirdPromise from "bluebird-lst"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { PublishConfiguration, VersionInfo } from "electron-builder-http/out/publishOptions"
import { createServer, IncomingMessage, Server, ServerResponse } from "http"
import { AppUpdater } from "./AppUpdater"
import { FileInfo } from "./main"
import AutoUpdater = Electron.AutoUpdater

export class MacUpdater extends AppUpdater {
private readonly nativeUpdater: AutoUpdater = require("electron").autoUpdater

private server: Server | null

constructor(options?: PublishConfiguration) {
super(options)

Expand All @@ -26,8 +29,29 @@ export class MacUpdater extends AppUpdater {
}

protected onUpdateAvailable(versionInfo: VersionInfo, fileInfo: FileInfo) {
this.nativeUpdater.setFeedURL((<any>versionInfo).releaseJsonUrl, Object.assign({"Cache-Control": "no-cache"}, this.computeRequestHeaders(fileInfo)))
super.onUpdateAvailable(versionInfo, fileInfo)

let server = this.server
if (server != null) {
return
}

server = createServer()
this.server = server
server.on("request", (request: IncomingMessage, response: ServerResponse) => {
if (request.url!.endsWith("/update.json")) {
response.writeHead(200, {"Content-Type": "application/json"})
response.end(`{ "url": "${this.getServerUrl()}/app.zip" }`)
}
else {
response.writeHead(404)
response.end()

}
})
server.listen(0, "127.0.0.1", 16, () => {
this.nativeUpdater.setFeedURL(`${this.getServerUrl()}`, Object.assign({"Cache-Control": "no-cache"}, this.computeRequestHeaders(fileInfo)))
})
}

protected doDownloadUpdate(versionInfo: VersionInfo, fileInfo: FileInfo, cancellationToken: CancellationToken) {
Expand All @@ -38,4 +62,9 @@ export class MacUpdater extends AppUpdater {
quitAndInstall(): void {
this.nativeUpdater.quitAndInstall()
}

private getServerUrl() {
const address = this.server!.address()
return `http://${address.address}:${address.port}`
}
}
43 changes: 10 additions & 33 deletions packages/electron-updater/src/PrivateGitHubProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parse as parseUrl } from "url"
import { NET_SESSION_NAME } from "./electronHttpExecutor"
import { validateUpdateInfo } from "./GenericProvider"
import { BaseGitHubProvider } from "./GitHubProvider"
import { FileInfo, formatUrl, getChannelFilename, getCurrentPlatform, getDefaultChannelName } from "./main"
import { FileInfo, formatUrl, getChannelFilename, getDefaultChannelName } from "./main"

export interface PrivateGitHubUpdateInfo extends UpdateInfo {
assets: Array<Asset>
Expand All @@ -36,16 +36,7 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
}, parseUrl(assets.find(it => it.name == channelFile)!.url))
let result: any
try {
result = await request<UpdateInfo>(requestOptions, cancellationToken)

if (typeof result === "string") {
if (getCurrentPlatform() === "darwin") {
result = JSON.parse(result)
}
else {
result = safeLoad(result)
}
}
result = safeLoad(await request<string>(requestOptions, cancellationToken))
}
catch (e) {
if (e instanceof HttpError && e.response.statusCode === 404) {
Expand All @@ -54,10 +45,7 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
throw e
}

validateUpdateInfo(result)
if (getCurrentPlatform() === "darwin") {
result.releaseJsonUrl = `${this.options.protocol || "https"}://${this.options.host || "api.github.com"}${requestOptions.path}`
}
validateUpdateInfo(result);
(<PrivateGitHubUpdateInfo>result).assets = assets
return result
}
Expand Down Expand Up @@ -106,24 +94,13 @@ export class PrivateGitHubProvider extends BaseGitHubProvider<PrivateGitHubUpdat
Authorization: `token ${this.token}`
}

// space is not supported on GitHub
if (getCurrentPlatform() === "darwin") {
const info = <any>versionInfo
const name = info.url.split("/").pop()
const assetPath = parseUrl(versionInfo.assets.find(it => it.name == name)!.url).path
info.url = formatUrl(Object.assign({path: `${assetPath}`}, this.baseUrl))
info.headers = headers
return info
}
else {
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
return <any>{
name: name,
url: versionInfo.assets.find(it => it.name == name)!.url,
sha2: versionInfo.sha2,
headers: headers,
session: this.netSession
}
const name = versionInfo.githubArtifactName || path.posix.basename(versionInfo.path).replace(/ /g, "-")
return <any>{
name: name,
url: versionInfo.assets.find(it => it.name == name)!.url,
sha2: versionInfo.sha2,
headers: headers,
session: this.netSession
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions packages/electron-updater/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { ProgressInfo } from "electron-builder-http/out/ProgressCallbackTransfor
import { VersionInfo } from "electron-builder-http/out/publishOptions"
import { EventEmitter } from "events"
import { format as buggyFormat, Url } from "url"
// autoUpdater to mimic electron bundled autoUpdater
import { AppUpdater } from "./AppUpdater"
import { LoginCallback } from "./electronHttpExecutor"

export { NET_SESSION_NAME } from "./electronHttpExecutor"
export { AppUpdater } from "./AppUpdater"

// autoUpdater to mimic electron bundled autoUpdater
let _autoUpdater: any

// required for jsdoc
export declare const autoUpdater: AppUpdater

function _load_autoUpdater(): AppUpdater {
if (process.platform === "win32") {
_autoUpdater = new (require("./NsisUpdater").NsisUpdater)()
Expand All @@ -26,9 +29,6 @@ function _load_autoUpdater(): AppUpdater {
return _autoUpdater
}

// required for jsdoc
export declare const autoUpdater: AppUpdater

Object.defineProperty(exports, "autoUpdater", {
enumerable: true,
get: function () {
Expand Down Expand Up @@ -72,8 +72,13 @@ export function getCurrentPlatform () {
return process.env.TEST_UPDATER_PLATFORM || process.platform
}

export function isUseOldMacProvider() {
// getCurrentPlatform() === "darwin"
return false
}

export function getChannelFilename(channel: string) {
return `${channel}.${getCurrentPlatform() === "darwin" ? "json" : "yml"}`
return `${channel}.yml`
}

export interface UpdateCheckResult {
Expand Down
36 changes: 18 additions & 18 deletions test/out/linux/__snapshots__/debTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,25 @@ Array [
"/",
"/opt/",
"/usr/",
"/opt/Test App \\\\303\\\\237W/",
"/opt/Test App \\\\303\\\\237W/blink_image_resources_200_percent.pak",
"/opt/Test App \\\\303\\\\237W/Boo",
"/opt/Test App \\\\303\\\\237W/content_resources_200_percent.pak",
"/opt/Test App \\\\303\\\\237W/content_shell.pak",
"/opt/Test App \\\\303\\\\237W/icudtl.dat",
"/opt/Test App \\\\303\\\\237W/libffmpeg.so",
"/opt/Test App \\\\303\\\\237W/libnode.so",
"/opt/Test App \\\\303\\\\237W/LICENSE.electron.txt",
"/opt/Test App \\\\303\\\\237W/LICENSES.chromium.html",
"/opt/Test App \\\\303\\\\237W/natives_blob.bin",
"/opt/Test App \\\\303\\\\237W/pdf_viewer_resources.pak",
"/opt/Test App \\\\303\\\\237W/snapshot_blob.bin",
"/opt/Test App \\\\303\\\\237W/ui_resources_200_percent.pak",
"/opt/Test App \\\\303\\\\237W/views_resources_200_percent.pak",
"/opt/Test App ßW/",
"/opt/Test App ßW/blink_image_resources_200_percent.pak",
"/opt/Test App ßW/Boo",
"/opt/Test App ßW/content_resources_200_percent.pak",
"/opt/Test App ßW/content_shell.pak",
"/opt/Test App ßW/icudtl.dat",
"/opt/Test App ßW/libffmpeg.so",
"/opt/Test App ßW/libnode.so",
"/opt/Test App ßW/LICENSE.electron.txt",
"/opt/Test App ßW/LICENSES.chromium.html",
"/opt/Test App ßW/natives_blob.bin",
"/opt/Test App ßW/pdf_viewer_resources.pak",
"/opt/Test App ßW/snapshot_blob.bin",
"/opt/Test App ßW/ui_resources_200_percent.pak",
"/opt/Test App ßW/views_resources_200_percent.pak",
"/usr/share/",
"/opt/Test App \\\\303\\\\237W/resources/",
"/opt/Test App \\\\303\\\\237W/resources/app.asar",
"/opt/Test App \\\\303\\\\237W/resources/electron.asar",
"/opt/Test App ßW/resources/",
"/opt/Test App ßW/resources/app.asar",
"/opt/Test App ßW/resources/electron.asar",
"/usr/share/applications/",
"/usr/share/applications/Boo.desktop",
"/usr/share/doc/",
Expand Down
3 changes: 2 additions & 1 deletion test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
}

async function getContents(path: string) {
const result = await exec("dpkg", ["--contents", path])
// without LC_CTYPE dpkg can returns encoded unicode symbols
const result = await exec("dpkg", ["--contents", path], {env: Object.assign({}, process.env, {LANG: "en_US.UTF-8", LC_CTYPE: "UTF-8"})})
return pathSorter(parseFileList(result, true)
.filter(it => !(it.includes(`/locales/`) || it.includes(`/libgcrypt`)))
)
Expand Down
Loading

0 comments on commit 5f43249

Please sign in to comment.