From 23ba4bfdc77c8bf594bf0c817320a31f59ca0bd4 Mon Sep 17 00:00:00 2001 From: t2t2 Date: Thu, 22 Apr 2021 21:36:29 +0300 Subject: [PATCH] feat: add ESM builds for packages used in browser (#2112) * feat: add ESM builds for packages used in browser * Update CONTRIBUTING.md Co-authored-by: Bartlomiej Obecny Co-authored-by: Bartlomiej Obecny Co-authored-by: Daniel Dyla Co-authored-by: Valentin Marchaud --- CONTRIBUTING.md | 4 +- package.json | 6 +-- .../opentelemetry-api-metrics/package.json | 11 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 10 ++-- .../tsconfig.esm.json | 14 +++++ .../opentelemetry-context-zone/package.json | 10 ++-- .../tsconfig.esm.json | 11 ++++ packages/opentelemetry-core/package.json | 11 ++-- packages/opentelemetry-core/tsconfig.esm.json | 11 ++++ .../package.json | 11 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 11 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 10 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 10 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 11 ++-- .../tsconfig.esm.json | 11 ++++ packages/opentelemetry-metrics/package.json | 10 ++-- packages/opentelemetry-metrics/src/Meter.ts | 2 +- .../src/MeterProvider.ts | 2 +- .../opentelemetry-metrics/tsconfig.esm.json | 11 ++++ .../opentelemetry-propagator-b3/package.json | 10 ++-- .../tsconfig.esm.json | 11 ++++ .../package.json | 10 ++-- .../tsconfig.esm.json | 11 ++++ packages/opentelemetry-resources/package.json | 9 +++- .../opentelemetry-resources/tsconfig.esm.json | 11 ++++ .../package.json | 7 +-- .../tsconfig.esm.json | 11 ++++ packages/opentelemetry-tracing/package.json | 11 ++-- .../src/BasicTracerProvider.ts | 6 ++- .../opentelemetry-tracing/tsconfig.esm.json | 11 ++++ packages/opentelemetry-web/package.json | 10 ++-- packages/opentelemetry-web/tsconfig.esm.json | 11 ++++ packages/template/package.json | 12 ++++- packages/template/tsconfig.esm.json | 11 ++++ tsconfig.base.esm.json | 7 +++ tsconfig.esm.json | 54 +++++++++++++++++++ 41 files changed, 387 insertions(+), 58 deletions(-) create mode 100644 packages/opentelemetry-api-metrics/tsconfig.esm.json create mode 100644 packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json create mode 100644 packages/opentelemetry-context-zone/tsconfig.esm.json create mode 100644 packages/opentelemetry-core/tsconfig.esm.json create mode 100644 packages/opentelemetry-exporter-collector/tsconfig.esm.json create mode 100644 packages/opentelemetry-exporter-zipkin/tsconfig.esm.json create mode 100644 packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json create mode 100644 packages/opentelemetry-instrumentation-xml-http-request/tsconfig.esm.json create mode 100644 packages/opentelemetry-instrumentation/tsconfig.esm.json create mode 100644 packages/opentelemetry-metrics/tsconfig.esm.json create mode 100644 packages/opentelemetry-propagator-b3/tsconfig.esm.json create mode 100644 packages/opentelemetry-propagator-jaeger/tsconfig.esm.json create mode 100644 packages/opentelemetry-resources/tsconfig.esm.json create mode 100644 packages/opentelemetry-semantic-conventions/tsconfig.esm.json create mode 100644 packages/opentelemetry-tracing/tsconfig.esm.json create mode 100644 packages/opentelemetry-web/tsconfig.esm.json create mode 100644 packages/template/tsconfig.esm.json create mode 100644 tsconfig.base.esm.json create mode 100644 tsconfig.esm.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15f0c22583..11e38bf053 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -163,9 +163,9 @@ npm run lint:fix ### Adding a package -To add a new package, copy `packages/template` to your new package directory and modify the `package.json` file to reflect your desired package settings. If the package will not support browser, the `karma.conf` file may be deleted. If the package will support es5 targets, the reference to `tsconfig.base.json` in `tsconfig.json` should be changed to `tsconfig.es5.json`. +To add a new package, copy `packages/template` to your new package directory and modify the `package.json` file to reflect your desired package settings. If the package will not support browser, the `karma.conf` and `tsconifg.esm.json` files may be deleted. If the package will support es5 targets, the reference to `tsconfig.base.json` in `tsconfig.json` should be changed to `tsconfig.es5.json`. -After adding the package, run `npm install` from the root of the project. This will update the `tsconfig.json` project references automatically and install all dependencies in your new package. +After adding the package, run `npm install` from the root of the project. This will update the `tsconfig.json` project references automatically and install all dependencies in your new package. For packages supporting browser, file `tsconfig.esm.json` needs to be manually updated to include reference to ES modules build. ### Guidelines for Pull Requests diff --git a/package.json b/package.json index 996a0acaf6..3b6211ae12 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "main": "build/src/index.js", "types": "build/src/index.d.ts", "scripts": { - "compile": "tsc --build", - "watch": "tsc --build --watch", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "bench": "node benchmark", "postinstall": "update-ts-references && npm run bootstrap", "postcompile": "npm run submodule && npm run protos:copy", diff --git a/packages/opentelemetry-api-metrics/package.json b/packages/opentelemetry-api-metrics/package.json index 9aade961d8..47e04d8eb0 100644 --- a/packages/opentelemetry-api-metrics/package.json +++ b/packages/opentelemetry-api-metrics/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "Public metrics API for OpenTelemetry", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", "test:browser": "nyc karma start --single-run", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", @@ -20,7 +22,7 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -37,6 +39,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-api-metrics/tsconfig.esm.json b/packages/opentelemetry-api-metrics/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-api-metrics/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-context-zone-peer-dep/package.json b/packages/opentelemetry-context-zone-peer-dep/package.json index 30af24047e..d43cb8984f 100644 --- a/packages/opentelemetry-context-zone-peer-dep/package.json +++ b/packages/opentelemetry-context-zone-peer-dep/package.json @@ -3,18 +3,19 @@ "version": "0.19.0", "description": "OpenTelemetry Context Zone with peer dependency for zone.js", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", "test:browser": "nyc karma start --single-run", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -30,6 +31,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json new file mode 100644 index 0000000000..b3530914ff --- /dev/null +++ b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "files": [ + "node_modules/zone.js/dist/zone.js.d.ts" + ], + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-context-zone/package.json b/packages/opentelemetry-context-zone/package.json index 26fa66539c..c3d8030fa4 100644 --- a/packages/opentelemetry-context-zone/package.json +++ b/packages/opentelemetry-context-zone/package.json @@ -3,15 +3,16 @@ "version": "0.19.0", "description": "OpenTelemetry Context Zone", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -27,6 +28,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-context-zone/tsconfig.esm.json b/packages/opentelemetry-context-zone/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-context-zone/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index f4ddd99f38..b253aed77d 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "OpenTelemetry Core provides default and no-op implementations of the OpenTelemetry types for trace and metrics", "main": "build/src/index.js", + "module": "build/esm/index.js", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts --exclude 'test/platform/browser/**/*.ts'", "test:browser": "nyc karma start --single-run", "tdd": "npm run tdd:node", @@ -22,7 +24,7 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -39,6 +41,9 @@ "node": ">=8.5.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-core/tsconfig.esm.json b/packages/opentelemetry-core/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-core/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-exporter-collector/package.json b/packages/opentelemetry-exporter-collector/package.json index e6233f0521..feff7bbf38 100644 --- a/packages/opentelemetry-exporter-collector/package.json +++ b/packages/opentelemetry-exporter-collector/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "OpenTelemetry Collector Exporter allows user to send collected traces to the OpenTelemetry Collector", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", @@ -20,7 +22,7 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "test:browser": "nyc karma start --single-run", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -37,6 +39,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-exporter-collector/tsconfig.esm.json b/packages/opentelemetry-exporter-collector/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-exporter-collector/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index 6f8221d647..59e7e60ea1 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "OpenTelemetry Zipkin Exporter allows the user to send collected traces to Zipkin.", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", @@ -20,7 +22,7 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "test:browser": "nyc karma start --single-run", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -35,6 +37,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-exporter-zipkin/tsconfig.esm.json b/packages/opentelemetry-exporter-zipkin/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-exporter-zipkin/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-instrumentation-fetch/package.json b/packages/opentelemetry-instrumentation-fetch/package.json index 459fd4481a..c586b3b1b9 100644 --- a/packages/opentelemetry-instrumentation-fetch/package.json +++ b/packages/opentelemetry-instrumentation-fetch/package.json @@ -3,18 +3,19 @@ "version": "0.19.0", "description": "OpenTelemetry fetch automatic instrumentation package.", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", "test:browser": "nyc karma start --single-run", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "fetch", @@ -31,6 +32,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json b/packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-instrumentation-xml-http-request/package.json b/packages/opentelemetry-instrumentation-xml-http-request/package.json index 329d5c6023..a4392d6128 100644 --- a/packages/opentelemetry-instrumentation-xml-http-request/package.json +++ b/packages/opentelemetry-instrumentation-xml-http-request/package.json @@ -3,18 +3,19 @@ "version": "0.19.0", "description": "OpenTelemetry XMLHttpRequest automatic instrumentation package.", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", "test:browser": "nyc karma start --single-run", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -31,6 +32,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-instrumentation-xml-http-request/tsconfig.esm.json b/packages/opentelemetry-instrumentation-xml-http-request/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-instrumentation-xml-http-request/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-instrumentation/package.json b/packages/opentelemetry-instrumentation/package.json index 91111a91e6..78de724d28 100644 --- a/packages/opentelemetry-instrumentation/package.json +++ b/packages/opentelemetry-instrumentation/package.json @@ -6,6 +6,7 @@ "homepage": "https://github.com/open-telemetry/opentelemetry-js#readme", "license": "Apache-2.0", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "publishConfig": { "access": "public" @@ -16,9 +17,13 @@ }, "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", @@ -27,8 +32,8 @@ "README.md" ], "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", @@ -39,7 +44,7 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "test:browser": "nyc karma start --single-run", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", diff --git a/packages/opentelemetry-instrumentation/tsconfig.esm.json b/packages/opentelemetry-instrumentation/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-instrumentation/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index ba179d4beb..8da6d03371 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -3,18 +3,19 @@ "version": "0.19.0", "description": "OpenTelemetry metrics SDK", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "tdd": "npm run test -- --watch-extensions ts --watch", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -29,6 +30,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-metrics/src/Meter.ts b/packages/opentelemetry-metrics/src/Meter.ts index ab2ce90def..d42c9f15c6 100644 --- a/packages/opentelemetry-metrics/src/Meter.ts +++ b/packages/opentelemetry-metrics/src/Meter.ts @@ -31,7 +31,7 @@ import { UpDownCounterMetric } from './UpDownCounterMetric'; import { UpDownSumObserverMetric } from './UpDownSumObserverMetric'; import { ValueObserverMetric } from './ValueObserverMetric'; import { ValueRecorderMetric } from './ValueRecorderMetric'; -import merge = require('lodash.merge'); +const merge = require('lodash.merge'); /** * Meter is an implementation of the {@link Meter} interface. diff --git a/packages/opentelemetry-metrics/src/MeterProvider.ts b/packages/opentelemetry-metrics/src/MeterProvider.ts index 3b645b8a91..b305456a9e 100644 --- a/packages/opentelemetry-metrics/src/MeterProvider.ts +++ b/packages/opentelemetry-metrics/src/MeterProvider.ts @@ -18,7 +18,7 @@ import * as api from '@opentelemetry/api-metrics'; import { Resource } from '@opentelemetry/resources'; import { Meter } from '.'; import { DEFAULT_CONFIG, MeterConfig } from './types'; -import merge = require('lodash.merge'); +const merge = require('lodash.merge'); /** * This class represents a meter provider which platform libraries can extend diff --git a/packages/opentelemetry-metrics/tsconfig.esm.json b/packages/opentelemetry-metrics/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-metrics/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-propagator-b3/package.json b/packages/opentelemetry-propagator-b3/package.json index 2b7e83591d..336ca825d4 100644 --- a/packages/opentelemetry-propagator-b3/package.json +++ b/packages/opentelemetry-propagator-b3/package.json @@ -3,17 +3,18 @@ "version": "0.19.0", "description": "OpenTelemetry B3 propagator provides context propagation for systems that are using the B3 header format", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -29,6 +30,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-propagator-b3/tsconfig.esm.json b/packages/opentelemetry-propagator-b3/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-propagator-b3/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-propagator-jaeger/package.json b/packages/opentelemetry-propagator-jaeger/package.json index 92ebaeff05..e8bcb7bc0e 100644 --- a/packages/opentelemetry-propagator-jaeger/package.json +++ b/packages/opentelemetry-propagator-jaeger/package.json @@ -3,21 +3,22 @@ "version": "0.19.0", "description": "OpenTelemetry Jaeger propagator provides HTTP header propagation for systems that are using Jaeger HTTP header format.", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/index-webpack.ts'", "test:browser": "nyc karma start --single-run", "tdd": "npm run tdd:node", "tdd:node": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", - "clean": "tsc --build --clean", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -32,6 +33,9 @@ "node": ">=8.5.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-propagator-jaeger/tsconfig.esm.json b/packages/opentelemetry-propagator-jaeger/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-propagator-jaeger/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-resources/package.json b/packages/opentelemetry-resources/package.json index 338a3bdd26..903a378b18 100644 --- a/packages/opentelemetry-resources/package.json +++ b/packages/opentelemetry-resources/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "OpenTelemetry SDK resources", "main": "build/src/index.js", + "module": "build/esm/index.js", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", @@ -32,6 +34,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-resources/tsconfig.esm.json b/packages/opentelemetry-resources/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-resources/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-semantic-conventions/package.json b/packages/opentelemetry-semantic-conventions/package.json index 498d85ad18..f1165770a2 100644 --- a/packages/opentelemetry-semantic-conventions/package.json +++ b/packages/opentelemetry-semantic-conventions/package.json @@ -3,17 +3,18 @@ "version": "0.19.0", "description": "OpenTelemetry semantic conventions", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'", "tdd": "npm run test -- --watch-extensions ts --watch", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", diff --git a/packages/opentelemetry-semantic-conventions/tsconfig.esm.json b/packages/opentelemetry-semantic-conventions/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-semantic-conventions/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index 8bda102da2..08a856c02f 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -3,15 +3,17 @@ "version": "0.19.0", "description": "OpenTelemetry Tracing", "main": "build/src/index.js", + "module": "build/esm/index.js", "browser": { "./src/platform/index.ts": "./src/platform/browser/index.ts", + "./build/esm/platform/index.js": "./build/esm/platform/browser/index.js", "./build/src/platform/index.js": "./build/src/platform/browser/index.js" }, "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/index-webpack.ts'", "test:browser": "nyc karma start --single-run", "tdd": "npm run tdd:node", @@ -21,7 +23,7 @@ "lint:fix": "eslint . --ext .ts --fix", "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -37,6 +39,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts index b5db060271..86d5f4d077 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts @@ -34,7 +34,7 @@ import { DEFAULT_CONFIG } from './config'; import { MultiSpanProcessor } from './MultiSpanProcessor'; import { NoopSpanProcessor } from './NoopSpanProcessor'; import { SDKRegistrationConfig, TracerConfig } from './types'; -import merge = require('lodash.merge'); +const merge = require('lodash.merge'); export type PROPAGATOR_FACTORY = () => TextMapPropagator; @@ -122,7 +122,9 @@ export class BasicTracerProvider implements TracerProvider { protected _buildPropagatorFromEnv(): TextMapPropagator | undefined { // per spec, propagators from env must be deduplicated - const uniquePropagatorNames = [...new Set(getEnv().OTEL_PROPAGATORS)]; + const uniquePropagatorNames = Array.from( + new Set(getEnv().OTEL_PROPAGATORS) + ); const propagators = uniquePropagatorNames.map(name => { const propagator = this._getPropagator(name); diff --git a/packages/opentelemetry-tracing/tsconfig.esm.json b/packages/opentelemetry-tracing/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-tracing/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/opentelemetry-web/package.json b/packages/opentelemetry-web/package.json index a8b7fa6c2e..71af31964f 100644 --- a/packages/opentelemetry-web/package.json +++ b/packages/opentelemetry-web/package.json @@ -3,18 +3,19 @@ "version": "0.19.0", "description": "OpenTelemetry Web Tracer", "main": "build/src/index.js", + "module": "build/esm/index.js", "types": "build/src/index.d.ts", "repository": "open-telemetry/opentelemetry-js", "scripts": { - "compile": "tsc --build", - "clean": "tsc --build --clean", + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", "version": "node ../../scripts/version-update.js", "tdd": "karma start", "test:browser": "nyc karma start --single-run", - "watch": "tsc --build --watch" + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -30,6 +31,9 @@ "node": ">=8.0.0" }, "files": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts", "build/src/**/*.js", "build/src/**/*.js.map", "build/src/**/*.d.ts", diff --git a/packages/opentelemetry-web/tsconfig.esm.json b/packages/opentelemetry-web/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/opentelemetry-web/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/packages/template/package.json b/packages/template/package.json index ce93aa74a5..83ea22f40f 100644 --- a/packages/template/package.json +++ b/packages/template/package.json @@ -35,9 +35,12 @@ "version": "node ../../scripts/version-update.js", "watch": "tsc --build --watch" }, - "Add these to scripts if browser is supported": { + "Add/change these to scripts if browser is supported": { + "compile": "tsc --build tsconfig.json tsconfig.esm.json", + "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json", "test:browser": "nyc karma start --single-run", - "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../" + "codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", + "watch": "tsc --build --watch tsconfig.json tsconfig.esm.json" }, "keywords": [ "opentelemetry", @@ -56,6 +59,11 @@ "LICENSE", "README.md" ], + "Add these to files if browser is supported": [ + "build/esm/**/*.js", + "build/esm/**/*.js.map", + "build/esm/**/*.d.ts" + ], "devDependencies": { "@types/node": "14.14.41", "typescript": "4.2.4" diff --git a/packages/template/tsconfig.esm.json b/packages/template/tsconfig.esm.json new file mode 100644 index 0000000000..a94adff6aa --- /dev/null +++ b/packages/template/tsconfig.esm.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.esm.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build/esm", + "tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo" + }, + "include": [ + "src/**/*.ts" + ] +} diff --git a/tsconfig.base.esm.json b/tsconfig.base.esm.json new file mode 100644 index 0000000000..e65651a426 --- /dev/null +++ b/tsconfig.base.esm.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.es5.json", + "compilerOptions": { + "module": "ES6", + "moduleResolution": "node" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000000..6b6b6fe8be --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,54 @@ +{ + "extends": "./tsconfig.base.esm.json", + "files": [], + "references": [ + { + "path": "packages/opentelemetry-api-metrics/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-context-zone/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-core/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-exporter-collector/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-exporter-zipkin/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-instrumentation-xml-http-request/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-instrumentation/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-metrics/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-propagator-b3/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-propagator-jaeger/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-resources/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-semantic-conventions/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-tracing/tsconfig.esm.json" + }, + { + "path": "packages/opentelemetry-web/tsconfig.esm.json" + } + ] +}