Skip to content

Commit

Permalink
feat: add ESM builds for packages used in browser (#2112)
Browse files Browse the repository at this point in the history
* feat: add ESM builds for packages used in browser

* Update CONTRIBUTING.md

Co-authored-by: Bartlomiej Obecny <bobecny@gmail.com>

Co-authored-by: Bartlomiej Obecny <bobecny@gmail.com>
Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
  • Loading branch information
4 people authored Apr 22, 2021
1 parent 7775c0e commit 23ba4bf
Show file tree
Hide file tree
Showing 41 changed files with 387 additions and 58 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 8 additions & 3 deletions packages/opentelemetry-api-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../../",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-api-metrics/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
10 changes: 7 additions & 3 deletions packages/opentelemetry-context-zone-peer-dep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
10 changes: 7 additions & 3 deletions packages/opentelemetry-context-zone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-context-zone/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
11 changes: 8 additions & 3 deletions packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-core/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
11 changes: 8 additions & 3 deletions packages/opentelemetry-exporter-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-exporter-collector/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
11 changes: 8 additions & 3 deletions packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-exporter-zipkin/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
10 changes: 7 additions & 3 deletions packages/opentelemetry-instrumentation-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.esm.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Loading

0 comments on commit 23ba4bf

Please sign in to comment.