@@ -6,6 +6,14 @@ import ignoreModule from 'ignore';
66const ignore = ignoreModule . default || ignoreModule ;
77type Ignore = ReturnType < typeof ignore > ;
88
9+ // Files that must never be pushed, deleted, or overwritten on the server via CLI.
10+ // These are server-managed config files - corrupting them can break a realm.
11+ export const PROTECTED_FILES = new Set ( [ '.realm.json' ] ) ;
12+
13+ export function isProtectedFile ( relativePath : string ) : boolean {
14+ return PROTECTED_FILES . has ( relativePath ) ;
15+ }
16+
917export const SupportedMimeType = {
1018 CardJson : 'application/vnd.card+json' ,
1119 CardSource : 'application/vnd.card+source' ,
@@ -142,27 +150,6 @@ export abstract class RealmSyncBase {
142150 throw error ;
143151 }
144152
145- // Check for .realm.json in root directory
146- if ( ! dir ) {
147- try {
148- const realmJsonUrl = this . buildFileUrl ( '.realm.json' ) ;
149- const jwt = await this . realmAuthClient . getJWT ( ) ;
150-
151- const response = await fetch ( realmJsonUrl , {
152- method : 'HEAD' ,
153- headers : {
154- Authorization : jwt ,
155- } ,
156- } ) ;
157-
158- if ( response . ok ) {
159- files . set ( '.realm.json' , true ) ;
160- }
161- } catch {
162- console . log ( 'Note: .realm.json not found in remote realm' ) ;
163- }
164- }
165-
166153 return files ;
167154 }
168155
@@ -289,6 +276,11 @@ export abstract class RealmSyncBase {
289276 }
290277
291278 protected async uploadFile ( relativePath : string , localPath : string ) : Promise < void > {
279+ if ( isProtectedFile ( relativePath ) ) {
280+ console . log ( ` Skipped (protected): ${ relativePath } ` ) ;
281+ return ;
282+ }
283+
292284 console . log ( `Uploading: ${ relativePath } ` ) ;
293285
294286 if ( this . options . dryRun ) {
@@ -362,6 +354,11 @@ export abstract class RealmSyncBase {
362354 }
363355
364356 protected async deleteFile ( relativePath : string ) : Promise < void > {
357+ if ( isProtectedFile ( relativePath ) ) {
358+ console . log ( ` Skipped (protected): ${ relativePath } ` ) ;
359+ return ;
360+ }
361+
365362 console . log ( `Deleting remote: ${ relativePath } ` ) ;
366363
367364 if ( this . options . dryRun ) {
@@ -451,9 +448,6 @@ export abstract class RealmSyncBase {
451448 }
452449
453450 if ( fileName . startsWith ( '.' ) ) {
454- if ( fileName === '.realm.json' ) {
455- return false ;
456- }
457451 return true ;
458452 }
459453
@@ -467,9 +461,6 @@ export abstract class RealmSyncBase {
467461 private shouldIgnoreRemoteFile ( relativePath : string ) : boolean {
468462 const fileName = path . basename ( relativePath ) ;
469463 if ( fileName . startsWith ( '.' ) ) {
470- if ( fileName === '.realm.json' ) {
471- return false ;
472- }
473464 return true ;
474465 }
475466 return false ;
0 commit comments