From 7c410c71bb8b6eb80113ab9d089fb8938a6ee0a6 Mon Sep 17 00:00:00 2001 From: Daniel Rozenberg Date: Wed, 12 Jul 2023 15:27:34 -0400 Subject: [PATCH] Change how Preact's `render`/`hydrate` functions are re-export via the `preact/dom` namespace to match changes in upstream --- build-system/common/update-packages.js | 9 --------- src/preact/preact-dom.d.ts | 12 ------------ src/preact/preact-dom.ts | 12 ++++++++++++ src/preact/tsconfig.json | 7 ++++++- 4 files changed, 18 insertions(+), 22 deletions(-) delete mode 100644 src/preact/preact-dom.d.ts create mode 100644 src/preact/preact-dom.ts diff --git a/build-system/common/update-packages.js b/build-system/common/update-packages.js index fe06b890695b6..e45f3b53e6890 100644 --- a/build-system/common/update-packages.js +++ b/build-system/common/update-packages.js @@ -179,14 +179,6 @@ function patchShadowDom() { writeIfUpdated(patchedName, file); } -/** - * Adds a missing export statement to the preact module. - */ -function patchPreact() { - fs.ensureDirSync('node_modules/preact/dom'); - const file = `export { render, hydrate } from 'preact';`; - writeIfUpdated('node_modules/preact/dom/index.js', file); -} /** * Deletes the map file for rrule, which breaks closure compiler. @@ -235,7 +227,6 @@ function updatePackages() { patchIntersectionObserver(); patchResizeObserver(); patchShadowDom(); - patchPreact(); removeRruleSourcemap(); if (isCiBuild()) { runNpmChecks(); diff --git a/src/preact/preact-dom.d.ts b/src/preact/preact-dom.d.ts deleted file mode 100644 index 2d104fc351591..0000000000000 --- a/src/preact/preact-dom.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Provides type information for a Preact subdirectory. - * - * We render/hydrate from 'preact/dom' instead of 'preact' in order to make it more consistent with - * React. This makes remapping the imports for React builds simple (preact/dom --> react-dom). - * - * @fileoverview - */ -declare module 'preact/dom' { - export const hydrate: typeof import('preact').hydrate; - export const render: typeof import('preact').render; -} diff --git a/src/preact/preact-dom.ts b/src/preact/preact-dom.ts new file mode 100644 index 0000000000000..3d243dfeae2aa --- /dev/null +++ b/src/preact/preact-dom.ts @@ -0,0 +1,12 @@ +/** + * Re-export render/hydrate from 'preact' as 'preact/dom' (see ./tsconfig.json) + * in order to make it more consistent with React. This makes remapping the + * imports for React builds simple (preact/dom --> react-dom). + * + * @fileoverview + */ + +export {hydrate, render} from 'preact'; + +// eslint-disable-next-line no-restricted-syntax +declare module 'preact/dom' {} diff --git a/src/preact/tsconfig.json b/src/preact/tsconfig.json index cb5eba77ec881..94ed6998da53b 100644 --- a/src/preact/tsconfig.json +++ b/src/preact/tsconfig.json @@ -6,5 +6,10 @@ "**/*.d.ts", "../core/**/globals.d.ts", "../**/base-element.d.ts" - ] + ], + "compilerOptions": { + "paths": { + "preact/dom": ["./preact-dom.ts"] + } + } }