From 7b779e4a734da1f5e4e35fcccd9f1d289b27b860 Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Tue, 7 Jan 2025 00:07:09 +0800 Subject: [PATCH 1/6] feat: add post install --- .changeset/smart-eagles-hope.md | 5 ++++ packages/utilities/shared-utils/package.json | 4 ++- .../shared-utils/scripts/postinstall.js | 19 ++++++++++++ .../utilities/shared-utils/src/demi/demi.d.ts | 15 ++++++++++ .../utilities/shared-utils/src/demi/index.ts | 2 ++ .../shared-utils/src/demi/react18/index.ts | 17 +++++++++++ .../shared-utils/src/demi/react19/index.ts | 17 +++++++++++ .../utilities/shared-utils/src/functions.ts | 29 ------------------- packages/utilities/shared-utils/src/index.ts | 2 ++ 9 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 .changeset/smart-eagles-hope.md create mode 100644 packages/utilities/shared-utils/scripts/postinstall.js create mode 100644 packages/utilities/shared-utils/src/demi/demi.d.ts create mode 100644 packages/utilities/shared-utils/src/demi/index.ts create mode 100644 packages/utilities/shared-utils/src/demi/react18/index.ts create mode 100644 packages/utilities/shared-utils/src/demi/react19/index.ts diff --git a/.changeset/smart-eagles-hope.md b/.changeset/smart-eagles-hope.md new file mode 100644 index 0000000000..c8cf276405 --- /dev/null +++ b/.changeset/smart-eagles-hope.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/shared-utils": patch +--- + +Tabs with prop destroyInactiveTabPanel error in nextjs15(#4344) diff --git a/packages/utilities/shared-utils/package.json b/packages/utilities/shared-utils/package.json index e6eb2579ea..7e16c8c5ce 100644 --- a/packages/utilities/shared-utils/package.json +++ b/packages/utilities/shared-utils/package.json @@ -25,6 +25,7 @@ "url": "https://github.com/nextui-org/nextui/issues" }, "scripts": { + "postinstall": "node -e \"try{require('./scripts/postinstall.js')}catch(e){}\"", "build": "tsup src --dts", "dev": "pnpm build:fast --watch", "clean": "rimraf dist .turbo", @@ -43,6 +44,7 @@ "format": [ "cjs", "esm" - ] + ], + "splitting": false } } \ No newline at end of file diff --git a/packages/utilities/shared-utils/scripts/postinstall.js b/packages/utilities/shared-utils/scripts/postinstall.js new file mode 100644 index 0000000000..7baf14e5b1 --- /dev/null +++ b/packages/utilities/shared-utils/scripts/postinstall.js @@ -0,0 +1,19 @@ +const { switchVersion, loadModule } = require('./utils') + +const Vue = loadModule('vue') + +if (!Vue || typeof Vue.version !== 'string') { + console.warn('[vue-demi] Vue is not found. Please run "npm install vue" to install.') +} +else if (Vue.version.startsWith('2.7.')) { + switchVersion(2.7) +} +else if (Vue.version.startsWith('2.')) { + switchVersion(2) +} +else if (Vue.version.startsWith('3.')) { + switchVersion(3) +} +else { + console.warn(`[vue-demi] Vue version v${Vue.version} is not supported.`) +} diff --git a/packages/utilities/shared-utils/src/demi/demi.d.ts b/packages/utilities/shared-utils/src/demi/demi.d.ts new file mode 100644 index 0000000000..3c60423032 --- /dev/null +++ b/packages/utilities/shared-utils/src/demi/demi.d.ts @@ -0,0 +1,15 @@ +/** + * Returns an appropriate value for the `inert` attribute based on the React version. + * + * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute + * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. + * + * @param {boolean} v - The desired boolean state for the `inert` attribute. + * @returns {boolean | string | undefined} - Depending on the React version: + * - Returns `boolean` if React version is 19 (the input value `v` directly). + * - Returns `string` (empty string) if `v` is `true` in older React versions. + * - Returns `undefined` if `v` is `false` in older React versions. + * + * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. + */ +export declare function getInertValue(v: boolean): boolean | string | undefined; diff --git a/packages/utilities/shared-utils/src/demi/index.ts b/packages/utilities/shared-utils/src/demi/index.ts new file mode 100644 index 0000000000..12d535cfb8 --- /dev/null +++ b/packages/utilities/shared-utils/src/demi/index.ts @@ -0,0 +1,2 @@ +export * from "./react19"; +export * from "./react18"; diff --git a/packages/utilities/shared-utils/src/demi/react18/index.ts b/packages/utilities/shared-utils/src/demi/react18/index.ts new file mode 100644 index 0000000000..fecfe49700 --- /dev/null +++ b/packages/utilities/shared-utils/src/demi/react18/index.ts @@ -0,0 +1,17 @@ +/** + * Returns an appropriate value for the `inert` attribute based on the React version. + * + * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute + * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. + * + * @param {boolean} v - The desired boolean state for the `inert` attribute. + * @returns {boolean | string | undefined} - Depending on the React version: + * - Returns `boolean` if React version is 19 (the input value `v` directly). + * - Returns `string` (empty string) if `v` is `true` in older React versions. + * - Returns `undefined` if `v` is `false` in older React versions. + * + * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. + */ +export const getInertValueReact18 = (v: boolean): boolean | string | undefined => { + return v ? "" : undefined; +}; diff --git a/packages/utilities/shared-utils/src/demi/react19/index.ts b/packages/utilities/shared-utils/src/demi/react19/index.ts new file mode 100644 index 0000000000..1e38de5503 --- /dev/null +++ b/packages/utilities/shared-utils/src/demi/react19/index.ts @@ -0,0 +1,17 @@ +/** + * Returns an appropriate value for the `inert` attribute based on the React version. + * + * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute + * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. + * + * @param {boolean} v - The desired boolean state for the `inert` attribute. + * @returns {boolean | string | undefined} - Depending on the React version: + * - Returns `boolean` if React version is 19 (the input value `v` directly). + * - Returns `string` (empty string) if `v` is `true` in older React versions. + * - Returns `undefined` if `v` is `false` in older React versions. + * + * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. + */ +export const getInertValueReact19 = (v: boolean): boolean | string | undefined => { + return v; +}; diff --git a/packages/utilities/shared-utils/src/functions.ts b/packages/utilities/shared-utils/src/functions.ts index bdbcec3db4..2eece226c6 100644 --- a/packages/utilities/shared-utils/src/functions.ts +++ b/packages/utilities/shared-utils/src/functions.ts @@ -1,5 +1,3 @@ -import React from "react"; - type Args = T extends (...args: infer R) => any ? R : never; type AnyFunction = (...args: T[]) => any; @@ -391,30 +389,3 @@ export const intersectionBy = (...args: [...arrays: T[][], iteratee: Iteratee return res; }; - -/** - * Checks if the current React version is 19.x.x - * - * @returns {boolean} - Returns `true` if the React major version is 19, otherwise returns `false`. - */ -export const isReact19 = (): boolean => { - return React.version.split(".")[0] === "19"; -}; - -/** - * Returns an appropriate value for the `inert` attribute based on the React version. - * - * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute - * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. - * - * @param {boolean} v - The desired boolean state for the `inert` attribute. - * @returns {boolean | string | undefined} - Depending on the React version: - * - Returns `boolean` if React version is 19 (the input value `v` directly). - * - Returns `string` (empty string) if `v` is `true` in older React versions. - * - Returns `undefined` if `v` is `false` in older React versions. - * - * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. - */ -export const getInertValue = (v: boolean): boolean | string | undefined => { - return isReact19() ? v : v ? "" : undefined; -}; diff --git a/packages/utilities/shared-utils/src/index.ts b/packages/utilities/shared-utils/src/index.ts index eec14e1c31..34293353b2 100644 --- a/packages/utilities/shared-utils/src/index.ts +++ b/packages/utilities/shared-utils/src/index.ts @@ -9,3 +9,5 @@ export * from "./console"; export * from "./types"; export * from "./dates"; export * from "./regex"; + +export type {getInertValue} from "./demi/demi"; From 00ed91e2c179cbafbbdfd4cc94129053c2f8e2ff Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 12 Jan 2025 12:45:15 +0800 Subject: [PATCH 2/6] feat: add postinstall --- packages/utilities/shared-utils/README.md | 18 +++++-- packages/utilities/shared-utils/package.json | 8 +-- .../shared-utils/scripts/postinstall.js | 50 +++++++++++++------ .../src/{ => common}/assertion.ts | 0 .../shared-utils/src/{ => common}/clsx.ts | 0 .../shared-utils/src/{ => common}/console.ts | 0 .../shared-utils/src/{ => common}/dates.ts | 0 .../src/{ => common}/dimensions.ts | 0 .../src/{ => common}/functions.ts | 0 .../shared-utils/src/{ => common}/index.ts | 2 - .../shared-utils/src/{ => common}/numbers.ts | 0 .../shared-utils/src/{ => common}/object.ts | 0 .../shared-utils/src/{ => common}/regex.ts | 0 .../shared-utils/src/{ => common}/text.ts | 0 .../shared-utils/src/{ => common}/types.ts | 0 .../utilities/shared-utils/src/demi/index.ts | 2 - .../src/demi/react18/getInertValue.ts | 17 +++++++ .../shared-utils/src/demi/react18/index.ts | 20 ++------ .../{demi.d.ts => react19/getInertValue.ts} | 4 +- .../shared-utils/src/demi/react19/index.ts | 20 ++------ 20 files changed, 81 insertions(+), 60 deletions(-) rename packages/utilities/shared-utils/src/{ => common}/assertion.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/clsx.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/console.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/dates.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/dimensions.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/functions.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/index.ts (85%) rename packages/utilities/shared-utils/src/{ => common}/numbers.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/object.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/regex.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/text.ts (100%) rename packages/utilities/shared-utils/src/{ => common}/types.ts (100%) delete mode 100644 packages/utilities/shared-utils/src/demi/index.ts create mode 100644 packages/utilities/shared-utils/src/demi/react18/getInertValue.ts rename packages/utilities/shared-utils/src/demi/{demi.d.ts => react19/getInertValue.ts} (89%) diff --git a/packages/utilities/shared-utils/README.md b/packages/utilities/shared-utils/README.md index 59f5377314..38016f5bad 100644 --- a/packages/utilities/shared-utils/README.md +++ b/packages/utilities/shared-utils/README.md @@ -1,4 +1,4 @@ -# @nextui-org/system +# @nextui-org/shared-utils A Quick description of the component @@ -7,9 +7,9 @@ A Quick description of the component ## Installation ```sh -yarn add @nextui-org/system +yarn add @nextui-org/shared-utils # or -npm i @nextui-org/system +npm i @nextui-org/shared-utils ``` ## Contribution @@ -18,7 +18,17 @@ Yes please! See the [contributing guidelines](https://github.com/nextui-org/nextui/blob/master/CONTRIBUTING.md) for details. +## File structure + +``` +src/ +├── common/ # Common utilities for all React versions +└── demi/ # Demi utilities for different React versions + ├── react18/ + └── react19/ +``` + ## License This project is licensed under the terms of the -[MIT license](https://github.com/nextui-org/nextui/blob/master/LICENSE). +[MIT license](https://github.com/nextui-org/nextui/blob/master/LICENSE). \ No newline at end of file diff --git a/packages/utilities/shared-utils/package.json b/packages/utilities/shared-utils/package.json index 7e16c8c5ce..fe0ce15f6b 100644 --- a/packages/utilities/shared-utils/package.json +++ b/packages/utilities/shared-utils/package.json @@ -11,7 +11,8 @@ "main": "src/index.ts", "sideEffects": false, "files": [ - "dist" + "dist", + "scripts" ], "publishConfig": { "access": "public" @@ -45,6 +46,7 @@ "cjs", "esm" ], - "splitting": false + "splitting": false, + "entry": ["src/demi/react18", "src/demi/react19"] } -} \ No newline at end of file +} diff --git a/packages/utilities/shared-utils/scripts/postinstall.js b/packages/utilities/shared-utils/scripts/postinstall.js index 7baf14e5b1..910a60dede 100644 --- a/packages/utilities/shared-utils/scripts/postinstall.js +++ b/packages/utilities/shared-utils/scripts/postinstall.js @@ -1,19 +1,41 @@ -const { switchVersion, loadModule } = require('./utils') +const path = require('path') +const fs = require('fs') -const Vue = loadModule('vue') - -if (!Vue || typeof Vue.version !== 'string') { - console.warn('[vue-demi] Vue is not found. Please run "npm install vue" to install.') -} -else if (Vue.version.startsWith('2.7.')) { - switchVersion(2.7) +function tryRequirePkg(pkg) { + try { + return require(pkg); + } catch (e) { + return null; + } } -else if (Vue.version.startsWith('2.')) { - switchVersion(2) + +function copyDemiDir(dir) { + const src = path.join(__dirname, '..', 'dist', 'demi', dir) + const dest = path.join(__dirname, '..', 'dist') + + fs.cpSync(src, dest, { recursive: true }) } -else if (Vue.version.startsWith('3.')) { - switchVersion(3) + +function modifyDts(path) { + const dts = fs.readFileSync(path, 'utf8') + const modifiedDts = dts.replace(/\.\.\/\.\.\/common/g, './common') + + fs.writeFileSync(path, modifiedDts, 'utf8') } -else { - console.warn(`[vue-demi] Vue version v${Vue.version} is not supported.`) + +function postinstall() { + const nextjs = tryRequirePkg('next') + const react = tryRequirePkg('react') + const nextjsVersion = nextjs?.version?.version || '' + const reactVersion = react?.version || '' + + if (nextjsVersion.startsWith('14') || reactVersion.startsWith('18')) { + copyDemiDir('react18') + } else { + copyDemiDir('react19') + } + + modifyDts(path.join(__dirname, '..', 'dist', 'index.d.ts')) } + +postinstall(); diff --git a/packages/utilities/shared-utils/src/assertion.ts b/packages/utilities/shared-utils/src/common/assertion.ts similarity index 100% rename from packages/utilities/shared-utils/src/assertion.ts rename to packages/utilities/shared-utils/src/common/assertion.ts diff --git a/packages/utilities/shared-utils/src/clsx.ts b/packages/utilities/shared-utils/src/common/clsx.ts similarity index 100% rename from packages/utilities/shared-utils/src/clsx.ts rename to packages/utilities/shared-utils/src/common/clsx.ts diff --git a/packages/utilities/shared-utils/src/console.ts b/packages/utilities/shared-utils/src/common/console.ts similarity index 100% rename from packages/utilities/shared-utils/src/console.ts rename to packages/utilities/shared-utils/src/common/console.ts diff --git a/packages/utilities/shared-utils/src/dates.ts b/packages/utilities/shared-utils/src/common/dates.ts similarity index 100% rename from packages/utilities/shared-utils/src/dates.ts rename to packages/utilities/shared-utils/src/common/dates.ts diff --git a/packages/utilities/shared-utils/src/dimensions.ts b/packages/utilities/shared-utils/src/common/dimensions.ts similarity index 100% rename from packages/utilities/shared-utils/src/dimensions.ts rename to packages/utilities/shared-utils/src/common/dimensions.ts diff --git a/packages/utilities/shared-utils/src/functions.ts b/packages/utilities/shared-utils/src/common/functions.ts similarity index 100% rename from packages/utilities/shared-utils/src/functions.ts rename to packages/utilities/shared-utils/src/common/functions.ts diff --git a/packages/utilities/shared-utils/src/index.ts b/packages/utilities/shared-utils/src/common/index.ts similarity index 85% rename from packages/utilities/shared-utils/src/index.ts rename to packages/utilities/shared-utils/src/common/index.ts index 34293353b2..eec14e1c31 100644 --- a/packages/utilities/shared-utils/src/index.ts +++ b/packages/utilities/shared-utils/src/common/index.ts @@ -9,5 +9,3 @@ export * from "./console"; export * from "./types"; export * from "./dates"; export * from "./regex"; - -export type {getInertValue} from "./demi/demi"; diff --git a/packages/utilities/shared-utils/src/numbers.ts b/packages/utilities/shared-utils/src/common/numbers.ts similarity index 100% rename from packages/utilities/shared-utils/src/numbers.ts rename to packages/utilities/shared-utils/src/common/numbers.ts diff --git a/packages/utilities/shared-utils/src/object.ts b/packages/utilities/shared-utils/src/common/object.ts similarity index 100% rename from packages/utilities/shared-utils/src/object.ts rename to packages/utilities/shared-utils/src/common/object.ts diff --git a/packages/utilities/shared-utils/src/regex.ts b/packages/utilities/shared-utils/src/common/regex.ts similarity index 100% rename from packages/utilities/shared-utils/src/regex.ts rename to packages/utilities/shared-utils/src/common/regex.ts diff --git a/packages/utilities/shared-utils/src/text.ts b/packages/utilities/shared-utils/src/common/text.ts similarity index 100% rename from packages/utilities/shared-utils/src/text.ts rename to packages/utilities/shared-utils/src/common/text.ts diff --git a/packages/utilities/shared-utils/src/types.ts b/packages/utilities/shared-utils/src/common/types.ts similarity index 100% rename from packages/utilities/shared-utils/src/types.ts rename to packages/utilities/shared-utils/src/common/types.ts diff --git a/packages/utilities/shared-utils/src/demi/index.ts b/packages/utilities/shared-utils/src/demi/index.ts deleted file mode 100644 index 12d535cfb8..0000000000 --- a/packages/utilities/shared-utils/src/demi/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./react19"; -export * from "./react18"; diff --git a/packages/utilities/shared-utils/src/demi/react18/getInertValue.ts b/packages/utilities/shared-utils/src/demi/react18/getInertValue.ts new file mode 100644 index 0000000000..6350003e57 --- /dev/null +++ b/packages/utilities/shared-utils/src/demi/react18/getInertValue.ts @@ -0,0 +1,17 @@ +/** + * Returns an appropriate value for the `inert` attribute based on the React version. + * + * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute + * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. + * + * @param {boolean} v - The desired boolean state for the `inert` attribute. + * @returns {boolean | string | undefined} - Depending on the React version: + * - Returns `boolean` if React version is 19 (the input value `v` directly). + * - Returns `string` (empty string) if `v` is `true` in older React versions. + * - Returns `undefined` if `v` is `false` in older React versions. + * + * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. + */ +export const getInertValue = (v: boolean): boolean | string | undefined => { + return v ? "" : undefined; +}; diff --git a/packages/utilities/shared-utils/src/demi/react18/index.ts b/packages/utilities/shared-utils/src/demi/react18/index.ts index fecfe49700..a7b20e28e0 100644 --- a/packages/utilities/shared-utils/src/demi/react18/index.ts +++ b/packages/utilities/shared-utils/src/demi/react18/index.ts @@ -1,17 +1,3 @@ -/** - * Returns an appropriate value for the `inert` attribute based on the React version. - * - * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute - * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. - * - * @param {boolean} v - The desired boolean state for the `inert` attribute. - * @returns {boolean | string | undefined} - Depending on the React version: - * - Returns `boolean` if React version is 19 (the input value `v` directly). - * - Returns `string` (empty string) if `v` is `true` in older React versions. - * - Returns `undefined` if `v` is `false` in older React versions. - * - * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. - */ -export const getInertValueReact18 = (v: boolean): boolean | string | undefined => { - return v ? "" : undefined; -}; +export * from "./getInertValue"; + +export * from "../../common"; diff --git a/packages/utilities/shared-utils/src/demi/demi.d.ts b/packages/utilities/shared-utils/src/demi/react19/getInertValue.ts similarity index 89% rename from packages/utilities/shared-utils/src/demi/demi.d.ts rename to packages/utilities/shared-utils/src/demi/react19/getInertValue.ts index 3c60423032..80703a4a89 100644 --- a/packages/utilities/shared-utils/src/demi/demi.d.ts +++ b/packages/utilities/shared-utils/src/demi/react19/getInertValue.ts @@ -12,4 +12,6 @@ * * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. */ -export declare function getInertValue(v: boolean): boolean | string | undefined; +export const getInertValue = (v: boolean): boolean | string | undefined => { + return v; +}; diff --git a/packages/utilities/shared-utils/src/demi/react19/index.ts b/packages/utilities/shared-utils/src/demi/react19/index.ts index 1e38de5503..a7b20e28e0 100644 --- a/packages/utilities/shared-utils/src/demi/react19/index.ts +++ b/packages/utilities/shared-utils/src/demi/react19/index.ts @@ -1,17 +1,3 @@ -/** - * Returns an appropriate value for the `inert` attribute based on the React version. - * - * In React 19, the attribute `inert` is a boolean. In versions prior to 19, the attribute - * behaves differently: setting `inert=""` will make it `true`, and `inert=undefined` will make it `false`. - * - * @param {boolean} v - The desired boolean state for the `inert` attribute. - * @returns {boolean | string | undefined} - Depending on the React version: - * - Returns `boolean` if React version is 19 (the input value `v` directly). - * - Returns `string` (empty string) if `v` is `true` in older React versions. - * - Returns `undefined` if `v` is `false` in older React versions. - * - * @see {@link https://github.com/facebook/react/issues/17157} for more details on the behavior in older React versions. - */ -export const getInertValueReact19 = (v: boolean): boolean | string | undefined => { - return v; -}; +export * from "./getInertValue"; + +export * from "../../common"; From 9d9224b5a1b0ae675feeecb9e51cd863af71da0a Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 12 Jan 2025 12:48:28 +0800 Subject: [PATCH 3/6] feat: add postinstall --- packages/utilities/shared-utils/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utilities/shared-utils/package.json b/packages/utilities/shared-utils/package.json index fe0ce15f6b..a4e8bc395d 100644 --- a/packages/utilities/shared-utils/package.json +++ b/packages/utilities/shared-utils/package.json @@ -8,7 +8,7 @@ "author": "Junior Garcia ", "homepage": "https://nextui.org", "license": "MIT", - "main": "src/index.ts", + "main": "dist/index.js", "sideEffects": false, "files": [ "dist", From 60d1d82875078c63f7a984d947f8e0c73364e2f4 Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 12 Jan 2025 13:04:34 +0800 Subject: [PATCH 4/6] fix: type --- packages/utilities/shared-utils/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/utilities/shared-utils/package.json b/packages/utilities/shared-utils/package.json index a4e8bc395d..cc13467187 100644 --- a/packages/utilities/shared-utils/package.json +++ b/packages/utilities/shared-utils/package.json @@ -33,7 +33,8 @@ "typecheck": "tsc --noEmit", "build:fast": "tsup src", "prepack": "clean-package", - "postpack": "clean-package restore" + "postpack": "clean-package restore", + "postbuild": "npm run postinstall" }, "devDependencies": { "clean-package": "2.2.0" From ede6b12ad4fafd1c11233c6c336e08c7823820c7 Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 12 Jan 2025 14:19:15 +0800 Subject: [PATCH 5/6] fix: type --- packages/utilities/shared-utils/package.json | 2 +- packages/utilities/shared-utils/src/index.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 packages/utilities/shared-utils/src/index.ts diff --git a/packages/utilities/shared-utils/package.json b/packages/utilities/shared-utils/package.json index cc13467187..3dc113656f 100644 --- a/packages/utilities/shared-utils/package.json +++ b/packages/utilities/shared-utils/package.json @@ -8,7 +8,7 @@ "author": "Junior Garcia ", "homepage": "https://nextui.org", "license": "MIT", - "main": "dist/index.js", + "main": "src/index.ts", "sideEffects": false, "files": [ "dist", diff --git a/packages/utilities/shared-utils/src/index.ts b/packages/utilities/shared-utils/src/index.ts new file mode 100644 index 0000000000..c2647d2579 --- /dev/null +++ b/packages/utilities/shared-utils/src/index.ts @@ -0,0 +1,5 @@ +/** + * For Development + */ +export * from "./common"; +export * from "./demi/react18"; From 2d1d69226ebf73d78ebde75afb2cee90c6d61e8d Mon Sep 17 00:00:00 2001 From: winches <329487092@qq.com> Date: Sun, 12 Jan 2025 15:38:43 +0800 Subject: [PATCH 6/6] fix: next version --- .../utilities/shared-utils/scripts/postinstall.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/utilities/shared-utils/scripts/postinstall.js b/packages/utilities/shared-utils/scripts/postinstall.js index 910a60dede..d1e19df28d 100644 --- a/packages/utilities/shared-utils/scripts/postinstall.js +++ b/packages/utilities/shared-utils/scripts/postinstall.js @@ -24,12 +24,12 @@ function modifyDts(path) { } function postinstall() { - const nextjs = tryRequirePkg('next') - const react = tryRequirePkg('react') - const nextjsVersion = nextjs?.version?.version || '' - const reactVersion = react?.version || '' - - if (nextjsVersion.startsWith('14') || reactVersion.startsWith('18')) { + const nextjs = tryRequirePkg('next/package.json') + const react = tryRequirePkg('react/package.json') + const nextjsVersion = Number((nextjs?.version || '').split('.')[0]) + const reactVersion = Number((react?.version || '').split('.')[0]) + + if (reactVersion === 18 && nextjsVersion < 15) { copyDemiDir('react18') } else { copyDemiDir('react19')