Skip to content

Commit e9f80ea

Browse files
authored
refactor: make type option readable and refactor workflow (#718)
This makes the `type` option more readable: e.g. `turbo-module` instead of `module-new`. It also means our CI builds are easier to read without needing to translate module new to turbo module etc.
1 parent 50bfbb8 commit e9f80ea

File tree

7 files changed

+36
-57
lines changed

7 files changed

+36
-57
lines changed

.github/workflows/build-templates.yml

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -30,44 +30,30 @@ jobs:
3030
- ubuntu-latest
3131
- macos-14 # macos latest defaults to macos 12 at the moment.
3232
type:
33-
- module-legacy
34-
- module-new
35-
- view-legacy
36-
- view-new
33+
- turbo-module
34+
- fabric-view
35+
- legacy-module
36+
- legacy-view
3737
language:
3838
- kotlin-objc
3939
- kotlin-swift
40-
arch:
41-
- auto
40+
- cpp
4241
exclude:
43-
- type: module-new
42+
- type: turbo-module
4443
language: kotlin-swift
45-
- type: view-new
44+
- type: fabric-view
4645
language: kotlin-swift
46+
- type: fabric-view
47+
language: cpp
48+
- type: legacy-module
49+
language: cpp
4750
include:
4851
- os: ubuntu-latest
4952
type: library
5053
language: js
51-
arch: auto
52-
- os: ubuntu-latest
53-
type: module-legacy
54-
language: cpp
55-
arch: auto
56-
- os: ubuntu-latest
57-
type: module-new
58-
language: cpp
59-
arch: auto
60-
- os: macos-14
61-
type: module-legacy
62-
language: cpp
63-
arch: auto
64-
- os: macos-14
65-
type: module-new
66-
language: cpp
67-
arch: auto
6854

6955
concurrency:
70-
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}-${{ matrix.arch }}
56+
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}
7157
cancel-in-progress: true
7258

7359
runs-on: ${{ matrix.os }}
@@ -79,20 +65,13 @@ jobs:
7965
- name: Setup
8066
uses: ./.github/actions/setup
8167

82-
- name: Set environment variables
83-
run: |
84-
if [[ "${{ matrix.arch }}" == "new" ]]; then
85-
echo "RCT_NEW_ARCH_ENABLED=1" >> $GITHUB_ENV
86-
echo "ORG_GRADLE_PROJECT_newArchEnabled=true" >> $GITHUB_ENV
87-
fi
88-
8968
- name: Build package
9069
run: |
9170
yarn workspace create-react-native-library prepare
9271
9372
- name: Get working directory
9473
run: |
95-
echo "work_dir=${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}-${{ matrix.arch }}" >> $GITHUB_ENV
74+
echo "work_dir=${{ matrix.os }}-${{ matrix.type }}-${{ matrix.language }}" >> $GITHUB_ENV
9675
9776
- name: Create library
9877
run: |
@@ -142,14 +121,14 @@ jobs:
142121
run: |
143122
# Build Android for only some matrices to skip redundant builds
144123
if [[ ${{ matrix.os }} == ubuntu-latest ]]; then
145-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
124+
if [[ ${{ matrix.type }} == *-view && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == *-objc ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == cpp ]]; then
146125
echo "android_build=1" >> $GITHUB_ENV
147126
fi
148127
fi
149128
150129
# Build iOS for only some matrices to skip redundant builds
151130
if [[ ${{ matrix.os }} == macos-14 ]]; then
152-
if [[ ${{ matrix.type }} == view-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == module-* && ${{ matrix.language }} == cpp ]]; then
131+
if [[ ${{ matrix.type }} == *-view && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == kotlin-* ]] || [[ ${{ matrix.type }} == *-module && ${{ matrix.language }} == cpp ]]; then
153132
echo "ios_build=1" >> $GITHUB_ENV
154133
fi
155134
fi
@@ -160,9 +139,9 @@ jobs:
160139
with:
161140
path: |
162141
${{ env.work_dir }}/.turbo
163-
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ matrix.arch }}-${{ hashFiles(format('{0}/yarn.lock', env.work_dir)) }}
142+
key: ${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ hashFiles(format('{0}/yarn.lock', env.work_dir)) }}
164143
restore-keys: |
165-
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-${{ matrix.arch }}-
144+
${{ runner.os }}-library-turborepo-${{ matrix.type }}-${{ matrix.language }}-
166145
167146
- name: Check turborepo cache
168147
if: env.android_build == 1 || env.ios_build == 1

packages/create-react-native-library/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async function create(_argv: yargs.Arguments<Args>) {
121121
: devDependencies;
122122
}
123123

