Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1699674 - Fix support for ES6 importing #123

Merged
merged 7 commits into from
Mar 22, 2021
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Unreleased changes

* [#123](https://github.com/mozilla/glean.js/pull/123): BUGFIX: Fix support for ES6 environments.
* Include `.js` extensions in all local import statements.
* ES6' module resolution algorithm does not currently support automatic resolution of file extensions and does not have the hability to import directories that have an index file. The extension and the name of the file being import need to _always_ be specified. See: https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm
* Add a `type: module` declaration to the main `package.json`.
* Without this statement, ES6 support is disabled. See: https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_enabling.:
* To keep support for CommonJS, in our CommonJS build we include a `package.json` that overrides the `type: module` of the main `package.json` with a `type: commonjs`.

[Full changelog](https://github.com/mozilla/glean.js/compare/v0.5.0...main)

# v0.5.0 (2021-03-18)
Expand Down
2,693 changes: 812 additions & 1,881 deletions glean/package-lock.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions glean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@mozilla/glean",
"version": "0.5.0",
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for Javascript environments.",
"type": "module",
"exports": {
"./package.json": "./package.json",
"./webext": {
Expand Down Expand Up @@ -51,15 +52,16 @@
},
"scripts": {
"test": "npm run test:core && npm run test:platform && npm run test:plugins",
"test:core": "ts-mocha \"tests/core/**/*.spec.ts\" --recursive",
"test:plugins": "ts-mocha \"tests/plugins/**/*.spec.ts\" --recursive",
"test:platform": "npm run build:test-webext && ts-mocha \"tests/platform/**/*.spec.ts\" --recursive --timeout 0",
"test:core": "npm run test:base -- \"tests/core/**/*.spec.ts\" --recursive",
"test:plugins": "npm run test:base -- \"tests/plugins/**/*.spec.ts\" --recursive",
"test:platform": "npm run build:test-webext && npm run test:base -- \"tests/platform/**/*.spec.ts\" --recursive --timeout 0",
"test:base": "node --experimental-modules --experimental-specifier-resolution=node --loader=ts-node/esm node_modules/mocha/lib/cli/cli.js",
"build:test-webext": "cd tests/platform/utils/webext/sample/ && npm install && npm run build:xpi",
"lint": "eslint . --ext .ts,.js,.json --max-warnings=0",
"fix": "eslint . --ext .ts,.js,.json --fix",
"build:cli": "tsc -p ./tsconfig/cli.json",
"build:webext:lib:esm": "tsc -p ./tsconfig/webext/esm.json",
"build:webext:lib:cjs": "tsc -p ./tsconfig/webext/cjs.json",
"build:webext:lib:cjs": "tsc -p ./tsconfig/webext/cjs.json && echo '{\"type\": \"commonjs\"}'> dist/webext/esm/package.json",
Dexterp37 marked this conversation as resolved.
Show resolved Hide resolved
"build:webext:lib:browser": "tsc -p ./tsconfig/webext/browser.json",
"build:webext:types": "tsc -p ./tsconfig/webext/types.json",
"build:webext": "rm -rf dist/webext && npm run build:webext:lib:esm && npm run build:webext:lib:cjs && npm run build:webext:lib:browser && npm run build:webext:types",
Expand Down Expand Up @@ -101,7 +103,6 @@
"selenium-webdriver": "^4.0.0-alpha.8",
"sinon": "^9.2.4",
"ts-loader": "^8.0.17",
"ts-mocha": "^8.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.5",
"web-ext-types": "^3.2.1",
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 { DEFAULT_TELEMETRY_ENDPOINT, GLEAN_MAX_SOURCE_TAGS } from "./constants";
import Plugin from "../plugins";
import { validateHeader, validateURL } from "./utils";
import { DEFAULT_TELEMETRY_ENDPOINT, GLEAN_MAX_SOURCE_TAGS } from "./constants.js";
import Plugin from "../plugins/index.js";
import { validateHeader, validateURL } from "./utils.js";

/**
* Lists Glean's debug options.
Expand Down
2 changes: 1 addition & 1 deletion glean/src/core/dispatcher.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 { generateUUIDv4 } from "./utils";
import { generateUUIDv4 } from "./utils.js";

// The possible states a dispatcher instance can be in.
export const enum DispatcherState {
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 Plugin from "../../plugins";
import Plugin from "../../plugins/index.js";

import { PingPayload } from "../pings/database";
import { JSONObject } from "../utils";
import { PingPayload } from "../pings/database.js";
import { JSONObject } from "../utils.js";

export class CoreEvent<
// An array of arguments that the event will provide as context to the plugin action.
Expand Down
4 changes: 2 additions & 2 deletions glean/src/core/events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 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 CoreEvents, { CoreEvent } from "./index";
import Plugin from "../../plugins";
import CoreEvents, { CoreEvent } from "./index.js";
import Plugin from "../../plugins/index.js";

/**
* Registers a plugin to the desired Glean event.
Expand Down
34 changes: 17 additions & 17 deletions glean/src/core/glean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
* 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 { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "./constants";
import { Configuration, ConfigurationInterface } from "./config";
import MetricsDatabase from "./metrics/database";
import PingsDatabase from "./pings/database";
import PingUploader from "./upload";
import { isUndefined, sanitizeApplicationId } from "./utils";
import { CoreMetrics } from "./internal_metrics";
import { Lifetime } from "./metrics";
import EventsDatabase from "./metrics/events_database";
import UUIDMetricType from "./metrics/types/uuid";
import DatetimeMetricType, { DatetimeMetric } from "./metrics/types/datetime";
import Dispatcher from "./dispatcher";
import CorePings from "./internal_pings";
import { registerPluginToEvent, testResetEvents } from "./events/utils";

import Platform from "../platform/index";
import TestPlatform from "../platform/test";
import { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "./constants.js";
import { Configuration, ConfigurationInterface } from "./config.js";
import MetricsDatabase from "./metrics/database.js";
import PingsDatabase from "./pings/database.js";
import PingUploader from "./upload/index.js";
import { isUndefined, sanitizeApplicationId } from "./utils.js";
import { CoreMetrics } from "./internal_metrics.js";
import { Lifetime } from "./metrics/index.js";
import EventsDatabase from "./metrics/events_database.js";
import UUIDMetricType from "./metrics/types/uuid.js";
import DatetimeMetricType, { DatetimeMetric } from "./metrics/types/datetime.js";
import Dispatcher from "./dispatcher.js";
import CorePings from "./internal_pings.js";
import { registerPluginToEvent, testResetEvents } from "./events/utils.js";

import Platform from "../platform/index.js";
import TestPlatform from "../platform/test/index.js";

class Glean {
// The Glean singleton.
Expand Down
18 changes: 9 additions & 9 deletions glean/src/core/internal_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* 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 { KNOWN_CLIENT_ID, CLIENT_INFO_STORAGE } from "./constants";
import UUIDMetricType from "./metrics/types/uuid";
import DatetimeMetricType from "./metrics/types/datetime";
import StringMetricType from "./metrics/types/string";
import { createMetric } from "./metrics/utils";
import TimeUnit from "./metrics/time_unit";
import { Lifetime } from "./metrics";
import { generateUUIDv4 } from "./utils";
import Glean from "./glean";
import { KNOWN_CLIENT_ID, CLIENT_INFO_STORAGE } from "./constants.js";
import UUIDMetricType from "./metrics/types/uuid.js";
import DatetimeMetricType from "./metrics/types/datetime.js";
import StringMetricType from "./metrics/types/string.js";
import { createMetric } from "./metrics/utils.js";
import TimeUnit from "./metrics/time_unit.js";
import { Lifetime } from "./metrics/index.js";
import { generateUUIDv4 } from "./utils.js";
import Glean from "./glean.js";

/**
* Glean internal metrics.
Expand Down
4 changes: 2 additions & 2 deletions glean/src/core/internal_pings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 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 { DELETION_REQUEST_PING_NAME } from "./constants";
import PingType from "./pings";
import { DELETION_REQUEST_PING_NAME } from "./constants.js";
import PingType from "./pings/index.js";

/**
* Glean-provided pings, all enabled by default.
Expand Down
10 changes: 5 additions & 5 deletions glean/src/core/metrics/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// * 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 Store from "../storage";
import { MetricType, Lifetime, Metric } from "./";
import { createMetric, validateMetricInternalRepresentation } from "./utils";
import { isObject, isUndefined, JSONObject, JSONValue } from "../utils";
import { StorageBuilder } from "../../platform";
import Store from "../storage/index.js";
import { MetricType, Lifetime, Metric } from "./index.js";
import { createMetric, validateMetricInternalRepresentation } from "./utils.js";
import { isObject, isUndefined, JSONObject, JSONValue } from "../utils.js";
import { StorageBuilder } from "../../platform/index.js";

export interface Metrics {
[aMetricType: string]: {
Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/metrics/events_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// * 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 Store from "../storage";
import { isUndefined, JSONArray, JSONObject, JSONValue } from "../utils";
import EventMetricType from "./types/event";
import Glean from "../glean";
import Store from "../storage/index.js";
import { isUndefined, JSONArray, JSONObject, JSONValue } from "../utils.js";
import EventMetricType from "./types/event.js";
import Glean from "../glean.js";

export interface Metrics {
[aMetricType: string]: {
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 { isUndefined, JSONValue } from "../utils";
import Glean from "../glean";
import LabeledMetricType from "./types/labeled";
import { isUndefined, JSONValue } from "../utils.js";
import Glean from "../glean.js";
import LabeledMetricType from "./types/labeled.js";

/**
* The Metric class describes the shared behaviour amongst concrete metrics.
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/metrics/types/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 { Metric, MetricType, CommonMetricData } from "../";
import { isBoolean } from "../../utils";
import Glean from "../../glean";
import { Metric, MetricType, CommonMetricData } from "../index.js";
import { isBoolean } from "../../utils.js";
import Glean from "../../glean.js";

export class BooleanMetric extends Metric<boolean, boolean> {
constructor(v: unknown) {
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/metrics/types/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 { Metric, MetricType, CommonMetricData } from "../";
import { isNumber, isUndefined, JSONValue } from "../../utils";
import Glean from "../../glean";
import { Metric, MetricType, CommonMetricData } from "../index.js";
import { isNumber, isUndefined, JSONValue } from "../../utils.js";
import Glean from "../../glean.js";

export class CounterMetric extends Metric<number, number> {
constructor(v: unknown) {
Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/metrics/types/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 { Metric, MetricType, CommonMetricData } from "../";
import TimeUnit from "../../metrics/time_unit";
import Glean from "../../glean";
import { isNumber, isObject, isString } from "../../utils";
import { Metric, MetricType, CommonMetricData } from "../index.js";
import TimeUnit from "../../metrics/time_unit.js";
import Glean from "../../glean.js";
import { isNumber, isObject, isString } from "../../utils.js";

/**
* Builds the formatted timezone offset string frim a given timezone.
Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/metrics/types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 { MetricType, CommonMetricData } from "../";
import Glean from "../../glean";
import { ExtraMap, RecordedEvent } from "../events_database";
import { isUndefined } from "../../utils";
import { MetricType, CommonMetricData } from "../index.js";
import Glean from "../../glean.js";
import { ExtraMap, RecordedEvent } from "../events_database.js";
import { isUndefined } from "../../utils.js";

const MAX_LENGTH_EXTRA_KEY_VALUE = 100;

Expand Down
10 changes: 5 additions & 5 deletions glean/src/core/metrics/types/labeled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* 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 { CommonMetricData, MetricType } from "..";
import Glean from "../../glean";
import CounterMetricType from "./counter";
import BooleanMetricType from "./boolean";
import StringMetricType from "./string";
import { CommonMetricData, MetricType } from "../index.js";
import Glean from "../../glean.js";
import CounterMetricType from "./counter.js";
import BooleanMetricType from "./boolean.js";
import StringMetricType from "./string.js";

const MAX_LABELS = 16;
const OTHER_LABEL = "__other__";
Expand Down
6 changes: 3 additions & 3 deletions glean/src/core/metrics/types/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* 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 { Metric, MetricType, CommonMetricData } from "../";
import { isString } from "../../utils";
import Glean from "../../glean";
import { Metric, MetricType, CommonMetricData } from "../index.js";
import { isString } from "../../utils.js";
import Glean from "../../glean.js";

export const MAX_LENGTH_VALUE = 100;

Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/metrics/types/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import { validate as UUIDvalidate } from "uuid";

import { KNOWN_CLIENT_ID } from "../../constants";
import { Metric, MetricType, CommonMetricData } from "../";
import { isString, generateUUIDv4 } from "../../utils";
import Glean from "../../glean";
import { KNOWN_CLIENT_ID } from "../../constants.js";
import { Metric, MetricType, CommonMetricData } from "../index.js";
import { isString, generateUUIDv4 } from "../../utils.js";
import Glean from "../../glean.js";

export class UUIDMetric extends Metric<string, string> {
constructor(v: unknown) {
Expand Down
14 changes: 7 additions & 7 deletions glean/src/core/metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* 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 { Metric, LabeledMetric } from "./index";
import { JSONValue } from "../utils";
import { Metric, LabeledMetric } from "./index.js";
import { JSONValue } from "../utils.js";

import { BooleanMetric } from "./types/boolean";
import { CounterMetric } from "./types/counter";
import { DatetimeMetric } from "./types/datetime";
import { StringMetric } from "./types/string";
import { UUIDMetric } from "./types/uuid";
import { BooleanMetric } from "./types/boolean.js";
import { CounterMetric } from "./types/counter.js";
import { DatetimeMetric } from "./types/datetime.js";
import { StringMetric } from "./types/string.js";
import { UUIDMetric } from "./types/uuid.js";

/**
* A map containing all supported internal metrics and its constructors.
Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/pings/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 Store from "../storage";
import { Metrics as MetricsPayload } from "../metrics/database";
import { isObject, isJSONValue, JSONObject, isString, JSONArray } from "../utils";
import { StorageBuilder } from "../../platform";
import Store from "../storage/index.js";
import { Metrics as MetricsPayload } from "../metrics/database.js";
import { isObject, isJSONValue, JSONObject, isString, JSONArray } from "../utils.js";
import { StorageBuilder } from "../../platform/index.js";

export interface PingInfo extends JSONObject {
seq: number,
Expand Down
8 changes: 4 additions & 4 deletions glean/src/core/pings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 { DELETION_REQUEST_PING_NAME } from "../constants";
import { generateUUIDv4 } from "../utils";
import collectAndStorePing from "../pings/maker";
import Glean from "../glean";
import { DELETION_REQUEST_PING_NAME } from "../constants.js";
import { generateUUIDv4 } from "../utils.js";
import collectAndStorePing from "../pings/maker.js";
import Glean from "../glean.js";

/**
* The common set of data for creating a new ping.
Expand Down
18 changes: 9 additions & 9 deletions glean/src/core/pings/maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* 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 { GLEAN_SCHEMA_VERSION, GLEAN_VERSION, PING_INFO_STORAGE, CLIENT_INFO_STORAGE } from "../constants";
import CounterMetricType, { CounterMetric } from "../metrics/types/counter";
import DatetimeMetricType, { DatetimeMetric } from "../metrics/types/datetime";
import { Lifetime } from "../metrics";
import TimeUnit from "../metrics/time_unit";
import { ClientInfo, PingInfo, PingPayload } from "../pings/database";
import PingType from "../pings";
import Glean from "../glean";
import CoreEvents from "../events";
import { GLEAN_SCHEMA_VERSION, GLEAN_VERSION, PING_INFO_STORAGE, CLIENT_INFO_STORAGE } from "../constants.js";
import CounterMetricType, { CounterMetric } from "../metrics/types/counter.js";
import DatetimeMetricType, { DatetimeMetric } from "../metrics/types/datetime.js";
import { Lifetime } from "../metrics/index.js";
import TimeUnit from "../metrics/time_unit.js";
import { ClientInfo, PingInfo, PingPayload } from "../pings/database.js";
import PingType from "../pings/index.js";
import Glean from "../glean.js";
import CoreEvents from "../events/index.js";

// The moment the current Glean.js session started.
const GLEAN_START_TIME = new Date();
Expand Down
Loading