From 21b79af5f23c4ae283088514e689160335584d6f Mon Sep 17 00:00:00 2001 From: Anton Nikolaev Date: Fri, 17 Apr 2020 09:58:24 -0700 Subject: [PATCH] Split package "flipper-pkg" into two: lib and cli Summary: "flipper-pkg" added ~2MB to Flipper disttributive size, because of heavy dependencies which are only required for CLI functionality. See size warning in diff D21068373 in this stack where I added pkg as dependency to flipper. Here I'm splitting it into library and CLI packages, so Flipper app will only reference the library. Reviewed By: passy Differential Revision: D21087336 fbshipit-source-id: d9d62f1e75a835d1c0fa78ff1addb0d9a761a9c7 --- desktop/package.json | 7 +++- desktop/pkg-lib/LICENSE | 21 ++++++++++ desktop/pkg-lib/README.md | 4 ++ desktop/pkg-lib/jestconfig.json | 8 ++++ desktop/pkg-lib/package.json | 41 +++++++++++++++++++ desktop/pkg-lib/src/__tests__/index.node.ts | 12 ++++++ .../utils => pkg-lib/src}/getWatchFolders.ts | 0 desktop/pkg-lib/src/index.ts | 11 +++++ .../src/utils => pkg-lib/src}/runBuild.ts | 0 desktop/{pkg => pkg-lib}/src/types/metro.d.ts | 0 desktop/pkg-lib/tsconfig.json | 13 ++++++ desktop/pkg-lib/tslint.json | 7 ++++ desktop/pkg/package.json | 6 +-- desktop/pkg/src/commands/bundle.ts | 2 +- desktop/pkg/src/index.ts | 2 - desktop/pkg/tsconfig.json | 2 +- desktop/scripts/build-utils.ts | 2 +- desktop/scripts/get-app-watch-folders.ts | 2 +- desktop/static/compilePlugins.ts | 2 +- desktop/static/package.json | 2 +- desktop/tsconfig.json | 1 + 21 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 desktop/pkg-lib/LICENSE create mode 100644 desktop/pkg-lib/README.md create mode 100644 desktop/pkg-lib/jestconfig.json create mode 100644 desktop/pkg-lib/package.json create mode 100644 desktop/pkg-lib/src/__tests__/index.node.ts rename desktop/{pkg/src/utils => pkg-lib/src}/getWatchFolders.ts (100%) create mode 100644 desktop/pkg-lib/src/index.ts rename desktop/{pkg/src/utils => pkg-lib/src}/runBuild.ts (100%) rename desktop/{pkg => pkg-lib}/src/types/metro.d.ts (100%) create mode 100644 desktop/pkg-lib/tsconfig.json create mode 100644 desktop/pkg-lib/tslint.json diff --git a/desktop/package.json b/desktop/package.json index 746e4393b..4351997b3 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -15,6 +15,7 @@ "doctor", "headless-tests", "pkg", + "pkg-lib", "static", "plugins/*" ], @@ -98,7 +99,8 @@ "moduleNameMapper": { "^flipper$": "/app/src", "^flipper-doctor$": "/doctor/src", - "^flipper-pkg$": "/pkg/src" + "^flipper-pkg$": "/pkg/src", + "^flipper-pkg-lib$": "/pkg-lib/src" }, "clearMocks": true }, @@ -168,7 +170,8 @@ "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-react": "^7.16.0", "eslint-plugin-relay": "^1.4.1", - "flipper-pkg": "0.37.0", + "flipper-babel-transformer": "0.37.0", + "flipper-pkg-lib": "0.37.0", "flow-bin": "^0.122.0", "fs-extra": "^8.1.0", "glob": "^7.1.2", diff --git a/desktop/pkg-lib/LICENSE b/desktop/pkg-lib/LICENSE new file mode 100644 index 000000000..b96dcb048 --- /dev/null +++ b/desktop/pkg-lib/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Facebook, Inc. and its affiliates. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/desktop/pkg-lib/README.md b/desktop/pkg-lib/README.md new file mode 100644 index 000000000..c40d9b27a --- /dev/null +++ b/desktop/pkg-lib/README.md @@ -0,0 +1,4 @@ +# flipper-pkg + +`flipper-pkg-lib` is a **work-in-progress** library for bundling and publishing +Flipper plugins. diff --git a/desktop/pkg-lib/jestconfig.json b/desktop/pkg-lib/jestconfig.json new file mode 100644 index 000000000..bab48ba29 --- /dev/null +++ b/desktop/pkg-lib/jestconfig.json @@ -0,0 +1,8 @@ +{ + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "testPathIgnorePatterns": ["/node_modules/", "/lib/"], + "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"] +} diff --git a/desktop/pkg-lib/package.json b/desktop/pkg-lib/package.json new file mode 100644 index 000000000..f358e184b --- /dev/null +++ b/desktop/pkg-lib/package.json @@ -0,0 +1,41 @@ +{ + "name": "flipper-pkg-lib", + "version": "0.37.0", + "description": "Library for building and publishing Flipper plugins", + "repository": "facebook/flipper", + "main": "lib/index.js", + "flipper:source": "src", + "types": "lib/index.d.ts", + "license": "MIT", + "bugs": "https://github.com/facebook/flipper/issues", + "dependencies": { + "@types/fs-extra": "^8.1.0", + "@types/node": "^13.7.5", + "fs-extra": "^8.1.0", + "flipper-babel-transformer": "0.37.0", + "metro": "^0.59.0" + }, + "devDependencies": { + "@types/jest": "^25.1.0", + "globby": "^10", + "jest": "^25.1.0", + "prettier": "^2.0.0", + "rimraf": "^3.0.2", + "ts-jest": "^25.2.1", + "ts-node": "^8", + "typescript": "^3.7.2" + }, + "scripts": { + "reset": "rimraf lib *.tsbuildinfo", + "build": "tsc -b", + "prepack": "yarn reset && yarn build" + }, + "files": [ + "lib/**/*" + ], + "homepage": "https://github.com/facebook/flipper", + "keywords": [ + "Flipper" + ], + "author": "Facebook, Inc" +} diff --git a/desktop/pkg-lib/src/__tests__/index.node.ts b/desktop/pkg-lib/src/__tests__/index.node.ts new file mode 100644 index 000000000..f055e4541 --- /dev/null +++ b/desktop/pkg-lib/src/__tests__/index.node.ts @@ -0,0 +1,12 @@ +/** + * 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 + */ + +test('tests are working', () => { + expect(true).toBeTruthy(); +}); diff --git a/desktop/pkg/src/utils/getWatchFolders.ts b/desktop/pkg-lib/src/getWatchFolders.ts similarity index 100% rename from desktop/pkg/src/utils/getWatchFolders.ts rename to desktop/pkg-lib/src/getWatchFolders.ts diff --git a/desktop/pkg-lib/src/index.ts b/desktop/pkg-lib/src/index.ts new file mode 100644 index 000000000..e5ab0987d --- /dev/null +++ b/desktop/pkg-lib/src/index.ts @@ -0,0 +1,11 @@ +/** + * 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 + */ + +export {default as runBuild} from './runBuild'; +export {default as getWatchFolders} from './getWatchFolders'; diff --git a/desktop/pkg/src/utils/runBuild.ts b/desktop/pkg-lib/src/runBuild.ts similarity index 100% rename from desktop/pkg/src/utils/runBuild.ts rename to desktop/pkg-lib/src/runBuild.ts diff --git a/desktop/pkg/src/types/metro.d.ts b/desktop/pkg-lib/src/types/metro.d.ts similarity index 100% rename from desktop/pkg/src/types/metro.d.ts rename to desktop/pkg-lib/src/types/metro.d.ts diff --git a/desktop/pkg-lib/tsconfig.json b/desktop/pkg-lib/tsconfig.json new file mode 100644 index 000000000..44063987e --- /dev/null +++ b/desktop/pkg-lib/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src", + "allowJs": true, + "esModuleInterop": true, + "composite": true + }, + "references": [{"path": "../babel-transformer"}], + "include": ["src"], + "exclude": ["node_modules", "**/__tests__/*"] +} diff --git a/desktop/pkg-lib/tslint.json b/desktop/pkg-lib/tslint.json new file mode 100644 index 000000000..c98e4b003 --- /dev/null +++ b/desktop/pkg-lib/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": ["tslint:recommended", "tslint-config-prettier"], + "rules": { + "interface-name": false, + "variable-name": false + } +} diff --git a/desktop/pkg/package.json b/desktop/pkg/package.json index 79dc5014c..5a21b9606 100644 --- a/desktop/pkg/package.json +++ b/desktop/pkg/package.json @@ -20,10 +20,8 @@ "@types/node": "^13.7.5", "cli-ux": "^5.4.5", "fs-extra": "^8.1.0", - "flipper-babel-transformer": "0.37.0", - "inquirer": "^7.0.5", - "metro": "^0.59.0", - "tslib": "^1" + "flipper-pkg-lib": "0.37.0", + "inquirer": "^7.0.5" }, "devDependencies": { "@oclif/dev-cli": "^1", diff --git a/desktop/pkg/src/commands/bundle.ts b/desktop/pkg/src/commands/bundle.ts index 5f89bc849..0f8195a42 100644 --- a/desktop/pkg/src/commands/bundle.ts +++ b/desktop/pkg/src/commands/bundle.ts @@ -14,7 +14,7 @@ import * as inquirer from 'inquirer'; import * as path from 'path'; import * as yarn from '../utils/yarn'; import cli from 'cli-ux'; -import runBuild from '../utils/runBuild'; +import {runBuild} from 'flipper-pkg-lib'; async function deriveOutputFileName(inputDirectory: string): Promise { const packageJson = await readJSON(path.join(inputDirectory, 'package.json')); diff --git a/desktop/pkg/src/index.ts b/desktop/pkg/src/index.ts index e00be6139..e7557e685 100644 --- a/desktop/pkg/src/index.ts +++ b/desktop/pkg/src/index.ts @@ -9,5 +9,3 @@ export {run} from '@oclif/command'; export const PKG = 'flipper-pkg'; -export {default as runBuild} from './utils/runBuild'; -export {default as getWatchFolders} from './utils/getWatchFolders'; diff --git a/desktop/pkg/tsconfig.json b/desktop/pkg/tsconfig.json index 02e10e499..bbbae2486 100644 --- a/desktop/pkg/tsconfig.json +++ b/desktop/pkg/tsconfig.json @@ -6,7 +6,7 @@ "allowJs": true, "esModuleInterop": true }, - "references": [{"path": "../babel-transformer"}], + "references": [{"path": "../pkg-lib"}], "include": ["src"], "exclude": ["node_modules", "**/__tests__/*"] } diff --git a/desktop/scripts/build-utils.ts b/desktop/scripts/build-utils.ts index 7634e4033..4ffc28ccb 100644 --- a/desktop/scripts/build-utils.ts +++ b/desktop/scripts/build-utils.ts @@ -12,7 +12,7 @@ import tmp from 'tmp'; import path from 'path'; import fs from 'fs-extra'; import {spawn} from 'promisify-child-process'; -import {getWatchFolders} from 'flipper-pkg'; +import {getWatchFolders} from 'flipper-pkg-lib'; import getAppWatchFolders from './get-app-watch-folders'; import getPlugins from '../static/getPlugins'; import { diff --git a/desktop/scripts/get-app-watch-folders.ts b/desktop/scripts/get-app-watch-folders.ts index 89c023eff..ba1ab8cb8 100644 --- a/desktop/scripts/get-app-watch-folders.ts +++ b/desktop/scripts/get-app-watch-folders.ts @@ -9,7 +9,7 @@ import fs from 'fs-extra'; import path from 'path'; -import {getWatchFolders} from 'flipper-pkg'; +import {getWatchFolders} from 'flipper-pkg-lib'; import {appDir, pluginsDir} from './paths'; /** diff --git a/desktop/static/compilePlugins.ts b/desktop/static/compilePlugins.ts index ecfdf1d40..98de73274 100644 --- a/desktop/static/compilePlugins.ts +++ b/desktop/static/compilePlugins.ts @@ -14,7 +14,7 @@ import util from 'util'; import recursiveReaddir from 'recursive-readdir'; import pMap from 'p-map'; import {homedir} from 'os'; -import {getWatchFolders} from 'flipper-pkg'; +import {getWatchFolders} from 'flipper-pkg-lib'; import {default as getPlugins, PluginManifest, PluginInfo} from './getPlugins'; import startWatchPlugins from './startWatchPlugins'; diff --git a/desktop/static/package.json b/desktop/static/package.json index 13607d236..1270cb2ae 100644 --- a/desktop/static/package.json +++ b/desktop/static/package.json @@ -11,7 +11,7 @@ "fix-path": "^3.0.0", "fs-extra": "^8.1.0", "flipper-babel-transformer": "0.37.0", - "flipper-pkg": "0.37.0", + "flipper-pkg-lib": "0.37.0", "mem": "^6.0.0", "metro": "^0.59.0", "mkdirp": "^1.0.0", diff --git a/desktop/tsconfig.json b/desktop/tsconfig.json index 30985e539..eea1056f4 100644 --- a/desktop/tsconfig.json +++ b/desktop/tsconfig.json @@ -6,6 +6,7 @@ "flipper": ["./app/src"], "flipper-doctor": ["./doctor/src"], "flipper-pkg": ["./pkg/src"], + "flipper-pkg-lib": ["./pkg-lib/src"], "live-plugin-manager": ["./types/live-plugin-manager.d.tsx"], "flipper-babel-transformer": ["./babel-transformer/src"] }