Skip to content

Commit

Permalink
feat: upgrade template and repo to Yarn 3
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 14, 2023
1 parent 1902e5f commit 06c72a0
Show file tree
Hide file tree
Showing 24 changed files with 12,207 additions and 6,805 deletions.
3 changes: 2 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ runs:
with:
path: |
**/node_modules
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
run: yarn install --immutable
shell: bash
10 changes: 6 additions & 4 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ jobs:
- name: Install dependencies of library
if: steps.library-yarn-cache.outputs.cache-hit != 'true'
working-directory: ${{ env.work_dir }}
env:
POD_INSTALL: 0
run: |
yarn install --cwd example
yarn install
touch yarn.lock # Without this Yarn will fail due to the parent directory being a Yarn workspace
yarn install --no-immutable
- name: Get build target
working-directory: ${{ env.work_dir }}
Expand Down Expand Up @@ -163,8 +165,8 @@ jobs:
if: env.android_build == 1 || env.ios_build == 1
working-directory: ${{ env.work_dir }}
run: |
TURBO_CACHE_STATUS_ANDROID=$(node -p "($(yarn --silent turbo run build:android --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
TURBO_CACHE_STATUS_ANDROID=$(node -p "($(yarn turbo run build:android --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS_IOS=$(node -p "($(yarn turbo run build:ios --cache-dir=".turbo/cache" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS_ANDROID == "HIT" ]]; then
echo "turbo_cache_hit_android=1" >> $GITHUB_ENV
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ build/Release
node_modules/
jspm_packages/

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

# Typescript v1 declaration files
typings/

Expand Down
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"type": "git",
"url": "git+https://github.com/react-navigation/react-navigation.git"
},
"packageManager": "yarn@3.6.1",
"engines": {
"node": ">= 16.0.0"
"node": ">= 18.0.0"
},
"packageManager": "^yarn@1.22.15",
"scripts": {
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"typecheck": "tsc --noEmit",
Expand Down
4 changes: 1 addition & 3 deletions packages/create-react-native-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
},
"homepage": "https://github.com/callstack/react-native-builder-bob/blob/main/README.md",
"main": "lib/index.js",
"bin": {
"create-react-native-library": "bin/create-react-native-library"
},
"bin": "bin/create-react-native-library",
"files": [
"lib",
"templates"
Expand Down
8 changes: 6 additions & 2 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import generateExampleApp from './utils/generateExampleApp';

const FALLBACK_BOB_VERSION = '0.20.0';

const BINARIES = /(gradlew|\.(jar|keystore|png|jpg|gif))$/;
const BINARIES = [
/(gradlew|\.(jar|keystore|png|jpg|gif))$/,
/\$\.yarn(?![a-z])/,
];

const COMMON_FILES = path.resolve(__dirname, '../templates/common');
const JS_FILES = path.resolve(__dirname, '../templates/js-library');
Expand Down Expand Up @@ -596,7 +599,7 @@ async function create(argv: yargs.Arguments<any>) {

if (stats.isDirectory()) {
await copyDir(file, target);
} else if (!file.match(BINARIES)) {
} else if (!BINARIES.some((r) => r.test(file))) {
const content = await fs.readFile(file, 'utf8');

await fs.writeFile(target, ejs.render(content, options));
Expand Down Expand Up @@ -627,6 +630,7 @@ async function create(argv: yargs.Arguments<any>) {
await generateExampleApp({
type: example,
dest: folder,
slug: options.project.slug,
projectName: options.project.name,
arch,
reactNativeVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ const PACKAGES_TO_ADD_WEB_DEV = {
'babel-loader': '^8.1.0',
};

const SCRIPTS_TO_ADD = {
'pods': 'pod-install --quiet',
'build:android':
'cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a',
'build:ios':
'cd ios && xcodebuild -workspace TestLibExample.xcworkspace -scheme TestLibExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO',
};

export default async function generateExampleApp({
type,
dest,
slug,
projectName,
arch,
reactNativeVersion = 'latest',
}: {
type: 'expo' | 'native';
dest: string;
slug: string;
projectName: string;
arch: 'new' | 'mixed' | 'legacy';
reactNativeVersion?: string;
Expand Down Expand Up @@ -110,6 +120,8 @@ export default async function generateExampleApp({
await fs.readFile(path.join(directory, 'package.json'), 'utf8')
);

pkg.name = `${slug}-example`;

// Remove Jest config for now
delete pkg.jest;

Expand All @@ -119,7 +131,7 @@ export default async function generateExampleApp({
delete scripts.lint;

if (type === 'native') {
scripts.pods = 'pod-install --quiet';
Object.assign(scripts, SCRIPTS_TO_ADD);
}

PACKAGES_TO_REMOVE.forEach((name) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ runs:
with:
path: |
**/node_modules
.yarn/install-state.gz
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
${{ runner.os }}-yarn-
- name: Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
yarn install --cwd example --frozen-lockfile
yarn install --frozen-lockfile
run: yarn install --immutable
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Check turborepo cache for Android
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:android').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Check turborepo cache for iOS
run: |
TURBO_CACHE_STATUS=$(node -p "($(yarn --silent turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
TURBO_CACHE_STATUS=$(node -p "($(yarn turbo run build:ios --cache-dir="${{ env.TURBO_CACHE_DIR }}" --dry=json)).tasks.find(t => t.task === 'build:ios').cache.status")
if [[ $TURBO_CACHE_STATUS == "HIT" ]]; then
echo "turbo_cache_hit=1" >> $GITHUB_ENV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ buck-out/
android/app/libs
android/keystores/debug.keystore

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

# Expo
.expo/

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

This file was deleted.

13 changes: 13 additions & 0 deletions packages/create-react-native-library/templates/common/$.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
nodeLinker: node-modules
nmHoistingLimits: workspaces

plugins:
<% if (example === 'native') { -%>
- path: scripts/pod-install.cjs
<% } -%>
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.6.1.cjs
20 changes: 10 additions & 10 deletions packages/create-react-native-library/templates/common/$package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@
"test": "jest",
"typecheck": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"prepack": "bob build",
"release": "release-it",
"example": "yarn --cwd example",
<% if (example === 'native') { -%>
"build:android": "cd example/android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a",
"build:ios": "cd example/ios && xcodebuild -workspace <%- project.name %>Example.xcworkspace -scheme <%- project.name %>Example -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO",
"bootstrap": "yarn example && yarn install && yarn example pods",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
<% } else { -%>
"bootstrap": "yarn example && yarn install"
"clean": "del-cli lib",
<% } -%>
"prepack": "bob build",
"release": "release-it",
"example": "yarn workspace <%- project.slug -%>-example"
},
"keywords": [
"react-native",
Expand Down Expand Up @@ -89,10 +86,13 @@
"react": "*",
"react-native": "*"
},
"workspaces": [
"example"
],
"packageManager": "yarn@3.6.1",
"engines": {
"node": ">= 16.0.0"
"node": ">= 18.0.0"
},
"packageManager": "^yarn@1.22.15",
"jest": {
"preset": "react-native",
"modulePathIgnorePatterns": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@ 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:

- 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:

```sh
yarn
```

> While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development.
> 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.

While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app.
<% if (project.native) { -%>
If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/<%- project.name -%>Example.xcworkspace` in XCode and find the source files at `Pods > Development Pods > <%- project.slug -%>`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.identifier -%>` under `Android`.

<% } -%>
You can use various commands from the root directory to work with the project.

To start the packager:

Expand Down Expand Up @@ -94,13 +109,6 @@ Remember to add tests for your change if possible. Run the unit tests by:
yarn test
```

<% if (project.native) { -%>
To edit the Objective-C or Swift files, open `example/ios/<%- project.name -%>Example.xcworkspace` in XCode and find the source files at `Pods > Development Pods > <%- project.slug -%>`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.identifier -%>` under `Android`.

<% } -%>

### Commit message convention

We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
Expand Down Expand Up @@ -136,7 +144,7 @@ yarn release

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

- `yarn bootstrap`: setup project by installing all dependencies and pods.
- `yarn`: setup project by installing all dependencies and pods.
- `yarn typecheck`: type-check files with TypeScript.
- `yarn lint`: lint files with ESLint.
- `yarn test`: run unit tests with Jest.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const child_process = require('child_process');

module.exports = {
name: 'pod-install',
factory() {
return {
hooks: {
afterAllInstalled(project, options) {
if (process.env.POD_INSTALL === '0') {
return;
}

if (
options &&
(options.mode === 'update-lockfile' ||
options.mode === 'skip-build')
) {
return;
}

const result = child_process.spawnSync(
'yarn',
['pod-install', 'example/ios'],
{
cwd: project.cwd,
env: process.env,
stdio: 'inherit',
encoding: 'utf-8',
shell: true,
}
);

if (result.status !== 0) {
throw new Error('Failed to run pod-install');
}
},
},
};
},
};
Loading

0 comments on commit 06c72a0

Please sign in to comment.