Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 439746c

Browse files
authored
fix: fix axios incompatible with edge runtime (#357)
1 parent 7c57f76 commit 439746c

File tree

18 files changed

+623
-237
lines changed

18 files changed

+623
-237
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
"uuid": "^9.0.1",
5757
"vite": "^4.5.3",
5858
"vite-plugin-css-injected-by-js": "^3.5.0",
59-
"vue-instantsearch": "^4.13.2",
59+
"vue-instantsearch": "^4.15.0",
6060
"vue3-lazy-hydration": "^1.2.1"
6161
},
6262
"devDependencies": {
63-
"@antfu/eslint-config": "2.12.2",
64-
"@moonrepo/cli": "1.23.3",
63+
"@antfu/eslint-config": "2.13.0",
64+
"@moonrepo/cli": "1.23.4",
6565
"@nuxt/image": "1.0.0-rc.1",
6666
"@nuxtjs/tailwindcss": "6.8.0",
6767
"@rollup/plugin-virtual": "3.0.2",

packages/karbon/moon.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dependsOn:
44
- code-highlight
55
- custom-field
66
- jose-browser
7+
- typesense-xior
78

89
tasks:
910
build:

packages/karbon/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"dependencies": {
4848
"@apollo/client": "^3.9.10",
4949
"@babel/runtime": "^7.24.4",
50-
"@haverstack/axios-fetch-adapter": "0.8.0",
5150
"@iframely/embed.js": "^1.10.3",
5251
"@noble/ciphers": "^0.4.1",
5352
"@nuxt/devalue": "^2.0.2",
@@ -61,13 +60,13 @@
6160
"@storipress/code-highlight": "^0.0.3",
6261
"@storipress/custom-field": "^1.1.7",
6362
"@storipress/jose-browser": "^1.1.5",
63+
"@storipress/typesense-xior": "workspace:^",
6464
"@storipress/vue-advertising": "^1.1.0",
6565
"@vueuse/core": "^10.1.2",
6666
"@vueuse/head": "^1.1.26",
6767
"@vueuse/math": "^10.1.2",
6868
"@vueuse/nuxt": "^10.1.2",
6969
"@zhead/schema": "^1.1.0",
70-
"axios": "0.26.1",
7170
"chalk": "^5.3.0",
7271
"cross-fetch": "^4.0.0",
7372
"defu": "^6.1.4",
@@ -90,7 +89,7 @@
9089
"lodash.truncate": "^4.4.2",
9190
"minimist": "^1.2.8",
9291
"node-fetch-native": "^1.4.1",
93-
"node-html-parser": "^6.1.12",
92+
"node-html-parser": "^6.1.13",
9493
"nuxt-link-checker": "^2.1.10",
9594
"nuxt-schema-org": "^2.2.0",
9695
"nuxt-simple-robots": "^3.1.2",
@@ -124,7 +123,7 @@
124123
"vite-plugin-css-injected-by-js": "^3.5.0",
125124
"vite-tsconfig-paths": "^4.3.2",
126125
"vue": "^3.3.13",
127-
"vue-instantsearch": "^4.13.2",
126+
"vue-instantsearch": "^4.15.0",
128127
"vue-router": "^4.2.5",
129128
"vue3-lazy-hydration": "^1.2.1",
130129
"zod": "^3.22.4",
@@ -160,10 +159,10 @@
160159
"tsx": "4.7.2",
161160
"typescript": "5.4.4",
162161
"vitest": "0.34.6",
163-
"zx": "8.0.0"
162+
"zx": "8.0.1"
164163
},
165164
"publishConfig": {
166165
"access": "public"
167166
},
168167
"gitHead": "8df1f4d5837a7e2ddbff6cc79f5fec256c34a394"
169-
}
168+
}

packages/karbon/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ declare module '#app' {
5959
}
6060

