From e15e7e718b1f9101c168dcc45a6c55045e64d574 Mon Sep 17 00:00:00 2001 From: Reino Muhl <10620585+StaberindeZA@users.noreply.github.com> Date: Fri, 9 Aug 2024 12:28:49 -0400 Subject: [PATCH] feat(next): add glean-generate script Because: - Have project target to generate glean code. This commit: - Adds glean metrics library. - Adds blank subplat-backend-metrics.yaml - Add glean-generate target to project. Closes #FXA-9996 --- apps/payments/next/project.json | 12 +++++- libs/shared/metrics/glean/.eslintrc.json | 18 +++++++++ libs/shared/metrics/glean/.swcrc | 15 ++++++++ libs/shared/metrics/glean/README.md | 15 ++++++++ libs/shared/metrics/glean/jest.config.ts | 30 +++++++++++++++ libs/shared/metrics/glean/package.json | 8 ++++ libs/shared/metrics/glean/project.json | 38 +++++++++++++++++++ libs/shared/metrics/glean/src/index.ts | 3 ++ .../src/registry/subplat-backend-metrics.yaml | 3 ++ libs/shared/metrics/glean/tsconfig.json | 22 +++++++++++ libs/shared/metrics/glean/tsconfig.lib.json | 10 +++++ libs/shared/metrics/glean/tsconfig.spec.json | 14 +++++++ package.json | 1 + tsconfig.base.json | 1 + yarn.lock | 14 +++++++ 15 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 libs/shared/metrics/glean/.eslintrc.json create mode 100644 libs/shared/metrics/glean/.swcrc create mode 100644 libs/shared/metrics/glean/README.md create mode 100644 libs/shared/metrics/glean/jest.config.ts create mode 100644 libs/shared/metrics/glean/package.json create mode 100644 libs/shared/metrics/glean/project.json create mode 100644 libs/shared/metrics/glean/src/index.ts create mode 100644 libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml create mode 100644 libs/shared/metrics/glean/tsconfig.json create mode 100644 libs/shared/metrics/glean/tsconfig.lib.json create mode 100644 libs/shared/metrics/glean/tsconfig.spec.json diff --git a/apps/payments/next/project.json b/apps/payments/next/project.json index 5bede5a0bdb..8b83b527c31 100644 --- a/apps/payments/next/project.json +++ b/apps/payments/next/project.json @@ -12,7 +12,7 @@ "outputPath": "dist/apps/payments/next", "postcssConfig": "apps/payments/next/postcss.config.js" }, - "dependsOn": ["l10n-bundle"] + "dependsOn": ["l10n-bundle", "glean-generate"] }, "dev": { "options": { @@ -37,7 +37,8 @@ "outputs": ["{options.outputFile}"], "options": { "lintFilePatterns": ["apps/payments/next/**/*.{ts,tsx,js,jsx}"] - } + }, + "dependsOn": ["glean-lint"] }, "start": { "command": "pm2 start apps/payments/next/pm2.config.js && yarn check:url localhost:3035/__heartbeat__" @@ -70,6 +71,13 @@ "dependsOn": ["l10n-prime"], "command": "node -r esbuild-register apps/payments/next/app/_lib/scripts/convert.ts" }, + "glean-generate": { + "dependsOn": ["glean-lint"], + "command": "yarn glean translate libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml -f typescript_server -o apps/payments/next/lib/metrics/glean" + }, + "glean-lint": { + "command": "yarn glean glinter libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml" + }, "storybook": { "executor": "@nx/storybook:storybook", "options": { diff --git a/libs/shared/metrics/glean/.eslintrc.json b/libs/shared/metrics/glean/.eslintrc.json new file mode 100644 index 00000000000..632e9b0e222 --- /dev/null +++ b/libs/shared/metrics/glean/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": {} + }, + { + "files": ["*.ts", "*.tsx"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "rules": {} + } + ] +} diff --git a/libs/shared/metrics/glean/.swcrc b/libs/shared/metrics/glean/.swcrc new file mode 100644 index 00000000000..42938ddcefd --- /dev/null +++ b/libs/shared/metrics/glean/.swcrc @@ -0,0 +1,15 @@ +{ + "jsc": { + "target": "es2017", + "parser": { + "syntax": "typescript", + "decorators": true, + "dynamicImport": true + }, + "transform": { + "decoratorMetadata": true, + "legacyDecorator": true + } + } +} + diff --git a/libs/shared/metrics/glean/README.md b/libs/shared/metrics/glean/README.md new file mode 100644 index 00000000000..888f9606917 --- /dev/null +++ b/libs/shared/metrics/glean/README.md @@ -0,0 +1,15 @@ +# shared-glean + +This library was generated with [Nx](https://nx.dev). + +## Building + +Run `nx build shared-glean` to build the library. + +## Running unit tests + +Run `nx run shared-glean:test-unit` to execute the unit tests via [Jest](https://jestjs.io). + +## Running integration tests + +Run `nx run shared-glean:test-integration` to execute the integration tests via [Jest](https://jestjs.io). diff --git a/libs/shared/metrics/glean/jest.config.ts b/libs/shared/metrics/glean/jest.config.ts new file mode 100644 index 00000000000..3f20dbbb7ef --- /dev/null +++ b/libs/shared/metrics/glean/jest.config.ts @@ -0,0 +1,30 @@ +/* eslint-disable */ +import { readFileSync } from 'fs'; + +// Reading the SWC compilation config and remove the "exclude" +// for the test files to be compiled by SWC +const { exclude: _, ...swcJestConfig } = JSON.parse( + readFileSync(`${__dirname}/.swcrc`, 'utf-8') +); + +// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves. +// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude" +if (swcJestConfig.swcrc === undefined) { + swcJestConfig.swcrc = false; +} + +// Uncomment if using global setup/teardown files being transformed via swc +// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries +// jest needs EsModule Interop to find the default exported setup/teardown functions +// swcJestConfig.module.noInterop = false; + +export default { + displayName: 'shared-glean', + preset: '../../../../jest.preset.js', + testEnvironment: 'node', + transform: { + '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig], + }, + moduleFileExtensions: ['ts', 'js', 'html'], + coverageDirectory: '../../../../coverage/libs/shared/metrics/glean', +}; diff --git a/libs/shared/metrics/glean/package.json b/libs/shared/metrics/glean/package.json new file mode 100644 index 00000000000..d290f411949 --- /dev/null +++ b/libs/shared/metrics/glean/package.json @@ -0,0 +1,8 @@ +{ + "name": "@fxa/shared/glean", + "version": "0.0.1", + "dependencies": {}, + "type": "commonjs", + "main": "./index.cjs", + "private": true +} diff --git a/libs/shared/metrics/glean/project.json b/libs/shared/metrics/glean/project.json new file mode 100644 index 00000000000..4b3ba9b95c9 --- /dev/null +++ b/libs/shared/metrics/glean/project.json @@ -0,0 +1,38 @@ +{ + "name": "shared-glean", + "$schema": "../../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/shared/metrics/glean/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "@nx/esbuild:esbuild", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/shared/metrics/glean", + "main": "libs/shared/metrics/glean/src/index.ts", + "tsConfig": "libs/shared/metrics/glean/tsconfig.lib.json", + "assets": ["libs/shared/metrics/glean/*.md"], + "generatePackageJson": true, + "declaration": true, + "format": ["cjs"] + } + }, + "test-unit": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/shared/metrics/glean/jest.config.ts", + "testPathPattern": ["^(?!.*\\.in\\.spec\\.ts$).*$"] + } + }, + "test-integration": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/shared/metrics/glean/jest.config.ts", + "testPathPattern": ["\\.in\\.spec\\.ts$"] + } + } + } +} diff --git a/libs/shared/metrics/glean/src/index.ts b/libs/shared/metrics/glean/src/index.ts new file mode 100644 index 00000000000..e0032240a4d --- /dev/null +++ b/libs/shared/metrics/glean/src/index.ts @@ -0,0 +1,3 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ diff --git a/libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml b/libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml new file mode 100644 index 00000000000..50df535098e --- /dev/null +++ b/libs/shared/metrics/glean/src/registry/subplat-backend-metrics.yaml @@ -0,0 +1,3 @@ +--- +# Schema +$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0 diff --git a/libs/shared/metrics/glean/tsconfig.json b/libs/shared/metrics/glean/tsconfig.json new file mode 100644 index 00000000000..4022fd4d0ad --- /dev/null +++ b/libs/shared/metrics/glean/tsconfig.json @@ -0,0 +1,22 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/shared/metrics/glean/tsconfig.lib.json b/libs/shared/metrics/glean/tsconfig.lib.json new file mode 100644 index 00000000000..18f2d37a19a --- /dev/null +++ b/libs/shared/metrics/glean/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] +} diff --git a/libs/shared/metrics/glean/tsconfig.spec.json b/libs/shared/metrics/glean/tsconfig.spec.json new file mode 100644 index 00000000000..6668655fc39 --- /dev/null +++ b/libs/shared/metrics/glean/tsconfig.spec.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +} diff --git a/package.json b/package.json index d36014d260f..0fc9215b80d 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@google-cloud/pubsub": "^4.3.1", "@google-cloud/translate": "^8.2.0", "@grpc/grpc-js": "^1.11.1", + "@mozilla/glean": "^5.0.3", "@nestjs/apollo": "^12.1.0", "@nestjs/common": "^10.3.4", "@nestjs/config": "^3.2.0", diff --git a/tsconfig.base.json b/tsconfig.base.json index 5939eeaa74f..d39c37c253e 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -49,6 +49,7 @@ ], "@fxa/shared/error": ["libs/shared/error/src/index.ts"], "@fxa/shared/geodb": ["libs/shared/geodb/src/index.ts"], + "@fxa/shared/glean": ["libs/shared/metrics/glean/src/index.ts"], "@fxa/shared/l10n": ["libs/shared/l10n/src/index.ts"], "@fxa/shared/l10n/client": ["libs/shared/l10n/src/client.ts"], "@fxa/shared/l10n/server": ["libs/shared/l10n/src/server.ts"], diff --git a/yarn.lock b/yarn.lock index 9afcb74a05b..d8ac8d6ce00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12774,6 +12774,19 @@ __metadata: languageName: node linkType: hard +"@mozilla/glean@npm:^5.0.3": + version: 5.0.3 + resolution: "@mozilla/glean@npm:5.0.3" + dependencies: + fflate: ^0.8.0 + tslib: ^2.3.1 + uuid: ^9.0.0 + bin: + glean: dist/cli/cli.js + checksum: 58ec9e831855d57f319738378694ca04b99217c10fee2c370f62624e61ca9b65b799cd16d499cd3cf9a2d18fc1ea512360c10fba2da0af62971e409e43aaa88d + languageName: node + linkType: hard + "@mrmlnc/readdir-enhanced@npm:^2.2.1": version: 2.2.1 resolution: "@mrmlnc/readdir-enhanced@npm:2.2.1" @@ -40115,6 +40128,7 @@ fsevents@~2.1.1: "@graphql-codegen/typescript": ^4.0.1 "@graphql-codegen/typescript-document-nodes": ^4.0.1 "@grpc/grpc-js": ^1.11.1 + "@mozilla/glean": ^5.0.3 "@nestjs/apollo": ^12.1.0 "@nestjs/cli": ^10.4.2 "@nestjs/common": ^10.3.4