expo / snack

Expo Snack lets you run Expo in the browser.
https://snack.expo.dev
MIT License
348 stars 97 forks source link

feature!: move snack runtime URLs to `snack-content` and add EAS Update URLs #527

Closed byCedric closed 6 months ago

byCedric commented 6 months ago

Why

Part of ENG-11039

Since the Snack Runtime URL is generated and used in various places of Snack, let's centralize this. Note, that these URLs are automatically generated through the snack-sdk's (new Snack()).url property.

⚠️ One bigger change in these URLs is that we will mostly be using Snack hashes, or the ID for a saved hash. Previously, we used a combination of @owner-name/snack-name.

Usage

import { createSnackRuntimeUrl, parseSnackRuntimeUrl } from 'snack-content'; // or `snack-sdk`, we re-export them

// This link can be opened directly in Expo Go, it's prefixed with `exp://<URL>`
// All parameters are optional, as there are quite a few combinations to make
const canBeOpenedInExpoGo = createSnackRuntimeUrl({
  snack: 'snack-hash',
  channel: 'xyz!s',
  sdkVersion: '50.0.0', // Or just the major version as number: `50`
});

// This is used in the Snack Runtime, to load the right data with either classic or EAS Updates
// Note, we do return the `sdkVersion` if defined, but once this is executed from Snack Runtime,
// it already loaded the right sdk version
const { snack, channel } = parseSnackRuntimeUrl(initialUrl);

// If you need to create/parse the newer/older URL format specifically, you can also use these methods
// Be aware that we will slowly move over to the newer URL format, and these methods may be refactored into the ones above
import {
  createEASUpdateSnackRuntimeUrl,
  parseEASUpdateSnackRuntimeUrl,
  createClassicUpdateSnackRuntimeUrl,
  parseClassicUpdateSnackRuntimeUrl
} from 'snack-content';

How

Test Plan

See added tests, full testing can only be done once we have SDK 50 merged.