Skip to content

Commit 5bb7e60

Browse files
authored
feat(manifest): add environment-based manifest management (#153)
* feat(manifest): add environment-based manifest management Add scripts to update snap manifests based on SNAP_ENV variable for different environments (local/production). Update build and start scripts to run manifest updates automatically. Add documentation explaining the manifest management system.
1 parent 0329bea commit 5bb7e60

File tree

18 files changed

+353
-257
lines changed

18 files changed

+353
-257
lines changed

.github/workflows/build-lint-test.yml

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
node-version: [21.x]
22+
node-version: [22.x]
2323
outputs:
2424
child-workspace-package-names: ${{ steps.workspace-package-names.outputs.child-workspace-package-names }}
2525
steps:
2626
- name: Checkout and setup environment
2727
uses: MetaMask/action-checkout-and-setup@v1
2828
with:
2929
is-high-risk-environment: false
30-
cache-node-modules: ${{ matrix.node-version == '21.x' }}
30+
cache-node-modules: ${{ matrix.node-version == '22.x' }}
3131
- name: Fetch workspace package names
3232
id: workspace-package-names
3333
run: |
@@ -41,7 +41,7 @@ jobs:
4141
- prepare
4242
strategy:
4343
matrix:
44-
node-version: [21.x]
44+
node-version: [22.x]
4545
steps:
4646
- name: Checkout and setup environment
4747
uses: MetaMask/action-checkout-and-setup@v1
@@ -63,7 +63,7 @@ jobs:
6363
- prepare
6464
strategy:
6565
matrix:
66-
node-version: [21.x]
66+
node-version: [22.x]
6767
steps:
6868
- name: Checkout and setup environment
6969
uses: MetaMask/action-checkout-and-setup@v1
@@ -82,7 +82,6 @@ jobs:
8282
key: gator-permissions-${{ runner.os }}-${{ github.sha }}
8383
- name: Cache manifests
8484
uses: actions/cache@v4
85-
if: ${{ github.base_ref == 'dev' }}
8685
with:
8786
path: |
8887
./packages/gator-permissions-snap/snap.manifest.json
@@ -91,18 +90,9 @@ jobs:
9190
- name: Require clean working directory
9291
shell: bash
9392
run: |
94-
# Check if target branch is 'dev' and exclude snap.manifest.json files if so
95-
if [[ "${{ github.base_ref }}" == "dev" || "${{ github.ref_name }}" == "dev" ]]; then
96-
echo "Target branch is 'dev', ignoring changes to snap.manifest.json files"
97-
if ! git diff --exit-code -- . ':!**/snap.manifest.json'; then
98-
echo "Working tree dirty at end of job (excluding snap.manifest.json)"
99-
exit 1
100-
fi
101-
else
102-
if ! git diff --exit-code; then
103-
echo "Working tree dirty at end of job"
104-
exit 1
105-
fi
93+
if ! git diff --exit-code; then
94+
echo "Working tree dirty at end of job"
95+
exit 1
10696
fi
10797
10898
lint:
@@ -112,7 +102,7 @@ jobs:
112102
- prepare
113103
strategy:
114104
matrix:
115-
node-version: [21.x]
105+
node-version: [22.x]
116106
steps:
117107
- name: Checkout and setup environment
118108
uses: MetaMask/action-checkout-and-setup@v1
@@ -135,7 +125,7 @@ jobs:
135125
- build
136126
strategy:
137127
matrix:
138-
node-version: [21.x]
128+
node-version: [22.x]
139129
steps:
140130
- name: Checkout and setup environment
141131
uses: MetaMask/action-checkout-and-setup@v1
@@ -153,7 +143,6 @@ jobs:
153143
key: gator-permissions-${{ runner.os }}-${{ github.sha }}
154144
- name: Restore manifests
155145
uses: actions/cache@v4
156-
if: ${{ github.base_ref == 'dev' }}
157146
with:
158147
path: |
159148
./packages/gator-permissions-snap/snap.manifest.json
@@ -164,16 +153,7 @@ jobs:
164153
- name: Require clean working directory
165154
shell: bash
166155
run: |
167-
# Check if target branch is 'dev' and exclude snap.manifest.json files if so
168-
if [[ "${{ github.base_ref }}" == "dev" || "${{ github.ref_name }}" == "dev" ]]; then
169-
echo "Target branch is 'dev', ignoring changes to snap.manifest.json files"
170-
if ! git diff --exit-code -- . ':!**/snap.manifest.json'; then
171-
echo "Working tree dirty at end of job (excluding snap.manifest.json)"
172-
exit 1
173-
fi
174-
else
175-
if ! git diff --exit-code; then
176-
echo "Working tree dirty at end of job"
177-
exit 1
178-
fi
156+
if ! git diff --exit-code; then
157+
echo "Working tree dirty at end of job"
158+
exit 1
179159
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ node_modules/
7878
.yarn/build-state.yml
7979
.yarn/install-state.gz
8080
.pnp.*
81+
82+
# Generated manifest files
83+
packages/*/snap.manifest.json

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v22.17.0
1+
v22.19.0

docs/manifest-management.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Manifest Management Guide
2+
3+
The 7715 permissions snaps use environment-based manifest configuration via `SNAP_ENV`.
4+
5+
## Quick Start
6+
7+
### Local Development
8+
```bash
9+
# Build or start with development environment
10+
SNAP_ENV=local yarn start
11+
```
12+
13+
### Production Build
14+
```bash
15+
# Default is production
16+
yarn build
17+
18+
# Or explicit
19+
SNAP_ENV=production yarn build
20+
```
21+
22+
## Configuration
23+
24+
| Environment | Gator Snap | Kernel Snap |
25+
|------------|------------|-------------|
26+
| `local`/`development` | Adds localhost:8081 | Adds localhost:8082 + gator snap |
27+
| `production` (default) | Only kernel snap connection | No connections |
28+
29+
30+
## How It Works
31+
32+
1. Each snap has a `snap.manifest.ts` file that defines the manifest using the `defineSnapManifest` helper
33+
2. The shared `generate-snap-manifest` command (provided by `@metamask/7715-permissions-shared`) compiles and executes the TypeScript file to generate `snap.manifest.json`
34+
3. The build/start commands automatically run this generation command
35+
36+
## Available Commands
37+
38+
### From individual snap packages:
39+
```bash
40+
# Generate manifest for current package
41+
yarn generate-snap-manifest .
42+
43+
# Build with manifest generation
44+
yarn build
45+
46+
# Start with manifest generation
47+
yarn start
48+
```
49+
50+
## File Structure
51+
52+
```
53+
packages/
54+
├── shared/
55+
│ └── src/
56+
│ └── scripts/
57+
│ └── generate-manifest.ts # Shared manifest generation script
58+
├── gator-permissions-snap/
59+
│ ├── snap.manifest.ts # TypeScript manifest definition (source of truth)
60+
│ └── snap.manifest.json # Generated from .ts file (git ignored)
61+
└── permissions-kernel-snap/
62+
├── snap.manifest.ts # TypeScript manifest definition (source of truth)
63+
└── snap.manifest.json # Generated from .ts file (git ignored)
64+
```
65+
66+
## Environment Variables
67+
68+
- `SNAP_ENV` - Controls which manifest template to use
69+
- `local` or `development` - Uses dev manifest
70+
- `production` (default) - Uses production manifest
71+
- Any other value - Falls back to production
72+
73+
## CI/CD Example
74+
75+
```yaml
76+
- name: Build for production
77+
env:
78+
SNAP_ENV: production
79+
run: yarn build
80+
```
81+

packages/gator-permissions-snap/docs/architecture.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ This document outlines the architecture of the Permissions Provider Snap system
5151

5252
### UI Components
5353

54-
- **HomePage**: Component that builds the snap's homepage, showing feature introduction, as well as granted permissions. This is only part of the pre-production feature, as the snap will be pre-installed in which case the homepage is not accessible.
5554
- **ConfirmationDialogFactory**: Creates confirmation dialogs for permission requests.
5655
- **ConfirmationDialog**: Manages the lifecycle and user interaction of confirmation dialogs.
5756

@@ -80,7 +79,6 @@ src/
8079
├── services/ # Business logic services (token prices, metadata)
8180
├── clients/ # External API clients (Account API, Price API, blockchain)
8281
├── profileSync/ # Cross-device permission storage synchronization
83-
├── homepage/ # Snap homepage UI component
8482
├── ui/ # Reusable UI components and utilities
8583
├── utils/ # Static utility functions
8684
└── permissions/ # Permission-specific implementations
@@ -103,8 +101,6 @@ src/
103101

104102
- **`profileSync/`**: Manages encrypted storage and synchronization of granted permissions across devices using MetaMask's profile sync infrastructure.
105103

106-
- **`homepage/`**: Class-based component that builds the snap's homepage interface, displaying account information and granted permissions.
107-
108104
- **`ui/`**: Reusable UI components and utilities used across different permission types and dialogs.
109105

110106
- **`utils/`**: Static utility functions for common operations like address formatting, validation, time handling, and value conversion.
@@ -201,7 +197,7 @@ The EntryPoint serves as the main initialization and configuration point for the
201197
- Core services (TokenMetadataService, TokenPricesService, AccountController)
202198
- State management (StateManager for snap persistence)
203199
- Profile sync (ProfileSyncManager for cross-device permission sync)
204-
- UI components (HomePage, ConfirmationDialogFactory, UserEventDispatcher)
200+
- UI components (ConfirmationDialogFactory, UserEventDispatcher)
205201
- Permission handling (PermissionHandlerFactory, PermissionRequestLifecycleOrchestrator)
206202
- RPC handling (createRpcHandler for processing requests)
207203

@@ -212,8 +208,7 @@ The EntryPoint serves as the main initialization and configuration point for the
212208
3. Handling lifecycle events:
213209
- `onRpcRequest`: Processes incoming JSON-RPC requests with origin validation
214210
- `onUserInput`: Handles user input events via UserEventDispatcher
215-
- `onHomePage`: Returns the snap's homepage content
216-
- `onInstall`: Shows welcome screen and handles local development setup
211+
- `onInstall`: Handles local development setup
217212

218213
4. Managing dependencies and configuration:
219214
- Uses dependency injection to create and wire up components

packages/gator-permissions-snap/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"scripts": {
2828
"allow-scripts": "yarn workspace root allow-scripts",
29-
"build": "mm-snap build && yarn build:preinstalled-snap",
29+
"build": "yarn generate-snap-manifest . && mm-snap build && yarn build:preinstalled-snap",
3030
"build:clean": "yarn clean && yarn build",
3131
"build:pack": "yarn build:clean && yarn pack --filename ../../deps/snap-b-0.1.0.tgz",
3232
"build:preinstalled-snap": "node scripts/build-preinstalled-snap.js",
@@ -43,7 +43,7 @@
4343
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
4444
"prepublishOnly": "mm-snap manifest",
4545
"serve": "mm-snap serve",
46-
"start": "mm-snap watch",
46+
"start": "yarn generate-snap-manifest . && mm-snap watch",
4747
"test": "TZ=UTC jest"
4848
},
4949
"dependencies": {

packages/gator-permissions-snap/snap.manifest.json

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
/* eslint-disable no-restricted-globals */
3+
4+
import type { SnapManifest } from '@metamask/7715-permissions-shared/types';
5+
6+
const kernelSnapId = process.env.KERNEL_SNAP_ID;
7+
8+
const manifest: SnapManifest = {
9+
version: '0.2.1',
10+
description: 'Grants 7715 permissions from a DeleGator smart account',
11+
proposedName: 'Gator Permissions',
12+
repository: {
13+
type: 'git',
14+
url: 'https://github.com/MetaMask/snap-7715-permissions.git',
15+
},
16+
source: {
17+
shasum: 'tQRss8KLZ2+OlG2QQyH81XYBcTLsWUzYXf/Xy0cHZsk=',
18+
location: {
19+
npm: {
20+
filePath: 'dist/bundle.js',
21+
iconPath: 'images/icon.svg',
22+
packageName: '@metamask/gator-permissions-snap',
23+
registry: 'https://registry.npmjs.org/',
24+
},
25+
},
26+
},
27+
initialPermissions: {
28+
'endowment:rpc': {
29+
dapps: false,
30+
snaps: true,
31+
},
32+
snap_manageState: {},
33+
'endowment:ethereum-provider': {},
34+
'endowment:network-access': {},
35+
snap_dialog: {},
36+
'endowment:lifecycle-hooks': {},
37+
snap_getPreferences: {},
38+
},
39+
platformVersion: '8.1.0',
40+
manifestVersion: '0.1',
41+
};
42+
43+
if (kernelSnapId) {
44+
manifest.initialConnections = {
45+
[kernelSnapId]: {},
46+
};
47+
}
48+
49+
export default manifest;

0 commit comments

Comments
 (0)