flipper-babel-transformer
Version:
Babel transformer for Flipper plugins
37 lines • 1.4 kB
JavaScript
;
/**
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
const replace_flipper_requires_1 = require("./replace-flipper-requires");
const path_1 = require("path");
const sourceRootDir = (0, path_1.resolve)(__dirname, '..', '..');
function isExcludedPath(path) {
// 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, state) {
if (isExcludedPath(state.file.opts.filename)) {
return;
}
(0, replace_flipper_requires_1.tryReplaceFlipperRequire)(path);
},
Identifier(path, state) {
if (isExcludedPath(state.file.opts.filename)) {
return;
}
(0, replace_flipper_requires_1.tryReplaceGlobalReactUsage)(path);
},
},
});
//# sourceMappingURL=app-flipper-requires.js.map