-
Notifications
You must be signed in to change notification settings - Fork 946
feat: bit update should update dependencies in env.jsonc #10128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zkochan
wants to merge
15
commits into
teambit:master
Choose a base branch
from
zkochan:update-env-jsonc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+785
−28
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c9dd8ce
feat: bit update should update dependencies in env.jsonc
zkochan aebcee6
remove redundant import
zkochan be82c86
Merge branch 'master' into update-env-jsonc
zkochan fc2082e
Merge branch 'master' into update-env-jsonc
zkochan 3d3ab9d
Merge branch 'master' into update-env-jsonc
zkochan c811f72
fix: implemented CR suggestions
zkochan 2b5eabf
fix: implemented CR suggestions
zkochan ae29be1
fix: implemented CR suggestions
zkochan bad13be
test: fix
zkochan 3b0c7ab
Merge branch 'master' into update-env-jsonc
zkochan 5585c44
fix: implemented CR suggestions
zkochan 006b23f
fix: implemented CR suggestions
zkochan 31987b7
fix: linting issues
zkochan 2280e0d
docs: use less examples
zkochan 6df1cc9
Merge branch 'master' into update-env-jsonc
zkochan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
scopes/dependencies/dependency-resolver/policy/env-policy/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| export { EnvPolicy, EnvPolicyConfigObject } from './env-policy'; | ||
| export { EnvPolicy, EnvPolicyConfigObject, EnvJsoncPolicyEntry, EnvPolicyEnvJsoncConfigObject } from './env-policy'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export { | ||
| detectJsoncFormatting, | ||
| parseJsoncWithFormatting, | ||
| stringifyJsonc, | ||
| updateJsoncPreservingFormatting, | ||
| type JsoncFormatting, | ||
| } from './jsonc-utils'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| labels: ['typescript', 'utils', 'json', 'jsonc', 'formatting', 'comments', 'parser'] | ||
| description: 'Utilities for parsing and stringifying JSONC files while preserving formatting and comments.' | ||
| --- | ||
|
|
||
| # JSONC Utils | ||
|
|
||
| Utilities for working with JSONC (JSON with Comments) files while preserving their original formatting, including: | ||
| - **Indentation style** (2 spaces, 4 spaces, tabs) | ||
| - **Newline characters** (LF, CRLF) | ||
| - **Comments** | ||
|
|
||
| This is particularly useful when you need to programmatically update configuration files without losing their human-readable formatting. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| bit install @teambit/toolbox.json.jsonc-utils | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| The easiest way to update a JSONC file while preserving its formatting: | ||
|
|
||
| ```ts | ||
| import { updateJsoncPreservingFormatting } from '@teambit/toolbox.json.jsonc-utils'; | ||
|
|
||
| const originalContent = `{ | ||
| // This is a comment | ||
| "name": "my-package", | ||
| "version": "1.0.0" | ||
| }`; | ||
|
|
||
| const updatedContent = updateJsoncPreservingFormatting(originalContent, (data) => { | ||
| data.version = "2.0.0"; | ||
| return data; | ||
| }); | ||
|
|
||
| // Output preserves comments and formatting: | ||
| // { | ||
| // // This is a comment | ||
| // "name": "my-package", | ||
| // "version": "2.0.0" | ||
| // } | ||
| ``` | ||
|
|
||
| ## Use Cases | ||
|
|
||
| ### Updating env.jsonc Files | ||
|
|
||
| When updating component environment configurations, preserve the original formatting: | ||
|
|
||
| ```ts | ||
| import fs from 'fs-extra'; | ||
| import { updateJsoncPreservingFormatting } from '@teambit/toolbox.json.jsonc-utils'; | ||
|
|
||
| async function updateEnvDependency( | ||
| envJsoncPath: string, | ||
| pkgName: string, | ||
| newVersion: string | ||
| ) { | ||
| const content = await fs.readFile(envJsoncPath, 'utf-8'); | ||
|
|
||
| const updated = updateJsoncPreservingFormatting(content, (envJsonc) => { | ||
| const dep = envJsonc.policy?.runtime?.find((d) => d.name === pkgName); | ||
| if (dep) { | ||
| dep.version = newVersion; | ||
| } | ||
| return envJsonc; | ||
| }); | ||
|
|
||
| await fs.writeFile(envJsoncPath, updated); | ||
| } | ||
| ``` | ||
|
|
||
| ### Working with Different Indentation Styles | ||
|
|
||
| Handle files with different formatting preferences: | ||
|
|
||
| ```ts | ||
| import { detectJsoncFormatting, stringifyJsonc } from '@teambit/toolbox.json.jsonc-utils'; | ||
|
|
||
| // Detect existing formatting | ||
| const formatting = detectJsoncFormatting(originalContent); | ||
|
|
||
| // Modify data | ||
| const updatedData = { ...parsedData, version: '2.0.0' }; | ||
|
|
||
| // Stringify with original formatting | ||
| const result = stringifyJsonc(updatedData, formatting); | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.