Skip to content

Commit

Permalink
fix(api): fix unreachable @opentelemetry/api/experimental entry
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Jan 30, 2024
1 parent 43e598e commit 0853854
Show file tree
Hide file tree
Showing 8 changed files with 709 additions and 8 deletions.
3 changes: 1 addition & 2 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ All notable changes to this project will be documented in this file.
## Unreleased

* feat(api): add SugaredTracer for functions not defined in the spec

## Unreleased
* fix(api): fix unreachable @opentelemetry/api/experimental entry [#4446](https://github.com/open-telemetry/opentelemetry-js/pull/4446) @legendecas

## 1.7.0

Expand Down
8 changes: 4 additions & 4 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"default": "./build/src/index.js"
},
"./experimental": {
"module": "./build/esm/experimental.js",
"esnext": "./build/esnext/experimental.js",
"types": "./build/src/experimental.d.ts",
"default": "./build/src/experimental.js"
"module": "./build/esm/experimental/index.js",
"esnext": "./build/esnext/experimental/index.js",
"types": "./build/src/experimental/index.d.ts",
"default": "./build/src/experimental/index.js"
}
},
"repository": "open-telemetry/opentelemetry-js",
Expand Down
14 changes: 12 additions & 2 deletions eslint.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module.exports = {
"node",
"prettier"
],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
extends: ["eslint:recommended", "plugin:prettier/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
"project": "./tsconfig.json"
"project": null,
},
rules: {
"quotes": ["error", "single", { "avoidEscape": true }],
Expand All @@ -29,6 +29,11 @@ module.exports = {
overrides: [
{
files: ['*.ts'],
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
},
rules: {
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-this-alias": "off",
Expand All @@ -54,6 +59,11 @@ module.exports = {
},
{
files: ["test/**/*.ts"],
// Enable typescript-eslint for ts files.
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
parserOptions: {
"project": "./tsconfig.json"
},
rules: {
"no-empty": "off",
"@typescript-eslint/ban-ts-ignore": "off",
Expand Down
24 changes: 24 additions & 0 deletions integration-tests/api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = {
env: {
mocha: true,
commonjs: true,
node: true,
browser: true,
},
...require('../../eslint.base.js'),
};
10 changes: 10 additions & 0 deletions integration-tests/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `opentelemetry/integration-tests-api`

This is an integration test suite for `@opentelemetry/api` that verifies the
api package works as expected when being imported.

## Test

```sh
npm run test
```
40 changes: 40 additions & 0 deletions integration-tests/api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@opentelemetry/integration-tests-api",
"version": "1.20.0",
"private": true,
"publishConfig": {
"access": "restricted"
},
"description": "Verifies @opentelemetry/api in integration tests",
"author": "OpenTelemetry Authors",
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/integration-tests/api",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/open-telemetry/opentelemetry-js.git"
},
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"engines": {
"node": ">=14"
},
"scripts": {
"compile": "cross-var lerna run version --scope $npm_package_name --include-dependencies",
"pretest": "npm run compile",
"test": "nyc mocha test/**/*.test.js",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"lint": "eslint . --ext .js",
"lint:fix": "eslint . --ext .js --fix"
},
"devDependencies": {
"@opentelemetry/api": "^1.0.0",
"@types/mocha": "9.1.1",
"@types/node": "18.6.5",
"codecov": "3.8.3",
"cross-var": "1.1.0",
"lerna": "6.6.2",
"mocha": "10.0.0",
"nyc": "15.1.0"
}
}
48 changes: 48 additions & 0 deletions integration-tests/api/test/api-entries.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const assert = require('assert');

// TypeScript v4.4.4 doesn't support `node16` or `nodenext` in
// [Module Resolution](https://www.typescriptlang.org/tsconfig#moduleResolution)
// which is required for typescript to resolve the `package.json#exports`
// entries.
// Additionally, using `node16` or `nodenext` in `tsconfig.json#moduleResolution`
// requires the TypeScript to generate ESModule outputs. This is a breaking
// change for CJS users.
// So we have to use plain JavaScript to verity the `package.json#exports` here.

describe('@opentelemetry/api entries', () => {
it('should import root entry', async () => {
const mod = await import('@opentelemetry/api');
assert.ok(mod.trace != null);
});

it('should require root entry', () => {
const mod = require('@opentelemetry/api');
assert.ok(mod.trace != null);
});

it('should import experimental entry', async () => {
const mod = await import('@opentelemetry/api/experimental');
assert.ok(mod.wrapTracer != null);
});

it('should require experimental entry', () => {
const mod = require('@opentelemetry/api/experimental');
assert.ok(mod.wrapTracer != null);
});
});

0 comments on commit 0853854

Please sign in to comment.