From 949ad2a2ae51c9ab4c84289fdf77692e5f42a48a Mon Sep 17 00:00:00 2001 From: Daniel Ayala <14967941+danielayala94@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:36:01 -0800 Subject: [PATCH 1/4] Moved nameHelpers to telemetry, updated references --- .../src/commands/initWindows/initWindows.ts | 2 +- .../cli/src/e2etest/initWindows.test.ts | 70 +---------------- .../cli/src/generator-windows/index.ts | 2 +- .../@react-native-windows/cli/tsconfig.json | 12 ++- .../telemetry/src/test/nameHelpers.test.ts | 75 +++++++++++++++++++ .../src/utils/nameHelpers.ts | 0 6 files changed, 86 insertions(+), 75 deletions(-) create mode 100644 packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts rename packages/@react-native-windows/{cli => telemetry}/src/utils/nameHelpers.ts (100%) diff --git a/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts b/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts index c21ad1e13cf..2bd03d221cb 100644 --- a/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts +++ b/packages/@react-native-windows/cli/src/commands/initWindows/initWindows.ts @@ -29,7 +29,7 @@ import { endTelemetrySession, } from '../../utils/telemetryHelpers'; import {copyAndReplaceWithChangedCallback} from '../../generator-common'; -import * as nameHelpers from '../../utils/nameHelpers'; +import * as nameHelpers from '@react-native-windows/telemetry/src/utils/nameHelpers'; import {InitOptions, initOptions} from './initWindowsOptions'; export interface TemplateFileMapping { diff --git a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts index 2c9a418f141..86065ca7fed 100644 --- a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts +++ b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts @@ -11,8 +11,6 @@ import { InitOptions, } from '../commands/initWindows/initWindowsOptions'; -import * as nameHelpers from '../utils/nameHelpers'; - function validateOptionName( name: string, optionName: keyof InitOptions, @@ -59,70 +57,4 @@ test('initOptions - validate options', () => { validateOptionName(commandOption.name, optionName as keyof InitOptions), ).toBe(true); } -}); - -test('nameHelpers - cleanName', () => { - expect(nameHelpers.cleanName('@scope/package')).toBe('Package'); - expect(nameHelpers.cleanName('@scope/package-name')).toBe('PackageName'); - expect(nameHelpers.cleanName('package')).toBe('Package'); - expect(nameHelpers.cleanName('package-name')).toBe('PackageName'); -}); - -test('nameHelpers - isValidProjectName', () => { - expect(nameHelpers.isValidProjectName('package')).toBe(true); - expect(nameHelpers.isValidProjectName('package-name')).toBe(false); - expect(nameHelpers.isValidProjectName('Package')).toBe(true); - expect(nameHelpers.isValidProjectName('Package-name')).toBe(false); - expect(nameHelpers.isValidProjectName('Package-Name')).toBe(false); - expect(nameHelpers.isValidProjectName('@scope/package')).toBe(false); - expect(nameHelpers.isValidProjectName('@scope/package-name')).toBe(false); -}); - -test('nameHelpers - cleanNamespace', () => { - expect(nameHelpers.cleanNamespace('@scope/package')).toBe('Package'); - expect(nameHelpers.cleanNamespace('@scope/package-name')).toBe('PackageName'); - expect(nameHelpers.cleanNamespace('package')).toBe('Package'); - expect(nameHelpers.cleanNamespace('package-name')).toBe('PackageName'); - expect(nameHelpers.cleanNamespace('com.company.app')).toBe('Com.Company.App'); - expect(nameHelpers.cleanNamespace('com.company.app-name')).toBe( - 'Com.Company.AppName', - ); - expect(nameHelpers.cleanNamespace('com.company.app-name.other')).toBe( - 'Com.Company.AppName.Other', - ); - expect(nameHelpers.cleanNamespace('com::company::app')).toBe( - 'Com.Company.App', - ); - expect(nameHelpers.cleanNamespace('com::company::app-name')).toBe( - 'Com.Company.AppName', - ); - expect(nameHelpers.cleanNamespace('com::company::app-name::other')).toBe( - 'Com.Company.AppName.Other', - ); -}); - -test('nameHelpers - isValidProjectNamespace', () => { - expect(nameHelpers.isValidProjectNamespace('package')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('package-name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('Package')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('Package-name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('Package-Name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('@scope/package')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('@scope/package-name')).toBe( - false, - ); - expect(nameHelpers.isValidProjectNamespace('com.company.app')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('com.company.app-name')).toBe( - false, - ); - expect( - nameHelpers.isValidProjectNamespace('com.company.app-name.other'), - ).toBe(false); - expect(nameHelpers.isValidProjectNamespace('com::company::app')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('com::company::app-name')).toBe( - false, - ); - expect( - nameHelpers.isValidProjectNamespace('com::company::app-name::other'), - ).toBe(false); -}); +}); \ No newline at end of file diff --git a/packages/@react-native-windows/cli/src/generator-windows/index.ts b/packages/@react-native-windows/cli/src/generator-windows/index.ts index 1e2fa094e0b..84a17725052 100644 --- a/packages/@react-native-windows/cli/src/generator-windows/index.ts +++ b/packages/@react-native-windows/cli/src/generator-windows/index.ts @@ -18,7 +18,7 @@ import { findPropertyValue, tryFindPropertyValueAsBoolean, } from '../commands/config/configUtils'; -import * as nameHelpers from '../utils/nameHelpers'; +import * as nameHelpers from '@react-native-windows/telemetry/src/utils/nameHelpers'; import { createDir, diff --git a/packages/@react-native-windows/cli/tsconfig.json b/packages/@react-native-windows/cli/tsconfig.json index 9b9d9b6ff47..314a444b0d0 100644 --- a/packages/@react-native-windows/cli/tsconfig.json +++ b/packages/@react-native-windows/cli/tsconfig.json @@ -8,10 +8,14 @@ "DOM.Iterable", "ES2019.String" ], - // Not clean "strictFunctionTypes": false, }, - "include": ["src"], - "exclude": ["node_modules"] -} + "include": [ + "src", + "../telemetry/src/utils/nameHelpers.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file diff --git a/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts new file mode 100644 index 00000000000..4731a098167 --- /dev/null +++ b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * @format + */ + +import * as nameHelpers from '../utils/nameHelpers'; + +test('nameHelpers - cleanName', () => { + expect(nameHelpers.cleanName('@scope/package')).toBe('Package'); + expect(nameHelpers.cleanName('@scope/package-name')).toBe('PackageName'); + expect(nameHelpers.cleanName('package')).toBe('Package'); + expect(nameHelpers.cleanName('package-name')).toBe('PackageName'); + }); + + test('nameHelpers - isValidProjectName', () => { + expect(nameHelpers.isValidProjectName('package')).toBe(true); + expect(nameHelpers.isValidProjectName('package-name')).toBe(false); + expect(nameHelpers.isValidProjectName('Package')).toBe(true); + expect(nameHelpers.isValidProjectName('Package-name')).toBe(false); + expect(nameHelpers.isValidProjectName('Package-Name')).toBe(false); + expect(nameHelpers.isValidProjectName('@scope/package')).toBe(false); + expect(nameHelpers.isValidProjectName('@scope/package-name')).toBe(false); + }); + + test('nameHelpers - cleanNamespace', () => { + expect(nameHelpers.cleanNamespace('@scope/package')).toBe('Package'); + expect(nameHelpers.cleanNamespace('@scope/package-name')).toBe('PackageName'); + expect(nameHelpers.cleanNamespace('package')).toBe('Package'); + expect(nameHelpers.cleanNamespace('package-name')).toBe('PackageName'); + expect(nameHelpers.cleanNamespace('com.company.app')).toBe('Com.Company.App'); + expect(nameHelpers.cleanNamespace('com.company.app-name')).toBe( + 'Com.Company.AppName', + ); + expect(nameHelpers.cleanNamespace('com.company.app-name.other')).toBe( + 'Com.Company.AppName.Other', + ); + expect(nameHelpers.cleanNamespace('com::company::app')).toBe( + 'Com.Company.App', + ); + expect(nameHelpers.cleanNamespace('com::company::app-name')).toBe( + 'Com.Company.AppName', + ); + expect(nameHelpers.cleanNamespace('com::company::app-name::other')).toBe( + 'Com.Company.AppName.Other', + ); + }); + + test('nameHelpers - isValidProjectNamespace', () => { + expect(nameHelpers.isValidProjectNamespace('package')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('package-name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('Package')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('Package-name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('Package-Name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('@scope/package')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('@scope/package-name')).toBe( + false, + ); + expect(nameHelpers.isValidProjectNamespace('com.company.app')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('com.company.app-name')).toBe( + false, + ); + expect( + nameHelpers.isValidProjectNamespace('com.company.app-name.other'), + ).toBe(false); + expect(nameHelpers.isValidProjectNamespace('com::company::app')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('com::company::app-name')).toBe( + false, + ); + expect( + nameHelpers.isValidProjectNamespace('com::company::app-name::other'), + ).toBe(false); + }); + \ No newline at end of file diff --git a/packages/@react-native-windows/cli/src/utils/nameHelpers.ts b/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts similarity index 100% rename from packages/@react-native-windows/cli/src/utils/nameHelpers.ts rename to packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts From a9f393f7f28a6bf1fec1a93b491cd54f1a3ce6f0 Mon Sep 17 00:00:00 2001 From: Daniel Ayala <14967941+danielayala94@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:31:30 -0800 Subject: [PATCH 2/4] Convert the package name --- .../telemetry/src/telemetry.ts | 8 ++++++-- .../telemetry/src/utils/nameHelpers.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/@react-native-windows/telemetry/src/telemetry.ts b/packages/@react-native-windows/telemetry/src/telemetry.ts index 00303817482..7bab83d4023 100644 --- a/packages/@react-native-windows/telemetry/src/telemetry.ts +++ b/packages/@react-native-windows/telemetry/src/telemetry.ts @@ -11,6 +11,7 @@ import * as basePropUtils from './utils/basePropUtils'; import * as versionUtils from './utils/versionUtils'; import * as errorUtils from './utils/errorUtils'; import * as projectUtils from './utils/projectUtils'; +import * as nameHelpers from './utils/nameHelpers'; export interface TelemetryOptions { setupString: string; @@ -246,10 +247,13 @@ export class Telemetry { return true; } - if (forceRefresh === true || !Telemetry.versionsProp[name]) { + // Convert the package name to comply with the backend requirements + const packageName = nameHelpers.isValidTelemetryPackageName(name) ? name : nameHelpers.cleanTelemetryPackageName(name); + + if (forceRefresh === true || !Telemetry.versionsProp[packageName]) { const value = await getValue(); if (value) { - Telemetry.versionsProp[name] = value; + Telemetry.versionsProp[packageName] = value; return true; } } diff --git a/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts b/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts index de6d66e9024..72f92ccbc88 100644 --- a/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts +++ b/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts @@ -41,3 +41,16 @@ export function isValidProjectNamespace(namespace: string): boolean { export function cleanNamespace(str: string): string { return str.split(/[.:]+/).map(cleanName).join('.'); } + +export function isValidTelemetryPackageName(name: string): boolean { + // Accepted characters: alphanumeric, underscore, dot, starts with letter. + // Size: 1-100 characters. + if (name.match(/^[a-zA-Z][a-zA-Z0-9_.]{0,99}$/gi)) { + return true; + } + return false; +} + +export function cleanTelemetryPackageName(str: string): string { + return str.replace(/[^a-zA-Z0-9_.]/g, '_'); +} \ No newline at end of file From c4f0842ecedfea2e9910e074ad9966f2c74b2243 Mon Sep 17 00:00:00 2001 From: Daniel Ayala <14967941+danielayala94@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:37:59 -0800 Subject: [PATCH 3/4] Added test cases --- .../telemetry/src/test/nameHelpers.test.ts | 146 ++++++++++-------- 1 file changed, 81 insertions(+), 65 deletions(-) diff --git a/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts index 4731a098167..47c45a8e58c 100644 --- a/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts +++ b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts @@ -8,68 +8,84 @@ import * as nameHelpers from '../utils/nameHelpers'; test('nameHelpers - cleanName', () => { - expect(nameHelpers.cleanName('@scope/package')).toBe('Package'); - expect(nameHelpers.cleanName('@scope/package-name')).toBe('PackageName'); - expect(nameHelpers.cleanName('package')).toBe('Package'); - expect(nameHelpers.cleanName('package-name')).toBe('PackageName'); - }); - - test('nameHelpers - isValidProjectName', () => { - expect(nameHelpers.isValidProjectName('package')).toBe(true); - expect(nameHelpers.isValidProjectName('package-name')).toBe(false); - expect(nameHelpers.isValidProjectName('Package')).toBe(true); - expect(nameHelpers.isValidProjectName('Package-name')).toBe(false); - expect(nameHelpers.isValidProjectName('Package-Name')).toBe(false); - expect(nameHelpers.isValidProjectName('@scope/package')).toBe(false); - expect(nameHelpers.isValidProjectName('@scope/package-name')).toBe(false); - }); - - test('nameHelpers - cleanNamespace', () => { - expect(nameHelpers.cleanNamespace('@scope/package')).toBe('Package'); - expect(nameHelpers.cleanNamespace('@scope/package-name')).toBe('PackageName'); - expect(nameHelpers.cleanNamespace('package')).toBe('Package'); - expect(nameHelpers.cleanNamespace('package-name')).toBe('PackageName'); - expect(nameHelpers.cleanNamespace('com.company.app')).toBe('Com.Company.App'); - expect(nameHelpers.cleanNamespace('com.company.app-name')).toBe( - 'Com.Company.AppName', - ); - expect(nameHelpers.cleanNamespace('com.company.app-name.other')).toBe( - 'Com.Company.AppName.Other', - ); - expect(nameHelpers.cleanNamespace('com::company::app')).toBe( - 'Com.Company.App', - ); - expect(nameHelpers.cleanNamespace('com::company::app-name')).toBe( - 'Com.Company.AppName', - ); - expect(nameHelpers.cleanNamespace('com::company::app-name::other')).toBe( - 'Com.Company.AppName.Other', - ); - }); - - test('nameHelpers - isValidProjectNamespace', () => { - expect(nameHelpers.isValidProjectNamespace('package')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('package-name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('Package')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('Package-name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('Package-Name')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('@scope/package')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('@scope/package-name')).toBe( - false, - ); - expect(nameHelpers.isValidProjectNamespace('com.company.app')).toBe(true); - expect(nameHelpers.isValidProjectNamespace('com.company.app-name')).toBe( - false, - ); - expect( - nameHelpers.isValidProjectNamespace('com.company.app-name.other'), - ).toBe(false); - expect(nameHelpers.isValidProjectNamespace('com::company::app')).toBe(false); - expect(nameHelpers.isValidProjectNamespace('com::company::app-name')).toBe( - false, - ); - expect( - nameHelpers.isValidProjectNamespace('com::company::app-name::other'), - ).toBe(false); - }); - \ No newline at end of file + expect(nameHelpers.cleanName('@scope/package')).toBe('Package'); + expect(nameHelpers.cleanName('@scope/package-name')).toBe('PackageName'); + expect(nameHelpers.cleanName('package')).toBe('Package'); + expect(nameHelpers.cleanName('package-name')).toBe('PackageName'); +}); + +test('nameHelpers - isValidProjectName', () => { + expect(nameHelpers.isValidProjectName('package')).toBe(true); + expect(nameHelpers.isValidProjectName('package-name')).toBe(false); + expect(nameHelpers.isValidProjectName('Package')).toBe(true); + expect(nameHelpers.isValidProjectName('Package-name')).toBe(false); + expect(nameHelpers.isValidProjectName('Package-Name')).toBe(false); + expect(nameHelpers.isValidProjectName('@scope/package')).toBe(false); + expect(nameHelpers.isValidProjectName('@scope/package-name')).toBe(false); +}); + +test('nameHelpers - cleanNamespace', () => { + expect(nameHelpers.cleanNamespace('@scope/package')).toBe('Package'); + expect(nameHelpers.cleanNamespace('@scope/package-name')).toBe('PackageName'); + expect(nameHelpers.cleanNamespace('package')).toBe('Package'); + expect(nameHelpers.cleanNamespace('package-name')).toBe('PackageName'); + expect(nameHelpers.cleanNamespace('com.company.app')).toBe('Com.Company.App'); + expect(nameHelpers.cleanNamespace('com.company.app-name')).toBe( + 'Com.Company.AppName', + ); + expect(nameHelpers.cleanNamespace('com.company.app-name.other')).toBe( + 'Com.Company.AppName.Other', + ); + expect(nameHelpers.cleanNamespace('com::company::app')).toBe( + 'Com.Company.App', + ); + expect(nameHelpers.cleanNamespace('com::company::app-name')).toBe( + 'Com.Company.AppName', + ); + expect(nameHelpers.cleanNamespace('com::company::app-name::other')).toBe( + 'Com.Company.AppName.Other', + ); +}); + +test('nameHelpers - isValidProjectNamespace', () => { + expect(nameHelpers.isValidProjectNamespace('package')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('package-name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('Package')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('Package-name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('Package-Name')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('@scope/package')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('@scope/package-name')).toBe( + false, + ); + expect(nameHelpers.isValidProjectNamespace('com.company.app')).toBe(true); + expect(nameHelpers.isValidProjectNamespace('com.company.app-name')).toBe( + false, + ); + expect( + nameHelpers.isValidProjectNamespace('com.company.app-name.other'), + ).toBe(false); + expect(nameHelpers.isValidProjectNamespace('com::company::app')).toBe(false); + expect(nameHelpers.isValidProjectNamespace('com::company::app-name')).toBe( + false, + ); + expect( + nameHelpers.isValidProjectNamespace('com::company::app-name::other'), + ).toBe(false); +}); + +test('Verify telemetry package name is valid', () => { + expect(nameHelpers.isValidTelemetryPackageName('package')).toBe(true); + expect(nameHelpers.isValidTelemetryPackageName('@react')).toBe(false); + expect(nameHelpers.isValidTelemetryPackageName('react-native')).toBe(false); + expect(nameHelpers.isValidTelemetryPackageName('react_native')).toBe(true); + expect(nameHelpers.isValidTelemetryPackageName('react_native/cli')).toBe(false); +}); + +test('Verify telemetry package name cleaning', () => { + expect(nameHelpers.cleanTelemetryPackageName('package')).toBe('package'); + expect(nameHelpers.cleanTelemetryPackageName('@react')).toBe('_react'); + expect(nameHelpers.cleanTelemetryPackageName('react-native')).toBe('react_native'); + expect(nameHelpers.cleanTelemetryPackageName('react_native')).toBe('react_native'); + expect(nameHelpers.cleanTelemetryPackageName('react_native/cli')).toBe('react_native_cli'); + expect(nameHelpers.cleanTelemetryPackageName('@react-native-windows/cli')).toBe('_react_native_windows_cli'); +}); \ No newline at end of file From 13d8eaab5bdd404cf4f54a9833dabb73e3a12c75 Mon Sep 17 00:00:00 2001 From: Daniel Ayala <14967941+danielayala94@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:55:59 -0800 Subject: [PATCH 4/4] Lint fixes blah blah --- .../cli/src/e2etest/initWindows.test.ts | 2 +- .../telemetry/src/telemetry.ts | 4 +++- .../telemetry/src/test/nameHelpers.test.ts | 22 ++++++++++++++----- .../telemetry/src/utils/nameHelpers.ts | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts index 86065ca7fed..30654353fb7 100644 --- a/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts +++ b/packages/@react-native-windows/cli/src/e2etest/initWindows.test.ts @@ -57,4 +57,4 @@ test('initOptions - validate options', () => { validateOptionName(commandOption.name, optionName as keyof InitOptions), ).toBe(true); } -}); \ No newline at end of file +}); diff --git a/packages/@react-native-windows/telemetry/src/telemetry.ts b/packages/@react-native-windows/telemetry/src/telemetry.ts index 7bab83d4023..4fb6439e6fe 100644 --- a/packages/@react-native-windows/telemetry/src/telemetry.ts +++ b/packages/@react-native-windows/telemetry/src/telemetry.ts @@ -248,7 +248,9 @@ export class Telemetry { } // Convert the package name to comply with the backend requirements - const packageName = nameHelpers.isValidTelemetryPackageName(name) ? name : nameHelpers.cleanTelemetryPackageName(name); + const packageName = nameHelpers.isValidTelemetryPackageName(name) + ? name + : nameHelpers.cleanTelemetryPackageName(name); if (forceRefresh === true || !Telemetry.versionsProp[packageName]) { const value = await getValue(); diff --git a/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts index 47c45a8e58c..6cee1f96ace 100644 --- a/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts +++ b/packages/@react-native-windows/telemetry/src/test/nameHelpers.test.ts @@ -78,14 +78,24 @@ test('Verify telemetry package name is valid', () => { expect(nameHelpers.isValidTelemetryPackageName('@react')).toBe(false); expect(nameHelpers.isValidTelemetryPackageName('react-native')).toBe(false); expect(nameHelpers.isValidTelemetryPackageName('react_native')).toBe(true); - expect(nameHelpers.isValidTelemetryPackageName('react_native/cli')).toBe(false); + expect(nameHelpers.isValidTelemetryPackageName('react_native/cli')).toBe( + false, + ); }); test('Verify telemetry package name cleaning', () => { expect(nameHelpers.cleanTelemetryPackageName('package')).toBe('package'); expect(nameHelpers.cleanTelemetryPackageName('@react')).toBe('_react'); - expect(nameHelpers.cleanTelemetryPackageName('react-native')).toBe('react_native'); - expect(nameHelpers.cleanTelemetryPackageName('react_native')).toBe('react_native'); - expect(nameHelpers.cleanTelemetryPackageName('react_native/cli')).toBe('react_native_cli'); - expect(nameHelpers.cleanTelemetryPackageName('@react-native-windows/cli')).toBe('_react_native_windows_cli'); -}); \ No newline at end of file + expect(nameHelpers.cleanTelemetryPackageName('react-native')).toBe( + 'react_native', + ); + expect(nameHelpers.cleanTelemetryPackageName('react_native')).toBe( + 'react_native', + ); + expect(nameHelpers.cleanTelemetryPackageName('react_native/cli')).toBe( + 'react_native_cli', + ); + expect( + nameHelpers.cleanTelemetryPackageName('@react-native-windows/cli'), + ).toBe('_react_native_windows_cli'); +}); diff --git a/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts b/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts index 72f92ccbc88..2023a706971 100644 --- a/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts +++ b/packages/@react-native-windows/telemetry/src/utils/nameHelpers.ts @@ -53,4 +53,4 @@ export function isValidTelemetryPackageName(name: string): boolean { export function cleanTelemetryPackageName(str: string): string { return str.replace(/[^a-zA-Z0-9_.]/g, '_'); -} \ No newline at end of file +}