peachsim 0.1.1902 → 0.1.1905

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.
Files changed (100) hide show
  1. package/cli/commands/record.ts +78 -43
  2. package/dist-lib/agent-daemon-client.cjs +1 -1
  3. package/dist-lib/agent-events.cjs +1 -1
  4. package/dist-lib/attached-projects.cjs +1 -1
  5. package/dist-lib/auth/shared-session.cjs +1 -1
  6. package/dist-lib/backend-origin.cjs +1 -1
  7. package/dist-lib/beta.cjs +1 -1
  8. package/dist-lib/beta.mjs +1 -1
  9. package/dist-lib/bridge-constants.cjs +1 -1
  10. package/dist-lib/bridge-contract-input.cjs +1 -1
  11. package/dist-lib/bridge-contract-input.mjs +1 -1
  12. package/dist-lib/bridge-contract.cjs +1 -1
  13. package/dist-lib/bridge-contract.mjs +1 -1
  14. package/dist-lib/bundle-channel.cjs +97 -40
  15. package/dist-lib/capture-contract.cjs +1 -1
  16. package/dist-lib/capture-contract.mjs +1 -1
  17. package/dist-lib/cloud-contract.cjs +2 -1
  18. package/dist-lib/cloud-contract.mjs +2 -1
  19. package/dist-lib/cloud-test-args.cjs +1 -1
  20. package/dist-lib/cloud-test-args.mjs +1 -1
  21. package/dist-lib/cloud.cjs +2 -1
  22. package/dist-lib/cloud.mjs +2 -1
  23. package/dist-lib/config.cjs +1 -1
  24. package/dist-lib/config.mjs +1 -1
  25. package/dist-lib/detox/index.cjs +3 -2
  26. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  27. package/dist-lib/expo-swift-bundle.cjs +91 -34
  28. package/dist-lib/expo-swift-metadata.cjs +1 -1
  29. package/dist-lib/expo-swift-metadata.mjs +1 -1
  30. package/dist-lib/home-paths.cjs +1 -1
  31. package/dist-lib/host/bridge-host.cjs +98 -40
  32. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  33. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  34. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  35. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  36. package/dist-lib/host/websocket-proxy.cjs +1 -1
  37. package/dist-lib/index.cjs +4 -3
  38. package/dist-lib/jump-to-source-babel.cjs +1 -1
  39. package/dist-lib/jump-to-source-native.cjs +1 -1
  40. package/dist-lib/kotlin-host.cjs +1 -1
  41. package/dist-lib/menu.cjs +1 -1
  42. package/dist-lib/menu.mjs +1 -1
  43. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  44. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  45. package/dist-lib/metro-production-bundle.cjs +1 -1
  46. package/dist-lib/metro-production-bundle.mjs +1 -1
  47. package/dist-lib/metro.cjs +3 -3
  48. package/dist-lib/native-app-identity-project.cjs +2 -2
  49. package/dist-lib/native-app-identity-project.mjs +2 -2
  50. package/dist-lib/native-app-identity.cjs +1 -1
  51. package/dist-lib/native-app-identity.mjs +1 -1
  52. package/dist-lib/native-firebase-metadata.cjs +1 -1
  53. package/dist-lib/native-firebase-metadata.mjs +1 -1
  54. package/dist-lib/pdfium-raster.cjs +1 -1
  55. package/dist-lib/pdfium-raster.mjs +1 -1
  56. package/dist-lib/plist.cjs +1 -1
  57. package/dist-lib/plist.mjs +1 -1
  58. package/dist-lib/profiles.cjs +1 -1
  59. package/dist-lib/public-brand.cjs +1 -1
  60. package/dist-lib/public-origins-lib-esm.json +24 -24
  61. package/dist-lib/public-origins-lib.json +53 -53
  62. package/dist-lib/react-native-host-modules.cjs +1 -1
  63. package/dist-lib/react-native-host-modules.mjs +1 -1
  64. package/dist-lib/reap-browser.cjs +1 -1
  65. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  66. package/dist-lib/sdk.cjs +1 -1
  67. package/dist-lib/sdk.mjs +1 -1
  68. package/dist-lib/skills.cjs +99 -41
  69. package/dist-lib/swift-compile.cjs +31 -18
  70. package/dist-lib/swift-compile.mjs +30 -18
  71. package/dist-lib/swift-package.cjs +1 -1
  72. package/dist-lib/swift-package.mjs +1 -1
  73. package/dist-lib/swift-submit.cjs +1 -1
  74. package/dist-lib/swift-submit.mjs +1 -1
  75. package/dist-lib/swift-toolchain.cjs +1 -1
  76. package/dist-lib/swift.cjs +1 -1
  77. package/dist-lib/vite-swift.cjs +30 -20
  78. package/dist-lib/vite.cjs +2 -2
  79. package/dist-lib/worklet-executable.cjs +1 -1
  80. package/dist-lib/worklet-executable.mjs +1 -1
  81. package/dist-types/packages/peach-engine/src/engine/fiber-debug-metadata.d.ts +1 -0
  82. package/dist-types/packages/peach-globals/src/recordingBridgeContract.d.ts +1 -0
  83. package/package.json +1 -1
  84. package/runtime-companion.json +1 -1
  85. package/sdk/ios/usr/include/darwin.modulemap +430 -0
  86. package/sdk/ios/usr/include/module.modulemap +1 -0
  87. package/src/bridge-contract.ts +25 -0
  88. package/src/cloud-contract.ts +1 -0
  89. package/src/expo-native-workspace.ts +31 -3
  90. package/src/expo-swift-host.ts +18 -8
  91. package/src/expo-workspace-exclusion.ts +15 -1
  92. package/src/nitro-adapter.lock.json +400 -1360
  93. package/src/nitro-superset.lock.json +4 -4
  94. package/src/swift-compile.ts +14 -14
  95. package/src/swift-distribution.lock.json +11 -11
  96. package/src/swift-host.ts +2 -1
  97. package/src/swift-shared-sdk.ts +12 -7
  98. package/src/swift-wasm-prune.ts +9 -1
  99. package/src/turbo-runtime.lock.json +20 -48
  100. package/src/workspace-root.ts +31 -7
