From ffc1a7c0365e800dcdd3d0a4fac33015b6754b7f Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Thu, 2 May 2024 11:52:19 +0100 Subject: [PATCH 1/3] chore[devtools-fusebox]: check in frontend.d.ts, include in build output --- packages/react-devtools-fusebox/package.json | 5 +-- .../react-devtools-fusebox/src/frontend.d.ts | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 packages/react-devtools-fusebox/src/frontend.d.ts diff --git a/packages/react-devtools-fusebox/package.json b/packages/react-devtools-fusebox/package.json index ccc64899051d0..bf5456d4cdac4 100644 --- a/packages/react-devtools-fusebox/package.json +++ b/packages/react-devtools-fusebox/package.json @@ -5,8 +5,9 @@ "license": "MIT", "files": ["dist"], "scripts": { - "build:frontend:local": "cross-env NODE_ENV=development webpack --config webpack.config.frontend.js", - "build:frontend": "cross-env NODE_ENV=production webpack --config webpack.config.frontend.js", + "build:frontend:copy-types": "cp src/*.d.ts dist/", + "build:frontend:local": "cross-env NODE_ENV=development webpack --config webpack.config.frontend.js && yarn build:frontend:copy-types", + "build:frontend": "cross-env NODE_ENV=production webpack --config webpack.config.frontend.js && yarn build:frontend:copy-types", "build": "yarn build:frontend" }, "devDependencies": { diff --git a/packages/react-devtools-fusebox/src/frontend.d.ts b/packages/react-devtools-fusebox/src/frontend.d.ts new file mode 100644 index 0000000000000..a4e582ad23c11 --- /dev/null +++ b/packages/react-devtools-fusebox/src/frontend.d.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +export type MessagePayload = null | string | number | boolean | {[key: string]: MessagePayload} | MessagePayload[]; +export type Message = {event: string, payload?: MessagePayload}; + +export type WallListener = (message: Message) => void; +export type Wall = { + listen: (fn: WallListener) => Function, + send: (event: string, payload?: MessagePayload) => void, +}; + +export type Bridge = { + shutdown: () => void, +}; +export type Store = Object; +export type BrowserTheme = 'dark' | 'light'; + +export function createBridge(wall: Wall): Bridge; +export function createStore(bridge: Bridge): Store; + +export type InitializationOptions = { + bridge: Bridge, + store: Store, + theme?: BrowserTheme, +}; +export function initialize(node: Element | Document, options: InitializationOptions): void; From 9cc52786ed5d7b815e76033500e2e8fb4ce84770 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Thu, 2 May 2024 11:55:21 +0100 Subject: [PATCH 2/3] chore[react-devtools-fusebox]: ignore dist/ for linting/formatting --- .eslintignore | 1 + .prettierignore | 1 + 2 files changed, 2 insertions(+) diff --git a/.eslintignore b/.eslintignore index 7d79ef6923112..5d7fa95f2b7a5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -18,6 +18,7 @@ packages/react-devtools-extensions/chrome/build packages/react-devtools-extensions/firefox/build packages/react-devtools-extensions/shared/build packages/react-devtools-extensions/src/ErrorTesterCompiled.js +packages/react-devtools-fusebox/dist packages/react-devtools-inline/dist packages/react-devtools-shared/src/hooks/__tests__/__source__/__compiled__/ packages/react-devtools-shared/src/hooks/__tests__/__source__/__untransformed__/ diff --git a/.prettierignore b/.prettierignore index 1ab5d680398d2..24caf7a7a1d70 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,6 +6,7 @@ packages/react-devtools-extensions/firefox/build packages/react-devtools-extensions/edge/build packages/react-devtools-extensions/shared/build packages/react-devtools-extensions/src/ErrorTesterCompiled.js +packages/react-devtools-fusebox/dist packages/react-devtools-inline/dist packages/react-devtools-shared/src/hooks/__tests__/__source__/__compiled__/ packages/react-devtools-shared/src/hooks/__tests__/__source__/__untransformed__/ From 6856781ea65ca05ce3203844b748492668c5bdb8 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Thu, 2 May 2024 12:25:01 +0100 Subject: [PATCH 3/3] chore: set up prettier for .d.ts files --- .prettierrc.js | 12 ++++++++- .../react-devtools-fusebox/src/frontend.d.ts | 27 ++++++++++++------- scripts/shared/pathsByLanguageVersion.js | 3 +++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 45986c05ee5cb..6342f131a0cf6 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,6 +1,9 @@ 'use strict'; -const {esNextPaths} = require('./scripts/shared/pathsByLanguageVersion'); +const { + esNextPaths, + typescriptPaths, +} = require('./scripts/shared/pathsByLanguageVersion'); module.exports = { bracketSpacing: false, @@ -17,5 +20,12 @@ module.exports = { trailingComma: 'all', }, }, + { + files: typescriptPaths, + options: { + trailingComma: 'all', + parser: 'typescript', + }, + }, ], }; diff --git a/packages/react-devtools-fusebox/src/frontend.d.ts b/packages/react-devtools-fusebox/src/frontend.d.ts index a4e582ad23c11..f17639a88c7be 100644 --- a/packages/react-devtools-fusebox/src/frontend.d.ts +++ b/packages/react-devtools-fusebox/src/frontend.d.ts @@ -5,17 +5,23 @@ * LICENSE file in the root directory of this source tree. */ -export type MessagePayload = null | string | number | boolean | {[key: string]: MessagePayload} | MessagePayload[]; -export type Message = {event: string, payload?: MessagePayload}; +export type MessagePayload = + | null + | string + | number + | boolean + | {[key: string]: MessagePayload} + | MessagePayload[]; +export type Message = {event: string; payload?: MessagePayload}; export type WallListener = (message: Message) => void; export type Wall = { - listen: (fn: WallListener) => Function, - send: (event: string, payload?: MessagePayload) => void, + listen: (fn: WallListener) => Function; + send: (event: string, payload?: MessagePayload) => void; }; export type Bridge = { - shutdown: () => void, + shutdown: () => void; }; export type Store = Object; export type BrowserTheme = 'dark' | 'light'; @@ -24,8 +30,11 @@ export function createBridge(wall: Wall): Bridge; export function createStore(bridge: Bridge): Store; export type InitializationOptions = { - bridge: Bridge, - store: Store, - theme?: BrowserTheme, + bridge: Bridge; + store: Store; + theme?: BrowserTheme; }; -export function initialize(node: Element | Document, options: InitializationOptions): void; +export function initialize( + node: Element | Document, + options: InitializationOptions, +): void; diff --git a/scripts/shared/pathsByLanguageVersion.js b/scripts/shared/pathsByLanguageVersion.js index 4a754f3cd491e..d4ee6daef3c16 100644 --- a/scripts/shared/pathsByLanguageVersion.js +++ b/scripts/shared/pathsByLanguageVersion.js @@ -25,7 +25,10 @@ const esNextPaths = [ // Files that we distribute on npm that should be ES5-only. const es5Paths = ['packages/*/npm/**/*.js']; +const typescriptPaths = ['packages/**/*.d.ts']; + module.exports = { esNextPaths, es5Paths, + typescriptPaths, };