Skip to content

Commit c268832

Browse files
dyladanMSNev
andauthored
chore: add api to monorepo (open-telemetry#3261)
* Add API to lerna * Update todo * Expect instead of ignore error * Add webpack test context * Block scope test variables * Fix linting * Fix lining path * Fix lint * Fix lint * Update index-webpack.worker.ts Co-authored-by: Nev <[email protected]>
1 parent 6111ae0 commit c268832

File tree

50 files changed

+282
-49
lines changed

Some content is hidden

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

50 files changed

+282
-49
lines changed

api/.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
"env": {
3+
"mocha": true,
4+
"commonjs": true,
5+
"shared-node-browser": true
6+
},
7+
...require('../eslint.config.js')
8+
}

api/TODO.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
These tasks must be completed before the API package can be released from this repository.
44

55
- [x] remove files specific to the API git repo
6-
- [ ] add to lerna monorepo
7-
- [ ] add tsconfig files
8-
- [ ] add web testing
9-
- [ ] build esm versions
6+
- [x] add to lerna monorepo
7+
- [x] add tsconfig files
8+
- [x] add web testing
9+
- [x] build esm versions
1010
- [ ] test node versions 8, 10, and 12
11-
- [ ] add to auto published docs
11+
- [x] add to auto published docs

api/karma.conf.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*!
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const karmaWebpackConfig = require('../karma.webpack');
18+
const karmaBaseConfig = require('../karma.base');
19+
20+
module.exports = (config) => {
21+
config.set(Object.assign({}, karmaBaseConfig, {
22+
webpack: karmaWebpackConfig,
23+
}))
24+
};

api/karma.worker.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*!
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const karmaWebpackConfig = require('../karma.webpack');
18+
const karmaBaseConfig = require('../karma.worker');
19+
20+
module.exports = (config) => {
21+
config.set(Object.assign({}, karmaBaseConfig, {
22+
webpack: karmaWebpackConfig,
23+
}))
24+
};

api/package.json

+27-31
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,25 @@
1212
},
1313
"repository": "https://github.com/open-telemetry/opentelemetry-js-api.git",
1414
"scripts": {
15-
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
16-
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p .",
17-
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p .",
18-
"precompile": "npm run version",
15+
"clean": "tsc --build --clean",
16+
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
17+
"codecov:webworker": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
18+
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
19+
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
1920
"compile": "tsc --build tsconfig.json tsconfig.esm.json",
2021
"docs": "typedoc",
2122
"docs:deploy": "gh-pages --dist docs/out",
2223
"docs:test": "linkinator docs/out --silent && linkinator docs/*.md *.md --markdown --silent",
23-
"lint:fix": "eslint src test --ext .ts --fix",
24-
"lint": "eslint src test --ext .ts",
24+
"lint:fix": "eslint . --ext .ts --fix",
25+
"lint": "eslint . --ext .ts",
2526
"test:browser": "nyc karma start --single-run",
2627
"test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
28+
"test:webworker": "nyc karma start karma.worker.js --single-run",
2729
"cycle-check": "dpdm --exit-code circular:1 src/index.ts",
28-
"version": "node scripts/version-update.js",
29-
"prewatch": "npm run version",
30-
"watch": "tsc --build --watch"
30+
"version": "node ../scripts/version-update.js",
31+
"prewatch": "npm run precompile",
32+
"watch": "tsc --build --watch",
33+
"peer-api-check": "node ../scripts/peer-api-check.js"
3134
},
3235
"keywords": [
3336
"opentelemetry",
@@ -57,34 +60,27 @@
5760
"access": "public"
5861
},
5962
"devDependencies": {
60-
"@types/mocha": "8.2.2",
61-
"@types/node": "14.17.4",
62-
"@types/sinon": "10.0.2",
63-
"@types/webpack-env": "1.16.0",
64-
"@typescript-eslint/eslint-plugin": "5.0.0",
65-
"@typescript-eslint/parser": "5.0.0",
66-
"codecov": "3.8.2",
67-
"dpdm": "3.7.1",
68-
"eslint": "7.32.0",
69-
"eslint-plugin-header": "3.1.1",
70-
"eslint-plugin-node": "11.1.0",
71-
"gh-pages": "3.2.0",
63+
"@types/mocha": "9.1.1",
64+
"@types/node": "18.6.5",
65+
"@types/sinon": "10.0.13",
66+
"@types/webpack-env": "1.16.3",
67+
"codecov": "3.8.3",
68+
"dpdm": "3.10.0",
7269
"istanbul-instrumenter-loader": "3.0.1",
73-
"karma": "5.2.3",
70+
"karma": "6.3.16",
7471
"karma-chrome-launcher": "3.1.0",
7572
"karma-coverage-istanbul-reporter": "3.0.3",
7673
"karma-mocha": "2.0.1",
74+
"karma-mocha-webworker": "1.3.0",
7775
"karma-spec-reporter": "0.0.32",
7876
"karma-webpack": "4.0.2",
79-
"lerna-changelog": "1.0.1",
80-
"linkinator": "2.13.6",
81-
"mocha": "7.2.0",
77+
"mocha": "10.0.0",
8278
"nyc": "15.1.0",
83-
"sinon": "11.1.1",
84-
"ts-loader": "8.2.0",
85-
"ts-mocha": "8.0.0",
86-
"typedoc": "0.21.2",
87-
"typescript": "4.3.5",
79+
"sinon": "14.0.0",
80+
"ts-loader": "8.4.0",
81+
"ts-mocha": "10.0.0",
82+
"typescript": "4.4.4",
8883
"webpack": "4.46.0"
89-
}
84+
},
85+
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api"
9086
}

