Yarn workspaces

Summary:
1) moved "sonar/desktop/src" to "sonar/desktop/app/src", so "app" is now a separate package containing the core Flipper app code
2) Configured yarn workspaces with the root in "sonar/desktop": app, static, pkg, doctor, headless-tests. Plugins are not included for now, I plan to do this later.

Reviewed By: jknoxville

Differential Revision: D20535782

fbshipit-source-id: 600b2301960f37c7d72166e0d04eba462bec9fc1
This commit is contained in:
Anton Nikolaev
2020-03-20 13:31:37 -07:00
committed by Facebook GitHub Bot
parent 676d7bbd24
commit 863f89351e
340 changed files with 1635 additions and 294 deletions

View File

@@ -14,7 +14,7 @@ import yazl from 'yazl';
const {exec: createBinary} = require('pkg');
import {
buildFolder,
compile,
compileHeadless,
compileDefaultPlugins,
getVersionNumber,
genMercurialRevision,
@@ -98,7 +98,7 @@ async function createZip(buildDir: string, distDir: string, targets: string[]) {
const distDir = path.join(__dirname, '..', '..', 'dist');
// eslint-disable-next-line no-console
console.log('Created build directory', buildDir);
await compile(buildDir, path.join(__dirname, '..', 'headless', 'index.tsx'));
await compileHeadless(buildDir);
const versionNumber = getVersionNumber();
const buildRevision = await genMercurialRevision();
await preludeBundle(buildDir, versionNumber, buildRevision);

View File

@@ -13,7 +13,7 @@ import {Platform, Arch, ElectronDownloadOptions, build} from 'electron-builder';
import {spawn} from 'promisify-child-process';
import {
buildFolder,
compile,
compileRenderer,
compileMain,
die,
compileDefaultPlugins,
@@ -21,7 +21,7 @@ import {
genMercurialRevision,
} from './build-utils';
import fetch from 'node-fetch';
import {getIcons, buildLocalIconPath, getIconURL} from '../src/utils/icons';
import {getIcons, buildLocalIconPath, getIconURL} from '../app/src/utils/icons';
function generateManifest(versionNumber: string) {
const filePath = path.join(__dirname, '..', '..', 'dist');
@@ -182,7 +182,7 @@ function downloadIcons(buildFolder: string) {
copyStaticFolder(dir);
await downloadIcons(dir);
await compileDefaultPlugins(path.join(dir, 'defaultPlugins'));
await compile(dir, path.join(__dirname, '..', 'src', 'init.tsx'));
await compileRenderer(dir);
const versionNumber = getVersionNumber();
const hgRevision = await genMercurialRevision();
modifyPackageManifest(dir, versionNumber, hgRevision);

View File

@@ -15,8 +15,8 @@ import path from 'path';
import fs from 'fs-extra';
import {spawn} from 'promisify-child-process';
import recursiveReaddir from 'recursive-readdir';
const projectRoot = path.join(__dirname, '..');
import {default as getWatchFolders} from '../static/get-watch-folders';
import {appDir, staticDir, pluginsDir, headlessDir} from './paths';
async function mostRecentlyChanged(
dir: string,
@@ -41,12 +41,7 @@ export function compileDefaultPlugins(
) {
return compilePlugins(
null,
skipAll
? []
: [
path.join(__dirname, '..', 'plugins'),
path.join(__dirname, '..', 'plugins', 'fb'),
],
skipAll ? [] : [pluginsDir, path.join(pluginsDir, 'fb')],
defaultPluginDir,
{force: true, failSilently: false, recompileOnChanges: false},
)
@@ -64,21 +59,20 @@ export function compileDefaultPlugins(
.catch(die);
}
export function compile(buildFolder: string, entry: string) {
console.log(`⚙️ Compiling renderer bundle...`);
return Metro.runBuild(
async function compile(
buildFolder: string,
projectRoot: string,
watchFolders: string[],
entry: string,
) {
await Metro.runBuild(
{
reporter: {update: () => {}},
projectRoot: projectRoot,
watchFolders: [projectRoot],
projectRoot,
watchFolders,
serializer: {},
transformer: {
babelTransformerPath: path.join(
projectRoot,
'static',
'transforms',
'index.js',
),
babelTransformerPath: path.join(staticDir, 'transforms', 'index.js'),
},
resolver: {
resolverMainFields: ['flipper:source', 'module', 'main'],
@@ -93,13 +87,56 @@ export function compile(buildFolder: string, entry: string) {
entry,
out: path.join(buildFolder, 'bundle.js'),
},
)
.then(() => console.log('✅ Compiled renderer bundle.'))
.catch(die);
);
}
export async function compileHeadless(buildFolder: string) {
console.log(`⚙️ Compiling headless bundle...`);
const watchFolders = [
headlessDir,
...(await getWatchFolders(staticDir)),
...(await getWatchFolders(appDir)),
path.join(pluginsDir, 'navigation'),
path.join(pluginsDir, 'fb', 'layout', 'sidebar_extensions'),
path.join(pluginsDir, 'fb', 'mobileconfig'),
path.join(pluginsDir, 'fb', 'watch'),
].filter(fs.pathExists);
try {
await compile(
buildFolder,
headlessDir,
watchFolders,
path.join(headlessDir, 'index.tsx'),
);
console.log('✅ Compiled headless bundle.');
} catch (err) {
die(err);
}
}
export async function compileRenderer(buildFolder: string) {
console.log(`⚙️ Compiling renderer bundle...`);
const watchFolders = [
...(await getWatchFolders(appDir)),
path.join(pluginsDir, 'navigation'),
path.join(pluginsDir, 'fb', 'layout', 'sidebar_extensions'),
path.join(pluginsDir, 'fb', 'mobileconfig'),
path.join(pluginsDir, 'fb', 'watch'),
].filter(fs.pathExists);
try {
await compile(
buildFolder,
appDir,
watchFolders,
path.join(appDir, 'src', 'init.tsx'),
);
console.log('✅ Compiled renderer bundle.');
} catch (err) {
die(err);
}
}
export async function compileMain({dev}: {dev: boolean}) {
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)) {
@@ -110,19 +147,14 @@ export async function compileMain({dev}: {dev: boolean}) {
return;
}
}
console.log(`⚙️ Compiling main bundle...`);
console.log(`⚙️ Compiling main bundle... ${staticDir}`);
try {
const config = Object.assign({}, await Metro.loadConfig(), {
reporter: {update: () => {}},
projectRoot: staticDir,
watchFolders: [projectRoot],
watchFolders: await getWatchFolders(staticDir),
transformer: {
babelTransformerPath: path.join(
projectRoot,
'static',
'transforms',
'index.js',
),
babelTransformerPath: path.join(staticDir, 'transforms', 'index.js'),
},
resolver: {
sourceExts: ['tsx', 'ts', 'js'],

16
desktop/scripts/paths.ts Normal file
View File

@@ -0,0 +1,16 @@
/**
* 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 path from 'path';
export const rootDir = path.resolve(__dirname, '..');
export const appDir = path.join(rootDir, 'app');
export const staticDir = path.join(rootDir, 'static');
export const pluginsDir = path.join(rootDir, 'plugins');
export const headlessDir = path.join(rootDir, 'headless');

View File

@@ -17,16 +17,17 @@ import AnsiToHtmlConverter from 'ansi-to-html';
import chalk from 'chalk';
import http from 'http';
import path from 'path';
import fs from 'fs';
import fs from 'fs-extra';
import {compileMain} from './build-utils';
import Watchman from '../static/watchman';
import Metro from 'metro';
import MetroResolver from 'metro-resolver';
import {default as getWatchFolders} from '../static/get-watch-folders';
import {staticDir, pluginsDir, appDir} from './paths';
const ansiToHtmlConverter = new AnsiToHtmlConverter();
const DEFAULT_PORT = (process.env.PORT || 3000) as number;
const STATIC_DIR = path.join(__dirname, '..', 'static');
let shutdownElectron: (() => void) | undefined = undefined;
@@ -40,13 +41,13 @@ function launchElectron({
electronURL: string;
}) {
const args = [
path.join(STATIC_DIR, 'index.js'),
path.join(staticDir, 'index.js'),
'--remote-debugging-port=9222',
...process.argv,
];
const proc = child.spawn(electronBinary, args, {
cwd: STATIC_DIR,
cwd: staticDir,
env: {
...process.env,
SONAR_ROOT: process.cwd(),
@@ -75,18 +76,19 @@ function launchElectron({
};
}
function startMetroServer(app: Express) {
const projectRoot = path.join(__dirname, '..');
return Metro.runMetro({
projectRoot,
watchFolders: [projectRoot],
async function startMetroServer(app: Express) {
const watchFolders = [
...(await getWatchFolders(appDir)),
path.join(pluginsDir, 'navigation'),
path.join(pluginsDir, 'fb', 'layout', 'sidebar_extensions'),
path.join(pluginsDir, 'fb', 'mobileconfig'),
path.join(pluginsDir, 'fb', 'watch'),
].filter(fs.pathExists);
const metroBundlerServer = await Metro.runMetro({
projectRoot: appDir,
watchFolders,
transformer: {
babelTransformerPath: path.join(
projectRoot,
'static',
'transforms',
'index.js',
),
babelTransformerPath: path.join(staticDir, 'transforms', 'index.js'),
},
resolver: {
resolverMainFields: ['flipper:source', 'module', 'main'],
@@ -103,9 +105,8 @@ function startMetroServer(app: Express) {
},
},
watch: true,
}).then((metroBundlerServer: any) => {
app.use(metroBundlerServer.processRequest.bind(metroBundlerServer));
});
app.use(metroBundlerServer.processRequest.bind(metroBundlerServer));
}
function startAssetServer(
@@ -141,12 +142,12 @@ function startAssetServer(
});
app.get('/', (req, res) => {
fs.readFile(path.join(STATIC_DIR, 'index.dev.html'), (err, content) => {
fs.readFile(path.join(staticDir, 'index.dev.html'), (err, content) => {
res.end(content);
});
});
app.use(express.static(STATIC_DIR));
app.use(express.static(staticDir));
app.use(function(err: any, req: any, res: any, _next: any) {
knownErrors[req.url] = err;

View File

@@ -13,15 +13,7 @@ import globImport from 'glob';
import {exec as execImport} from 'child_process';
const glob = util.promisify(globImport);
const exec = util.promisify(execImport);
const PACKAGES = [
'headless-tests',
'static',
'doctor',
'pkg',
'plugins/*',
'plugins/fb/*',
'plugins/fb/layout/*',
];
const PACKAGES = ['plugins/*', 'plugins/fb/*', 'plugins/fb/layout/*'];
const WINDOWS = /^win/.test(process.platform);
const YARN_PATH =
process.argv.length > 2