Skip to content

Commit

Permalink
refactor: use String.replaceAll() instead of .replace() with regex (
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Jun 18, 2024
1 parent 571e3b5 commit 9e32ba3
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/android-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function generateAndroidManifest(appManifestPath, manifestOutput, fs = nodefs) {

exports.generateAndroidManifest = generateAndroidManifest;

if (isMain(pathToFileURL(__filename).toString())) {
if (isMain(pathToFileURL(__filename))) {
const [, , appManifestPath, manifestOutput] = process.argv;
process.exitCode = generateAndroidManifest(appManifestPath, manifestOutput);
}
2 changes: 1 addition & 1 deletion example/test/config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function getLoadConfig() {
* @returns {RegExp}
*/
function regexp(p) {
return new RegExp(p.replace(/\\/g, "\\\\"));
return new RegExp(p.replaceAll("\\", "\\\\"));
}

test("react-native config", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion example/test/specs/wdio.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const findLatestIPhoneSimulator = (() => {
simulator?.name ?? "iPhone 15 Pro",
latestRuntime
.substring("com.apple.CoreSimulator.SimRuntime.iOS-".length)
.replace(/-/g, "."),
.replaceAll("-", "."),
];
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"generate:docs": "node scripts/generate-manifest-docs.mjs",
"generate:schema": "node scripts/generate-schema.mjs",
"lint:commit": "git log --format='%s' origin/trunk..HEAD | tail -1 | npx @rnx-kit/commitlint-lite@1.0.1",
"lint:js": "eslint $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' ':!:*.config.js' ':!:.yarn/releases') && tsc && tsc --project tsconfig.esm.json",
"lint:js": "eslint $(git ls-files '*.[cm]js' '*.[jt]s' '*.tsx' ':!:*.config.js' ':!:.yarn/releases') && tsc && tsc --project tsconfig.cjs.json",
"lint:kt": "ktlint --relative 'android/app/src/**/*.kt'",
"lint:rb": "bundle exec rubocop",
"lint:swift": "swiftlint",
Expand Down
4 changes: 2 additions & 2 deletions scripts/configure.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function reactNativeConfig(
}

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

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ export const getConfig = (() => {
"package.json": readTextFile(
path.join(templateDir, "package.json"),
fs
).replace(/HelloWorld/g, name),
).replaceAll("HelloWorld", name),
}),
},
oldFiles: [],
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { generateSchema } from "./schema.mjs";

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

/**
* @returns {Promise<Partial<Docs>>}
Expand Down
2 changes: 1 addition & 1 deletion scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function findNearest(

/**
* Returns whether the current module is main.
* @param {string} url
* @param {string | URL} url
* @param {string} script
* @returns {boolean}
*/
Expand Down
5 changes: 4 additions & 1 deletion scripts/release-notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ function main(lastRelease, nextRelease) {

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

const output = Buffer.concat(buffers).toString().trim().replace(/\n/g, ",");
const output = Buffer.concat(buffers)
.toString()
.trim()
.replaceAll("\n", ",");
const commits = JSON.parse(output);
if (commits.length === 0) {
return;
Expand Down
6 changes: 3 additions & 3 deletions test/configure/gatherConfig.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe("gatherConfig()", () => {
*/
function gatherConfig(params) {
/** @type {(p: string) => string} */
const normalize = (p) => p.replace(/\\/g, "/");
const normalize = (p) => p.replaceAll("\\", "/");

const config = gatherConfigActual(params, true);
config.files = Object.fromEntries(
Object.entries(config.files).map(([key, value]) => [
normalize(key),
typeof value === "string"
? value.replace(/\r/g, "")
? value.replaceAll("\r", "")
: { source: normalize(value.source) },
])
);
Expand All @@ -36,7 +36,7 @@ describe("gatherConfig()", () => {

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

it("returns configuration for all platforms", () => {
deepEqual(gatherConfig(mockParams()), {
Expand Down
11 changes: 11 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@rnx-kit/tsconfig/tsconfig.json",
"compilerOptions": {
"noEmit": true
},
"include": [
"plugins/**/*.js",
"react-native.config.js",
"scripts/**/*.js"
]
}
11 changes: 0 additions & 11 deletions tsconfig.esm.json

This file was deleted.

9 changes: 5 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": "@rnx-kit/tsconfig/tsconfig.json",
"extends": "@rnx-kit/tsconfig/tsconfig.esm.json",
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Node",
"noEmit": true
},
"include": [
"plugins/**/*.js",
"react-native.config.js",
"scripts/**/*.js"
"**/*.mjs"
]
}

0 comments on commit 9e32ba3

Please sign in to comment.