Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(snack-runtime): split runtime app into reusable package and app #456

Merged
merged 31 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
282df6a
chore(runtime): clone runtime basis as separate package
byCedric Aug 23, 2023
9190c9d
chore: add continuous integration for `snack-runtime`
byCedric Aug 23, 2023
a1e60ab
refactor(snack-runtime): fix linting issues
byCedric Aug 24, 2023
2949bcf
fix(snack-runtime): add missing dependencies
byCedric Aug 24, 2023
55c02ad
feature(runtime-shell): add new shell-like app that consumes `snack-r…
byCedric Aug 24, 2023
871dcc2
fix(snack-runtime): add S3 asset resolver for Snack assets
byCedric Aug 24, 2023
126ae34
feature(snack-runtime): add direct-load capability to render Snacks w…
byCedric Aug 24, 2023
e04f26b
refactor(snack-runtime): drop outdated amplitude
byCedric Aug 24, 2023
ef99ba9
feature(snack-runtime): add `snack-runtime` lifecycle event callbacks
byCedric Aug 24, 2023
3ac0d30
refactor(snack-runtime): drop `expo-updates` dependency in favor of `…
byCedric Aug 24, 2023
272bb71
feature(snack-runtime): add a vendored Reaniamted plugin to transpile…
byCedric Aug 24, 2023
e8a8b3d
fix(snack-runtime): resolve linting issue
byCedric Aug 24, 2023
afc0979
chore(runtime-shell): clean up index file
byCedric Aug 24, 2023
c3d154a
feature(snack-runtime): add context-based config API for runtime modules
byCedric Aug 28, 2023
2576377
chore(snack-runtime): fix linting issue
byCedric Aug 28, 2023
59fec66
fix(snack-runtime): move constants to production-first defaults
byCedric Aug 28, 2023
c41b955
chore(snack-runtime): prepare for initial official release `0.3.0-rc.1`
byCedric Aug 28, 2023
cda6f74
fix(snack-runtime): consolidate `UrlUtils` and `utils/SnackUrls`
byCedric Aug 28, 2023
c69cf14
fix(snack-runtime): replace environment validation with if statement
byCedric Aug 28, 2023
2877985
docs(snack-runtime): add basic readme documentation
byCedric Aug 28, 2023
1e421ff
chore(runtime-shell): clean up shell app
byCedric Aug 28, 2023
547a1a1
chore(snack-runtime): fix linting issue
byCedric Aug 28, 2023
f91b036
chore(runtime-shell): backport asset workaround for the runtime web app
byCedric Aug 28, 2023
a263acd
chore(snack-runtime): drop `prepublishOnly` task as there is no build…
byCedric Aug 28, 2023
8543b45
fix(snack-runtime): pull `ExpoRouterEntry` out of `snack-runtime`
byCedric Aug 28, 2023
15e1968
chore(snack-runtime): release `snack-runtime@0.3.0-rc.2` with `expo-r…
byCedric Aug 28, 2023
3d59735
chore(snack-runtime): add missing `path` dependency
byCedric Aug 28, 2023
653b85f
fix(snack-runtime): pull `ExpoRouterEntry` out of commonly aliased mo…
byCedric Aug 28, 2023
988ae32
fix(snack-runtime): use proper module source when initializing system…
byCedric Aug 28, 2023
148b461
chore(snack-runtime): prepare version `snack-runtime@0.3.0-rc.3`
byCedric Aug 28, 2023
f2762db
chore(snack-runtime): fix linting issue
byCedric Aug 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ jobs:
review:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package:
- snack-babel-standalone
- snack-content
- snack-eslint-standalone
- snack-proxies
- snack-require-context
- snack-runtime
- snack-sdk
- snack-term
include:
- package: snack-babel-standalone
local-install: true
- package: snack-eslint-standalone
local-install: true
- package: snack-runtime
local-install: true
steps:
- name: 🏗 Setup repository
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions packages/snack-runtime/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build/
example/
node_modules/
vendor/
4 changes: 4 additions & 0 deletions packages/snack-runtime/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['universe/native'],
};
2 changes: 2 additions & 0 deletions packages/snack-runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.expo/
web-build/
74 changes: 74 additions & 0 deletions packages/snack-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# snack-runtime

The core system to load and open Snacks within React Native apps.

> ⚠️ **Warning**:
> This package consumes Snack infrastructure and **requires** a license from Expo. If you are interested, [contact us](https://expo.dev/contact) and ask about the Snack custom runtime.

## Installation

```bash
$ yarn add snack-runtime
```

## Usage

```js
import * as Updates from 'expo-updates';
import {
type SnackConfig,
type SnackState,
defaultSnackModules,
SnackRuntimeProvider,
SnackRuntime,
} from 'snack-runtime';

