Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dferber90 committed Dec 12, 2024
0 parents commit be2a05e
Show file tree
Hide file tree
Showing 430 changed files with 33,865 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
21 changes: 21 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"partial-prerendering",
"summer-sale",
"svelte-example",
"next-13",
"next-14",
"next-15"
],
"snapshot": {
"useCalculatedVersion": true
}
}
46 changes: 46 additions & 0 deletions .changeset/olive-chairs-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
'@vercel/flags': minor
---

@vercel/flags/next: Export `dedupe` function

`dedupe` is a middleware-friendly version of `React.cache`. It allows ensuring a function only ever runs once for a request.

```ts
import { dedupe } from '@vercel/flags/next';

let i = 0;
const runOnce = dedupe(async () => {
return i++;
});

await runOnce(); // returns 0
await runOnce(); // still returns 0
```

This function is useful when you want to deduplicate work within each feature flag's `decide` function. For example if multiple flags need to check auth you can dedupe the auth function so it only runs once per request.

`dedupe` is also useful to optimistically generate a random visitor id to be set in a cookie, while also allowing each feature flag to access the id. You can call a dedupe'd function to generate the random id within your Edge Middleware and also within your feature flag's `decide` functions. The function will return a consistent id.

```ts
import { nanoid } from 'nanoid';
import { cookies, headers } from 'next/headers';
import { dedupe } from '@vercel/flags/next';

/**
* Reads the visitor id from a cookie or returns a new visitor id
*/
export const getOrGenerateVisitorId = dedupe(
async (): Promise<{ value: string; fresh: boolean }> => {
const visitorIdCookie = (await cookies()).get('visitor-id')?.value;

return visitorIdCookie
? { value: visitorIdCookie, fresh: false }
: { value: nanoid(), fresh: true };
},
);
```

> Note: "once per request" is an imprecise description. A `dedupe`d function actually runs once per request, per compute instance. If a dedupe'd function is used in Edge Middleware and in a React Server Component it will run twice, as there are two separate compute instances handling this request.
> Note: This function acts as a sort of polyfill until similar functionality lands in Next.js directly.
5 changes: 5 additions & 0 deletions .changeset/poor-rules-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/flags': major
---

add identify, drop getPrecomputationContext, change .run({})
5 changes: 5 additions & 0 deletions .changeset/ten-eagles-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/flags': major
---

remove unstable\_ prefixes
20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { resolve } = require('node:path');

module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ['custom'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'import/no-default-export': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off',
},
parserOptions: {
project: [
resolve(__dirname, './packages/*/tsconfig.json'),
resolve(__dirname, './tooling/*/tsconfig.json'),
resolve(__dirname, './examples/*/tsconfig.json'),
resolve(__dirname, './tests/*/tsconfig.json'),
],
},
};
34 changes: 34 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: ['*']
jobs:
test:
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 9
- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Playwright Browsers
run: pnpm exec playwright install chromium
- name: Install Playwright System Dependencies
run: pnpm exec playwright install-deps chromium
- name: Run Playwright tests
run: pnpm test:e2e
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
96 changes: 96 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Quality

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
prettier:
name: 'Prettier'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run Prettier check
run: pnpm prettier-check

eslint:
name: 'ESLint'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run ESLint
run: pnpm run lint

types:
name: 'TypeScript'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run TypeScript type check
run: pnpm run type-check

publint:
name: 'publint'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run Publint
run: pnpm run publint
95 changes: 95 additions & 0 deletions .github/workflows/release-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This workflow lets you manually create snapshot relases
#
# A snapshot release is useful when you want to try out changes on a pull request
# before making a full release and without making a pre release mode.
#
# Problem
#
# This is useful as changesets force pre release mode across all packages in our
# mono repo. When using pre releases then stable releases of all packages are
# blocked until pre release is exited.
#
# What are snapshot releases
#
# To work around this issue we have this workflow. It lets you create a
# once-off release for a specific branch. We call those snapshot releases.
# Snapshot releases are published under the `snapshot` dist-tag and have
# versions like 0.4.0-579bd13f016c7de43a2830340634b3948db358b6-20230913164912,
# which consist of the version that would be generated, the commit hash and
# the timestamp.
#
# How to create a snapshot release
#
# Make sure you have a branch pushed to GitHub, and make sure that branch has
# a changeset committed. You can generate a changeset with "pnpm changeset".
#
# Then open github.com/vercel/variants and click on Actions > Release Snapshot
# Then click "Run workflow" on the right and select the branch you want to
# create a snapshot release for and click the "Run workflow" button.
#
# Then wait for the run to kick off and open the details.
# Find the "Create Snapshot Release" step in the logs.
# The last line of that log should contain something like
# 🦋 success packages published successfully:
# 🦋 @vercel/edge-config@0.4.0-579bd13f016c7de43a2830340634b3948db358b6-20230913164912
# This shows the version which was generated.

name: Release Snapshot

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

on:
workflow_dispatch:

jobs:
release-snapshot:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Add npm auth token to pnpm
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN_ELEVATED}"
env:
NPM_TOKEN_ELEVATED: ${{secrets.NPM_TOKEN_ELEVATED}}

- name: Install Dependencies
run: pnpm install

- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${{ github.sha }} | cut -c1-8`" >> $GITHUB_ENV

- name: Version Packages
run: pnpm changeset version --snapshot ${SHORT_SHA}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}

- name: Build
run: pnpm build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
EDGE_CONFIG: ${{ secrets.EDGE_CONFIG }}
FLAGS_SECRET: ${{ secrets.FLAGS_SECRET }}
FLAGS: ${{ secrets.FLAGS }}
LAUNCHDARKLY_API_TOKEN: ${{ secrets.LAUNCHDARKLY_API_TOKEN }}
HAPPYKIT_API_TOKEN: ${{ secrets.HAPPYKIT_API_TOKEN }}
HAPPYKIT_ENV_KEY: ${{ secrets.HAPPYKIT_ENV_KEY }}

- name: Publish Snapshot Release
run: pnpm changeset publish --no-git-tag --tag snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Release

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v2

- uses: actions/setup-node@v3
with:
node-version-file: '.node-version'
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: pnpm release
version: pnpm version-packages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
EDGE_CONFIG: ${{ secrets.EDGE_CONFIG }}
FLAGS_SECRET: ${{ secrets.FLAGS_SECRET }}
LAUNCHDARKLY_API_TOKEN: ${{ secrets.LAUNCHDARKLY_API_TOKEN }}
HAPPYKIT_API_TOKEN: ${{ secrets.HAPPYKIT_API_TOKEN }}
HAPPYKIT_ENV_KEY: ${{ secrets.HAPPYKIT_ENV_KEY }}
Loading

0 comments on commit be2a05e

Please sign in to comment.