Skip to content

refactor(apple): port make_project! to JS#2422

Merged
tido64 merged 3 commits intotrunkfrom
tido/apple/app
Mar 21, 2025
Merged

refactor(apple): port make_project! to JS#2422
tido64 merged 3 commits intotrunkfrom
tido/apple/app

Conversation

@tido64
Copy link
Member

@tido64 tido64 commented Mar 20, 2025

Description

Port make_project! to JS and add tests for supporting code. Tests for make_project! will be added in a separate PR.

Platforms affected

  • Android
  • iOS
  • macOS
  • visionOS
  • Windows

Test plan

ℹ tests 68
ℹ suites 14
ℹ pass 68
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 299.061208
ℹ start of coverage report
ℹ -------------------------------------------------------------------------------------------------------------------
ℹ file                        | line % | branch % | funcs % | uncovered lines
ℹ -------------------------------------------------------------------------------------------------------------------
ℹ ios                         |        |          |         |
ℹ  assetsCatalog.mjs          |  91.39 |    94.74 |   80.00 | 63-73 120-121
ℹ  entitlements.mjs           | 100.00 |   100.00 |  100.00 |
ℹ  infoPlist.mjs              | 100.00 |   100.00 |  100.00 |
ℹ  localizations.mjs          | 100.00 |   100.00 |  100.00 |
ℹ  newArch.mjs                | 100.00 |   100.00 |  100.00 |
ℹ  privacyManifest.mjs        | 100.00 |   100.00 |  100.00 |
ℹ  utils.mjs                  |  95.70 |    86.67 |  100.00 | 39-40 58-59
ℹ  xcode.mjs                  | 100.00 |   100.00 |  100.00 |
ℹ scripts                     |        |          |         |
ℹ  appConfig.mjs              |  74.29 |    66.67 |   50.00 | 17-23 32-33
ℹ  helpers.js                 |  68.29 |    87.50 |   36.36 | 22-25 36-43 51-55 62-71 98-104 111-114 133-135 142-152
ℹ  utils                      |        |          |         |
ℹ   filesystem.mjs            | 100.00 |   100.00 |  100.00 |
ℹ test                        |        |          |         |
ℹ  fs.mock.ts                 | 100.00 |   100.00 |  100.00 |
ℹ  ios                        |        |          |         |
ℹ   assetsCatalog.test.ts     | 100.00 |   100.00 |  100.00 |
ℹ   entitlements.test.ts      | 100.00 |   100.00 |  100.00 |
ℹ   infoPlist.test.ts         | 100.00 |   100.00 |  100.00 |
ℹ   localizations.test.ts     | 100.00 |   100.00 |  100.00 |
ℹ   newArch.test.ts           | 100.00 |   100.00 |  100.00 |
ℹ   privacyManifest.test.ts   | 100.00 |   100.00 |  100.00 |
ℹ   xcode.test.ts             | 100.00 |   100.00 |  100.00 |
ℹ -------------------------------------------------------------------------------------------------------------------
ℹ all files                   |  97.57 |    98.07 |   93.38 |
ℹ -------------------------------------------------------------------------------------------------------------------
ℹ end of coverage report


const CP_R_OPTIONS = { force: true, recursive: true };
const MKDIR_P_OPTIONS = { recursive: true, mode: 0o755 };
const RM_R_OPTIONS = { force: true, maxRetries: 3, recursive: true };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, have you found that you actually need the retries?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it comes from previous uses

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is mostly intended for Windows where a file can be locked.

Copy link

@JasonVMo JasonVMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments but they are all effectively suggestions, nothing that blocks merging this. Feel free to address them or consider them for a future PR.

* @param {string} source
* @param {string} destination
*/
export function cp_r(source, destination, fs = nodefs) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I was concerned that the names here don't reflect the synchronous behavior, but once I realized the naming pattern was aligning with the shell commands it is fine. Maybe consider renaming the file to something like fsSync.mjs or filesystemSync.mjs to reflect this? Just something to consider, but for an internal script package not a requirement.

* @import { ProjectConfiguration } from "./xcode.mjs";
*/

const SUPPORTED_PLATFORMS = ["ios", "macos", "visionos"];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this to a more shared location as SUPPORTED_APPLE_PLATFORMS.

* @param {ApplePlatform} targetPlatform
* @returns {string}
*/
function findReactNativePath(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels shared, not really apple or ios specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move it to a more central place once the iOS stuff is done and working. I will have to go over the Android and Windows scripts to make sure we share as much as possible.

* @param {string} p
* @returns {number}
*/
function readPackageVersion(p, fs = nodefs) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the @rnx-kit/tools-package stuff for some of this? I haven't looked through all the code but it feels like we probably load the package.json multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is slightly different because we already have the location of the package and we just want to read the manifest. Not sure it makes sense outside of how we currently use it inside these scripts. But I will move it to a more central place once the iOS stuff is done and working. I will have to go over the Android and Windows scripts to make sure we share as much as possible.

ios/xcode.mjs Outdated
* buildSettings: Record<string, string | string[]>;
* testsBuildSettings: Record<string, string>;
* uitestsBuildSettings: Record<string, string>;
* }} ProjectConfiguration

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe manually create and check-in a .d.ts file with types like this? Feels dangerous to have something this complex defined inline like this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have a types.ts. Moved the type there.


preprocessors.push(`REACT_NATIVE_VERSION=${reactNativeVersion}`);

// In Xcode 15, `unary_function` and `binary_function` are no longer provided
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is a port, but maybe we wont' need this eventually as Xcode N - 1 support is quite quick to drop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the other way around. As long as we support older versions of React Native, we will need this workaround.

});

it("does not return true just because `RCT_NEW_ARCH_ENABLED` is set", () => {
// `RCT_NEW_ARCH_ENABLED` does not enable bridgeless
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on older versions. Will update comment.

@tido64 tido64 enabled auto-merge (squash) March 21, 2025 13:32
@tido64 tido64 merged commit 1319189 into trunk Mar 21, 2025
30 checks passed
@tido64 tido64 deleted the tido/apple/app branch March 21, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: Android This affects Android platform: iOS This affects iOS platform: Windows This affects Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants