Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* [#411](https://github.com/mozilla/glean.js/pull/411): Tag all messages logged by Glean with the component they are coming from.
* [#399](https://github.com/mozilla/glean.js/pull/399): Check if there are ping data before attempting to delete it.
* This change lowers the amount of log messages related to attempting to delete inexistent data.
* [#415](https://github.com/mozilla/glean.js/pull/415): Gzip ping paylod before upload
* [#415](https://github.com/mozilla/glean.js/pull/415), [#430](https://github.com/mozilla/glean.js/pull/430): Gzip ping paylod before upload
* This changes the signature of `Uploader.post` to accept `string | Uint8Array` for the `body` parameter, instead of only `string`.
* The gizpping functionality is disabled in Qt/QML environments. Follow [Bug 1716322](https://bugzilla.mozilla.org/show_bug.cgi?id=1716322) for updates on the status of this feature on that platform.
* [#431](https://github.com/mozilla/glean.js/pull/431): BUGFIX: Record the timestamp for events before dispatching to the internal task queue.

# v0.15.0 (2021-06-03)
Expand Down
5 changes: 2 additions & 3 deletions glean/src/core/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { gzipSync } from "fflate";
import { gzipSync, strToU8 } from "fflate";

import type Platform from "../../platform/index.js";
import type { Configuration } from "../config.js";
Expand Down Expand Up @@ -140,8 +140,7 @@ class PingUploader implements PingsDatabaseObserver {

const stringifiedBody = JSON.stringify(ping.payload);
try {
const encoder = new TextEncoder();
const compressedBody = gzipSync(encoder.encode(stringifiedBody));
const compressedBody = gzipSync(strToU8(stringifiedBody));
headers["Content-Encoding"] = "gzip";
headers["Content-Length"] = compressedBody.length.toString();
return {
Expand Down
17 changes: 0 additions & 17 deletions glean/src/platform/qt/fflate.stub.js

This file was deleted.

9 changes: 7 additions & 2 deletions glean/src/platform/qt/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import log, { LoggingLevel } from "../../core/log.js";
import type Uploader from "../../core/upload/uploader.js";
import type { UploadResult } from "../../core/upload/uploader.js";
import { DEFAULT_UPLOAD_TIMEOUT_MS, UploadResultStatus } from "../../core/upload/uploader.js";
import { isString } from "../../core/utils.js";

const LOG_TAG = "platform.qt.Uploader";

class QtUploader implements Uploader {
async post(url: string, body: string, headers: Record<string, string> = {}): Promise<UploadResult> {
async post(url: string, body: string | Uint8Array, headers: Record<string, string> = {}): Promise<UploadResult> {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.timeout = DEFAULT_UPLOAD_TIMEOUT_MS;
Expand Down Expand Up @@ -48,7 +49,11 @@ class QtUploader implements Uploader {
});
};

xhr.send(body);
if (!isString(body)) {
xhr.send(body.buffer);
} else {
xhr.send(body);
}
});
}
}
Expand Down
28 changes: 23 additions & 5 deletions glean/webpack.config.qt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const OUTPUT = "glean.lib.js";

/**
* Hacky plugin that removes ".js" extensions from imports before resolving.
*
Expand All @@ -30,6 +32,22 @@ class TsResolvePlugin {
}
}

/**
* Plugin to remove the "use strict" statement added by Webpack before emmiting final bundle.
*
* Context on why this is necessary: https://github.com/101arrowz/fflate/pull/75#issuecomment-865016941,
* tl;dr; "use strict" makes accessing a negative index throw an error in QML,
* and not anywhere else.
*/
class RemoveUseStrictPlugin {
apply(compiler) {
compiler.hooks.shouldEmit.tap("RemoveUseStrictPlugin", compilation => {
compilation.assets[OUTPUT]._value = compilation.assets[OUTPUT]._value.replace("\"use strict\";", "");
return true;
});
}
}

export default {
entry: "./src/index/qt.ts",
mode: "production",
Expand Down Expand Up @@ -58,14 +76,14 @@ export default {
extensions: [ ".tsx", ".ts", ".js" ],
plugins: [
new TsResolvePlugin()
],
alias: {
"fflate": path.resolve(__dirname, "src/platform/qt/fflate.stub.js")
}
]
},
plugins: [
new RemoveUseStrictPlugin(),
],
output: {
path: path.resolve(__dirname, "dist/qt/org/mozilla/Glean"),
filename: "glean.lib.js",
filename: OUTPUT,
libraryTarget: "var",
library: "Glean",
}
Expand Down