1+ import * as NodeChildProcess from "node:child_process" ;
12import * as NodeFS from "node:fs" ;
23import * as NodeModule from "node:module" ;
34import * as NodeOS from "node:os" ;
45import * as NodePath from "node:path" ;
56import { expect , it } from "vite-plus/test" ;
67
78const require = NodeModule . createRequire ( import . meta. url ) ;
9+ const { IOSConfig } = require ( "expo/config-plugins" ) ;
810const withIosControls = require ( "./withIosControls.cjs" ) ;
911const withWidgetLogoAsset = require ( "./withWidgetLogoAsset.cjs" ) ;
1012const withWidgets = require ( "expo-widgets/app.plugin.js" ) . default ;
@@ -14,7 +16,18 @@ it.each(["t3code", "t3code-dev", "t3code-preview"])(
1416 async ( scheme ) => {
1517 const root = NodeFS . mkdtempSync ( NodePath . join ( NodeOS . tmpdir ( ) , "t3-task-control-" ) ) ;
1618 try {
17- NodeFS . writeFileSync ( NodePath . join ( root , "Podfile" ) , 'target "T3Code" do\nend\n' ) ;
19+ const iosRoot = NodePath . join ( root , "ios" ) ;
20+ const projectPath = NodePath . join ( iosRoot , "HelloWorld.xcodeproj" , "project.pbxproj" ) ;
21+ NodeFS . mkdirSync ( NodePath . dirname ( projectPath ) , { recursive : true } ) ;
22+ NodeFS . writeFileSync (
23+ projectPath ,
24+ NodeChildProcess . execFileSync ( "tar" , [
25+ "-xzOf" ,
26+ NodePath . join ( NodePath . dirname ( require . resolve ( "expo/package.json" ) ) , "template.tgz" ) ,
27+ "package/ios/HelloWorld.xcodeproj/project.pbxproj" ,
28+ ] ) ,
29+ ) ;
30+ NodeFS . writeFileSync ( NodePath . join ( iosRoot , "Podfile" ) , 'target "T3Code" do\nend\n' ) ;
1831 NodeFS . mkdirSync ( NodePath . join ( root , "assets/widget" ) , { recursive : true } ) ;
1932 NodeFS . copyFileSync (
2033 NodePath . join ( import . meta. dirname , "../assets/widget/T3Mark.svg" ) ,
@@ -43,16 +56,49 @@ it.each(["t3code", "t3code-dev", "t3code-preview"])(
4356 ) ;
4457 await config . mods . ios . dangerous ( {
4558 ...config ,
46- modRequest : { projectRoot : root , platformProjectRoot : root , platform : "ios" } ,
59+ modRequest : { projectRoot : root , platformProjectRoot : iosRoot , platform : "ios" } ,
60+ } ) ;
61+ const generated = await config . mods . ios . xcodeproj ( {
62+ ...config ,
63+ modResults : IOSConfig . XcodeUtils . getPbxproj ( root ) ,
64+ modRequest : { projectRoot : root , platformProjectRoot : iosRoot , platform : "ios" } ,
4765 } ) ;
48- const widgetRoot = NodePath . join ( root , "ExpoWidgetsTarget" ) ;
66+ NodeFS . writeFileSync ( projectPath , generated . modResults . writeSync ( ) ) ;
67+ const project = IOSConfig . XcodeUtils . getPbxproj ( root ) ;
68+ const [ widgetTargetId , widgetTarget ] = Object . entries ( project . pbxNativeTargetSection ( ) ) . find (
69+ ( [ key , target ] ) => ! key . endsWith ( "_comment" ) && target . name === "ExpoWidgetsTarget" ,
70+ ) ;
71+ const buildFiles = project . pbxBuildFileSection ( ) ;
72+ const fileReferences = project . pbxFileReferenceSection ( ) ;
73+ const sourcePaths = ( targetId ) =>
74+ project
75+ . pbxSourcesBuildPhaseObj ( targetId )
76+ . files . map ( ( { value } ) =>
77+ fileReferences [ buildFiles [ value ] . fileRef ] . path . replaceAll ( '"' , "" ) ,
78+ ) ;
79+ expect ( sourcePaths ( project . getFirstTarget ( ) . uuid ) ) . toContain ( "T3ControlIntents.swift" ) ;
80+ expect ( sourcePaths ( widgetTargetId ) ) . toEqual (
81+ expect . arrayContaining ( [
82+ "ExpoWidgetsTarget/T3ControlIntents.swift" ,
83+ "ExpoWidgetsTarget/T3StartTaskControl.swift" ,
84+ "ExpoWidgetsTarget/T3OpenAppControl.swift" ,
85+ ] ) ,
86+ ) ;
87+ const configurations = project . pbxXCConfigurationList ( ) [ widgetTarget . buildConfigurationList ] ;
88+ for ( const { value } of configurations . buildConfigurations ) {
89+ expect (
90+ project . pbxXCBuildConfigurationSection ( ) [ value ] . buildSettings
91+ . SWIFT_ACTIVE_COMPILATION_CONDITIONS ,
92+ ) . toContain ( "T3_WIDGET_EXTENSION" ) ;
93+ }
94+ const widgetRoot = NodePath . join ( iosRoot , "ExpoWidgetsTarget" ) ;
4995 const index = NodeFS . readFileSync ( NodePath . join ( widgetRoot , "index.swift" ) , "utf8" ) ;
5096 expect ( index ) . toContain ( "if #available(iOS 18.0, *)" ) ;
5197 expect ( index ) . toContain ( "T3StartTaskControl()" ) ;
5298 expect ( index ) . toContain ( "T3OpenAppControl()" ) ;
5399 expect ( index ) . toContain ( "SubscriptionUsage()" ) ;
54100 expect ( index ) . toContain ( "WidgetLiveActivity()" ) ;
55- const intent = NodeFS . readFileSync ( NodePath . join ( root , "T3ControlIntents.swift" ) , "utf8" ) ;
101+ const intent = NodeFS . readFileSync ( NodePath . join ( iosRoot , "T3ControlIntents.swift" ) , "utf8" ) ;
56102 expect ( intent ) . toContain ( `"${ scheme } ://new"` ) ;
57103 expect ( NodeFS . readFileSync ( NodePath . join ( widgetRoot , "T3ControlIntents.swift" ) , "utf8" ) ) . toBe (
58104 intent ,
0 commit comments