Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add api to monorepo #3261

Merged
merged 11 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"shared-node-browser": true
},
...require('../eslint.config.js')
}
10 changes: 5 additions & 5 deletions api/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
These tasks must be completed before the API package can be released from this repository.

- [x] remove files specific to the API git repo
- [ ] add to lerna monorepo
- [ ] add tsconfig files
- [ ] add web testing
- [ ] build esm versions
- [x] add to lerna monorepo
- [x] add tsconfig files
- [x] add web testing
- [x] build esm versions
- [ ] test node versions 8, 10, and 12
- [ ] add to auto published docs
- [x] add to auto published docs
24 changes: 24 additions & 0 deletions api/karma.conf.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
*
* http://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 karmaWebpackConfig = require('../karma.webpack');
const karmaBaseConfig = require('../karma.base');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig,
}))
};
24 changes: 24 additions & 0 deletions api/karma.worker.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
*
* http://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 karmaWebpackConfig = require('../karma.webpack');
const karmaBaseConfig = require('../karma.worker');

module.exports = (config) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: karmaWebpackConfig,
}))
};
58 changes: 27 additions & 31 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
},
"repository": "https://github.com/open-telemetry/opentelemetry-js-api.git",
"scripts": {
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p .",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p .",
"precompile": "npm run version",
"clean": "tsc --build --clean",
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
"codecov:webworker": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"compile": "tsc --build tsconfig.json tsconfig.esm.json",
"docs": "typedoc",
"docs:deploy": "gh-pages --dist docs/out",
"docs:test": "linkinator docs/out --silent && linkinator docs/*.md *.md --markdown --silent",
"lint:fix": "eslint src test --ext .ts --fix",
"lint": "eslint src test --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"lint": "eslint . --ext .ts",
"test:browser": "nyc karma start --single-run",
"test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
"test:webworker": "nyc karma start karma.worker.js --single-run",
"cycle-check": "dpdm --exit-code circular:1 src/index.ts",
"version": "node scripts/version-update.js",
"prewatch": "npm run version",
"watch": "tsc --build --watch"
"version": "node ../scripts/version-update.js",
"prewatch": "npm run precompile",
"watch": "tsc --build --watch",
"peer-api-check": "node ../scripts/peer-api-check.js"
},
"keywords": [
"opentelemetry",
Expand Down Expand Up @@ -57,34 +60,27 @@
"access": "public"
},
"devDependencies": {
"@types/mocha": "8.2.2",
"@types/node": "14.17.4",
"@types/sinon": "10.0.2",
"@types/webpack-env": "1.16.0",
"@typescript-eslint/eslint-plugin": "5.0.0",
"@typescript-eslint/parser": "5.0.0",
"codecov": "3.8.2",
"dpdm": "3.7.1",
"eslint": "7.32.0",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-node": "11.1.0",
"gh-pages": "3.2.0",
"@types/mocha": "9.1.1",
"@types/node": "18.6.5",
"@types/sinon": "10.0.13",
"@types/webpack-env": "1.16.3",
"codecov": "3.8.3",
"dpdm": "3.10.0",
"istanbul-instrumenter-loader": "3.0.1",
"karma": "5.2.3",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
"karma-mocha-webworker": "1.3.0",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"lerna-changelog": "1.0.1",
"linkinator": "2.13.6",
"mocha": "7.2.0",
"mocha": "10.0.0",
"nyc": "15.1.0",
"sinon": "11.1.1",
"ts-loader": "8.2.0",
"ts-mocha": "8.0.0",
"typedoc": "0.21.2",
"typescript": "4.3.5",
"sinon": "14.0.0",
"ts-loader": "8.4.0",
"ts-mocha": "10.0.0",
"typescript": "4.4.4",
"webpack": "4.46.0"
}
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api"
}
6 changes: 3 additions & 3 deletions api/src/platform/browser/globalThis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// eslint-disable-next-line node/no-unsupported-features/es-builtins, no-undef
export const _globalThis: typeof globalThis =
typeof globalThis === 'object' ? globalThis :
typeof self === 'object' ? self :
typeof window === 'object' ? window :
typeof global === 'object' ? global :
typeof self === 'object' ? self :
typeof window === 'object' ? window :
typeof global === 'object' ? global :
{} as typeof globalThis;
6 changes: 3 additions & 3 deletions api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { SpanOptions } from './SpanOptions';
import { SpanContext } from './span_context';
import { Tracer } from './tracer';

const context = ContextAPI.getInstance();
const contextApi = ContextAPI.getInstance();

/**
* No-op implementations of {@link Tracer}.
Expand Down Expand Up @@ -87,11 +87,11 @@ export class NoopTracer implements Tracer {
fn = arg4 as F;
}

const parentContext = ctx ?? context.active();
const parentContext = ctx ?? contextApi.active();
const span = this.startSpan(name, opts, parentContext);
const contextWithSpanSet = setSpan(parentContext, span);

return context.with(contextWithSpanSet, fn, undefined, span);
return contextApi.with(contextWithSpanSet, fn, undefined, span);
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('API', () => {
const span = new NonRecordingSpan();
const ctx = trace.setSpan(ROOT_CONTEXT, span);
context.setGlobalContextManager({ active: () => ctx, disable: () => {} } as any);

const active = trace.getActiveSpan();
assert.strictEqual(active, span);

Expand Down
6 changes: 4 additions & 2 deletions api/test/diag/consoleLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export const diagLoggerFunctions = [
'error',
] as const;

const consoleFuncs: Array<keyof Console> = [
const consoleFuncs = [
'debug',
'info',
'warn',
'error',
'log',
'trace',
];
] as const;

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

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

it(`should log ${fName} message even when console doesn't support ${cName} call after construction`, () => {
const consoleLogger: any = new DiagConsoleLogger();
// @ts-expect-error removing a console property is not allowed by types
console[cName] = undefined;
consoleLogger[fName](`${fName} called %s`, 'param1');
if (cName !== expectedConsoleMap[fName]) {
Expand Down
12 changes: 8 additions & 4 deletions api/test/index-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);
{
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);
}

const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
{
const srcContext = require.context('.', true, /src$/);
srcContext.keys().forEach(srcContext);
}
19 changes: 19 additions & 0 deletions api/test/index-webpack.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 testsContext = require.context('./', true, /test$/);
testsContext.keys().forEach(testsContext);
}
9 changes: 9 additions & 0 deletions api/tsconfig.all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.base.json",
"files": [],
"references": [
{ "path": "./tsconfig.json" },
{ "path": "./tsconfig.esm.json" },
{ "path": "./tsconfig.esnext.json" }
]
}
11 changes: 11 additions & 0 deletions api/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: 11 additions & 0 deletions api/tsconfig.esnext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.base.esnext.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esnext",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"include": [
"src/**/*.ts"
]
}
13 changes: 13 additions & 0 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
],
"references": [
]
}
5 changes: 5 additions & 0 deletions experimental/packages/api-logs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"include": [
"src/**/*.ts",
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
"include": [
"src/**/*.ts",
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"test/**/*.ts"
],
"references": [
{
"path": "../../../api"
},
{
"path": "../../../packages/opentelemetry-core"
},
Expand Down
Loading