Fix hyper-annoying importFile.worker.worker.js warning on startup
Summary:
Gets rid of
{F1074904830}
See D48603710 for some more information.
This patches the bundle which includes the reference to silence the error.
Changelog: No longer show importFile.worker.worker.js warning on startup
Reviewed By: lblasa
Differential Revision: D48605129
fbshipit-source-id: 20dc292191742400c8c390a75b1e53f11630ad5a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cac3436e01
commit
15271ea911
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
/* eslint-disable no-restricted-imports */
|
||||
|
||||
/*
|
||||
* This script attempts to get rid of a sourcemap reference in react-devtools-frontend
|
||||
* that is causing a rather annoying non-fetal error at Flipper startup.
|
||||
*
|
||||
* It will gracefully fail as Flipper will still work without it, just show the error again.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
|
||||
const SOURCEMAP_REFERENCE =
|
||||
'//# 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() {
|
||||
const frontendPath = path.resolve(
|
||||
__dirname,
|
||||
'../../node_modules/react-devtools-inline/dist/frontend.js',
|
||||
);
|
||||
console.log(`Looking up ${frontendPath} for patching ...`);
|
||||
// Check if path exists
|
||||
if (!(await fs.pathExists(frontendPath))) {
|
||||
console.warn('react-devtools-inline frontend not found, skipping patching');
|
||||
return 0;
|
||||
}
|
||||
|
||||
const content = await fs.readFile(frontendPath, 'utf-8');
|
||||
if (!content.includes(SOURCEMAP_REFERENCE)) {
|
||||
console.log('react-devtools-inline appears to already be patched.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
await fs.writeFile(
|
||||
frontendPath,
|
||||
replaceAll(content, SOURCEMAP_REFERENCE, ''),
|
||||
);
|
||||
|
||||
console.log('react-devtools-inline patched successfully.');
|
||||
return 0;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
process.exit(await main());
|
||||
})();
|
||||
Reference in New Issue
Block a user