Use String.prototype.replaceAll in sourcemap removal script

Summary: Apply suggestion from D48605129 to have access to "modern" `replaceAll`.

Reviewed By: lblasa

Differential Revision: D48642120

fbshipit-source-id: 1e273fe5590e7b4a48c9176ef5f1afdab688b7d6
This commit is contained in:
Pascal Hartig
2023-08-30 09:14:07 -07:00
committed by Facebook GitHub Bot
parent caf55f5b12
commit 072d618681
2 changed files with 2 additions and 14 deletions

View File

@@ -22,14 +22,6 @@ import path from 'path';
const SOURCEMAP_REFERENCE = const SOURCEMAP_REFERENCE =
'//# sourceMappingURL=importFile.worker.worker.js.map'; '//# sourceMappingURL=importFile.worker.worker.js.map';
// Remove this once we're upgrade to a newer JS version. String.prototype.replaceAll is a thing.
function replaceAll(s: string, find: string, replace: string): string {
return s.replace(
new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'),
replace,
);
}
async function main() { async function main() {
const frontendPath = path.resolve( const frontendPath = path.resolve(
__dirname, __dirname,
@@ -48,10 +40,7 @@ async function main() {
return 0; return 0;
} }
await fs.writeFile( await fs.writeFile(frontendPath, content.replaceAll(SOURCEMAP_REFERENCE, ''));
frontendPath,
replaceAll(content, SOURCEMAP_REFERENCE, ''),
);
console.log('react-devtools-inline patched successfully.'); console.log('react-devtools-inline patched successfully.');
return 0; return 0;

View File

@@ -1,6 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2017", "target": "ES2021",
"module": "nodenext", "module": "nodenext",
"jsx": "react", "jsx": "react",
"noEmit": true, "noEmit": true,
@@ -9,4 +9,3 @@
"esModuleInterop": true "esModuleInterop": true
} }
} }