@@ -1539,7 +1539,7 @@ const SWIFT_HEADER_PRODUCTS_TARGET = 'PeachHeaderProducts'
1539
1539
 
1540
1540
  // build-cli replaces this in every bundle; source runs read the files directly.
1541
1541
  declare const __SWIFT_COMPILER_DIGEST__: string | undefined
1542
- const compilerSourceDigest =
1542
+ export const compilerSourceDigest =
1543
1543
  typeof __SWIFT_COMPILER_DIGEST__ === 'string'
1544
1544
  ? __SWIFT_COMPILER_DIGEST__
1545
1545
  : swiftCompilerSourceDigest(import.meta.dirname)
@@ -1747,8 +1747,6 @@ export function emitSwiftPackageManifest(args: {
1747
1747
  * then links only the stdlib and system archives its sources reference.
1748
1748
  */
1749
1749
  distributionLink?: { path: string; files: Map<string, string | Buffer> }
1750
- /** link the distribution as an archive pruned after the link: size-optimized artifacts only. */
1751
- lazyDistribution?: boolean
1752
1750
  /**
1753
1751
  * framework products already built in their own scratch. objects link whole,
1754
1752
  * and modules import from that scratch, so this package's targets never
@@ -1811,11 +1809,9 @@ export function emitSwiftPackageManifest(args: {
1811
1809
  foundationCategoryObjects.map((name) => `lib/Foundation-${name}.o`),
1812
1810
  )
1813
1811
  const roots = swiftObjcRootObjects(distribution.id, moduleRoot, distribution.objects)
1814
- const eager = args.lazyDistribution
1815
- ? new Set(
1816
- objects.filter((object) => roots.has(object) || categoryObjects.has(object)),
1817
- )
1818
- : new Set(objects)
1812
+ const eager = new Set(
1813
+ objects.filter((object) => roots.has(object) || categoryObjects.has(object)),
1814
+ )
1819
1815
  // native headers can reference a framework without a Swift import, and a
1820
1816
  // native target can share a module name with distribution Swift helpers.
1821
1817
  // retain those objects in the archive so undefined symbols select them.
@@ -5698,7 +5694,6 @@ export function writeSwiftProject(
5698
5694
  path: path.join(layout.root, '.peach-distribution-objects.rsp'),
5699
5695
  files,
5700
5696
  },
5701
- lazyDistribution: input.optimize,
5702
5697
  }
5703
5698
  : {}),
5704
5699
  ...(prebuilt && frameworkLink
@@ -6515,9 +6510,14 @@ async function buildFrameworkProducts(
6515
6510
  objects.push(object)
6516
6511
  linked.owners.set(object, 'Foundation')
6517
6512
  }
6518
- // the providers compile from this revision's source, once per scratch
6513
+ // the providers compile from this revision's source; a slot that moved to
6514
+ // another revision rebuilds them
6519
6515
  const providerDir = path.join(scratch, 'darwin-records')
6520
- if (!existsSync(path.join(providerDir, '.complete'))) {
6516
+ const providerStamp = path.join(providerDir, '.complete')
6517
+ if (
6518
+ !existsSync(providerStamp) ||
6519
+ readFileSync(providerStamp, 'utf8') !== args.frameworkKey
6520
+ ) {
6521
6521
  rmSync(providerDir, { recursive: true, force: true })
6522
6522
  mkdirSync(providerDir)
6523
6523
  const sdkPaths = swiftSdkPaths(args.moduleRoot, args.toolchainBin)
@@ -6529,7 +6529,7 @@ async function buildFrameworkProducts(
6529
6529
  minimum: darwinRecordsMinimum(),
6530
6530
  out: providerDir,
6531
6531
  })
6532
- writeFileSync(path.join(providerDir, '.complete'), '')
6532
+ writeFileSync(providerStamp, args.frameworkKey)
6533
6533
  }
6534
6534
  const providers = readdirSync(providerDir)
6535
6535
  .filter((file) => file.endsWith('.o'))
@@ -6926,7 +6926,7 @@ function compileSwiftProjectOnce(
6926
6926
  .join(':'),
6927
6927
  }
6928
6928
  : {}),
6929
- ...(input.optimize ? { PEACH_DEFER_WASM_LINK: '1' } : {}),
6929
+ PEACH_DEFER_WASM_LINK: '1',
6930
6930
  },
6931
6931
  maxBuffer: 64 * 1024 * 1024,
6932
6932
  timeout: options.timeoutMs,
@@ -7202,7 +7202,7 @@ function compileSwiftProjectOnce(
7202
7202
  }
7203
7203
  if (options.project) removeProjectLinks(root)
7204
7204
  // the guest link prunes and links the response file itself.
7205
- if (input.optimize && !guestGraph)
7205
+ if (!guestGraph)
7206
7206
  pruneSwiftWasmLink(
7207
7207
  root,
7208
7208
  options.toolchainBin,
@@ -1,10 +1,10 @@
1
1
  {
2
- "id": "91e49f74031b87f6",
2
+ "id": "5b877d1f76e5632c",
3
3
  "release": "swift-6.4.0-RELEASE-custom-a560ff35bf882b5c",
4
- "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-d9785d4d",
5
- "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-d9785d4d.artifactbundle.tar.gz",
6
- "wasmSdkChecksum": "10f60222995decf97824628087e1069aa74b57eaa8f76bcc488fd7a73a841c30",
7
- "source": "ebddb03dd3a0ab61117f39c763182c91035a4400",
4
+ "wasmSdkId": "swift-6.4.0-RELEASE_wasm-peach-5d19b8c2",
5
+ "wasmSdkUrl": "https://r2.sootsim.com/swift-wasm-sdk/swift-6.4.0-RELEASE_wasm-peach-5d19b8c2.artifactbundle.tar.gz",
6
+ "wasmSdkChecksum": "126c1ffe1333693500bf20fd4636ef875763219ddd01eda44739e4d0507b982b",
7
+ "source": "66933eae0596429b7e226afed62a3378bfeeaaa5",
8
8
  "targets": [
9
9
  "ImagePlayground",
10
10
  "QuickLookThumbnailing",
@@ -231,16 +231,16 @@
231
231
  },
232
232
  "hosts": {
233
233
  "darwin-arm64": {
234
- "sha256": "124252c2fe726e7a8c715dfd40a00c3ad2fff05d157a27430027fdee994c7025",
235
- "size": 99264450
234
+ "sha256": "e7deb164da91f1db28e61446222c55307cc72205b6cebc09c8fa6ba3d8c6ebaa",
235
+ "size": 99291577
236
236
  },
237
237
  "linux-x64": {
238
- "sha256": "e04815bc4ce4b5c5865139843bcfedc5ad89b69100b4e0c3ffd7bf1764938faf",
239
- "size": 101983664
238
+ "sha256": "539f08f19e935db924207a9bbf9dc3d078918d00d5fcc6978c0a96de34d2de08",
239
+ "size": 102010416
240
240
  },
241
241
  "linux-arm64": {
242
- "sha256": "821e456fe93c41e0aaf8b5854808b2a1f68c696c230d97196fe3d7a320767b71",
243
- "size": 101472592
242
+ "sha256": "618d3171b5a2d005e35024512666650c714129a89cdcfdd48be034cd7e124074",
243
+ "size": 101501579
244
244
  }
245
245
  }
246
246
  }
package/src/swift-host.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  swiftCPredefines,
41
41
  swiftDistributionAt,
42
42
  swiftOptionalFramework,
43
+ compilerSourceDigest,
43
44
  } from './swift-compile'
44
45
  import {
45
46
  assetSymbolText,
@@ -1575,7 +1576,6 @@ function sourceTreeFiles(dir: string, canonicalRoot: string): string[] {
1575
1576
  walk(full)
1576
1577
  } else if (stat.isFile()) {
1577
1578
  found.push(full)
1578
- if (found.length > 4096) throw new Error('swift package exceeds 4096 input files')
1579
1579
  }
1580
1580
  }
1581
1581
  ancestors.delete(realDirectory)
@@ -2201,6 +2201,7 @@ export function sourceContentStamp(
2201
2201
  moduleRootOverride?: string,
2202
2202
  ): string {
2203
2203
  const hash = createHash('sha256')
2204
+ hash.update(compilerSourceDigest)
2204
2205
  hash.update(JSON.stringify(xcodeProjects().get(packagePath)?.behavior ?? {}))
2205
2206
  const libraries = projects().get(packagePath)?.libraries
2206
2207
  if (libraries) hash.update(JSON.stringify(libraries))
@@ -260,7 +260,7 @@ export function swiftSharedSdkViewOptions(
260
260
  .map((entry) => path.join(entry.parentPath, entry.name))
261
261
  .sort()
262
262
  const key = JSON.stringify([
263
- 'v17',
263
+ 'v18',
264
264
  toolchainBin,
265
265
  sdk,
266
266
  frameworks,
@@ -312,12 +312,17 @@ export function swiftSharedSdkViewOptions(
312
312
  // IFF_* flags and if_indextoname that native packages compile against.
313
313
  const overrides = new Map<string, string>([
314
314
  [path.join(sysroot, 'darwin/System/Library/Frameworks'), frameworks],
315
- ...['MacTypes.h', 'net/if.h', 'notify.h', 'notify.modulemap'].map(
316
- (header): [string, string] => [
317
- path.join(sysroot, 'darwin/usr/include', header),
318
- path.join(swiftSharedSdkRoot(moduleRoot, distribution), 'usr/include', header),
319
- ],
320
- ),
315
+ ...[
316
+ 'MacTypes.h',
317
+ 'net/if.h',
318
+ 'notify.h',
319
+ 'notify.modulemap',
320
+ 'module.modulemap',
321
+ 'darwin.modulemap',
322
+ ].map((header): [string, string] => [
323
+ path.join(sysroot, 'darwin/usr/include', header),
324
+ path.join(swiftSharedSdkRoot(moduleRoot, distribution), 'usr/include', header),
325
+ ]),
321
326
  ])
322
327
  // preserve bundle-only support headers while taking the shared darwin
323
328
  // overlays from the same owner as the framework declarations.
@@ -1171,6 +1171,10 @@ export function pruneSwiftWasmLink(
1171
1171
  } else {
1172
1172
  eagerFiles.push(t)
1173
1173
  }
1174
+ } else {
1175
+ // an archive region of build objects, such as source-built darwin
1176
+ // record providers, links lazily ahead of the sdk archive they override.
1177
+ lazyBuildObjects.set(t, parseWasmObjectCached(t, false, false))
1174
1178
  }
1175
1179
  } else if (
1176
1180
  !inStartLib &&
@@ -2088,7 +2092,11 @@ export function pruneSwiftWasmLink(
2088
2092
  outTokens.push('--end-lib')
2089
2093
  continue
2090
2094
  }
2091
- if (inStartLib) continue
2095
+ if (inStartLib) {
2096
+ if (lazyBuildObjects.has(t) && extractedObjs.has(lazyBuildObjects.get(t)!))
2097
+ outTokens.push(t)
2098
+ continue
2099
+ }
2092
2100
  if (lazyBuildObjects.has(t)) {
2093
2101
  if (extractedObjs.has(lazyBuildObjects.get(t)!)) outTokens.push(t)
2094
2102
  } else if (t === swiftrtOrigPath && patchedSwiftrtPath) {
@@ -8,11 +8,11 @@
8
8
  },
9
9
  "compiler": "swift-6.4.0-RELEASE-custom-a560ff35bf882b5c",
10
10
  "sdk": {
11
- "id": "swift-6.4.0-RELEASE_wasm-peach-d9785d4d",
12
- "checksum": "10f60222995decf97824628087e1069aa74b57eaa8f76bcc488fd7a73a841c30"
11
+ "id": "swift-6.4.0-RELEASE_wasm-peach-5d19b8c2",
12
+ "checksum": "126c1ffe1333693500bf20fd4636ef875763219ddd01eda44739e4d0507b982b"
13
13
  },
14
14
  "framework": {
15
- "distribution": "91e49f74031b87f6",
15
+ "distribution": "5b877d1f76e5632c",
16
16
  "wireAbi": "246b8412514b644113e6a26252c8ebd6de49ab4156ac5f5c98bb9e4c2ff2568b"
17
17
  },
18
18
  "archives": [
@@ -20,99 +20,71 @@
20
20
  "headers": {
21
21
  "reactNativeJsi": "0f8c2defbca69a27a848a81ae72363073bf9602fd316e57a75811be1a0528358"
22
22
  },
23
- "sha256": "69881e59a09527fcef947b83f8d8ed8af485ba957c1da2827ec5c2731349a149",
23
+ "sha256": "b7b687d712180e51c13ca264a4ca6419ed5905f80daba8eef846ce9cc8a43b9e",
24
24
  "size": 25397
25
25
  },
26
26
  {
27
27
  "headers": {
28
28
  "reactNativeJsi": "21a624ea24fd17d56bf26832d496fc1177067f89640414c20e6486c7984dfb0a"
29
29
  },
30
- "sha256": "48db16de9d866b73ef249eec6b16de64487be1e280dd29e9c018cd820aefa066",
31
- "size": 26143
32
- },
33
- {
34
- "headers": {
35
- "reactNativeJsi": "253c4370ac99834de15e5e693d98675d1fcb985929be9c2334cac1cfdc53b1c8"
36
- },
37
- "sha256": "6b9a17fdb01d68f95b2624183a2e6f96572e9992cd3f9ff4af866f95327e45d5",
38
- "size": 25185
30
+ "sha256": "59a5f9a42a8bd6d071601a2a6f22884aee93aefffd750ebc7d26011fbc3700d3",
31
+ "size": 26142
39
32
  },
40
33
  {
41
34
  "headers": {
42
35
  "reactNativeJsi": "324aefd8591d9ce688bce7589c4c2b516cd33ecb95d35c47239a87a8fcf6a8da"
43
36
  },
44
- "sha256": "6b7be463ff18f6ca11881376501e03e4a54a0f4546d8c46daa7f81ec6c5940e9",
45
- "size": 25398
37
+ "sha256": "313efb2b9c8c07a9437297022ddab5498b9fbb1e15913ac8275847284ca29bf0",
38
+ "size": 25400
46
39
  },
47
40
  {
48
41
  "headers": {
49
42
  "reactNativeJsi": "33596664ee7d7a6623f0796a6feb429543316c3a41b211150acda6e1d835286c"
50
43
  },
51
- "sha256": "73932a51c10b19132be795636db2cab06eb2dd9bb02b762f743f7f1741e90739",
52
- "size": 25165
44
+ "sha256": "79cc33e915390266e1b5616ebd11bb87cb042be5c1ff9f66d0f7e06a5507ca70",
45
+ "size": 25171
53
46
  },
54
47
  {
55
48
  "headers": {
56
49
  "reactNativeJsi": "66b2cd5a38511195207f6c8a76aba735f9b9cc66a52a0d00780ffe5d331623f7"
57
50
  },
58
- "sha256": "eae7691bb60f705e661ca067dea354d9c25e95184638cbd11faef5abf21dec31",
59
- "size": 25398
60
- },
61
- {
62
- "headers": {
63
- "reactNativeJsi": "72f7c28bb4efe1266c3d10a030b02bb01b8907bc9322e5993ce41ebd950a381b"
64
- },
65
- "sha256": "59429c49aee7ab4e4536e2941423590bbeddaea210289f4642eee1a8b16cab01",
66
- "size": 25186
67
- },
68
- {
69
- "headers": {
70
- "reactNativeJsi": "92d95409cae874b4705931e94c48e89e2b5188f82f51bb69de790604e4bdf1f6"
71
- },
72
- "sha256": "b93158b2b6cab97515d3d2fac6897a8a5e37ab1fd891f1b4c253ee0e7297bd40",
73
- "size": 25190
51
+ "sha256": "ac01f2f3e42d725ade0c4b146c7d001a31b375a249ad212932d7400496d7704a",
52
+ "size": 25397
74
53
  },
75
54
  {
76
55
  "headers": {
77
56
  "reactNativeJsi": "96db4e758dd53e9320cef7cad485e00aa06e7a982cefd920f17007de8a5bd9f9"
78
57
  },
79
- "sha256": "ba33056cfef8d1a5581fd9fb616a784e11d0352830cd9237684319503fe6587e",
58
+ "sha256": "9efac07541cac3df7749d9e818d1903172a633e603f5b5cada291107e8ba629a",
80
59
  "size": 26142
81
60
  },
82
61
  {
83
62
  "headers": {
84
63
  "reactNativeJsi": "aeab590ddd1218df963462242d3954ce467b0fa88f70e91429e4ffc74d230893"
85
64
  },
86
- "sha256": "b5f36449ce2dfdbc9b500e2061f0a36f756bee7a88a93520044cadd494148300",
87
- "size": 26139
65
+ "sha256": "e3661c6c2f4e910e2effb2790c2352b1c17ca715e151e30706a26b63f2e81164",
66
+ "size": 26141
88
67
  },
89
68
  {
90
69
  "headers": {
91
70
  "reactNativeJsi": "b5fb260522384dd7ab07d740cdc534b529922446fcec798341c7817d9eaa49f4"
92
71
  },
93
- "sha256": "6dc907f4a7bbfacd1c0d5baccd731c6da1d28a72610eae9fc041723a0c56acd8",
94
- "size": 25266
72
+ "sha256": "0fb09a0aefaedcf5a3615c3d16ef5887493724f565ac1b4558ad95992fdc65c2",
73
+ "size": 25270
95
74
  },
96
75
  {
97
76
  "headers": {
98
77
  "reactNativeJsi": "c6b391a1e870ccf7cdd534be63582862840f8245b99ebd253317deece1e6ffd5"
99
78
  },
100
- "sha256": "6fb3ba9a59da451d2ff3209c24a6ae957f930da62a6db01066e6502181d88f4d",
79
+ "sha256": "5e399d924b76337831060b8efeea41c9dd96161b4fc97831d76f8320255a289b",
101
80
  "size": 26145
102
81
  },
103
82
  {
104
83
  "headers": {
105
84
  "reactNativeJsi": "c8270f1315745ecc204c4209a4f50f58ff6f14b4a385ad6820a69800270b53c6"
106
85
  },
107
- "sha256": "e5ea6969a2b87add3f9f4adde9366158e35177b01afce3e0fd66355daf372426",
108
- "size": 25107
109
- },
110
- {
111
- "headers": {
112
- "reactNativeJsi": "e986ff3c1eb684aa954f75fe5944e7e1a7867318684557ea113a1aa14c84ff4c"
113
- },
114
- "sha256": "eff53af48010757fddb321d2be9a4c7e5a5f665804e0e598caaebac951be5095",
115
- "size": 24915
86
+ "sha256": "784131eff39d4a98341918c993959c871c728afbfbcbe330796c4cadb6b07aa8",
87
+ "size": 25109
116
88
  }
117
89
  ]
118
90
  }
@@ -2,14 +2,38 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  // the nearest ancestor holding a workspace or lock file, else the app itself
5
+ const LOCKFILES = ['pnpm-workspace.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock']
6
+
7
+ function declaresMember(root: string, app: string) {
8
+ const manifest = path.join(root, 'package.json')
9
+ if (!fs.existsSync(manifest)) return false
10
+ const { workspaces } = JSON.parse(fs.readFileSync(manifest, 'utf8'))
11
+ const patterns: string[] = Array.isArray(workspaces)
12
+ ? workspaces
13
+ : (workspaces?.packages ?? [])
14
+ const relative = path.relative(root, app).split(path.sep).join('/')
15
+ return patterns.some((pattern) =>
16
+ new RegExp(
17
+ `^${path.posix
18
+ .normalize(pattern)
19
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
20
+ .replace(/\*\*/g, '\0')
21
+ .replace(/\*/g, '[^/]*')
22
+ .replace(/\0/g, '.*')}$`,
23
+ ).test(relative),
24
+ )
25
+ }
26
+
27
+ // the nearest lockfile names the install root unless a higher root's workspaces
28
+ // list the app, as a nested workspace root inside a larger monorepo does
5
29
  export function findWorkspaceRoot(app: string): string {
30
+ let nearest: string | null = null
31
+ let declared: string | null = null
6
32
  for (let dir = app; ; dir = path.dirname(dir)) {
7
- if (
8
- ['pnpm-workspace.yaml', 'package-lock.json', 'yarn.lock', 'bun.lock'].some((name) =>
9
- fs.existsSync(path.join(dir, name)),
10
- )
11
- )
12
- return dir
13
- if (path.dirname(dir) === dir) return app
33
+ if (LOCKFILES.some((name) => fs.existsSync(path.join(dir, name)))) {
34
+ nearest ??= dir
35
+ if (dir !== app && declaresMember(dir, app)) declared = dir
36
+ }
37
+ if (path.dirname(dir) === dir) return declared ?? nearest ?? app
14
38
  }
15
39
  }