@@ -73,22 +73,6 @@ async function updateEnvDependency(
7373}
7474```
7575
76- ### Updating workspace.jsonc
77-
78- Preserve team preferences for indentation when updating workspace config:
79-
80- ``` ts
81- import { updateJsoncPreservingFormatting } from ' @teambit/toolbox.json.jsonc-utils' ;
82-
83- const updatedWorkspace = updateJsoncPreservingFormatting (
84- workspaceContent ,
85- (config ) => {
86- config [' teambit.workspace/workspace' ].defaultScope = ' my-org.my-scope' ;
87- return config ;
88- }
89- );
90- ```
91-
9276### Working with Different Indentation Styles
9377
9478Handle files with different formatting preferences:
@@ -105,63 +89,3 @@ const updatedData = { ...parsedData, version: '2.0.0' };
10589// Stringify with original formatting
10690const result = stringifyJsonc (updatedData , formatting );
10791```
108-
109- ## Real-World Example
110-
111- This is exactly how Bit's ` bit update ` command preserves your env.jsonc formatting when updating dependencies:
112-
113- ``` ts
114- async updateEnvJsoncPolicies (outdatedPkgs ) {
115- await pMapSeries (components , async (component ) => {
116- const envJsoncFile = component .filesystem .files .find (
117- (file ) => file .relative === ' env.jsonc'
118- );
119- if (! envJsoncFile ) return ;
120-
121- const envJsoncContent = envJsoncFile .contents .toString ();
122- const updatedContent = updateJsoncPreservingFormatting (
123- envJsoncContent ,
124- (envJsonc ) => {
125- // Update dependency versions
126- const dep = envJsonc .policy ?.runtime ?.find (
127- (d ) => d .name === pkg .name
128- );
129- if (dep ) {
130- dep .version = pkg .latestRange ;
131- }
132- return envJsonc ;
133- }
134- );
135-
136- await fs .writeFile (absPath , updatedContent );
137- });
138- }
139- ```
140-
141- ## Type Definitions
142-
143- ``` ts
144- export type JsoncFormatting = {
145- indent: string ;
146- newline: string ;
147- };
148- ```
149-
150- ## Why Preserve Formatting?
151-
152- When working in teams, developers often have different preferences for code formatting:
153- - Some prefer 2 spaces, others 4 spaces or tabs
154- - Windows users might have CRLF line endings
155- - Comments provide important context
156-
157- By preserving the original formatting, you avoid:
158- - ❌ Unnecessary git diffs
159- - ❌ Formatting debates in code reviews
160- - ❌ Lost comments and documentation
161- - ❌ Breaking team conventions
162-
163- Instead, you get:
164- - ✅ Clean, minimal diffs showing only actual changes
165- - ✅ Preserved comments and documentation
166- - ✅ Respect for team and individual preferences
167- - ✅ Better collaboration
0 commit comments