vxrn 2.0.0-beta.117.1 → 2.0.0-beta.120.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ import { pathToFileURL } from "node:url";
5
5
  import { validateNativeApp } from "@vxrn/utils/nativeAppManifest";
6
6
  import FSExtra from "fs-extra";
7
7
  import sharp from "sharp";
8
+ import { kotlinSourceId, renderKotlinSourceGlue, swiftPodManifest, writeNativeSourceDeclaration, writeSwiftPackageArtifacts } from "../utils/nativeSourceContract.mjs";
8
9
  import { swiftPackageDirectories } from "../utils/swiftPackageId.mjs";
9
10
 
10
11
  const nativeProjectPatches = module.createRequire(import.meta.url)("../../native-project-patches.cjs");
@@ -1294,18 +1295,25 @@ ${schemes.map((scheme) => ` <data android:scheme="${scheme}" />`).joi
1294
1295
  }
1295
1296
  }
1296
1297
  if (platform === "ios" && relativePath.endsWith("/Info.plist")) {
1297
- const usage = [];
1298
+ const usage = /* @__PURE__ */ new Map();
1298
1299
  if (app.imagePicker?.camera !== void 0) {
1299
- usage.push(["NSCameraUsageDescription", app.imagePicker.camera]);
1300
+ usage.set("NSCameraUsageDescription", app.imagePicker.camera);
1301
+ }
1302
+ if (app.photoLibrary !== void 0) {
1303
+ usage.set("NSPhotoLibraryAddUsageDescription", app.photoLibrary.addOnly);
1300
1304
  }
1301
1305
  if (app.location !== void 0) {
1302
- usage.push(["NSLocationWhenInUseUsageDescription", app.location.whenInUse]);
1306
+ usage.set("NSLocationWhenInUseUsageDescription", app.location.whenInUse);
1303
1307
  }
1304
1308
  if (app.ios?.faceIdUsageDescription !== void 0) {
1305
- usage.push(["NSFaceIDUsageDescription", app.ios.faceIdUsageDescription]);
1309
+ usage.set("NSFaceIDUsageDescription", app.ios.faceIdUsageDescription);
1306
1310
  }
1307
1311
  if (app.speech !== void 0) {
1308
- usage.push(["NSSpeechRecognitionUsageDescription", app.speech.recognition], ["NSMicrophoneUsageDescription", app.speech.microphone]);
1312
+ usage.set("NSSpeechRecognitionUsageDescription", app.speech.recognition);
1313
+ usage.set("NSMicrophoneUsageDescription", app.speech.microphone);
1314
+ }
1315
+ if (app.audio !== void 0) {
1316
+ usage.set("NSMicrophoneUsageDescription", app.audio.microphone);
1309
1317
  }
1310
1318
  const additions = [];
1311
1319
  for (const [key, text] of usage) {
@@ -1473,7 +1481,42 @@ const generateForPlatform = async (root, platform, app, outDir = path.resolve(ro
1473
1481
  root,
1474
1482
  dest
1475
1483
  });
1484
+ if (platform === "android") generateKotlinSources({
1485
+ root,
1486
+ dest
1487
+ });
1476
1488
  };
1489
+ function generateKotlinSources({ root, dest }) {
1490
+ const skip = /* @__PURE__ */ new Set([
1491
+ "node_modules",
1492
+ "ios",
1493
+ "android",
1494
+ "dist",
1495
+ "types",
1496
+ "build",
1497
+ "tests",
1498
+ "__tests__",
1499
+ "scripts"
1500
+ ]);
1501
+ const collect = (dir) => {
1502
+ for (const entry of FSExtra.readdirSync(dir, { withFileTypes: true })) {
1503
+ if (entry.name.startsWith(".") || skip.has(entry.name)) continue;
1504
+ const source = path.join(dir, entry.name);
1505
+ if (entry.isDirectory()) collect(source);
1506
+ else if (entry.isFile() && entry.name.endsWith(".kt")) {
1507
+ const id = kotlinSourceId(root, source);
1508
+ const target = path.join(dest, "app/src/main/java/one/source", id);
1509
+ FSExtra.mkdirSync(target, { recursive: true });
1510
+ FSExtra.copyFileSync(source, path.join(target, entry.name));
1511
+ const contract = writeNativeSourceDeclaration(source);
1512
+ if (contract.modules.length > 0) {
1513
+ FSExtra.writeFileSync(path.join(target, `OneNativeSource_${id}.kt`), renderKotlinSourceGlue(id, contract).source);
1514
+ }
1515
+ }
1516
+ }
1517
+ };
1518
+ collect(root);
1519
+ }
1477
1520
  function generateSwiftPackages({ root, dest }) {
1478
1521
  const skip = /* @__PURE__ */ new Set([
1479
1522
  "node_modules",
@@ -1485,6 +1528,7 @@ function generateSwiftPackages({ root, dest }) {
1485
1528
  ]);
1486
1529
  for (const [id, packageDir] of swiftPackageDirectories(root)) {
1487
1530
  const podDir = path.join(dest, "OneSwiftPackages", id);
1531
+ const manifest = swiftPodManifest(path.join(packageDir, "Package.swift"), FSExtra.readFileSync(path.join(packageDir, "Package.swift"), "utf8"));
1488
1532
  const sources = [];
1489
1533
  const collect = (dir) => {
1490
1534
  for (const entry of FSExtra.readdirSync(dir, { withFileTypes: true })) {
@@ -1495,11 +1539,20 @@ function generateSwiftPackages({ root, dest }) {
1495
1539
  }
1496
1540
  };
1497
1541
  collect(packageDir);
1542
+ const artifacts = writeSwiftPackageArtifacts(packageDir);
1543
+ const contracts = artifacts.contracts;
1544
+ const hasView = contracts.some((contract) => contract.defaultView);
1545
+ if (contracts.filter((contract) => contract.defaultView).length > 1) {
1546
+ throw new Error(`[vxrn] swift package ${packageDir} has more than one @main type`);
1547
+ }
1498
1548
  for (const source of sources) {
1499
1549
  const link = path.join(podDir, "Sources", path.relative(packageDir, source));
1500
1550
  FSExtra.mkdirSync(path.dirname(link), { recursive: true });
1501
1551
  FSExtra.symlinkSync(FSExtra.realpathSync(source), link);
1502
1552
  }
1553
+ if (contracts.some((contract) => contract.modules.length > 0)) {
1554
+ FSExtra.writeFileSync(path.join(podDir, "Sources", "OneNativeSource.generated.swift"), artifacts.glue);
1555
+ }
1503
1556
  FSExtra.writeFileSync(path.join(podDir, `${id}.podspec`), `Pod::Spec.new do |s|
1504
1557
  s.name = '${id}'
1505
1558
  s.version = '0.0.0'
@@ -1508,15 +1561,15 @@ function generateSwiftPackages({ root, dest }) {
1508
1561
  s.license = 'MIT'
1509
1562
  s.author = 'one'
1510
1563
  s.source = { :path => '.' }
1511
- s.swift_version = '6.0'
1564
+ s.swift_version = '${manifest.languageMode}.0'
1512
1565
  s.source_files = 'Sources/**/*.swift', 'Register.m'
1513
1566
  s.dependency 'One'
1514
1567
  s.pod_target_xcconfig = {
1515
- 'OTHER_SWIFT_FLAGS' => '$(inherited) -cxx-interoperability-mode=default -Xcc -std=c++20 -Xfrontend -import-module -Xfrontend One -Xfrontend -entry-point-function-name -Xfrontend ${id}_main',
1568
+ 'OTHER_SWIFT_FLAGS' => '$(inherited) -cxx-interoperability-mode=default -Xcc -std=c++20 -Xfrontend -import-module -Xfrontend One${manifest.mainActorIsolation ? " -default-isolation MainActor" : ""}${hasView ? ` -Xfrontend -entry-point-function-name -Xfrontend ${id}_main` : ""}',
1516
1569
  }
1517
1570
  end
1518
1571
  `);
1519
- FSExtra.writeFileSync(path.join(podDir, "Register.m"), `#import <Foundation/Foundation.h>
1572
+ FSExtra.writeFileSync(path.join(podDir, "Register.m"), hasView ? `#import <Foundation/Foundation.h>
1520
1573
 
1521
1574
  extern int ${id}_main(int argc, char **argv);
1522
1575
  extern void OneSwiftRegisterPackage(const char *name, int (*entry)(int, char **));
@@ -1529,7 +1582,7 @@ extern void OneSwiftRegisterPackage(const char *name, int (*entry)(int, char **)
1529
1582
  OneSwiftRegisterPackage("${id}", ${id}_main);
1530
1583
  }
1531
1584
  @end
1532
- `);
1585
+ ` : "#import <Foundation/Foundation.h>\n");
1533
1586
  }
1534
1587
  }
1535
1588
  function applyAndroidDependencyPatches(args) {