Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 3 additions & 16 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@ runs:
using: composite
steps:
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
always-auth: true

- name: Cache dependencies
id: yarn-cache
uses: actions/cache@v3
with:
path: |
**/node_modules
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}-${{ hashFiles('**/package.json', '!node_modules/**') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-yarn-
cache: 'npm'

- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --immutable
run: npm ci
shell: bash
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,58 @@ on:
pull_request:
branches:
- main
# Lets the publish workflow gate the release on this validation.
workflow_call:

jobs:
lint:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Setup
uses: ./.github/actions/setup

- name: Lint files
run: yarn lint
run: npm run lint

- name: Typecheck files
run: yarn typecheck
run: npm run typecheck

test:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Setup
uses: ./.github/actions/setup

- name: Run unit tests
run: yarn test --maxWorkers=2 --coverage
run: npm test -- --maxWorkers=2 --coverage

build-library:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepare
run: npm run prepare

build-web:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Setup
uses: ./.github/actions/setup

- name: Build example for Web
run: |
yarn example expo export:web
npm exec -w @sellpy/react-native-scroll-anchor-example -- expo export -p web
13 changes: 13 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: PR Validation
on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]

jobs:
require-labels:
name: Exactly one Semantic Version label
runs-on: ubuntu-22.04
steps:
- uses: sellpy/package-release-actions/semver-label@v1
with:
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
54 changes: 26 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
name: Publish Package to npmjs
name: Publish main
on:
release:
types: [created]
workflow_dispatch:
pull_request:
branches:
- main
types:
- closed

jobs:
library:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup

- name: Build package
run: yarn prepare
# Serialise publishes. The next version is derived from the registry, so two runs reading
# the registry at once would resolve the same version and one would fail. Never cancel: a
# cancelled run could stop between publishing and tagging.
concurrency:
group: publish-main
cancel-in-progress: false

- name: Pack package
run: yarn pack

- name: Auth with npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN }}" > ~/.npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}

- name: Publish package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
jobs:
validate:
uses: ./.github/workflows/ci.yml
publish:
if: github.event.pull_request.merged == true
needs: validate
permissions:
# Granted here as required to perform the tagging in the called workflow.
contents: write
uses: sellpy/package-release-actions/.github/workflows/npm-publish-master.yml@v1
with:
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
secrets:
NPM_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}
12 changes: 2 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,17 @@ example/vendor/
#
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log
coverage/

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Expo
.expo/
example/dist/

# Turborepo
.turbo/
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18
v22
541 changes: 0 additions & 541 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

This file was deleted.

28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

874 changes: 0 additions & 874 deletions .yarn/releases/yarn-3.6.1.cjs

This file was deleted.

10 changes: 0 additions & 10 deletions .yarnrc.yml

This file was deleted.

56 changes: 36 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ We want this community to be friendly and respectful to each other. Please follo

## Development workflow

This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
This project is a monorepo managed using [npm workspaces](https://docs.npmjs.com/cli/using-npm/workspaces). It contains the following packages:

- The library package in the root directory.
- An example app in the `example/` directory.

To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:
To get started with the project, run `npm install` in the root directory to install the required dependencies for each package:

```sh
yarn
npm install
```

> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.

The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.
Expand All @@ -28,44 +26,50 @@ You can use various commands from the root directory to work with the project.
To start the packager:

```sh
yarn example start
npm run start -w @sellpy/react-native-scroll-anchor-example
```

To run the example app on Android:

```sh
yarn example android
npm run android -w @sellpy/react-native-scroll-anchor-example
```

To run the example app on iOS:

```sh
yarn example ios
npm run ios -w @sellpy/react-native-scroll-anchor-example
```

To run the example app on Web:

```sh
yarn example web
npm run web -w @sellpy/react-native-scroll-anchor-example
```

To run any other command in the example app, use `npm exec`:

```sh
npm exec -w @sellpy/react-native-scroll-anchor-example -- expo export -p web
```

Make sure your code passes TypeScript and ESLint. Run the following to verify:

```sh
yarn typecheck
yarn lint
npm run typecheck
npm run lint
```

To fix formatting errors, run the following:

```sh
yarn lint --fix
npm run lint -- --fix
```

Remember to add tests for your change if possible. Run the unit tests by:

```sh
yarn test
npm test
```

### Linting and tests
Expand All @@ -80,13 +84,13 @@ Our pre-commit hooks verify that the linter and tests pass when committing.

The `package.json` file contains various scripts for common tasks:

- `yarn`: setup project by installing dependencies.
- `yarn typecheck`: type-check files with TypeScript.
- `yarn lint`: lint files with ESLint.
- `yarn test`: run unit tests with Jest.
- `yarn example start`: start the Metro server for the example app.
- `yarn example android`: run the example app on Android.
- `yarn example ios`: run the example app on iOS.
- `npm install`: setup project by installing dependencies.
- `npm run typecheck`: type-check files with TypeScript.
- `npm run lint`: lint files with ESLint.
- `npm test`: run unit tests with Jest.
- `npm run prepare`: build the library with [bob](https://github.com/callstack/react-native-builder-bob). Also runs as part of `npm install` and `npm publish`.

The example app's own scripts (`start`, `android`, `ios`, `web`) live in [`example/package.json`](/example/package.json) and are run with `-w @sellpy/react-native-scroll-anchor-example`.

### Sending a pull request

Expand All @@ -99,3 +103,15 @@ When you're sending a pull request:
- Review the documentation to make sure it looks good.
- Follow the pull request template when opening a pull request.
- For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.
- Add exactly one of the `major`, `minor` or `patch` labels. The PR validation check fails without one.

### Releasing

Every merge to `main` publishes a new version. The semver label on the merged pull request
decides the bump, the new version is derived from the version already on the registry, and a
`vX.Y.Z` tag is pushed afterwards.

The `version` field in `package.json` is a `0.0.0-managed` placeholder that is never read —
the registry is the source of truth. The pipeline itself lives in
[`sellpy/package-release-actions`](https://github.com/sellpy/package-release-actions) and is
shared with the other Sellpy packages.
1 change: 1 addition & 0 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}
},
"web": {
"bundler": "metro",
"favicon": "./assets/favicon.png"
}
}
Expand Down
7 changes: 7 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { registerRootComponent } from 'expo';

import App from './App';

// npm hoists `expo` to the monorepo root, which breaks the relative import in
// `expo/AppEntry.js`. Register the root component from the workspace instead.
registerRootComponent(App);
21 changes: 9 additions & 12 deletions example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
const path = require('path');
const escape = require('escape-string-regexp');
const { getDefaultConfig } = require('@expo/metro-config');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const { getDefaultConfig } = require('expo/metro-config');
const pak = require('../package.json');

const root = path.resolve(__dirname, '..');
const modules = Object.keys({ ...pak.peerDependencies });

const defaultConfig = getDefaultConfig(__dirname);

// npm hoists dependencies shared with the root package, so resolve each
// peerDependency to wherever it actually landed instead of assuming it sits in
// example/node_modules.
const resolveModule = (name) =>
path.dirname(require.resolve(`${name}/package.json`, { paths: [__dirname] }));

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
Expand All @@ -22,19 +26,12 @@ const config = {
watchFolders: [root],

// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
// So we alias them to the single installed copy
resolver: {
...defaultConfig.resolver,

blacklistRE: exclusionList(
modules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),

extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
acc[name] = resolveModule(name);
return acc;
}, {}),
},
Expand Down
Loading