6161
// reference: https://github.com/harlan-zw/nuxt-simple-sitemap/blob/324719dff6bf5c4214a093adbac4d5105d35bcb3/src/module.ts#L236
62-
declare module 'nitropack/dist/runtime/types' {
62+
declare module 'nitropack' {
6363
interface NitroRuntimeHooks {
6464
'karbon:request': (ctx: RequestContext) => void
6565
'karbon:response': (ctx: ResponseContext) => void

packages/karbon/src/runtime/composables/front-page.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ if (import.meta.hot) {
4545

4646
export function getAllArticles(): Promise<UseArticleReturnWithURL[]> &
4747
AsyncData<UseArticleReturnWithURL[], true | null> {
48-
// @ts-expect-error unable to modal this type
4948
return useResourceList('article', {
5049
key: 'all',
5150
transform: (data) => {
@@ -62,7 +61,7 @@ export function getAllArticles(): Promise<UseArticleReturnWithURL[]> &
6261
}
6362

6463
export const useGetAllArticles = useEventOnce(() => {
65-
const promise = getAllArticles()
64+
const promise = getAllArticles() as AsyncData<UseArticleReturnWithURL[], unknown>
6665
onServerPrefetch(() => promise)
6766
return promise
6867
})

packages/karbon/src/runtime/composables/typesense-client.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { SearchClient } from 'typesense'
2-
import axios from 'axios'
3-
import * as adapter from '@haverstack/axios-fetch-adapter'
1+
import { SearchClient } from '@storipress/typesense-xior'
42
import { getStoripressConfig } from './storipress-base-client'
53

64
let typesenseClient: SearchClient
75

86
export function useTypesenseClient() {
97
if (typesenseClient) return typesenseClient
108

11-
axios.defaults.adapter = getAdapter()
129
const storipress = getStoripressConfig()
1310
typesenseClient = new SearchClient({
1411
nodes: [
@@ -77,13 +74,3 @@ export function getSearchQuery(page = 1, filter: TypesenseFilter = {}) {
7774
include_fields: propertiesToKeep.join(','),
7875
}
7976
}
80-
81-
// workaround for package issue
82-
function getAdapter() {
83-
const createFetchAdapter = (adapter.default as any).createFetchAdapter
84-
if (typeof createFetchAdapter === 'function') {
85-
return createFetchAdapter()
86-
}
87-
88-
return adapter.createFetchAdapter()
89-
}

packages/karbon/src/runtime/lib/split-article.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Element } from 'parse5/dist/tree-adapters/default'
21
import { parseFragment, serializeOuter } from 'parse5'
32

43
export interface NormalSegment {
@@ -28,12 +27,12 @@ export function splitArticle(source: string): Segment[] {
2827

2928
const fragment = parseFragment(source)
3029
const segments = fragment.childNodes.map((_segment) => {
31-
const segment = _segment as Element
30+
const segment = _segment
3231
const DATA_FORMAT = 'data-format'
33-
const format: { name: string; value: string } | undefined = segment.attrs?.find(
32+
const format: { name: string; value: string } | undefined = (segment as any).attrs?.find(
3433
({ name }: { name: string }) => name === DATA_FORMAT,
3534
)
36-
const type = format?.value || segment.tagName
35+
const type = format?.value || (segment as any).tagName
3736

3837
return { id: 'normal' as const, type: type || 'div', html: serializeOuter(segment) }
3938
})

packages/karbon/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"extends": "./playground/.nuxt/tsconfig.json",
3+
"compilerOptions": {
4+
"moduleResolution": "Bundler"
5+
},
36
"include": ["./src/**/*", "./playground/**/*.ts"]
47
}

packages/playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"uuid": "^9.0.1",
6464
"vite": "^4.5.3",
6565
"vite-plugin-css-injected-by-js": "^3.5.0",
66-
"vue-instantsearch": "^4.13.2",
66+
"vue-instantsearch": "^4.15.0",
6767
"vue3-lazy-hydration": "^1.2.1"
6868
},
6969
"devDependencies": {

packages/typesense-xior/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# typesense-xior
2+
3+
Rebundle [typesense](https://github.com/typesense/typesense-js) client with [xior](https://github.com/suhaotian/xior) to make it compatible with edge runtime like Cloudflare worker, Vercel

0 commit comments

Comments
 (0)