124-
if (config.example === 'vanilla' && config.project.arch !== 'legacy') {
124+
if (config.example === 'vanilla' && config.project.arch === 'new') {
125125
addCodegenBuildScript(folder);
126126
}
127127

packages/create-react-native-library/src/input.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export type ArgName =
2121
export type ProjectLanguages = 'kotlin-objc' | 'kotlin-swift' | 'cpp' | 'js';
2222

2323
export type ProjectType =
24-
| 'module-new'
25-
| 'view-new'
26-
| 'module-legacy'
27-
| 'view-legacy'
24+
| 'turbo-module'
25+
| 'fabric-view'
26+
| 'legacy-module'
27+
| 'legacy-view'
2828
| 'library';
2929

3030
const LANGUAGE_CHOICES: {
@@ -35,17 +35,17 @@ const LANGUAGE_CHOICES: {
3535
{
3636
title: 'Kotlin & Objective-C',
3737
value: 'kotlin-objc',
38-
types: ['module-new', 'view-new', 'module-legacy', 'view-legacy'],
38+
types: ['turbo-module', 'fabric-view', 'legacy-module', 'legacy-view'],
3939
},
4040
{
4141
title: 'Kotlin & Swift',
4242
value: 'kotlin-swift',
43-
types: ['module-legacy', 'view-legacy'],
43+
types: ['legacy-module', 'legacy-view'],
4444
},
4545
{
4646
title: 'C++ for Android & iOS',
4747
value: 'cpp',
48-
types: ['module-new', 'module-legacy'],
48+
types: ['turbo-module', 'legacy-module'],
4949
},
5050
{
5151
title: 'JavaScript for Android, iOS & Web',
@@ -86,22 +86,22 @@ const TYPE_CHOICES: {
8686
}[] = [
8787
{
8888
title: 'Turbo module',
89-
value: 'module-new',
89+
value: 'turbo-module',
9090
description: 'integration for native APIs to JS',
9191
},
9292
{
9393
title: 'Fabric view',
94-
value: 'view-new',
94+
value: 'fabric-view',
9595
description: 'integration for native views to JS',
9696
},
9797
{
9898
title: 'Legacy Native module',
99-
value: 'module-legacy',
99+
value: 'legacy-module',
100100
description: 'bridge for native APIs to JS (old architecture)',
101101
},
102102
{
103103
title: 'Legacy Native view',
104-
value: 'view-legacy',
104+
value: 'legacy-view',
105105
description: 'bridge for native views to JS (old architecture)',
106106
},
107107
{

packages/create-react-native-library/src/template.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function generateTemplateConfiguration({
104104
const { slug, languages, type } = answers;
105105

106106
const arch =
107-
type === 'module-legacy' || type === 'view-legacy' ? 'legacy' : 'new';
107+
type === 'legacy-module' || type === 'legacy-view' ? 'legacy' : 'new';
108108

109109
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
110110
let namespace: string | undefined;
@@ -144,8 +144,8 @@ export function generateTemplateConfiguration({
144144
arch,
145145
cpp: languages === 'cpp',
146146
swift: languages === 'kotlin-swift',
147-
view: answers.type.startsWith('view'),
148-
module: answers.type.startsWith('module'),
147+
view: answers.type.endsWith('-view'),
148+
module: answers.type.endsWith('-module'),
149149
},
150150
author: {
151151
name: answers.authorName,

packages/create-react-native-library/templates/common-local/$package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"description": "<%- project.description %>",
55
"main": "src/index",
6-
<% if (project.arch !== 'legacy') { -%>
6+
<% if (project.arch === 'new') { -%>
77
"codegenConfig": {
88
"name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec",
99
"type": <%- project.view ? '"all"': '"modules"' %>,

packages/create-react-native-library/templates/common/$package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
"source": "src",
173173
"output": "lib",
174174
"targets": [
175-
<% if (project.arch !== 'legacy') { -%>
175+
<% if (project.arch === 'new') { -%>
176176
"codegen",
177177
<% } -%>
178178
[
@@ -194,7 +194,7 @@
194194
}
195195
]
196196
]
197-
<% if (project.arch !== 'legacy') { -%>
197+
<% if (project.arch === 'new') { -%>
198198
},
199199
"codegenConfig": {
200200
"name": "RN<%- project.name -%><%- project.view ? 'View': '' -%>Spec",

packages/create-react-native-library/templates/common/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ To run the example app on iOS:
4949
yarn example ios
5050
```
5151

52-
<% if (project.arch !== 'legacy') { -%>
52+
<% if (project.arch === 'new') { -%>
5353
To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:
5454

5555
```sh

0 commit comments

Comments
 (0)