Summary: Currently, Flipper Server has a few productions dependencies (mac-ca, node-fetch) that are not bundled with the Flipper Server. It makes it harder to distribute Flipper Server, as now all potential consumers need not only to download the bundle, but also install these additional dependencies. This diff makes it possible to bundle `mac-ca` and `node-fetch` with Flipper Server. As a result, Flipper Server becomes dependency-free in production. Reviewed By: lblasa Differential Revision: D36345213 fbshipit-source-id: 2cd6ba1b3301b45dc2295891964ba020fd107586
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
/**
|
|
* 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} from '@babel/types';
|
|
import {NodePath} from '@babel/traverse';
|
|
|
|
// Core modules can be required as `node:fs` to bypass teh require cache
|
|
// https://nodejs.org/api/modules.html#core-modules
|
|
// It is not supported for "require" until Node v14.18.
|
|
// TODO: Remove this transform when we upgrade electron and node.js
|
|
const bypassRequireCachePrefix = 'node:';
|
|
|
|
module.exports = () => ({
|
|
name: 'change-require-to-electronRequire-in-electron-app',
|
|
visitor: {
|
|
CallExpression(path: NodePath<CallExpression>) {
|
|
const node = path.node;
|
|
if (
|
|
node.type === 'CallExpression' &&
|
|
node.callee.type === 'Identifier' &&
|
|
node.callee.name === 'require' &&
|
|
node.arguments.length === 1 &&
|
|
node.arguments[0].type === 'StringLiteral'
|
|
) {
|
|
const source = node.arguments[0].value;
|
|
if (source.startsWith(bypassRequireCachePrefix)) {
|
|
node.arguments[0].value = source.substring(
|
|
bypassRequireCachePrefix.length,
|
|
);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
});
|