1

Github 1699674 - Fix support for ES6 importing by brizental · Pull Request #123...

 3 years ago
source link: https://github.com/mozilla/glean.js/pull/123/commits/607c9d5285298f7afbc6187d3b2bdd7d0c1f25b3
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Fix support for ES6 importing by brizental · Pull Request #123 · mozilla/glean.js · GitHub

Add ".js" extensions to all local import statement in lib code

This is a very weird change, I know, but there is good reason behind it:

1. ESM 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 spcified. See:
https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm

2. Typescript does not provide features that change compiled JS code.
This means there is no Typescript feature to include the ".js" on
compiled code. See: microsoft/TypeScript#16577 (comment)

All of this results in this weird change. It is the accepted workaround
for this issue and until ES6 imports support automatic resolution of
extensions, we will keep it.

brizental

committed 19 days ago

commit 607c9d5285298f7afbc6187d3b2bdd7d0c1f25b3

@@ -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": {

@@ -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.

@@ -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 {

@@ -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.

@@ -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.

@@ -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.

@@ -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.

@@ -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.

@@ -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]: {

@@ -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]: {

@@ -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.

@@ -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) {

@@ -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) {

@@ -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.

@@ -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;

@@ -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__";

@@ -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;

@@ -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) {

@@ -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.

@@ -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,

@@ -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.

@@ -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();

@@ -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 { JSONObject, JSONValue } from "../utils";

import { JSONObject, JSONValue } from "../utils.js";

/**

* The storage index in the ordered list of keys to navigate on the store

@@ -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 { StorageIndex } from "../storage";

import { isJSONValue, isObject, JSONObject, JSONValue } from "../utils";

import { StorageIndex } from "../storage/index.js";

import { isJSONValue, isObject, JSONObject, JSONValue } from "../utils.js";

/**

* Gets an entry in a given object on a given index.

@@ -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 { GLEAN_VERSION } from "../constants";

import { Observer as PingsDatabaseObserver, PingInternalRepresentation } from "../pings/database";

import Glean from "../glean";

import { GLEAN_VERSION } from "../constants.js";

import { Observer as PingsDatabaseObserver, PingInternalRepresentation } from "../pings/database.js";

import Glean from "../glean.js";

interface QueuedPing extends PingInternalRepresentation {

identifier: string

@@ -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 { UploadResult } from "../upload";

import { UploadResult } from "../upload/index.js";

/**

* Uploader interface, actualy uploading logic varies per platform.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK