diff --git a/desktop/app/package.json b/desktop/app/package.json index 6f435fa18..b9fbfc23a 100644 --- a/desktop/app/package.json +++ b/desktop/app/package.json @@ -9,6 +9,10 @@ "category": "facebook-intern", "privileged": true, "license": "MIT", + "scripts": { + "reset": "rimraf lib *.tsbuildinfo", + "build": "tsc -b" + }, "dependencies": { "@ant-design/icons": "^4.5.0", "@emotion/css": "^11.0.0", diff --git a/desktop/types/globals.ts b/desktop/app/src/global.ts similarity index 80% rename from desktop/types/globals.ts rename to desktop/app/src/global.ts index dba80808c..7ca6d7e6d 100644 --- a/desktop/types/globals.ts +++ b/desktop/app/src/global.ts @@ -8,10 +8,7 @@ */ import {StoreEnhancerStoreCreator} from 'redux'; -import {ResizeObserver} from './ResizeObserver.d'; -import {Store} from '../app/src/reducers'; - -export {}; +import {Store} from './reducers'; declare global { interface StoreEnhancerStateSanitizer { @@ -28,7 +25,5 @@ declare global { Flipper: { init: () => void; }; - - ResizeObserver: ResizeObserver; } } diff --git a/desktop/app/src/store.tsx b/desktop/app/src/store.tsx index 20f06c979..7c8ca8cf8 100644 --- a/desktop/app/src/store.tsx +++ b/desktop/app/src/store.tsx @@ -7,6 +7,7 @@ * @format */ +import './global'; import {createStore} from 'redux'; import reducers, {Actions, State as StoreState, Store} from './reducers/index'; import {stateSanitizer} from './utils/reduxDevToolsConfig'; diff --git a/desktop/app/tsconfig.json b/desktop/app/tsconfig.json new file mode 100644 index 000000000..e713b0f88 --- /dev/null +++ b/desktop/app/tsconfig.json @@ -0,0 +1,32 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": "src", + "esModuleInterop": true, + "emitDeclarationOnly": true + }, + "references": [ + { + "path": "../doctor" + }, + { + "path": "../flipper-plugin" + }, + { + "path": "../plugin-lib" + }, + { + "path": "../test-utils" + }, + { + "path": "../plugins/navigation" + } + ], + "exclude": [ + "**/node_modules/", + "**/__tests__/", + "**/lib/", + "**/fb/" + ] +} diff --git a/desktop/babel-transformer/tsconfig.json b/desktop/babel-transformer/tsconfig.json index 2fb289f45..22dce4bac 100644 --- a/desktop/babel-transformer/tsconfig.json +++ b/desktop/babel-transformer/tsconfig.json @@ -3,7 +3,5 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src" - }, - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + } } diff --git a/desktop/doctor/tsconfig.json b/desktop/doctor/tsconfig.json index 2fb289f45..22dce4bac 100644 --- a/desktop/doctor/tsconfig.json +++ b/desktop/doctor/tsconfig.json @@ -3,7 +3,5 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src" - }, - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + } } diff --git a/desktop/eslint-plugin-flipper/tsconfig.json b/desktop/eslint-plugin-flipper/tsconfig.json index 2fb289f45..22dce4bac 100644 --- a/desktop/eslint-plugin-flipper/tsconfig.json +++ b/desktop/eslint-plugin-flipper/tsconfig.json @@ -3,7 +3,5 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src" - }, - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + } } diff --git a/desktop/flipper-plugin/src/ui/datatable/TableRow.tsx b/desktop/flipper-plugin/src/ui/datatable/TableRow.tsx index 39cd483fe..202f7eb7e 100644 --- a/desktop/flipper-plugin/src/ui/datatable/TableRow.tsx +++ b/desktop/flipper-plugin/src/ui/datatable/TableRow.tsx @@ -9,7 +9,7 @@ import React, {CSSProperties, memo} from 'react'; import styled from '@emotion/styled'; -import {theme} from 'flipper-plugin'; +import {theme} from '../theme'; import type {RenderContext} from './DataTable'; import {Width} from '../../utils/widthUtils'; import {DataFormatter} from '../DataFormatter'; diff --git a/desktop/flipper-plugin/tsconfig.json b/desktop/flipper-plugin/tsconfig.json index b9af3bc6d..7d199ae13 100644 --- a/desktop/flipper-plugin/tsconfig.json +++ b/desktop/flipper-plugin/tsconfig.json @@ -8,11 +8,5 @@ { "path": "../plugin-lib" } - ], - "include": [ - "src" - ], - "exclude": [ - "node_modules", ] } diff --git a/desktop/jest.config.js b/desktop/jest.config.js index 96d0bbee0..da53db036 100644 --- a/desktop/jest.config.js +++ b/desktop/jest.config.js @@ -15,10 +15,8 @@ module.exports = { setupFiles: ['/scripts/jest-setup.js'], moduleNameMapper: { '^flipper$': '/app/src', - '^flipper-doctor$': '/doctor/src', - '^flipper-pkg$': '/pkg/src', - '^flipper-pkg-lib$': '/pkg-lib/src', '^flipper-plugin$': '/flipper-plugin/src', + '^flipper-(pkg|pkg-lib|doctor|test-utils)$': '/$1/src', }, clearMocks: true, coverageReporters: ['json-summary', 'lcov', 'html'], diff --git a/desktop/package.json b/desktop/package.json index c1ee1cb30..ea2354b3e 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -115,6 +115,7 @@ "@types/redux-mock-store": "^1.0.1", "@types/redux-persist": "^4.3.1", "@types/requestidlecallback": "^0.3.1", + "@types/resize-observer-browser": "^0.1.5", "@types/rsocket-core": "^0.0.5", "@types/rsocket-tcp-server": "^0.0.2", "@types/socket.io": "^2.1.13", @@ -241,7 +242,7 @@ "publish-packages": "./ts-node scripts/publish-packages.ts", "reset": "yarn rm-dist && yarn rm-temp && yarn rm-metro-cache && yarn cache clean && yarn rm-bundle && yarn rm-modules", "resolve-plugin-dir": "./ts-node scripts/resolve-plugin-dir.ts", - "rm-bundle": "rimraf static/main.bundle.* **/lib **/*.tsbuildinfo", + "rm-bundle": "rimraf static/main.bundle.* **/dist/bundle.* **/lib **/*.tsbuildinfo", "rm-dist": "rimraf ../dist", "rm-metro-cache": "rimraf $TMPDIR/metro-cache*", "rm-modules": "rimraf **/*/node_modules node_modules", @@ -275,7 +276,8 @@ "e2e", "plugin-lib", "test-utils", - "eslint-plugin-flipper" + "eslint-plugin-flipper", + "types" ] } } diff --git a/desktop/pkg-lib/tsconfig.json b/desktop/pkg-lib/tsconfig.json index 21f1c3a3b..66b0f9867 100644 --- a/desktop/pkg-lib/tsconfig.json +++ b/desktop/pkg-lib/tsconfig.json @@ -11,12 +11,5 @@ { "path": "../plugin-lib" } - ], - "include": [ - "src" - ], - "exclude": [ - "node_modules", - "**/__tests__/*" ] } diff --git a/desktop/pkg/tsconfig.json b/desktop/pkg/tsconfig.json index e69693331..aa6acfa62 100644 --- a/desktop/pkg/tsconfig.json +++ b/desktop/pkg/tsconfig.json @@ -6,10 +6,14 @@ "esModuleInterop": true }, "references": [ - {"path": "../pkg-lib"}, - {"path": "../plugin-lib"}, - {"path": "../test-utils"} - ], - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + { + "path": "../pkg-lib" + }, + { + "path": "../plugin-lib" + }, + { + "path": "../test-utils" + } + ] } diff --git a/desktop/plugin-lib/tsconfig.json b/desktop/plugin-lib/tsconfig.json index 875c0ea8f..22dce4bac 100644 --- a/desktop/plugin-lib/tsconfig.json +++ b/desktop/plugin-lib/tsconfig.json @@ -3,8 +3,5 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src" - }, - "references": [{"path": "../test-utils"}], - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + } } diff --git a/desktop/plugins/navigation/tsconfig.json b/desktop/plugins/navigation/tsconfig.json new file mode 100644 index 000000000..fa1d478c5 --- /dev/null +++ b/desktop/plugins/navigation/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "lib", + "rootDir": ".", + "esModuleInterop": true + } +} diff --git a/desktop/plugins/network/package.json b/desktop/plugins/network/package.json index c93f9fcf6..651889b1b 100644 --- a/desktop/plugins/network/package.json +++ b/desktop/plugins/network/package.json @@ -22,8 +22,8 @@ "xml-beautifier": "^0.4.0" }, "peerDependencies": { - "flipper": "0.0.0", - "flipper-plugin": "0.0.0" + "flipper": "*", + "flipper-plugin": "*" }, "devDependencies": { "@types/pako": "^1.0.1", diff --git a/desktop/scripts/gen-type-index.ts b/desktop/scripts/gen-type-index.ts new file mode 100644 index 000000000..c763a4ab2 --- /dev/null +++ b/desktop/scripts/gen-type-index.ts @@ -0,0 +1,47 @@ +/** + * 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 {rootDir} from './paths'; +import path from 'path'; +import fs from 'fs-extra'; + +async function genTypeIndex() { + const typesDir = path.join(rootDir, 'types'); + const filePaths = (await fs.readdir(typesDir)) + .filter( + (filePath) => filePath.endsWith('.d.ts') && filePath !== 'index.d.ts', + ) + .sort(); + await fs.writeFile( + path.join(typesDir, 'index.d.ts'), + // @lint-ignore-every LICENSELINT + `/** + * 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 + */ + +${filePaths + .map((filePath) => `/// `) + .join('\n')} +`, + ); +} + +genTypeIndex() + .then(() => { + process.exit(0); + }) + .catch((err: any) => { + console.error(err); + process.exit(1); + }); diff --git a/desktop/test-utils/tsconfig.json b/desktop/test-utils/tsconfig.json index 2fb289f45..22dce4bac 100644 --- a/desktop/test-utils/tsconfig.json +++ b/desktop/test-utils/tsconfig.json @@ -3,7 +3,5 @@ "compilerOptions": { "outDir": "lib", "rootDir": "src" - }, - "include": ["src"], - "exclude": ["node_modules", "**/__tests__/*"] + } } diff --git a/desktop/tsc-root/tsconfig.json b/desktop/tsc-root/tsconfig.json index 57aa1165e..79804a212 100644 --- a/desktop/tsc-root/tsconfig.json +++ b/desktop/tsc-root/tsconfig.json @@ -6,6 +6,9 @@ { "path": "../plugin-lib" }, + { + "path": "../flipper-plugin" + }, { "path": "../pkg" }, diff --git a/desktop/tsconfig.base.json b/desktop/tsconfig.base.json index 0e40b4431..92d286bc8 100644 --- a/desktop/tsconfig.base.json +++ b/desktop/tsconfig.base.json @@ -1,13 +1,18 @@ { "compilerOptions": { "module": "commonjs", - "lib": ["es7", "dom", "es2019"], + "lib": [ + "es7", + "dom", + "es2019" + ], "esModuleInterop": true, "target": "ES2019", "removeComments": true, "preserveConstEnums": true, "sourceMap": true, "declaration": true, + "declarationMap": true, "jsx": "react", "moduleResolution": "node", "skipLibCheck": true, @@ -18,12 +23,15 @@ "allowJs": true, "rootDir": ".", "paths": { - "flipper": ["./app/src"], - "flipper-plugin": ["./flipper-plugin/src"], - "eslint-plugin-flipper": ["./eslint-plugin-flipper/src"], - "flipper-*": ["./*/src"], - "@js-shared/*": ["../../js-shared/*"], - "*": ["./*", "./types/*"] + "@js-shared/*": [ + "../../js-shared/*" + ] } - } + }, + "exclude": [ + "**/lib/", + "**/dist/", + "**/node_modules/", + "**/__tests__/" + ] } diff --git a/desktop/tsconfig.json b/desktop/tsconfig.json index fe3689dc4..327638682 100644 --- a/desktop/tsconfig.json +++ b/desktop/tsconfig.json @@ -6,5 +6,9 @@ "composite": false, "allowJs": false }, - "exclude": ["**/node_modules/", "**/*.spec.ts"] + "exclude": [ + "**/node_modules/", + "**/lib/", + "**/dist/" + ] } diff --git a/desktop/types/ResizeObserver.d.ts b/desktop/types/ResizeObserver.d.ts deleted file mode 100644 index 2a2af10d4..000000000 --- a/desktop/types/ResizeObserver.d.ts +++ /dev/null @@ -1,51 +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 - */ - -export interface ResizeObserver { - new (callback: ResizeObserverCallback): ResizeObserver; - observe: (target: Element) => void; - unobserve: (target: Element) => void; - disconnect: () => void; -} - -interface ResizeObserverCallback { - (entries: ResizeObserverEntry[], observer: ResizeObserver): void; -} - -export interface ResizeObserverEntry { - /** - * @param target The Element whose size has changed. - */ - new (target: Element): ResizeObserverEntry; - - /** - * The Element whose size has changed. - */ - readonly target: Element; - - /** - * Element's content rect when ResizeObserverCallback is invoked. - */ - readonly contentRect: DOMRectReadOnly; -} - -interface DOMRectReadOnly { - // static fromRect(other: DOMRectInit | undefined): DOMRectReadOnly; - - readonly x: number; - readonly y: number; - readonly width: number; - readonly height: number; - readonly top: number; - readonly right: number; - readonly bottom: number; - readonly left: number; - - toJSON: () => any; -} diff --git a/desktop/types/index.d.ts b/desktop/types/index.d.ts new file mode 100644 index 000000000..12664c672 --- /dev/null +++ b/desktop/types/index.d.ts @@ -0,0 +1,29 @@ +/** + * 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 + */ + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/desktop/types/memoize-weak.d.ts b/desktop/types/memoize-weak.d.ts new file mode 100644 index 000000000..16dca077c --- /dev/null +++ b/desktop/types/memoize-weak.d.ts @@ -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 + */ + +declare module 'memoize-weak' { + export default function memoize any>( + fn: T, + ): T & { + clear(...args: Parameters | []): void; + }; +} diff --git a/desktop/types/package.json b/desktop/types/package.json new file mode 100644 index 000000000..bcb027fc2 --- /dev/null +++ b/desktop/types/package.json @@ -0,0 +1,17 @@ +{ + "name": "@types/flipper-custom-typings", + "version": "0.0.0", + "private": "true", + "description": "Custom typings for untyped Flipper dependencies", + "repository": "facebook/flipper", + "license": "MIT", + "bugs": "https://github.com/facebook/flipper/issues", + "homepage": "https://github.com/facebook/flipper", + "keywords": [ + "Flipper" + ], + "author": "Facebook, Inc", + "scripts": { + "postinstall": "../ts-node ../scripts/gen-type-index.ts" + } +} diff --git a/desktop/yarn.lock b/desktop/yarn.lock index 0130206c0..4e6545291 100644 --- a/desktop/yarn.lock +++ b/desktop/yarn.lock @@ -2527,6 +2527,11 @@ resolved "https://registry.yarnpkg.com/@types/requestidlecallback/-/requestidlecallback-0.3.1.tgz#34bb89753b1cdc72d0547522527b1cb0f02b5ec4" integrity sha512-BnnRkgWYijCIndUn+LgoqKHX/hNpJC5G03B9y7mZya/C2gUQTSn75fEj3ZP1/Rl2E6EYeXh2/7/8UNEZ4X7HuQ== +"@types/resize-observer-browser@^0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@types/resize-observer-browser/-/resize-observer-browser-0.1.5.tgz#36d897708172ac2380cd486da7a3daf1161c1e23" + integrity sha512-8k/67Z95Goa6Lznuykxkfhq9YU3l1Qe6LNZmwde1u7802a3x8v44oq0j91DICclxatTr0rNnhXx7+VTIetSrSQ== + "@types/retry@*": version "0.12.0" resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"