Files
flipper/static/transforms/electron-stubs.js
Daniel Büchele 500007ccca use perf_hooks
Summary:
We were using `window.performance` to measure performance. This was because the equivalent node.js API `perf_hooks` wasn't available in the electron version we were using back then.
However, `perf_hooks` has landed in electron meanwhile, so I am moving to this API, as it works for the headless version and jest tests, too.

This allows us to delete the babel transform that was used for node-based tests, where the browser API was replaced with the node API

Reviewed By: jknoxville

Differential Revision: D13860133

fbshipit-source-id: cf1395004fac046dd55751ff465af494173b2cbf
2019-01-29 09:32:05 -08:00

34 lines
865 B
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
var babylon = require('@babel/parser');
var fs = require('fs');
var electronStubs = babylon.parseExpression(
fs.readFileSync('static/electron-stubs.notjs').toString(),
);
module.exports = function(babel) {
return {
name: 'replace-electron-requires-with-stubs',
visitor: {
CallExpression(path) {
if (
path.node.type === 'CallExpression' &&
path.node.callee.type === 'Identifier' &&
path.node.callee.name === 'require' &&
path.node.arguments.length > 0
) {
if (path.node.arguments[0].value === 'electron') {
path.replaceWith(electronStubs);
}
}
},
},
};
};