api/src/platform/browser/globalThis.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef
3030
export const _globalThis: typeof globalThis =
3131
typeof globalThis === 'object' ? globalThis :
32-
typeof self === 'object' ? self :
33-
typeof window === 'object' ? window :
34-
typeof global === 'object' ? global :
32+
typeof self === 'object' ? self :
33+
typeof window === 'object' ? window :
34+
typeof global === 'object' ? global :
3535
{} as typeof globalThis;

api/src/trace/NoopTracer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { SpanOptions } from './SpanOptions';
2424
import { SpanContext } from './span_context';
2525
import { Tracer } from './tracer';
2626

27-
const context = ContextAPI.getInstance();
27+
const contextApi = ContextAPI.getInstance();
2828

2929
/**
3030
* No-op implementations of {@link Tracer}.
@@ -87,11 +87,11 @@ export class NoopTracer implements Tracer {
8787
fn = arg4 as F;
8888
}
8989

90-
const parentContext = ctx ?? context.active();
90+
const parentContext = ctx ?? contextApi.active();
9191
const span = this.startSpan(name, opts, parentContext);
9292
const contextWithSpanSet = setSpan(parentContext, span);
9393

94-
return context.with(contextWithSpanSet, fn, undefined, span);
94+
return contextApi.with(contextWithSpanSet, fn, undefined, span);
9595
}
9696
}
9797

api/test/api/api.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('API', () => {
5656
const span = new NonRecordingSpan();
5757
const ctx = trace.setSpan(ROOT_CONTEXT, span);
5858
context.setGlobalContextManager({ active: () => ctx, disable: () => {} } as any);
59-
59+
6060
const active = trace.getActiveSpan();
6161
assert.strictEqual(active, span);
6262

api/test/diag/consoleLogger.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export const diagLoggerFunctions = [
2727
'error',
2828
] as const;
2929

30-
const consoleFuncs: Array<keyof Console> = [
30+
const consoleFuncs = [
3131
'debug',
3232
'info',
3333
'warn',
3434
'error',
3535
'log',
3636
'trace',
37-
];
37+
] as const;
3838

3939
const expectedConsoleMap: { [n: string]: keyof Console } = {
4040
error: 'error',
@@ -127,6 +127,7 @@ describe('DiagConsoleLogger', () => {
127127

128128
consoleFuncs.forEach(cName => {
129129
it(`should log ${fName} message even when console doesn't support ${cName} call before construction`, () => {
130+
// @ts-expect-error removing a console property is not allowed by types
130131
console[cName] = undefined;
131132
const consoleLogger: any = new DiagConsoleLogger();
132133
consoleLogger[fName](`${fName} called %s`, 'param1');
@@ -142,6 +143,7 @@ describe('DiagConsoleLogger', () => {
142143

143144
it(`should log ${fName} message even when console doesn't support ${cName} call after construction`, () => {
144145
const consoleLogger: any = new DiagConsoleLogger();
146+
// @ts-expect-error removing a console property is not allowed by types
145147
console[cName] = undefined;
146148
consoleLogger[fName](`${fName} called %s`, 'param1');
147149
if (cName !== expectedConsoleMap[fName]) {

api/test/index-webpack.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
const testsContext = require.context('.', true, /test$/);
17-
testsContext.keys().forEach(testsContext);
16+
{
17+
const testsContext = require.context('.', true, /test$/);
18+
testsContext.keys().forEach(testsContext);
19+
}
1820

19-
const srcContext = require.context('.', true, /src$/);
20-
srcContext.keys().forEach(srcContext);
21+
{
22+
const srcContext = require.context('.', true, /src$/);
23+
srcContext.keys().forEach(srcContext);
24+
}

api/test/index-webpack.worker.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
{
17+
const testsContext = require.context('./', true, /test$/);
18+
testsContext.keys().forEach(testsContext);
19+
}

api/tsconfig.all.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"files": [],
4+
"references": [
5+
{ "path": "./tsconfig.json" },
6+
{ "path": "./tsconfig.esm.json" },
7+
{ "path": "./tsconfig.esnext.json" }
8+
]
9+
}

api/tsconfig.esm.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.base.esm.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build/esm",
6+
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
7+
},
8+
"include": [
9+
"src/**/*.ts"
10+
]
11+
}

