Make flipper-server NPX-able

Summary: Make sure flipper-server is bundled in such a way that it is self-contained NPX-able. Also added some checks to make sure that dev dependencies don't accidentallly end up in in Flipper buidls

Reviewed By: nikoant

Differential Revision: D33190254

fbshipit-source-id: 443162e537d8ca9f956acac2d7bd52cbf0c92172
This commit is contained in:
Michel Weststrate
2021-12-24 02:15:25 -08:00
committed by Facebook GitHub Bot
parent 6ff4abbc67
commit 86b6d2c99d
8 changed files with 123 additions and 24 deletions

View File

@@ -27,3 +27,14 @@ yarn build:flipper-server
```
Pass the `--open` flag to open Flipper server after building
Use `--no-rebuild-plugins` to speed up subsequent builds if default plugins have been build already
### Test NPX build
```
cd <Flipper checkout>/desktop/
yarn build:flipper-server
cd flipper-server
yarn test:npx
```

View File

@@ -9,29 +9,31 @@
"flipperBundlerEntry": "src",
"license": "MIT",
"bugs": "https://github.com/facebook/flipper/issues",
"dependenciesComment": "mac-ca is required dynamically for darwin, node-fetch is treated special in electron-requires, not sure why",
"dependencies": {
"chalk": "^4.1.2",
"express": "^4.15.2",
"fs-extra": "^9.0.0",
"mac-ca": "^1.0.6",
"p-filter": "^2.1.0",
"socket.io": "^4.3.1"
"node-fetch": "^2.6.6"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^15.12.5",
"chalk": "^4.1.2",
"express": "^4.15.2",
"flipper-common": "0.0.0",
"flipper-pkg-lib": "0.0.0",
"flipper-server-core": "0.0.0",
"fs-extra": "^9.0.0",
"metro": "^0.66.2",
"open": "^8.3.0",
"p-filter": "^2.1.0",
"socket.io": "^4.3.1",
"yargs": "^17.0.1"
},
"peerDependencies": {},
"scripts": {
"reset": "rimraf lib *.tsbuildinfo",
"build": "tsc -b",
"prepack": "yarn reset && yarn build"
"test:npx": "yarn pack && cd ~/Desktop && rm -rf ~/.npm/_npx/ && mv ~/fbsource/xplat/sonar/desktop/flipper-server/flipper-server-v0.0.0.tgz . && npx flipper-server-v0.0.0.tgz"
},
"files": [
"dist/**/*",

View File

@@ -13,12 +13,7 @@ import http from 'http';
import path from 'path';
import fs from 'fs-extra';
import socketio from 'socket.io';
import {getWatchFolders} from 'flipper-pkg-lib';
import Metro from 'metro';
import pFilter from 'p-filter';
// provided by Metro
// eslint-disable-next-line
import MetroResolver from 'metro-resolver';
import {homedir} from 'os';
// This file is heavily inspired by scripts/start-dev-server.ts!
@@ -59,6 +54,11 @@ export async function startWebServerDev(
socket: socketio.Server,
rootDir: string,
) {
// prevent bundling!
const Metro = electronRequire('metro');
const MetroResolver = electronRequire('metro-resolver');
const {getWatchFolders} = electronRequire('flipper-pkg-lib');
const babelTransformationsDir = path.resolve(
rootDir,
'babel-transformer',