refactor: use `String.replaceAll()` instead of `.replace()` with regex (#2090)
This commit is contained in:
Родитель
571e3b5e79
Коммит
9e32ba36dd
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -104,7 +104,7 @@ const findLatestIPhoneSimulator = (() => {
|
|||
simulator?.name ?? "iPhone 15 Pro",
|
||||
latestRuntime
|
||||
.substring("com.apple.CoreSimulator.SimRuntime.iOS-".length)
|
||||
.replace(/-/g, "."),
|
||||
.replaceAll("-", "."),
|
||||
];
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -279,7 +279,7 @@ export const getConfig = (() => {
|
|||
"package.json": readTextFile(
|
||||
path.join(templateDir, "package.json"),
|
||||
fs
|
||||
).replace(/HelloWorld/g, name),
|
||||
).replaceAll("HelloWorld", name),
|
||||
}),
|
||||
},
|
||||
oldFiles: [],
|
||||
|
|
|
@ -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>>}
|
||||
|
|
|
@ -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}
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) },
|
||||
])
|
||||
);
|
||||
|
@ -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()), {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "@rnx-kit/tsconfig/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"plugins/**/*.js",
|
||||
"react-native.config.js",
|
||||
"scripts/**/*.js"
|
||||
]
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
{
|
||||
"extends": "@rnx-kit/tsconfig/tsconfig.esm.json",
|
||||
"compilerOptions": {
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "Node",
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.mjs"
|
||||
]
|
||||
}
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче