Enable eslint import checks and fixed the reported errors (#878)

Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/878

1) Enabled eslint error reporting for unresolved imports and fixed all the errors
2) Enabled eslint for typings (d.ts) and fixed all the errors

Reviewed By: passy

Differential Revision: D20335151

fbshipit-source-id: 7b142281a406b32df0f02a5cd0d7d05eba941acd
This commit is contained in:
Anton Nikolaev
2020-03-14 14:26:07 -07:00
committed by Facebook GitHub Bot
parent 85c13bb1f3
commit beb5c85e69
25 changed files with 1201 additions and 174 deletions

View File

@@ -7,7 +7,7 @@
* @format
*/
const Metro = require('../static/node_modules/metro');
import Metro from 'metro';
import compilePlugins from '../static/compilePlugins';
import util from 'util';
import tmp from 'tmp';
@@ -16,6 +16,8 @@ import fs from 'fs-extra';
import {spawn} from 'promisify-child-process';
import recursiveReaddir from 'recursive-readdir';
const projectRoot = path.join(__dirname, '..');
async function mostRecentlyChanged(
dir: string,
ignores: string[],
@@ -64,12 +66,11 @@ export function compileDefaultPlugins(
export function compile(buildFolder: string, entry: string) {
console.log(`⚙️ Compiling renderer bundle...`);
const projectRoots = path.join(__dirname, '..');
return Metro.runBuild(
{
reporter: {update: () => {}},
projectRoot: projectRoots,
watchFolders: [projectRoots],
projectRoot: projectRoot,
watchFolders: [projectRoot],
serializer: {},
transformer: {
babelTransformerPath: path.join(
@@ -98,7 +99,7 @@ export function compile(buildFolder: string, entry: string) {
}
export async function compileMain({dev}: {dev: boolean}) {
const staticDir = path.resolve(__dirname, '..', 'static');
const staticDir = path.resolve(projectRoot, 'static');
const out = path.join(staticDir, 'main.bundle.js');
// check if main needs to be compiled
if (await fs.pathExists(out)) {
@@ -114,7 +115,7 @@ export async function compileMain({dev}: {dev: boolean}) {
const config = Object.assign({}, await Metro.loadConfig(), {
reporter: {update: () => {}},
projectRoot: staticDir,
watchFolders: [staticDir],
watchFolders: [projectRoot],
transformer: {
babelTransformerPath: path.join(
__dirname,

View File

@@ -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
*/
const generate = require('babel-generator').default;
const babylon = require('babylon');
const babel = require('babel-core');
const metro = require('metro');
exports.transform = function({
filename,
options,
src,
plugins: defaultPlugins,
}) {
const presets = [];
let ast = babylon.parse(src, {
filename,
plugins: ['jsx', 'flow', 'classProperties', 'objectRestSpread'],
sourceType: filename.includes('node_modules') ? 'script' : 'module',
});
// run babel
const plugins = [
...defaultPlugins,
require('./babel-plugins/electron-requires.js'),
require('./babel-plugins/dynamic-requires.js'),
];
if (!filename.includes('node_modules')) {
plugins.unshift(require('babel-plugin-transform-es2015-modules-commonjs'));
}
ast = babel.transformFromAst(ast, src, {
babelrc: !filename.includes('node_modules'),
code: false,
comments: false,
compact: false,
filename,
plugins,
presets,
sourceMaps: true,
}).ast;
const result = generate(
ast,
{
filename,
sourceFileName: filename,
sourceMaps: true,
},
src,
);
return {
ast,
code: result.code,
filename,
map: result.rawMappings.map(metro.sourceMaps.compactMapping),
};
};

View File

@@ -20,8 +20,8 @@ import path from 'path';
import fs from 'fs';
import {compileMain} from './build-utils';
import Watchman from '../static/watchman';
const Metro = require('../static/node_modules/metro');
const MetroResolver = require('../static/node_modules/metro-resolver');
import Metro from 'metro';
import MetroResolver from 'metro-resolver';
const ansiToHtmlConverter = new AnsiToHtmlConverter();

View File

@@ -16,6 +16,8 @@ const exec = util.promisify(execImport);
const PACKAGES = [
'headless-tests',
'static',
'doctor',
'pkg',
'src/plugins/*',
'src/fb/plugins/*',
'src/fb/plugins/layout/*',