Skip to content

Commit 16afe14

Browse files
author
Beatriz Rizental
authored
1699674 - Fix support for ES6 importing (#123)
1 parent 6489e68 commit 16afe14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1014
-2041
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Unreleased changes
22

3+
* [#123](https://github.com/mozilla/glean.js/pull/123): BUGFIX: Fix support for ES6 environments.
4+
* Include `.js` extensions in all local import statements.
5+
* 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
6+
* Add a `type: module` declaration to the main `package.json`.
7+
* Without this statement, ES6 support is disabled. See: https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_enabling.:
8+
* 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`.
9+
310
[Full changelog](https://github.com/mozilla/glean.js/compare/v0.5.0...main)
411

512
# v0.5.0 (2021-03-18)

glean/package-lock.json

Lines changed: 812 additions & 1881 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glean/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@mozilla/glean",
33
"version": "0.5.0",
44
"description": "An implementation of the Glean SDK, a modern cross-platform telemetry client, for Javascript environments.",
5+
"type": "module",
56
"exports": {
67
"./package.json": "./package.json",
78
"./webext": {
@@ -51,15 +52,16 @@
5152
},
5253
"scripts": {
5354
"test": "npm run test:core && npm run test:platform && npm run test:plugins",
54-
"test:core": "ts-mocha \"tests/core/**/*.spec.ts\" --recursive",
55-
"test:plugins": "ts-mocha \"tests/plugins/**/*.spec.ts\" --recursive",
56-
"test:platform": "npm run build:test-webext && ts-mocha \"tests/platform/**/*.spec.ts\" --recursive --timeout 0",
55+
"test:core": "npm run test:base -- \"tests/core/**/*.spec.ts\" --recursive",
56+
"test:plugins": "npm run test:base -- \"tests/plugins/**/*.spec.ts\" --recursive",
57+
"test:platform": "npm run build:test-webext && npm run test:base -- \"tests/platform/**/*.spec.ts\" --recursive --timeout 0",
58+
"test:base": "node --experimental-modules --experimental-specifier-resolution=node --loader=ts-node/esm node_modules/mocha/lib/cli/cli.js",
5759
"build:test-webext": "cd tests/platform/utils/webext/sample/ && npm install && npm run build:xpi",
5860
"lint": "eslint . --ext .ts,.js,.json --max-warnings=0",
5961
"fix": "eslint . --ext .ts,.js,.json --fix",
6062
"build:cli": "tsc -p ./tsconfig/cli.json",
6163
"build:webext:lib:esm": "tsc -p ./tsconfig/webext/esm.json",
62-
"build:webext:lib:cjs": "tsc -p ./tsconfig/webext/cjs.json",
64+
"build:webext:lib:cjs": "tsc -p ./tsconfig/webext/cjs.json && echo '{\"type\": \"commonjs\"}'> dist/webext/esm/package.json",
6365
"build:webext:lib:browser": "tsc -p ./tsconfig/webext/browser.json",
6466
"build:webext:types": "tsc -p ./tsconfig/webext/types.json",
6567
"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",
@@ -101,7 +103,6 @@
101103
"selenium-webdriver": "^4.0.0-alpha.8",
102104
"sinon": "^9.2.4",
103105
"ts-loader": "^8.0.17",
104-
"ts-mocha": "^8.0.0",
105106
"ts-node": "^9.1.1",
106107
"typescript": "^4.1.5",
107108
"web-ext-types": "^3.2.1",

glean/src/core/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { DEFAULT_TELEMETRY_ENDPOINT, GLEAN_MAX_SOURCE_TAGS } from "./constants";
6-
import Plugin from "../plugins";
7-
import { validateHeader, validateURL } from "./utils";
5+
import { DEFAULT_TELEMETRY_ENDPOINT, GLEAN_MAX_SOURCE_TAGS } from "./constants.js";
6+
import Plugin from "../plugins/index.js";
7+
import { validateHeader, validateURL } from "./utils.js";
88

99
/**
1010
* Lists Glean's debug options.

glean/src/core/dispatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { generateUUIDv4 } from "./utils";
5+
import { generateUUIDv4 } from "./utils.js";
66

77
// The possible states a dispatcher instance can be in.
88
export const enum DispatcherState {

glean/src/core/events/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import Plugin from "../../plugins";
5+
import Plugin from "../../plugins/index.js";
66

7-
import { PingPayload } from "../pings/database";
8-
import { JSONObject } from "../utils";
7+
import { PingPayload } from "../pings/database.js";
8+
import { JSONObject } from "../utils.js";
99

1010
export class CoreEvent<
1111
// An array of arguments that the event will provide as context to the plugin action.

glean/src/core/events/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import CoreEvents, { CoreEvent } from "./index";
6-
import Plugin from "../../plugins";
5+
import CoreEvents, { CoreEvent } from "./index.js";
6+
import Plugin from "../../plugins/index.js";
77

88
/**
99
* Registers a plugin to the desired Glean event.

glean/src/core/glean.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "./constants";
6-
import { Configuration, ConfigurationInterface } from "./config";
7-
import MetricsDatabase from "./metrics/database";
8-
import PingsDatabase from "./pings/database";
9-
import PingUploader from "./upload";
10-
import { isUndefined, sanitizeApplicationId } from "./utils";
11-
import { CoreMetrics } from "./internal_metrics";
12-
import { Lifetime } from "./metrics";
13-
import EventsDatabase from "./metrics/events_database";
14-
import UUIDMetricType from "./metrics/types/uuid";
15-
import DatetimeMetricType, { DatetimeMetric } from "./metrics/types/datetime";
16-
import Dispatcher from "./dispatcher";
17-
import CorePings from "./internal_pings";
18-
import { registerPluginToEvent, testResetEvents } from "./events/utils";
19-
20-
import Platform from "../platform/index";
21-
import TestPlatform from "../platform/test";
5+
import { CLIENT_INFO_STORAGE, KNOWN_CLIENT_ID } from "./constants.js";
6+
import { Configuration, ConfigurationInterface } from "./config.js";
7+
import MetricsDatabase from "./metrics/database.js";
8+
import PingsDatabase from "./pings/database.js";
9+
import PingUploader from "./upload/index.js";
10+
import { isUndefined, sanitizeApplicationId } from "./utils.js";
11+
import { CoreMetrics } from "./internal_metrics.js";
12+
import { Lifetime } from "./metrics/index.js";
13+
import EventsDatabase from "./metrics/events_database.js";
14+
import UUIDMetricType from "./metrics/types/uuid.js";
15+
import DatetimeMetricType, { DatetimeMetric } from "./metrics/types/datetime.js";
16+
import Dispatcher from "./dispatcher.js";
17+
import CorePings from "./internal_pings.js";
18+
import { registerPluginToEvent, testResetEvents } from "./events/utils.js";
19+
20+
import Platform from "../platform/index.js";
21+
import TestPlatform from "../platform/test/index.js";
2222

2323
class Glean {
2424
// The Glean singleton.

glean/src/core/internal_metrics.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { KNOWN_CLIENT_ID, CLIENT_INFO_STORAGE } from "./constants";
6-
import UUIDMetricType from "./metrics/types/uuid";
7-
import DatetimeMetricType from "./metrics/types/datetime";
8-
import StringMetricType from "./metrics/types/string";
9-
import { createMetric } from "./metrics/utils";
10-
import TimeUnit from "./metrics/time_unit";
11-
import { Lifetime } from "./metrics";
12-
import { generateUUIDv4 } from "./utils";
13-
import Glean from "./glean";
5+
import { KNOWN_CLIENT_ID, CLIENT_INFO_STORAGE } from "./constants.js";
6+
import UUIDMetricType from "./metrics/types/uuid.js";
7+
import DatetimeMetricType from "./metrics/types/datetime.js";
8+
import StringMetricType from "./metrics/types/string.js";
9+
import { createMetric } from "./metrics/utils.js";
10+
import TimeUnit from "./metrics/time_unit.js";
11+
import { Lifetime } from "./metrics/index.js";
12+
import { generateUUIDv4 } from "./utils.js";
13+
import Glean from "./glean.js";
1414

1515
/**
1616
* Glean internal metrics.

glean/src/core/internal_pings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { DELETION_REQUEST_PING_NAME } from "./constants";
6-
import PingType from "./pings";
5+
import { DELETION_REQUEST_PING_NAME } from "./constants.js";
6+
import PingType from "./pings/index.js";
77

88
/**
99
* Glean-provided pings, all enabled by default.

0 commit comments

Comments
 (0)