From 23a7613fc2d3516a85183eae325aedacaac0a073 Mon Sep 17 00:00:00 2001 From: Enes Date: Wed, 9 Oct 2024 09:46:08 +0300 Subject: [PATCH] refactor: drop assert syntax to support old and new nodejs versions (#3036) Co-authored-by: tomiir --- .changeset/warm-cheetahs-explode.md | 23 +++++++++++++++++++++++ package.json | 1 + packages/appkit/exports/constants.ts | 1 + packages/appkit/exports/index.ts | 10 +++------- packages/appkit/exports/react.ts | 4 ++-- packages/appkit/exports/vue.ts | 8 ++------ scripts/inject-version.js | 18 ++++++++++++++++++ 7 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 .changeset/warm-cheetahs-explode.md create mode 100644 packages/appkit/exports/constants.ts create mode 100644 scripts/inject-version.js diff --git a/.changeset/warm-cheetahs-explode.md b/.changeset/warm-cheetahs-explode.md new file mode 100644 index 0000000000..fbc27ba38b --- /dev/null +++ b/.changeset/warm-cheetahs-explode.md @@ -0,0 +1,23 @@ +--- +'@reown/appkit': patch +'@apps/demo': patch +'@apps/gallery': patch +'@apps/laboratory': patch +'@reown/appkit-adapter-ethers': patch +'@reown/appkit-adapter-ethers5': patch +'@reown/appkit-adapter-polkadot': patch +'@reown/appkit-adapter-solana': patch +'@reown/appkit-adapter-wagmi': patch +'@reown/appkit-utils': patch +'@reown/appkit-cdn': patch +'@reown/appkit-common': patch +'@reown/appkit-core': patch +'@reown/appkit-experimental': patch +'@reown/appkit-polyfills': patch +'@reown/appkit-scaffold-ui': patch +'@reown/appkit-siwe': patch +'@reown/appkit-ui': patch +'@reown/appkit-wallet': patch +--- + +Removes assert syntax to import json modules diff --git a/package.json b/package.json index 570e2702d9..d3ac8d597c 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "type": "module", "scripts": { + "prebuild": "node scripts/inject-version.js", "build:clean": "turbo run build:clean --filter={./packages/*}", "build:sample-apps": "turbo run build --filter={./examples/*}", "build": "turbo run build --filter={./packages/*} --concurrency=31", diff --git a/packages/appkit/exports/constants.ts b/packages/appkit/exports/constants.ts new file mode 100644 index 0000000000..a298a3d1da --- /dev/null +++ b/packages/appkit/exports/constants.ts @@ -0,0 +1 @@ +export const PACKAGE_VERSION = '1.0.7' diff --git a/packages/appkit/exports/index.ts b/packages/appkit/exports/index.ts index 28548c210c..e8e7f77e49 100644 --- a/packages/appkit/exports/index.ts +++ b/packages/appkit/exports/index.ts @@ -1,7 +1,7 @@ +import { CoreHelperUtil } from '@reown/appkit-core' import { AppKit } from '../src/client.js' import type { AppKitOptions } from '../src/utils/TypesUtil.js' -import packageJson from '../package.json' assert { type: 'json' } -import { CoreHelperUtil } from '@reown/appkit-core' +import { PACKAGE_VERSION } from './constants.js' // -- Views ------------------------------------------------------------ export * from '@reown/appkit-scaffold-ui' @@ -17,11 +17,7 @@ type CreateAppKit = Omit export function createAppKit(options: CreateAppKit) { return new AppKit({ ...options, - sdkVersion: CoreHelperUtil.generateSdkVersion( - options.adapters ?? [], - 'html', - packageJson.version - ) + sdkVersion: CoreHelperUtil.generateSdkVersion(options.adapters ?? [], 'html', PACKAGE_VERSION) }) } diff --git a/packages/appkit/exports/react.ts b/packages/appkit/exports/react.ts index 9e05d823e2..35a9f84c6d 100644 --- a/packages/appkit/exports/react.ts +++ b/packages/appkit/exports/react.ts @@ -1,8 +1,8 @@ import { AppKit } from '../src/client.js' import type { AppKitOptions } from '../src/utils/TypesUtil.js' import { getAppKit } from '../src/library/react/index.js' -import packageJson from '../package.json' assert { type: 'json' } import { CoreHelperUtil } from '@reown/appkit-core' +import { PACKAGE_VERSION } from './constants.js' // -- Views ------------------------------------------------------------ export * from '@reown/appkit-scaffold-ui' @@ -27,7 +27,7 @@ export function createAppKit(options: CreateAppKit) { sdkVersion: CoreHelperUtil.generateSdkVersion( options.adapters ?? [], 'react', - packageJson.version + PACKAGE_VERSION ) }) getAppKit(modal) diff --git a/packages/appkit/exports/vue.ts b/packages/appkit/exports/vue.ts index 298a958fb4..e40296a99d 100644 --- a/packages/appkit/exports/vue.ts +++ b/packages/appkit/exports/vue.ts @@ -1,8 +1,8 @@ import { AppKit } from '../src/client.js' import type { AppKitOptions } from '../src/utils/TypesUtil.js' import { getAppKit } from '../src/library/vue/index.js' -import packageJson from '../package.json' assert { type: 'json' } import { CoreHelperUtil } from '@reown/appkit-core' +import { PACKAGE_VERSION } from './constants.js' // -- Views ------------------------------------------------------------ export * from '@reown/appkit-scaffold-ui' @@ -24,11 +24,7 @@ export function createAppKit(options: CreateAppKit) { if (!modal) { modal = new AppKit({ ...options, - sdkVersion: CoreHelperUtil.generateSdkVersion( - options.adapters ?? [], - 'html', - packageJson.version - ) + sdkVersion: CoreHelperUtil.generateSdkVersion(options.adapters ?? [], 'html', PACKAGE_VERSION) }) getAppKit(modal) } diff --git a/scripts/inject-version.js b/scripts/inject-version.js new file mode 100644 index 0000000000..0f71453916 --- /dev/null +++ b/scripts/inject-version.js @@ -0,0 +1,18 @@ +/** + * This script injects the version from the packages/appkit/package.json into the packages/appkit/exports/constants.ts file. + * This is a alternative solution to not import the package.json file in our packages due to restriction on bundlers. + * It's run before the build process of the packages starts with `prebuild` script. + * See https://pnpm.io/it/next/cli/run#enable-pre-post-scripts + */ +import fs from 'node:fs' +import packageJson from '../packages/appkit/package.json' assert { type: 'json' } + +const filePath = 'packages/appkit/exports/constants.ts' + +const fileContent = fs.readFileSync(filePath, 'utf8') +const updatedContent = fileContent.replace( + /export const PACKAGE_VERSION = '.*'/, + `export const PACKAGE_VERSION = '${packageJson.version}'` +) +fs.writeFileSync(filePath, updatedContent, 'utf8') +console.log(`Injected version ${packageJson.version} into ${filePath}`)