Skip to content

Commit 9e32ba3

Browse files
authored
refactor: use String.replaceAll() instead of .replace() with regex (#2090)
1 parent 571e3b5 commit 9e32ba3

12 files changed

+31
-27
lines changed

android/android-manifest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function generateAndroidManifest(appManifestPath, manifestOutput, fs = nodefs) {
107107

108108
exports.generateAndroidManifest = generateAndroidManifest;
109109

110-
if (isMain(pathToFileURL(__filename).toString())) {
110+
if (isMain(pathToFileURL(__filename))) {
111111
const [, , appManifestPath, manifestOutput] = process.argv;
112112
process.exitCode = generateAndroidManifest(appManifestPath, manifestOutput);
113113
}

example/test/config.test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function getLoadConfig() {
4141
* @returns {RegExp}
4242
*/
4343
function regexp(p) {
44-
return new RegExp(p.replace(/\\/g, "\\\\"));
44+
return new RegExp(p.replaceAll("\\", "\\\\"));
4545
}
4646

4747
test("react-native config", async (t) => {

example/test/specs/wdio.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const findLatestIPhoneSimulator = (() => {
104104
simulator?.name ?? "iPhone 15 Pro",
105105
latestRuntime
106106
.substring("com.apple.CoreSimulator.SimRuntime.iOS-".length)
107-
.replace(/-/g, "."),
107+
.replaceAll("-", "."),
108108
];
109109
}
110110
return result;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"generate:docs": "node scripts/generate-manifest-docs.mjs",
7878
"generate:schema": "node scripts/generate-schema.mjs",
7979
"lint:commit": "git log --format='%s' origin/trunk..HEAD | tail -1 | npx @rnx-kit/[email protected]",
80-
"lint:js": "eslint $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' ':!:*.config.js' ':!:.yarn/releases') && tsc && tsc --project tsconfig.esm.json",
80+
"lint:js": "eslint $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' ':!:*.config.js' ':!:.yarn/releases') && tsc && tsc --project tsconfig.cjs.json",
8181
"lint:kt": "ktlint --relative 'android/app/src/**/*.kt'",
8282
"lint:rb": "bundle exec rubocop",
8383
"lint:swift": "swiftlint",

scripts/configure.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function reactNativeConfig(
187187
}
188188

189189
const config = path.join(testAppPath, "example", "react-native.config.js");
190-
return readTextFile(config, fs).replace(/Example/g, name);
190+
return readTextFile(config, fs).replaceAll("Example", name);
191191
}
192192

193193
/**
@@ -279,7 +279,7 @@ export const getConfig = (() => {
279279
"package.json": readTextFile(
280280
path.join(templateDir, "package.json"),
281281
fs
282-
).replace(/HelloWorld/g, name),
282+
).replaceAll("HelloWorld", name),
283283
}),
284284
},
285285
oldFiles: [],

scripts/generate-schema.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { generateSchema } from "./schema.mjs";
1010

1111
/** @type {(str: string) => string} */
1212
const stripCarriageReturn =
13-
os.EOL === "\r\n" ? (str) => str.replace(/\r/g, "") : (str) => str;
13+
os.EOL === "\r\n" ? (str) => str.replaceAll("\r", "") : (str) => str;
1414

1515
/**
1616
* @returns {Promise<Partial<Docs>>}

scripts/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function findNearest(
6464

6565
/**
6666
* Returns whether the current module is main.
67-
* @param {string} url
67+
* @param {string | URL} url
6868
* @param {string} script
6969
* @returns {boolean}
7070
*/

scripts/release-notes.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ function main(lastRelease, nextRelease) {
6767

6868
buffers.push(Buffer.from("]"));
6969

70-
const output = Buffer.concat(buffers).toString().trim().replace(/\n/g, ",");
70+
const output = Buffer.concat(buffers)
71+
.toString()
72+
.trim()
73+
.replaceAll("\n", ",");
7174
const commits = JSON.parse(output);
7275
if (commits.length === 0) {
7376
return;

test/configure/gatherConfig.test.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ describe("gatherConfig()", () => {
1919
*/
2020
function gatherConfig(params) {
2121
/** @type {(p: string) => string} */
22-
const normalize = (p) => p.replace(/\\/g, "/");
22+
const normalize = (p) => p.replaceAll("\\", "/");
2323

2424
const config = gatherConfigActual(params, true);
2525
config.files = Object.fromEntries(
2626
Object.entries(config.files).map(([key, value]) => [
2727
normalize(key),
2828
typeof value === "string"
29-
? value.replace(/\r/g, "")
29+
? value.replaceAll("\r", "")
3030
: { source: normalize(value.source) },
3131
])
3232
);
@@ -36,7 +36,7 @@ describe("gatherConfig()", () => {
3636

3737
const gradleWrapper = readTextFile(
3838
"example/android/gradle/wrapper/gradle-wrapper.properties"
39-
).replace(/\r/g, "");
39+
).replaceAll("\r", "");
4040

4141
it("returns configuration for all platforms", () => {
4242
deepEqual(gatherConfig(mockParams()), {

tsconfig.cjs.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "@rnx-kit/tsconfig/tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true
5+
},
6+
"include": [
7+
"plugins/**/*.js",
8+
"react-native.config.js",
9+
"scripts/**/*.js"
10+
]
11+
}

tsconfig.esm.json

-11
This file was deleted.

tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"extends": "@rnx-kit/tsconfig/tsconfig.json",
2+
"extends": "@rnx-kit/tsconfig/tsconfig.esm.json",
33
"compilerOptions": {
4+
"target": "ES2022",
5+
"module": "ES2022",
6+
"moduleResolution": "Node",
47
"noEmit": true
58
},
69
"include": [
7-
"plugins/**/*.js",
8-
"react-native.config.js",
9-
"scripts/**/*.js"
10+
"**/*.mjs"
1011
]
1112
}

0 commit comments

Comments
 (0)