Skip to content

Commit 3d52dfb

Browse files
bmiddhaCopilot
andcommitted
refactor: deprecate Text.replaceAll
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8ebd5bf2-c44b-42d5-be25-e7936d4b0a14
1 parent 14f8043 commit 3d52dfb

17 files changed

Lines changed: 33 additions & 53 deletions

File tree

apps/api-extractor/src/analyzer/SourceFileLocationFormatter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'node:path';
55

66
import type * as ts from 'typescript';
77

8-
import { Path, Text } from '@rushstack/node-core-library';
8+
import { Path } from '@rushstack/node-core-library';
99

1010
export interface ISourceFileLocationFormatOptions {
1111
sourceFileLine?: number;
@@ -47,7 +47,7 @@ export class SourceFileLocationFormatter {
4747
}
4848

4949
// Convert it to a Unix-style path
50-
scrubbedPath = Text.replaceAll(scrubbedPath, '\\', '/');
50+
scrubbedPath = scrubbedPath.replaceAll('\\', '/');
5151
result += scrubbedPath;
5252

5353
if (options.sourceFileLine) {

apps/api-extractor/src/api/ExtractorConfig.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
PackageJsonLookup,
1818
type INodePackageJson,
1919
PackageName,
20-
Text,
2120
InternalError,
2221
Path,
2322
NewlineKind
@@ -1310,8 +1309,8 @@ function _expandStringWithTokens(
13101309
): string {
13111310
value = value ? value.trim() : '';
13121311
if (value !== '') {
1313-
value = Text.replaceAll(value, '<unscopedPackageName>', tokenContext.unscopedPackageName);
1314-
value = Text.replaceAll(value, '<packageName>', tokenContext.packageName);
1312+
value = value.replaceAll('<unscopedPackageName>', tokenContext.unscopedPackageName);
1313+
value = value.replaceAll('<packageName>', tokenContext.packageName);
13151314

13161315
const projectFolderToken: string = '<projectFolder>';
13171316
if (value.indexOf(projectFolderToken) === 0) {

apps/lockfile-explorer/src/graph/lfxGraphLoader.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import type * as lockfileTypes from '@pnpm/lockfile.types';
55
import type * as pnpmTypes from '@pnpm/types';
66

7-
import { Text } from '@rushstack/node-core-library';
8-
97
import {
108
type ILfxGraphDependencyOptions,
119
type ILfxGraphEntryOptions,
@@ -398,9 +396,9 @@ function createPackageLockfileEntry(options: {
398396

399397
// Rewrite to:
400398
// "@rushstack/m@1.0.0; @rushstack/n@2.0.0"
401-
suffix = Text.replaceAll(suffix, ')(', '; ');
402-
suffix = Text.replaceAll(suffix, '(', '');
403-
suffix = Text.replaceAll(suffix, ')', '');
399+
suffix = suffix.replaceAll(')(', '; ');
400+
suffix = suffix.replaceAll('(', '');
401+
suffix = suffix.replaceAll(')', '');
404402
result.entrySuffix = suffix;
405403

406404
// @rushstack/l@1.0.0(@rushstack/m@1.0.0)(@rushstack/n@2.0.0)
@@ -412,10 +410,10 @@ function createPackageLockfileEntry(options: {
412410
// --> @rushstack+l@1.0.0_@rushstack+m@1.0.0_@rushstack+n@2.0.0
413411

414412
// @rushstack/l 1.0.0 (@rushstack/m@1.0.0)(@rushstack/n@2.0.0)
415-
dotPnpmSubfolder = Text.replaceAll(slashlessRawEntryId, '/', '+');
416-
dotPnpmSubfolder = Text.replaceAll(dotPnpmSubfolder, ')(', '_');
417-
dotPnpmSubfolder = Text.replaceAll(dotPnpmSubfolder, '(', '_');
418-
dotPnpmSubfolder = Text.replaceAll(dotPnpmSubfolder, ')', '');
413+
dotPnpmSubfolder = slashlessRawEntryId.replaceAll('/', '+');
414+
dotPnpmSubfolder = dotPnpmSubfolder.replaceAll(')(', '_');
415+
dotPnpmSubfolder = dotPnpmSubfolder.replaceAll('(', '_');
416+
dotPnpmSubfolder = dotPnpmSubfolder.replaceAll(')', '');
419417
}
420418

421419
// Example:

apps/rundown/src/Rundown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as path from 'node:path';
66

77
import stringArgv from 'string-argv';
88

9-
import { FileSystem, PackageJsonLookup, Sort, Text } from '@rushstack/node-core-library';
9+
import { FileSystem, PackageJsonLookup, Sort } from '@rushstack/node-core-library';
1010

1111
import type { IpcMessage } from './LauncherTypes';
1212

@@ -57,7 +57,7 @@ export class Rundown {
5757
importedPackageFolders.add(path.basename(importedPackageFolder));
5858
} else {
5959
const relativePath: string = path.relative(process.cwd(), importedPackageFolder);
60-
importedPackageFolders.add(Text.replaceAll(relativePath, '\\', '/'));
60+
importedPackageFolders.add(relativePath.replaceAll('\\', '/'));
6161
}
6262
} else {
6363
// If the importedPath does not belong to an NPM package, then rundown-snapshot.log can ignore it.

common/changes/@rushstack/node-core-library/native-standard-apis_2026-08-18-03-14-05.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"changes": [
33
{
44
"packageName": "@rushstack/node-core-library",
5-
"comment": "Delegate Text.replaceAll() to the native implementation, including native empty search string behavior.",
5+
"comment": "Deprecate Text.replaceAll() in favor of the native String.prototype.replaceAll() method.",
66
"type": "patch"
77
}
88
],

common/reviews/api/node-core-library.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ export class Text {
968968
static padStart(s: string, minimumLength: number, paddingCharacter?: string): string;
969969
static readLinesFromIterable(iterable: Iterable<string | Buffer | null>, options?: IReadLinesFromIterableOptions): Generator<string>;
970970
static readLinesFromIterableAsync(iterable: AsyncIterable<string | Buffer>, options?: IReadLinesFromIterableOptions): AsyncGenerator<string>;
971+
// @deprecated
971972
static replaceAll(input: string, searchValue: string, replaceValue: string): string;
972973
static reverse(s: string): string;
973974
static splitByNewLines(s: undefined): undefined;

libraries/node-core-library/src/JsonFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ function _formatJsonHeaderComment(headerComment: string): string {
580580
JSON.stringify(line)
581581
);
582582
}
583-
result.push(Text.replaceAll(line, '\r', ''));
583+
result.push(line.replaceAll('\r', ''));
584584
}
585585
return lines.join('\n') + '\n';
586586
}

libraries/node-core-library/src/Text.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ export class Text {
107107
* @param input - The string to be modified
108108
* @param searchValue - The value to search for
109109
* @param replaceValue - The replacement text
110+
*
111+
* @deprecated Use `String.prototype.replaceAll()` instead.
110112
*/
111-
public static replaceAll(input: string, searchValue: string, replaceValue: string): string {
112-
return input.replaceAll(searchValue, replaceValue);
113-
}
113+
public static replaceAll(input: string, searchValue: string, replaceValue: string): string {
114+
return input.replaceAll(searchValue, replaceValue);
115+
}
114116

115117
/**
116118
* Converts all newlines in the provided string to use Windows-style CRLF end of line characters.

libraries/node-core-library/src/test/Executable.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from '../Executable';
1818
import { FileSystem } from '../FileSystem';
1919
import { PosixModeBits } from '../PosixModeBits';
20-
import { Text } from '../Text';
2120
import { Readable } from 'node:stream';
2221

2322
describe('Executable process tests', () => {
@@ -101,7 +100,7 @@ describe('Executable process tests', () => {
101100
test('Executable.tryResolve() pathless', () => {
102101
const resolved: string | undefined = Executable.tryResolve('npm-binary-wrapper', options);
103102
expect(resolved).toBeDefined();
104-
const resolvedRelative: string = Text.replaceAll(path.relative(executableFolder, resolved!), '\\', '/');
103+
const resolvedRelative: string = path.relative(executableFolder, resolved!).replaceAll('\\', '/');
105104

106105
if (os.platform() === 'win32') {
107106
// On Windows, we should find npm-binary-wrapper.cmd instead of npm-binary-wrapper

libraries/node-core-library/src/test/Text.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
import { Text } from '../Text';
55

66
describe(Text.name, () => {
7-
describe(Text.replaceAll.name, () => {
8-
it('replaces every occurrence', () => {
9-
expect(Text.replaceAll('one two one', 'one', 'three')).toEqual('three two three');
10-
});
11-
12-
it('uses native empty search string semantics', () => {
13-
expect(Text.replaceAll('abc', '', '-')).toEqual('-a-b-c-');
14-
expect(Text.replaceAll('', '', '-')).toEqual('-');
15-
});
16-
});
17-
187
describe(Text.padEnd.name, () => {
198
it("Throws an exception if the padding character isn't a single character", () => {
209
expect(() => Text.padEnd('123', 1, '')).toThrow();

0 commit comments

Comments
 (0)