Skip to content

Commit 15ded06

Browse files
committed
chore: Fixed bun integration
Signed-off-by: Frederik Bußmann <frederik@bussmann.io>
1 parent c165ce0 commit 15ded06

13 files changed

Lines changed: 62 additions & 94 deletions

File tree

bun.lock

Lines changed: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default createConfigForNuxt({
1515
}).override('nuxt/vue/rules', {
1616
rules: {
1717
'vue/multi-word-component-names': 'off',
18+
'vue/no-v-html': 'off',
1819
},
1920
}).override('nuxt/import/rules', {
2021
rules: {

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@
3333
],
3434
"scripts": {
3535
"build": "nuxt-module-build build",
36-
"build:template": "bun run --filter=./template --elide-lines=0 build",
36+
"build:template": "bun run --filter=./template --env-file=.env --elide-lines=0 build",
3737
"build:docs": "vitepress build docs",
38-
"dev": "bun run --filter=playground --elide-lines=0 dev",
39-
"dev:v4": "bun run --filter=playground-nuxt-v4 --elide-lines=0 dev",
40-
"dev:template": "bun run --filter=./template --elide-lines=0 dev",
38+
"dev": "bun run --filter=playground --env-file=.env --elide-lines=0 dev",
39+
"dev:v4": "bun run --filter=playground-nuxt-v4 --env-file=.env --elide-lines=0 dev",
40+
"dev:template": "bun run --filter=./template --env-file=.env --elide-lines=0 dev",
4141
"dev:docs": "vitepress dev docs",
4242
"preview:docs": "vitepress preview docs",
4343
"release": "bun publish --no-git-checks",
4444
"lint": "eslint .",
4545
"typecheck": "vue-tsc --noEmit",
46-
"analyze": "bun run --filter=./playgrounds/playground --elide-lines=0 analyze",
46+
"typecheck:template": "bun run --filter=./template --env-file=.env --elide-lines=0 typecheck",
47+
"analyze": "bun run --filter=./playgrounds/playground --env-file=.env --elide-lines=0 analyze",
4748
"prepare": "nuxt-module-build prepare",
48-
"prepare:dev": "bun run --filter=./playgrounds/* --elide-lines=0 prepare",
49-
"cleanup": "bun run --filter={./playgrounds/*,./template} --elide-lines=0 cleanup && nuxt cleanup"
49+
"prepare:dev": "bun run --filter={./playgrounds/*,./template} --env-file=.env --elide-lines=0 prepare",
50+
"cleanup": "bun run --filter={./playgrounds/*,./template} --env-file=.env --elide-lines=0 cleanup && nuxt cleanup"
5051
},
5152
"dependencies": {
5253
"@graphql-codegen/cli": "^5.0.5",
@@ -68,7 +69,7 @@
6869
"@nuxt/module-builder": "^1.0.1",
6970
"@nuxt/schema": "^3.16.2",
7071
"@nuxt/test-utils": "^3.17.2",
71-
"@types/node": "^20.17.31",
72+
"@types/bun": "^1.2.10",
7273
"eslint": "^9.25.1",
7374
"nuxt": "^3.16.2",
7475
"vitepress": "^1.6.3",

template/app/components/Navigation.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { FetchCollectionsQuery } from '#build/types/storefront'
2+
import type { FetchCollectionsQuery } from '#shopify/storefront'
33
44
const props = defineProps<{
55
collections: FetchCollectionsQuery['collections']['edges']

template/app/components/product/Card.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import type { FetchCollectionQuery } from '#shopify/storefront'
33
44
import { z } from 'zod'
55
6-
import { useCart } from '#imports'
7-
86
const props = defineProps<{
97
product: FetchCollectionQuery['collection']['products']['edges']
108
index: number

template/app/components/product/Slider.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const items = [
1818
class="w-full max-w-screen-md"
1919
>
2020
<img
21-
:src="item"
21+
:src="item as string"
2222
width="250"
2323
height="250"
2424
class="rounded-lg"

template/app/composables/useCart.ts

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,29 @@ export async function useCart() {
44
const toast = useToast()
55

66
const id = useLocalStorage<string | null>('shopify-cart-id', null)
7-
const cartItems = useState<any[]>('cart-items', () => [])
8-
const numItems = computed(() => {
9-
return cartItems.value.reduce((acc, item) => {
10-
return acc + item.node.quantity
11-
}, 0)
12-
})
7+
8+
const cartItems = useState<unknown[]>('cart-items', () => [])
139

1410
const first = ref(10)
1511

1612
const init = async () => {
17-
try {
18-
const data = await $fetch('/api/cart/create', {
19-
method: 'POST',
20-
})
21-
22-
if (!data?.cartCreate?.cart?.id) {
23-
throw new Error('Failed to create cart')
24-
}
25-
26-
id.value = data.cartCreate.cart.id
27-
}
28-
catch (error) {
29-
id.value = null
30-
31-
toast.add({
32-
title: 'Failed to initialize cart',
33-
description: 'Please try again later',
34-
color: 'error',
35-
})
36-
}
13+
// TODO: Init cart
3714
}
3815

3916
const fetchCart = async () => {
4017
try {
41-
const { data, error } = await useFetch('/api/cart', {
18+
const { data: _data, error } = await useFetch('/api/cart', {
4219
method: 'POST',
4320
body: { id: id.value, lines: { first: first.value } },
4421
})
4522

4623
if (error.value) {
4724
throw new Error('Failed to fetch cart')
4825
}
49-
50-
cartItems.value = data.value?.cart?.lines?.edges || []
5126
}
5227
catch (error) {
28+
console.error(error)
29+
5330
toast.add({
5431
title: 'Failed to fetch cart',
5532
description: 'Please try again later',
@@ -60,7 +37,7 @@ export async function useCart() {
6037

6138
const addItems = async (...items: { merchandiseId: string, quantity: number }[]) => {
6239
try {
63-
const { data, error } = await useFetch('/api/cart/add-items', {
40+
const { data: _data, error } = await useFetch('/api/cart/add-items', {
6441
method: 'POST',
6542
body: {
6643
id: id.value,
@@ -72,37 +49,33 @@ export async function useCart() {
7249
if (error.value) {
7350
throw new Error('Failed to add items to cart')
7451
}
75-
76-
cartItems.value = data.value?.cartLinesAdd?.cart?.lines?.edges || []
7752
}
7853
catch (error) {
79-
toast.add({
80-
title: 'Failed to add items to cart',
81-
description: error.message,
82-
color: 'error',
83-
})
54+
if (error instanceof Error) {
55+
toast.add({
56+
title: 'Failed to add items to cart',
57+
description: error.message,
58+
color: 'error',
59+
})
60+
}
8461
}
8562
}
8663

8764
const removeItems = async (lineIds: string[]) => {
8865
try {
89-
const { data, error } = await $fetch('/api/cart/remove-items', {
66+
const _data = await $fetch('/api/cart/remove-items', {
9067
method: 'POST',
9168
body: { id: id.value, lineIds },
9269
})
93-
94-
if (error) {
95-
throw new Error('Failed to remove items from cart')
96-
}
97-
98-
cartItems.value = data.value?.cartLinesRemove?.cart?.lines?.edges || []
9970
}
10071
catch (error) {
101-
toast.add({
102-
title: 'Failed to remove items from cart',
103-
description: error.message,
104-
color: 'error',
105-
})
72+
if (error instanceof Error) {
73+
toast.add({
74+
title: 'Failed to remove items from cart',
75+
description: error.message,
76+
color: 'error',
77+
})
78+
}
10679
}
10780
}
10881

@@ -116,7 +89,6 @@ export async function useCart() {
11689
return {
11790
id,
11891
cartItems,
119-
numItems,
12092
init,
12193
addItems,
12294
removeItems,

template/app/pages/cart.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@ const handleCheckout = async () => {
99
1010
try {
1111
checkoutLoading.value = true
12-
const { data, error } = await useFetch('/api/cart/checkout-url', {
12+
const { data: _data, error } = await useFetch('/api/cart/checkout-url', {
1313
method: 'POST',
1414
body: { id: cart.id.value },
1515
})
1616
1717
if (error.value) {
1818
throw new Error('Could not retrieve checkout URL')
1919
}
20-
21-
const checkoutUrl = data.value?.cart?.checkoutUrl
22-
if (checkoutUrl) {
23-
// Redirect to the external checkout page
24-
window.location.href = checkoutUrl
25-
}
2620
}
2721
catch (err) {
2822
console.error('Checkout error:', err)

template/app/pages/product/[handle].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { data } = await useFetch('/api/product', {
1818
})
1919
2020
const product = computed(() => data.value?.product)
21-
const variants = computed(() => product.value?.variants?.edges)
21+
const _variants = computed(() => product.value?.variants?.edges)
2222
const selectedVariant = ref<ProductVariant | null>(product.value?.variants?.edges?.[0]?.node ?? null)
2323
</script>
2424

template/app/plugins/tour.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export default defineNuxtPlugin(({ app }) => {
1+
export default defineNuxtPlugin(({ _app }) => {
22

33
})

0 commit comments

Comments
 (0)