File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Foundation
2+
3+ private class Token { }
4+
5+ extension Bundle {
6+ // NB: Alternative to `Bundle.module` that does not crash when the bundle is not found
7+ static let textual : Bundle ? = {
8+ let bundleName = " textual_Textual "
9+
10+ let overrides : [ URL ]
11+ #if DEBUG
12+ // The 'PACKAGE_RESOURCE_BUNDLE_PATH' name is preferred since the expected value is a path. The
13+ // check for 'PACKAGE_RESOURCE_BUNDLE_URL' will be removed when all clients have switched over.
14+ // This removal is tracked by rdar://107766372.
15+ if let override = ProcessInfo . processInfo. environment [ " PACKAGE_RESOURCE_BUNDLE_PATH " ]
16+ ?? ProcessInfo . processInfo. environment [ " PACKAGE_RESOURCE_BUNDLE_URL " ]
17+ {
18+ overrides = [ URL ( fileURLWithPath: override) ]
19+ } else {
20+ overrides = [ ]
21+ }
22+ #else
23+ overrides = [ ]
24+ #endif
25+
26+ let candidates =
27+ overrides + [
28+ // Bundle should be present here when the package is linked into an App.
29+ Bundle . main. resourceURL,
30+
31+ // Bundle should be present here when the package is linked into a framework.
32+ Bundle ( for: Token . self) . resourceURL,
33+
34+ // For command-line tools.
35+ Bundle . main. bundleURL,
36+ ]
37+
38+ for candidate in candidates {
39+ let bundlePath = candidate? . appendingPathComponent ( bundleName + " .bundle " )
40+ if let bundle = bundlePath. flatMap ( Bundle . init ( url: ) ) {
41+ return bundle
42+ }
43+ }
44+
45+ return nil
46+ } ( )
47+ }
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ struct CodeToken: Hashable, Sendable {
3333 }
3434
3535 guard
36- let bundleURL = Bundle . module . url (
36+ let bundleURL = Bundle . textual ? . url (
3737 forResource: " prism-bundle " ,
3838 withExtension: " js "
3939 ) ,
You can’t perform that action at this time.
0 commit comments