Skip to content

Commit

Permalink
Fix bundle issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloriestra committed Dec 5, 2024
1 parent 7a1c90c commit 276b93c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
25 changes: 25 additions & 0 deletions packages/cli-kit/assets/fetch-notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fetch from 'node-fetch'
import Conf from 'conf'

async function fetchNotifications() {
try {
const url = process.env.SHOPIFY_CLI_NOTIFICATIONS_URL ?? 'https://cdn.shopify.com/static/cli/notifications.json'
const response = await fetch(url, {signal: AbortSignal.timeout(3 * 1000)})
if (response.status === 200) {
storeNotifications(url, await response.text())
console.log(`Notifications from ${url} cached successfully`)
}
} catch (error) {
const errorMessage = `Error fetching notifications: ${error.message}`
console.error(errorMessage)
}
}

function storeNotifications(url, notifications) {
const config = new Conf({projectName: 'shopify-cli-kit'})
const cache = config.get('cache') || {}
cache[`notifications-${url}`] = {value: notifications, timestamp: Date.now()}
config.set('cache', cache)
}

await fetchNotifications()
21 changes: 0 additions & 21 deletions packages/cli-kit/bin/fetch-notifications.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/cli-kit/src/public/node/hooks/postrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {Command, Hook} from '@oclif/core'
export const hook: Hook.Postrun = async ({config, Command}) => {
await detectStopCommand(Command as unknown as typeof Command)
await reportAnalyticsEvent({config, exitMode: 'ok'})
await exec('node', ['./packages/cli-kit/bin/fetch-notifications.js'], {
background: true,
})
await exec('node', [require.resolve('@shopify/cli-kit/assets/fetch-notifications.js')], {background: true})
deprecationsHook(Command)

const command = Command.id.replace(/:/g, ' ')
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-kit/src/public/node/notifications-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function renderNotifications(notifications: Notification[]) {
}

/**
* Get notifications list from cache, that is updated in the background from bin/fetch-notifications.json.
* Get notifications list from cache, that is updated in the background from the fetch-notifications.json script.
*
* @returns A Notifications object.
*/
Expand Down

0 comments on commit 276b93c

Please sign in to comment.