api/tsconfig.esnext.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "../tsconfig.base.esnext.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build/esnext",
6+
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
7+
},
8+
"include": [
9+
"src/**/*.ts"
10+
]
11+
}

api/tsconfig.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"outDir": "build"
6+
},
7+
"include": [
8+
"src/**/*.ts",
9+
"test/**/*.ts"
10+
],
11+
"references": [
12+
]
13+
}

experimental/packages/api-logs/tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
"include": [
88
"src/**/*.ts",
99
"test/**/*.ts"
10+
],
11+
"references": [
12+
{
13+
"path": "../../../api"
14+
}
1015
]
1116
}

experimental/packages/exporter-trace-otlp-grpc/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"test/**/*.ts"
1010
],
1111
"references": [
12+
{
13+
"path": "../../../api"
14+
},
1215
{
1316
"path": "../../../packages/opentelemetry-core"
1417
},

experimental/packages/exporter-trace-otlp-http/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"test/**/*.ts"
1010
],
1111
"references": [
12+
{
13+
"path": "../../../api"
14+
},
1215
{
1316
"path": "../../../packages/opentelemetry-core"
1417
},

experimental/packages/exporter-trace-otlp-proto/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"test/**/*.ts"
1010
],
1111
"references": [
12+
{
13+
"path": "../../../api"
14+
},
1215
{
1316
"path": "../../../packages/opentelemetry-core"
1417
},

experimental/packages/opentelemetry-api-metrics/tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
"include": [
88
"src/**/*.ts",
99
"test/**/*.ts"
10+
],
11+
"references": [
12+
{
13+
"path": "../../../api"
14+
}
1015
]
1116
}

experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"test/**/*.ts"
1010
],
1111
"references": [
12+
{
13+
"path": "../../../api"
14+
},
1215
{
1316
"path": "../../../packages/opentelemetry-core"
1417
},

experimental/packages/opentelemetry-exporter-metrics-otlp-http/tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"test/**/*.ts"
1010
],
1111
"references": [
12+
{
13+
"path": "../../../api"
14+
},
1215
{
1316
"path": "../../../packages/opentelemetry-core"
1417
},

0 commit comments

Comments
 (0)