Skip to content

Commit

Permalink
refactor: drop assert syntax to support old and new nodejs versions (#…
Browse files Browse the repository at this point in the history
…3036)

Co-authored-by: tomiir <rocchitomas@gmail.com>
  • Loading branch information
enesozturk and tomiir authored Oct 9, 2024
1 parent 392dd5d commit 23a7613
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
23 changes: 23 additions & 0 deletions .changeset/warm-cheetahs-explode.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/appkit/exports/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PACKAGE_VERSION = '1.0.7'
10 changes: 3 additions & 7 deletions packages/appkit/exports/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -17,11 +17,7 @@ type CreateAppKit = Omit<AppKitOptions, 'sdkType' | 'sdkVersion'>
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)
})
}

Expand Down
4 changes: 2 additions & 2 deletions packages/appkit/exports/react.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -27,7 +27,7 @@ export function createAppKit(options: CreateAppKit) {
sdkVersion: CoreHelperUtil.generateSdkVersion(
options.adapters ?? [],
'react',
packageJson.version
PACKAGE_VERSION
)
})
getAppKit(modal)
Expand Down
8 changes: 2 additions & 6 deletions packages/appkit/exports/vue.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
Expand Down
18 changes: 18 additions & 0 deletions scripts/inject-version.js
Original file line number Diff line number Diff line change
@@ -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}`)

0 comments on commit 23a7613

Please sign in to comment.