Skip to content

Commit ab6a417

Browse files
committed
Merge branch 'main' of github.com:dougg0k/react-native-node-api into replace-package-manager
2 parents af071fb + 9b231c1 commit ab6a417

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+355
-316
lines changed

.changeset/rich-donuts-mix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
"react-native-node-api-test-app": patch
2+
"@react-native-node-api/test-app": patch
33
"react-native-node-api": patch
44
---
55

.github/workflows/check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
node-version: lts/jod
3232
- run: pnpm install --frozen-lockfile
3333
- run: pnpm lint
34+
- run: pnpm prettier:check
3435
unit-tests:
3536
strategy:
3637
fail-fast: false

.prettierignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Ignore artifacts
2+
dist
3+
build
4+
Pods
5+
target
6+
.cxx
7+
8+
# Ignore hermes
9+
packages/host/hermes
10+
packages/node-addon-examples/examples
11+
packages/node-tests/node
12+
packages/node-tests/tests
13+
packages/node-tests/*.generated.js

apps/test-app/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { suites as nodeAddonExamplesSuites } from "@react-native-node-api/node-a
1313
function describeIf(
1414
condition: boolean,
1515
title: string,
16-
fn: (this: Mocha.Suite) => void
16+
fn: (this: Mocha.Suite) => void,
1717
) {
1818
return condition ? describe(title, fn) : describe.skip(title, fn);
1919
}
@@ -31,7 +31,7 @@ function loadTests({
3131
}: Context) {
3232
describeIf(nodeAddonExamples, "Node Addon Examples", () => {
3333
for (const [suiteName, examples] of Object.entries(
34-
nodeAddonExamplesSuites
34+
nodeAddonExamplesSuites,
3535
)) {
3636
describe(suiteName, () => {
3737
for (const [exampleName, requireExample] of Object.entries(examples)) {

apps/test-app/babel.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
presets: ['module:@react-native/babel-preset'],
2+
presets: ["module:@react-native/babel-preset"],
33
// plugins: [['module:react-native-node-api/babel-plugin', { stripPathSuffix: true }]],
4-
plugins: ['module:react-native-node-api/babel-plugin'],
4+
plugins: ["module:react-native-node-api/babel-plugin"],
55
};

apps/test-app/react-native.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const project = (() => {
32
try {
43
const { configureProjects } = require("react-native-test-app");
@@ -25,4 +24,4 @@ const project = (() => {
2524

2625
module.exports = {
2726
...(project ? { project } : undefined),
28-
};
27+
};

docs/HOW-IT-WORKS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The generated code looks something like this:
2525

2626
```javascript
2727
module.exports = require("react-native-node-api").requireNodeAddon(
28-
"calculator-lib--prebuild"
28+
"calculator-lib--prebuild",
2929
);
3030
```
3131

eslint.config.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22

33
import { globalIgnores } from "eslint/config";
44
import globals from "globals";
5-
import eslint from '@eslint/js';
6-
import tseslint from 'typescript-eslint';
5+
import eslint from "@eslint/js";
6+
import tseslint from "typescript-eslint";
7+
import eslintConfigPrettier from "eslint-config-prettier/flat";
78

89
export default tseslint.config(
9-
globalIgnores([".nx/**"]),
10-
globalIgnores(["**/dist/**"]),
11-
globalIgnores(["apps/test-app/ios/**"]),
12-
globalIgnores(["packages/host/hermes/**"]),
13-
globalIgnores(["packages/node-addon-examples/examples/**"]),
14-
globalIgnores(["packages/ferric-example/ferric_example.d.ts"]),
10+
globalIgnores([
11+
"**/dist/**",
12+
"apps/test-app/ios/**",
13+
"packages/host/hermes/**",
14+
"packages/node-addon-examples/examples/**",
15+
"packages/ferric-example/ferric_example.d.ts",
16+
]),
1517
eslint.configs.recommended,
1618
tseslint.configs.recommended,
19+
eslintConfigPrettier,
1720
{
1821
files: [
1922
"apps/test-app/*.js",
2023
"packages/node-addon-examples/*.js",
2124
"packages/host/babel-plugin.js",
22-
"packages/host/react-native.config.js"
25+
"packages/host/react-native.config.js",
2326
],
2427
languageOptions: {
2528
parserOptions: {
@@ -38,7 +41,7 @@ export default tseslint.config(
3841
files: [
3942
"packages/gyp-to-cmake/bin/*.js",
4043
"packages/host/bin/*.mjs",
41-
"packages/host/scripts/*.mjs"
44+
"packages/host/scripts/*.mjs",
4245
],
4346
languageOptions: {
4447
globals: {

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"test": "pnpm --filter react-native-node-api --filter cmake-rn --filter gyp-to-cmake --filter node-addon-examples test",
1313
"bootstrap": "pnpm --recursive --if-present build",
1414
"prerelease": "pnpm --recursive --if-present prerelease",
15+
"prettier:check": "prettier --experimental-cli --check .",
16+
"prettier:write": "prettier --experimental-cli --write .",
1517
"release": "changeset publish"
1618
},
1719
"author": {
@@ -32,15 +34,18 @@
3234
"devDependencies": {
3335
"@changesets/cli": "^2.29.5",
3436
"@eslint/js": "^9.19.0",
37+
"@prettier/plugin-oxc": "^0.0.4",
3538
"@reporters/github": "^1.7.2",
3639
"@tsconfig/node22": "^22.0.0",
3740
"@tsconfig/react-native": "3.0.5",
3841
"@types/node": "^22.13.0",
3942
"eslint": "^9.19.0",
43+
"eslint-config-prettier": "^10.1.5",
4044
"globals": "^16.0.0",
45+
"prettier": "^3.6.2",
4146
"react-native": "0.79.5",
47+
"tsx": "^4.20.3",
4248
"typescript": "^5.7.3",
43-
"typescript-eslint": "^8.22.0",
44-
"tsx": "^4.19.3"
49+
"typescript-eslint": "^8.22.0"
4550
}
4651
}

packages/cmake-rn/src/cli.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ EventEmitter.defaultMaxListeners = 100;
2525

2626
const verboseOption = new Option(
2727
"--verbose",
28-
"Print more output during the build"
28+
"Print more output during the build",
2929
).default(process.env.CI === "true");
3030

3131
const sourcePathOption = new Option(
3232
"--source <path>",
33-
"Specify the source directory containing a CMakeLists.txt file"
33+
"Specify the source directory containing a CMakeLists.txt file",
3434
).default(process.cwd());
3535

3636
// TODO: Add "MinSizeRel" and "RelWithDebInfo"
@@ -48,40 +48,40 @@ const defaultTargets = CMAKE_RN_TARGETS ? CMAKE_RN_TARGETS.split(",") : [];
4848
for (const target of defaultTargets) {
4949
assert(
5050
(allTargets as string[]).includes(target),
51-
`Unexpected target in CMAKE_RN_TARGETS: ${target}`
51+
`Unexpected target in CMAKE_RN_TARGETS: ${target}`,
5252
);
5353
}
5454

5555
const targetOption = new Option("--target <target...>", "Targets to build for")
5656
.choices(allTargets)
5757
.default(
5858
defaultTargets,
59-
"CMAKE_RN_TARGETS environment variable split by ','"
59+
"CMAKE_RN_TARGETS environment variable split by ','",
6060
);
6161

6262
const buildPathOption = new Option(
6363
"--build <path>",
64-
"Specify the build directory to store the configured CMake project"
64+
"Specify the build directory to store the configured CMake project",
6565
);
6666

6767
const cleanOption = new Option(
6868
"--clean",
69-
"Delete the build directory before configuring the project"
69+
"Delete the build directory before configuring the project",
7070
);
7171

7272
const outPathOption = new Option(
7373
"--out <path>",
74-
"Specify the output directory to store the final build artifacts"
74+
"Specify the output directory to store the final build artifacts",
7575
).default(false, "./{build}/{configuration}");
7676

7777
const noAutoLinkOption = new Option(
7878
"--no-auto-link",
79-
"Don't mark the output as auto-linkable by react-native-node-api"
79+
"Don't mark the output as auto-linkable by react-native-node-api",
8080
);
8181

8282
const noWeakNodeApiLinkageOption = new Option(
8383
"--no-weak-node-api-linkage",
84-
"Don't pass the path of the weak-node-api library from react-native-node-api"
84+
"Don't pass the path of the weak-node-api library from react-native-node-api",
8585
);
8686

8787
let program = new Command("cmake-rn")
@@ -99,7 +99,7 @@ let program = new Command("cmake-rn")
9999
for (const platform of platforms) {
100100
const allOption = new Option(
101101
`--${platform.id}`,
102-
`Enable all ${platform.name} triplets`
102+
`Enable all ${platform.name} triplets`,
103103
);
104104
program = program.addOption(allOption);
105105
program = platform.amendCommand(program);
@@ -133,13 +133,13 @@ program = program.action(
133133
}
134134
if (targets.size === 0) {
135135
throw new Error(
136-
"Found no default targets: Install some platform specific build tools"
136+
"Found no default targets: Install some platform specific build tools",
137137
);
138138
} else {
139139
console.error(
140140
chalk.yellowBright("ℹ"),
141141
"Using default targets",
142-
chalk.dim("(" + [...targets].join(", ") + ")")
142+
chalk.dim("(" + [...targets].join(", ") + ")"),
143143
);
144144
}
145145
}
@@ -162,20 +162,20 @@ program = program.action(
162162

163163
// Configure every triplet project
164164
const targetsSummary = chalk.dim(
165-
`(${getTargetsSummary(targetContexts)})`
165+
`(${getTargetsSummary(targetContexts)})`,
166166
);
167167
await oraPromise(
168168
Promise.all(
169169
targetContexts.map(({ platform, ...context }) =>
170-
configureProject(platform, context, baseOptions)
171-
)
170+
configureProject(platform, context, baseOptions),
171+
),
172172
),
173173
{
174174
text: `Configuring projects ${targetsSummary}`,
175175
isSilent: baseOptions.verbose,
176176
successText: `Configured projects ${targetsSummary}`,
177177
failText: ({ message }) => `Failed to configure projects: ${message}`,
178-
}
178+
},
179179
);
180180

181181
// Build every triplet project
@@ -189,20 +189,20 @@ program = program.action(
189189
force: true,
190190
});
191191
await buildProject(platform, context, baseOptions);
192-
})
192+
}),
193193
),
194194
{
195195
text: "Building projects",
196196
isSilent: baseOptions.verbose,
197197
successText: "Built projects",
198198
failText: ({ message }) => `Failed to build projects: ${message}`,
199-
}
199+
},
200200
);
201201

202202
// Perform post-build steps for each platform in sequence
203203
for (const platform of platforms) {
204204
const relevantTargets = targetContexts.filter(({ target }) =>
205-
platformHasTarget(platform, target)
205+
platformHasTarget(platform, target),
206206
);
207207
if (relevantTargets.length == 0) {
208208
continue;
@@ -212,7 +212,7 @@ program = program.action(
212212
outputPath: baseOptions.out || baseOptions.source,
213213
targets: relevantTargets,
214214
},
215-
baseOptions
215+
baseOptions,
216216
);
217217
}
218218
} catch (error) {
@@ -221,11 +221,11 @@ program = program.action(
221221
}
222222
throw error;
223223
}
224-
}
224+
},
225225
);
226226

227227
function getTargetsSummary(
228-
targetContexts: { target: string; platform: Platform }[]
228+
targetContexts: { target: string; platform: Platform }[],
229229
) {
230230
const targetsPerPlatform: Record<string, string[]> = {};
231231
for (const { target, platform } of targetContexts) {
@@ -257,7 +257,7 @@ function getTargetBuildPath(buildPath: string, target: unknown) {
257257
async function configureProject<T extends string>(
258258
platform: Platform<T[], Record<string, unknown>>,
259259
context: TargetContext<T>,
260-
options: BaseOpts
260+
options: BaseOpts,
261261
) {
262262
const { target, buildPath, outputPath } = context;
263263
const { verbose, source, weakNodeApiLinkage } = options;
@@ -286,14 +286,14 @@ async function configureProject<T extends string>(
286286
{
287287
outputMode: verbose ? "inherit" : "buffered",
288288
outputPrefix: verbose ? chalk.dim(`[${target}] `) : undefined,
289-
}
289+
},
290290
);
291291
}
292292

293293
async function buildProject<T extends string>(
294294
platform: Platform<T[], Record<string, unknown>>,
295295
context: TargetContext<T>,
296-
options: BaseOpts
296+
options: BaseOpts,
297297
) {
298298
const { target, buildPath } = context;
299299
const { verbose, configuration } = options;
@@ -310,7 +310,7 @@ async function buildProject<T extends string>(
310310
{
311311
outputMode: verbose ? "inherit" : "buffered",
312312
outputPrefix: verbose ? chalk.dim(`[${target}] `) : undefined,
313-
}
313+
},
314314
);
315315
}
316316

0 commit comments

Comments
 (0)