const config: SnackConfig = {
modules: {
// Inherit the default set of modules from Snack
...defaultSnackModules,
// Add modules that are available through imports within Snacks
'react-native-blurhash': require('react-native-blurhash'),
}
};

export function Snack() {
return (
<SnackRuntimeProvider config={config}>
<SnackRuntime
onSnackState={onStateChange}
onSnackReload={onReloadRequested}
snackUrl="<snackUrl>"
/>
</SnackRuntimeProvider>
);
}

// Requested through the Snack website
function onReloadRequested() {
return Updates.reloadAsync();
}

// When the lifecycle of a Snack changes
function onStateChange(state: SnackState) {
if (state === 'loading') console.log('Snack is initializing the code...');
if (state === 'finished') console.log('Snack is ready and rendered!');
if (state === 'error') console.error('Snack failed to initialize, check the logs for more info.');

throw new Error(`Unexpected Snack state received "${state}"`);
}
```

## Patches required

Snack virtualizes the whole bundling and module systems, and because of that, requires a few patches to some libraries:

- [`react-native`](../../runtime-shell/patches/react-native+0.71.8.patch) → To avoid "ViewManager is already loaded" errors
- [`react-native-web`](../../runtime-shell/patches/react-native+0.71.8.patch) → To make sure the assets from Snack are loaded properly

## Contributing

This package has a few commands to help contributing to this package.

- `yarn lint` → Ensures a unified code styling across the code base.
- `yarn test` → Runs all unit tests to ensure functionality remains as-expected.
Binary file added packages/snack-runtime/assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/snack-runtime/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
// plugins: ['@babel/plugin-proposal-export-namespace-from', 'react-native-reanimated/plugin'],
};
};
7 changes: 7 additions & 0 deletions packages/snack-runtime/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './src/utils/ExpoApi';
export * from './src/utils/SnackAssets';
export * from './src/utils/SnackUrls';

export { default as SnackRuntime, type SnackState } from './src/App';
export { SnackRuntimeProvider, type SnackConfig } from './src/config/SnackConfig';
export { modules as defaultSnackModules } from './src/config/modules';
88 changes: 88 additions & 0 deletions packages/snack-runtime/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"name": "snack-runtime",
"version": "0.3.0-rc.3",
"description": "Load and run Expo Snacks in any React Native app",
"main": "index.ts",
"files": [
"assets",
"src",
"types",
"vendor"
],
"repository": {
"type": "git",
"url": "git+https://github.com/expo/snack.git",
"directory": "packages/snack-runtime"
},
"bugs": {
"url": "https://github.com/expo/snack/issues"
},
"author": "Expo <support@expo.dev>",
"license": "MIT",
"volta": {
"node": "16.14.2"
},
"scripts": {
"test": "jest",
"lint": "eslint . --ext js,jsx,ts,tsx",
"build": "echo 'This package ships TypeScript for Metro to compile.'"
},
"dependencies": {
"@babel/polyfill": "^7.8.3",
"@react-native-async-storage/async-storage": "1.17.11",
"await-lock": "^2.2.2",
"canvaskit-wasm": "0.38.0",
"diff": "^5.0.0",
"escape-string-regexp": "^5.0.0",
"path": "^0.12.7",
"pubnub": "^7.2.0",
"snack-babel-standalone": "^2.2.2",
"snack-require-context": "^0.1.0",
"socket.io-client": "~4.5.4",
"source-map": "0.6.1"
},
"devDependencies": {
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react-native": "^12.2.2",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"babel-preset-expo": "^9.3.0",
"eslint": "^8.20.0",
"eslint-config-universe": "^11.2.0",
"expo": "^48.0.19",
"expo-asset": "~8.9.0",
"expo-barcode-scanner": "~12.3.0",
"expo-constants": "~14.2.0",
"expo-file-system": "~15.2.0",
"expo-keep-awake": "~12.0.0",
"expo-random": "~13.1.0",
"expo-splash-screen": "~0.18.0",
"expo-status-bar": "~1.4.0",
"jest": "^29.2.1",
"jest-expo": "^48.0.0",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native-gesture-handler": "~2.9.0",
"react-native-view-shot": "3.5.0",
"react-test-renderer": "18.2.0"
},
"peerDependencies": {
"expo": "^48.0.0",
"expo-asset": "~8.9.0",
"expo-barcode-scanner": "~12.3.0",
"expo-constants": "~14.2.0",
"expo-file-system": "~15.2.0",
"expo-keep-awake": "~12.0.0",
"expo-random": "~13.1.0",
"expo-splash-screen": "~0.18.0",
"expo-status-bar": "~1.4.0",
"react": "~18.2.0",
"react-native": "~0.71.8",
"react-native-gesture-handler": "~2.9.0",
"react-native-view-shot": "~3.5.0"
},
"jest": {
"preset": "jest-expo",
"clearMocks": true
}
}
Loading