@@ -119,23 +119,14 @@ function writeSidecar(appRoot, frameworks) {
119119}
120120
121121function projectFiles ( xcodeprojPath ) {
122- const files = { } ;
123- const walk = dir => {
124- for ( const entry of fs . readdirSync ( dir , { withFileTypes : true } ) ) {
125- const full = path . join ( dir , entry . name ) ;
126- if ( entry . isDirectory ( ) ) {
127- walk ( full ) ;
128- } else {
129- files [ path . relative ( xcodeprojPath , full ) ] = fs . readFileSync ( full ) ;
130- }
131- }
132- } ;
133- walk ( xcodeprojPath ) ;
134- return files ;
122+ return [ 'project.pbxproj' , SPM_INJECTED_MARKER ] . map ( name => {
123+ const file = path . join ( xcodeprojPath , name ) ;
124+ return fs . existsSync ( file ) ? fs . readFileSync ( file , 'utf8' ) : null ;
125+ } ) ;
135126}
136127
137- // Runs the check and proves it wrote nothing under the .xcodeproj (pbxproj,
138- // marker, scheme). Returns the printed lines and the thrown error, if any.
128+ // Runs the check and proves it wrote neither the pbxproj nor the marker.
129+ // Returns the printed lines and the thrown error, if any.
139130function check ( app , env = { } ) {
140131 const before = projectFiles ( app . xcodeprojPath ) ;
141132 let error = null ;
@@ -175,24 +166,6 @@ describe('assertPluginFrameworksLinked', () => {
175166 ] ) ;
176167 } ) ;
177168
178- it ( 'reports every mismatch in both directions' , ( ) => {
179- const app = scaffoldApp ( ) ;
180- const other = frameworkEntry (
181- 'other-plugin' ,
182- 'OtherPlugin' ,
183- 'plugins/other-plugin.xcframework' ,
184- ) ;
185- inject ( app , [ REACT , EXPO ] ) ;
186- writeSidecar ( app . appRoot , [ other ] ) ;
187-
188- const { error, lines} = check ( app ) ;
189-
190- expect ( error ) . toBeInstanceOf ( PluginFrameworkMismatchError ) ;
191- expect ( lines ) . toHaveLength ( 2 ) ;
192- expect ( lines [ 0 ] ) . toMatch ( / ^ e r r o r : O t h e r P l u g i n \( o t h e r - p l u g i n \) / ) ;
193- expect ( lines [ 1 ] ) . toMatch ( / ^ e r r o r : T h e X c o d e p r o j e c t l i n k s E x p o C o r e \. / ) ;
194- } ) ;
195-
196169 it ( 'fails when a plugin renames its framework but keeps its id' , ( ) => {
197170 const app = scaffoldApp ( ) ;
198171 inject ( app , [ REACT , EXPO ] ) ;
@@ -238,25 +211,12 @@ describe('assertPluginFrameworksLinked', () => {
238211 inject ( app , [ REACT , HERMES , EXPO ] ) ;
239212 writeSidecar ( app . appRoot , [ EXPO ] ) ;
240213 fs . rmSync (
241- path . join (
242- app . appRoot ,
243- 'build' ,
244- 'xcframeworks' ,
245- 'flavored-frameworks.json' ,
246- ) ,
214+ path . join ( app . appRoot , 'build/xcframeworks/flavored-frameworks.json' ) ,
247215 ) ;
248216
249217 expect ( check ( app ) ) . toEqual ( { error : null , lines : [ ] } ) ;
250218 } ) ;
251219
252- it ( 'never reports built-in frameworks' , ( ) => {
253- const app = scaffoldApp ( ) ;
254- inject ( app , [ REACT , HERMES ] ) ;
255- writeSidecar ( app . appRoot , [ ] ) ;
256-
257- expect ( check ( app ) ) . toEqual ( { error : null , lines : [ ] } ) ;
258- } ) ;
259-
260220 it ( 'skips a project that was never injected' , ( ) => {
261221 const app = scaffoldApp ( ) ;
262222 writeSidecar ( app . appRoot , [ EXPO ] ) ;
@@ -268,27 +228,19 @@ describe('assertPluginFrameworksLinked', () => {
268228 const app = scaffoldApp ( ) ;
269229 inject ( app , [ REACT ] ) ;
270230 writeSidecar ( app . appRoot , [ EXPO ] ) ;
271- const markerPath = path . join ( app . xcodeprojPath , SPM_INJECTED_MARKER ) ;
272- const marker = JSON . parse ( fs . readFileSync ( markerPath , 'utf8' ) ) ;
273- fs . writeFileSync (
274- markerPath ,
275- JSON . stringify ( { ...marker , rootUuid : 'NOT_THE_PROJECT_ROOT' } ) ,
276- ) ;
231+ fs . writeFileSync ( path . join ( app . xcodeprojPath , 'project.pbxproj' ) , PLAIN ) ;
277232
278233 expect ( check ( app ) ) . toEqual ( { error : null , lines : [ ] } ) ;
279234 } ) ;
280235} ) ;
281236
282- describe ( 'injectSpmIntoExistingXcodeproj with a plugin framework' , ( ) => {
283- it ( 'is idempotent' , ( ) => {
284- const app = scaffoldApp ( ) ;
285- inject ( app , [ REACT , EXPO ] ) ;
286- const pbxprojPath = path . join ( app . xcodeprojPath , 'project.pbxproj' ) ;
287- const once = fs . readFileSync ( pbxprojPath , 'utf8' ) ;
288- expect ( once ) . toContain ( '$(RN_SPM_EXPO_CORE_FRAMEWORK)' ) ;
237+ it ( 'injects a plugin framework idempotently' , ( ) => {
238+ const app = scaffoldApp ( ) ;
239+ inject ( app , [ REACT , EXPO ] ) ;
240+ const pbxprojPath = path . join ( app . xcodeprojPath , 'project.pbxproj' ) ;
241+ const once = fs . readFileSync ( pbxprojPath , 'utf8' ) ;
289242
290- inject ( app , [ REACT , EXPO ] ) ;
243+ inject ( app , [ REACT , EXPO ] ) ;
291244
292- expect ( fs . readFileSync ( pbxprojPath , 'utf8' ) ) . toBe ( once ) ;
293- } ) ;
245+ expect ( fs . readFileSync ( pbxprojPath , 'utf8' ) ) . toBe ( once ) ;
294246} ) ;
0 commit comments