Allow direct references of doctor and pkg from the main bundle

Summary: This diff allows direct referencing pkg and doctor packages from the main bundle so they can be changed and used in the main app without publishing to npm

Reviewed By: mweststrate

Differential Revision: D20390416

fbshipit-source-id: af625a8b7cead4481743a88aec198493d363ce76
This commit is contained in:
Anton Nikolaev
2020-03-14 15:56:58 -07:00
committed by Facebook GitHub Bot
parent 10d990c32c
commit 952cb7783a
6 changed files with 33 additions and 22 deletions

View File

@@ -3,6 +3,7 @@
"version": "0.7.0", "version": "0.7.0",
"description": "Utility for checking for issues with a flipper installation", "description": "Utility for checking for issues with a flipper installation",
"main": "lib/index.js", "main": "lib/index.js",
"flipper:source": "src",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {

View File

@@ -9,6 +9,7 @@
"icon": "icon.png", "icon": "icon.png",
"category": "facebook-intern", "category": "facebook-intern",
"privileged": true, "privileged": true,
"license": "MIT",
"build": { "build": {
"appId": "flipper", "appId": "flipper",
"productName": "Flipper", "productName": "Flipper",
@@ -77,7 +78,9 @@
"<rootDir>/static/globalTestSetup.js" "<rootDir>/static/globalTestSetup.js"
], ],
"moduleNameMapper": { "moduleNameMapper": {
"^flipper$": "<rootDir>/src/index.tsx" "^flipper$": "<rootDir>/src",
"^flipper-doctor$": "<rootDir>/doctor/src",
"^flipper-pkg$": "<rootDir>/pkg/src"
}, },
"clearMocks": true "clearMocks": true
}, },

View File

@@ -4,6 +4,7 @@
"description": "Utility for building and publishing Flipper plugins", "description": "Utility for building and publishing Flipper plugins",
"repository": "facebook/flipper", "repository": "facebook/flipper",
"main": "lib/index.js", "main": "lib/index.js",
"flipper:source": "src",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"license": "MIT", "license": "MIT",
"bin": { "bin": {

View File

@@ -74,15 +74,15 @@ export function compile(buildFolder: string, entry: string) {
serializer: {}, serializer: {},
transformer: { transformer: {
babelTransformerPath: path.join( babelTransformerPath: path.join(
__dirname, projectRoot,
'..',
'static', 'static',
'transforms', 'transforms',
'index.js', 'index.js',
), ),
}, },
resolver: { resolver: {
blacklistRE: /(\/|\\)(sonar|flipper|flipper-public)(\/|\\)(desktop)(\/|\\)(dist|doctor)(\/|\\)|(\.native\.js$)/, resolverMainFields: ['flipper:source', 'module', 'main'],
blacklistRE: /\.native\.js$/,
}, },
}, },
{ {
@@ -118,8 +118,7 @@ export async function compileMain({dev}: {dev: boolean}) {
watchFolders: [projectRoot], watchFolders: [projectRoot],
transformer: { transformer: {
babelTransformerPath: path.join( babelTransformerPath: path.join(
__dirname, projectRoot,
'..',
'static', 'static',
'transforms', 'transforms',
'index.js', 'index.js',
@@ -127,7 +126,8 @@ export async function compileMain({dev}: {dev: boolean}) {
}, },
resolver: { resolver: {
sourceExts: ['tsx', 'ts', 'js'], sourceExts: ['tsx', 'ts', 'js'],
blacklistRE: /(\/|\\)(sonar|flipper|flipper-public)(\/|\\)(desktop)(\/|\\)(dist|doctor)(\/|\\)|(\.native\.js$)/, resolverMainFields: ['flipper:source', 'module', 'main'],
blacklistRE: /\.native\.js$/,
}, },
}); });
await Metro.runBuild(config, { await Metro.runBuild(config, {

View File

@@ -82,15 +82,15 @@ function startMetroServer(app: Express) {
watchFolders: [projectRoot], watchFolders: [projectRoot],
transformer: { transformer: {
babelTransformerPath: path.join( babelTransformerPath: path.join(
__dirname, projectRoot,
'..',
'static', 'static',
'transforms', 'transforms',
'index.js', 'index.js',
), ),
}, },
resolver: { resolver: {
blacklistRE: /(\/|\\)(sonar|flipper|flipper-public)(\/|\\)(desktop)(\/|\\)(dist|doctor)(\/|\\)|(\.native\.js$)/, resolverMainFields: ['flipper:source', 'module', 'main'],
blacklistRE: /\.native\.js$/,
resolveRequest: (context: any, moduleName: string, platform: string) => { resolveRequest: (context: any, moduleName: string, platform: string) => {
if (moduleName.startsWith('./localhost:3000')) { if (moduleName.startsWith('./localhost:3000')) {
moduleName = moduleName.replace('./localhost:3000', '.'); moduleName = moduleName.replace('./localhost:3000', '.');
@@ -134,7 +134,7 @@ function startAssetServer(
} }
shutdownElectron = launchElectron({ shutdownElectron = launchElectron({
devServerURL: `http://localhost:${port}`, devServerURL: `http://localhost:${port}`,
bundleURL: `http://localhost:${port}/src/init.bundle?dev=true&platform=web&minify=false&excludeSource=false`, bundleURL: `http://localhost:${port}/src/init.bundle`,
electronURL: `http://localhost:${port}/index.dev.html`, electronURL: `http://localhost:${port}/index.dev.html`,
}); });
res.end(); res.end();
@@ -174,16 +174,20 @@ async function addWebsocket(server: http.Server) {
// refresh the app on changes to the src folder // refresh the app on changes to the src folder
// this can be removed once metroServer notifies us about file changes // this can be removed once metroServer notifies us about file changes
try { try {
const watchman = new Watchman(path.resolve(__dirname, '..', 'src')); const watchman = new Watchman(path.resolve(__dirname, '..'));
await watchman.initialize(); await watchman.initialize();
await watchman.startWatchFiles( await Promise.all(
'', ['src', 'pkg', 'doctor'].map(dir =>
watchman.startWatchFiles(
dir,
() => { () => {
io.emit('refresh'); io.emit('refresh');
}, },
{ {
excludes: ['**/__tests__/**/*', '**/node_modules/**/*', '**/.*'], excludes: ['**/__tests__/**/*', '**/node_modules/**/*', '**/.*'],
}, },
),
),
); );
} catch (err) { } catch (err) {
console.error( console.error(

View File

@@ -13,11 +13,13 @@
"downlevelIteration": true, "downlevelIteration": true,
"skipLibCheck": true, "skipLibCheck": true,
"paths": { "paths": {
"flipper": ["./src/index.tsx"], "flipper": ["./src"],
"flipper-doctor": ["./doctor/src"],
"flipper-pkg": ["./pkg/src"],
"live-plugin-manager": ["./types/live-plugin-manager.d.tsx"] "live-plugin-manager": ["./types/live-plugin-manager.d.tsx"]
}, },
"strict": true "strict": true
}, },
"include": ["src/**/*", "static/**/*", "scripts/**/*", "types/*", "headless/*", "plugins/**/*"], "include": ["src/**/*", "doctor/**/*", "pkg/**/*", "static/**/*", "scripts/**/*", "types/**/*", "headless/**/*", "plugins/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"] "exclude": ["node_modules", "**/*.spec.ts"]
} }