diff --git a/packages/telemetry/.eslintrc.js b/packages/telemetry/.eslintrc.js new file mode 100644 index 00000000000..6c2d7e1b033 --- /dev/null +++ b/packages/telemetry/.eslintrc.js @@ -0,0 +1,26 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +module.exports = { + extends: '../../config/.eslintrc.js', + parserOptions: { + project: 'tsconfig.json', + // to make vscode-eslint work with monorepo + // https://github.com/typescript-eslint/typescript-eslint/issues/251#issuecomment-463943250 + tsconfigRootDir: __dirname + } +}; diff --git a/packages/telemetry/CHANGELOG.md b/packages/telemetry/CHANGELOG.md new file mode 100644 index 00000000000..9f41ee41628 --- /dev/null +++ b/packages/telemetry/CHANGELOG.md @@ -0,0 +1 @@ +# @firebase/telemetry diff --git a/packages/telemetry/README.md b/packages/telemetry/README.md new file mode 100644 index 00000000000..c9b01e6d58e --- /dev/null +++ b/packages/telemetry/README.md @@ -0,0 +1,3 @@ +# @firebase/telemetry + +This package provides instrumentation functionality for javascript applications. diff --git a/packages/telemetry/index.node.ts b/packages/telemetry/index.node.ts new file mode 100644 index 00000000000..726f98a1289 --- /dev/null +++ b/packages/telemetry/index.node.ts @@ -0,0 +1,28 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +/** + * This is the file that people using Node.js will actually import. You should + * only include this file if you have something specific about your + * implementation that mandates having a separate entrypoint. Otherwise you can + * just use index.ts + */ + +import { testFxn } from './src'; + +console.log('Hi Node.js Users!'); +testFxn(); diff --git a/packages/telemetry/index.ts b/packages/telemetry/index.ts new file mode 100644 index 00000000000..218b9afbb10 --- /dev/null +++ b/packages/telemetry/index.ts @@ -0,0 +1,20 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +import { testFxn } from './src'; + +testFxn(); diff --git a/packages/telemetry/karma.conf.js b/packages/telemetry/karma.conf.js new file mode 100644 index 00000000000..02647ba4c35 --- /dev/null +++ b/packages/telemetry/karma.conf.js @@ -0,0 +1,32 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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 karmaBase = require('../../config/karma.base'); + +const files = [`src/**/*.test.ts`]; + +module.exports = function (config) { + const karmaConfig = { + ...karmaBase, + files, + frameworks: ['mocha'] + }; + + config.set(karmaConfig); +}; + +module.exports.files = files; diff --git a/packages/telemetry/package.json b/packages/telemetry/package.json new file mode 100644 index 00000000000..110c6ef7cc9 --- /dev/null +++ b/packages/telemetry/package.json @@ -0,0 +1,70 @@ +{ + "name": "@firebase/telemetry", + "version": "0.0.1", + "private": true, + "description": "The Firebase Web Telemetry package of the Firebase JS SDK", + "author": "Firebase (https://firebase.google.com/)", + "main": "dist/index.node.cjs.js", + "browser": "dist/index.esm.js", + "module": "dist/index.esm.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "node": { + "import": "./dist/node-esm/index.node.esm.js", + "require": "./dist/index.node.cjs.js" + }, + "browser": { + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm.js" + }, + "default": "./dist/index.esm.js" + }, + "./package.json": "./package.json" + }, + "files": [ + "dist" + ], + "scripts": { + "lint": "eslint -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", + "lint:fix": "eslint --fix -c .eslintrc.js '**/*.ts' --ignore-path '../../.gitignore'", + "build": "rollup -c", + "build:deps": "lerna run --scope @firebase/telemetry --include-dependencies build", + "dev": "rollup -c -w", + "test": "run-p --npm-path npm lint test:all", + "test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all", + "test:all": "run-p --npm-path npm test:browser test:node", + "test:browser": "karma start", + "test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha src/**/*.test.* --config ../../config/mocharc.node.js", + "trusted-type-check": "tsec -p tsconfig.json --noEmit" + }, + "peerDependencies": { + "@firebase/app": "0.x", + "@firebase/app-types": "0.x" + }, + "dependencies": { + "tslib": "^2.1.0" + }, + "license": "Apache-2.0", + "devDependencies": { + "@firebase/app": "0.14.1", + "rollup": "2.79.2", + "rollup-plugin-typescript2": "0.36.0", + "typescript": "5.5.4" + }, + "repository": { + "directory": "packages/telemetry", + "type": "git", + "url": "git+https://github.com/firebase/firebase-js-sdk.git" + }, + "bugs": { + "url": "https://github.com/firebase/firebase-js-sdk/issues" + }, + "typings": "dist/index.d.ts", + "nyc": { + "extension": [ + ".ts" + ], + "reportDir": "./coverage/node" + } +} diff --git a/packages/telemetry/rollup.config.js b/packages/telemetry/rollup.config.js new file mode 100644 index 00000000000..1450a975ce6 --- /dev/null +++ b/packages/telemetry/rollup.config.js @@ -0,0 +1,75 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +import typescriptPlugin from 'rollup-plugin-typescript2'; +import typescript from 'typescript'; +import pkg from './package.json'; +import { emitModulePackageFile } from '../../scripts/build/rollup_emit_module_package_file'; + +const deps = Object.keys( + Object.assign({}, pkg.peerDependencies, pkg.dependencies) +); + +const buildPlugins = [typescriptPlugin({ typescript })]; + +const browserBuilds = [ + { + input: 'index.ts', + output: { + file: pkg.module, + format: 'es', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'index.ts', + output: { + file: './dist/index.cjs.js', + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + } +]; + +const nodeBuilds = [ + { + input: 'index.node.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: buildPlugins, + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + }, + { + input: 'index.node.ts', + output: { + file: pkg.exports['.'].node.import, + format: 'es', + sourcemap: true + }, + plugins: [...buildPlugins, emitModulePackageFile()], + external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)) + } +]; + +export default [...browserBuilds, ...nodeBuilds]; diff --git a/packages/telemetry/src/index.test.ts b/packages/telemetry/src/index.test.ts new file mode 100644 index 00000000000..4b314ac8835 --- /dev/null +++ b/packages/telemetry/src/index.test.ts @@ -0,0 +1,31 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +import { expect } from 'chai'; +import { testFxn } from './index'; + +describe('Simple test', () => { + it('Should skip this test'); + it('Should test this function', () => { + expect(testFxn()).to.equal(42); + }); + it('Should test this async thing', async () => { + // Do some async assertions, you can use `await` syntax if it helps + const val = await Promise.resolve(42); + expect(val).to.equal(42); + }); +}); diff --git a/packages/telemetry/src/index.ts b/packages/telemetry/src/index.ts new file mode 100644 index 00000000000..8dca8834e11 --- /dev/null +++ b/packages/telemetry/src/index.ts @@ -0,0 +1,24 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +import { TestType } from './types/index'; + +export function testFxn(): number { + const _thing: TestType = {}; + console.log('hi'); + return 42; +} diff --git a/packages/telemetry/src/types/index.ts b/packages/telemetry/src/types/index.ts new file mode 100644 index 00000000000..8626d54ad64 --- /dev/null +++ b/packages/telemetry/src/types/index.ts @@ -0,0 +1,20 @@ +/** + * @license + * Copyright 2025 Google LLC + * + * 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. + */ + +export interface TestType { + prop?: string; +} diff --git a/packages/telemetry/tsconfig.json b/packages/telemetry/tsconfig.json new file mode 100644 index 00000000000..4e0ae05eebc --- /dev/null +++ b/packages/telemetry/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../config/tsconfig.base.json", + "compilerOptions": { + "outDir": "dist" + }, + "exclude": ["dist/**/*"] +}