rename babel-transformer files from ts to tsx
Summary: group files rename Reviewed By: passy Differential Revision: D33889860 fbshipit-source-id: 888e173fc72b5e126c1e41324b6cae6be29274c5
This commit is contained in:
committed by
Facebook GitHub Bot
parent
69bac4a3d6
commit
844728d9dc
43
desktop/babel-transformer/src/app-flipper-requires.tsx
Normal file
43
desktop/babel-transformer/src/app-flipper-requires.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
import {CallExpression, Identifier} from '@babel/types';
|
||||
import {NodePath} from '@babel/traverse';
|
||||
import {
|
||||
tryReplaceFlipperRequire,
|
||||
tryReplaceGlobalReactUsage,
|
||||
} from './replace-flipper-requires';
|
||||
|
||||
import {resolve} from 'path';
|
||||
|
||||
const sourceRootDir = resolve(__dirname, '..', '..');
|
||||
|
||||
function isExcludedPath(path: string) {
|
||||
// We shouldn't apply transformations for the plugins which are part of the repository
|
||||
// as they are bundled with Flipper app and all use the single "react" dependency.
|
||||
// But we should apply it for the plugins outside of Flipper folder, so they can be loaded
|
||||
// in dev mode and use "react" from Flipper bundle.
|
||||
return path.startsWith(sourceRootDir);
|
||||
}
|
||||
module.exports = () => ({
|
||||
visitor: {
|
||||
CallExpression(path: NodePath<CallExpression>, state: any) {
|
||||
if (isExcludedPath(state.file.opts.filename)) {
|
||||
return;
|
||||
}
|
||||
tryReplaceFlipperRequire(path);
|
||||
},
|
||||
Identifier(path: NodePath<Identifier>, state: any) {
|
||||
if (isExcludedPath(state.file.opts.filename)) {
|
||||
return;
|
||||
}
|
||||
tryReplaceGlobalReactUsage(path);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user