Killed Flipper headless
Reviewed By: nikoant Differential Revision: D24160480 fbshipit-source-id: 221e60473dddc0a49cea674e210beb6f85b1b03c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
41a1af33cb
commit
08b5644253
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its 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 {transform} from '@babel/core';
|
||||
const electronStubs = require('../electron-stubs');
|
||||
|
||||
const babelOptions = {
|
||||
ast: true,
|
||||
plugins: [electronStubs],
|
||||
filename: 'index.js',
|
||||
};
|
||||
|
||||
test('transform electron requires to inlined stubs', () => {
|
||||
const src = 'require("electron")';
|
||||
const transformed = transform(src, babelOptions)!.ast;
|
||||
const body = transformed!.program.body[0];
|
||||
expect(body.type).toBe('ExpressionStatement');
|
||||
if (body.type !== 'ExpressionStatement') {
|
||||
return;
|
||||
}
|
||||
expect(body.expression.type).toBe('ObjectExpression');
|
||||
if (body.expression.type !== 'ObjectExpression') {
|
||||
return;
|
||||
}
|
||||
expect(body.expression.properties.map((p) => (p as any).key.name)).toContain(
|
||||
'remote',
|
||||
);
|
||||
});
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its 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 {parseExpression} from '@babel/parser';
|
||||
import {CallExpression} from '@babel/types';
|
||||
import {NodePath} from '@babel/traverse';
|
||||
|
||||
const electronStubs = parseExpression(
|
||||
`{
|
||||
remote: {
|
||||
process: {
|
||||
env: {},
|
||||
},
|
||||
getCurrentWindow: function() {
|
||||
return {
|
||||
isFocused: function() {return true;},
|
||||
on: function() {return true;}
|
||||
};
|
||||
},
|
||||
app: {
|
||||
getVersion: function() {return global.__VERSION__ || '1';},
|
||||
getName: function() {return '';},
|
||||
getAppPath: function() {return process.cwd();}
|
||||
},
|
||||
shell: {
|
||||
openExternal: function() {}
|
||||
},
|
||||
Menu: {
|
||||
buildFromTemplate: function() {
|
||||
return {items: []}
|
||||
},
|
||||
setApplicationMenu: function() {}
|
||||
}
|
||||
},
|
||||
ipcRenderer: {
|
||||
on: function() {return true;}
|
||||
},
|
||||
}
|
||||
`,
|
||||
);
|
||||
|
||||
module.exports = () => ({
|
||||
name: 'replace-electron-requires-with-stubs',
|
||||
visitor: {
|
||||
CallExpression(path: NodePath<CallExpression>) {
|
||||
const node = path.node;
|
||||
if (
|
||||
node.type === 'CallExpression' &&
|
||||
node.callee.type === 'Identifier' &&
|
||||
node.callee.name === 'require' &&
|
||||
node.arguments.length > 0 &&
|
||||
node.arguments[0].type === 'StringLiteral' &&
|
||||
node.arguments[0].value === 'electron'
|
||||
) {
|
||||
path.replaceWith(electronStubs);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -12,7 +12,6 @@
|
||||
* They are used in get-cache-key.ts for cache key generation.
|
||||
*/
|
||||
type FlipperEnvVars = {
|
||||
FLIPPER_HEADLESS?: string;
|
||||
FLIPPER_FB?: string;
|
||||
FLIPPER_TEST_RUNNER?: string;
|
||||
FLIPPER_ELECTRON_VERSION?: string;
|
||||
@@ -21,7 +20,6 @@ type FlipperEnvVars = {
|
||||
|
||||
const flipperEnv = new Proxy(
|
||||
{
|
||||
FLIPPER_HEADLESS: undefined,
|
||||
FLIPPER_FB: undefined,
|
||||
FLIPPER_TEST_RUNNER: undefined,
|
||||
FLIPPER_ELECTRON_VERSION: undefined,
|
||||
|
||||
@@ -17,9 +17,6 @@ const plugins = [
|
||||
require('./import-react'),
|
||||
require('./app-flipper-requires'),
|
||||
];
|
||||
if (flipperEnv.FLIPPER_HEADLESS) {
|
||||
plugins.unshift(require('./electron-stubs'));
|
||||
}
|
||||
if (flipperEnv.FLIPPER_FB) {
|
||||
plugins.unshift(require('./fb-stubs'));
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ import {default as flipperEnv} from './flipper-env';
|
||||
|
||||
const presets = [require('@babel/preset-react')];
|
||||
const plugins = [require('./import-react')];
|
||||
if (flipperEnv.FLIPPER_HEADLESS) {
|
||||
plugins.unshift(require('./electron-stubs'));
|
||||
}
|
||||
if (flipperEnv.FLIPPER_FB) {
|
||||
plugins.unshift(require('./fb-stubs'));
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@ const plugins = [
|
||||
require('./electron-requires'),
|
||||
require('./plugin-flipper-requires'),
|
||||
];
|
||||
if (flipperEnv.FLIPPER_HEADLESS) {
|
||||
plugins.unshift(require('./electron-stubs'));
|
||||
}
|
||||
if (flipperEnv.FLIPPER_FB) {
|
||||
plugins.unshift(require('./fb-stubs'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user