-
Notifications
You must be signed in to change notification settings - Fork 4
fix: if json variable, use stringified value for reco #551
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,64 +12,19 @@ import { | |||||||
| fetchFeatures, | ||||||||
| } from '../../api/features' | ||||||||
| import { fetchCustomProperties } from '../../api/customProperties' | ||||||||
|
|
||||||||
| const reactImports = (oldRepos: boolean, strictCustomData: boolean) => { | ||||||||
| if (oldRepos) { | ||||||||
| return `import { DVCVariable, DVCVariableValue } from '@devcycle/devcycle-js-sdk' | ||||||||
| import { | ||||||||
| useVariable as originalUseVariable, | ||||||||
| useVariableValue as originalUseVariableValue | ||||||||
| } from '@devcycle/devcycle-react-sdk' | ||||||||
|
|
||||||||
| export type DevCycleJSON = { [key: string]: string | boolean | number } | ||||||||
|
|
||||||||
| ` | ||||||||
| } else { | ||||||||
| return `import { | ||||||||
| useVariable as originalUseVariable, | ||||||||
| useVariableValue as originalUseVariableValue, | ||||||||
| DVCVariable, | ||||||||
| DVCVariableValue,${!strictCustomData ? '\n DVCCustomDataJSON,' : ''} | ||||||||
| DevCycleJSON | ||||||||
| } from '@devcycle/react-client-sdk' | ||||||||
|
|
||||||||
| ` | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| const nextImports = (strictCustomData: boolean) => { | ||||||||
| return `import { | ||||||||
| useVariable as originalUseVariable, | ||||||||
| useVariableValue as originalUseVariableValue, | ||||||||
| DVCVariable, | ||||||||
| DVCVariableValue,${!strictCustomData ? '\n DVCCustomDataJSON,' : ''} | ||||||||
| DevCycleJSON | ||||||||
| } from '@devcycle/nextjs-sdk' | ||||||||
|
|
||||||||
| ` | ||||||||
| } | ||||||||
|
|
||||||||
| const reactOverrides = ` | ||||||||
| export type UseVariableValue = < | ||||||||
| K extends string & keyof DVCVariableTypes | ||||||||
| >( | ||||||||
| key: K, | ||||||||
| defaultValue: DVCVariableTypes[K] | ||||||||
| ) => DVCVariableTypes[K] | ||||||||
|
|
||||||||
| export const useVariableValue = originalUseVariableValue as UseVariableValue | ||||||||
|
|
||||||||
| export type UseVariable = < | ||||||||
| K extends string & keyof DVCVariableTypes, | ||||||||
| T extends DVCVariableValue & DVCVariableTypes[K], | ||||||||
| >( | ||||||||
| key: K, | ||||||||
| defaultValue: DVCVariableTypes[K] | ||||||||
| ) => DVCVariable<T> | ||||||||
|
|
||||||||
| export const useVariable = originalUseVariable as UseVariable | ||||||||
|
|
||||||||
| ` | ||||||||
| blockComment, | ||||||||
| findCreatorName, | ||||||||
| generateCustomDataType, | ||||||||
| getRecommendedValueForStale, | ||||||||
| getVariableType, | ||||||||
| isVariableDeprecated, | ||||||||
| isVariableStale, | ||||||||
| nextImports, | ||||||||
| reactImports, | ||||||||
| reactOverrides, | ||||||||
| sanitizeDescription, | ||||||||
| } from '../../utils/types' | ||||||||
|
|
||||||||
| export default class GenerateTypes extends Base { | ||||||||
| static hidden = false | ||||||||
|
|
@@ -324,8 +279,38 @@ export default class GenerateTypes extends Base { | |||||||
| variable, | ||||||||
| staleInfo.feature as Feature, | ||||||||
| ) | ||||||||
|
|
||||||||
| const formatRecommendedValueForComment = ( | ||||||||
| recommendedValue: string, | ||||||||
| ) => { | ||||||||
| if (recommendedValue) { | ||||||||
| try { | ||||||||
| const parsed = JSON.parse(recommendedValue) | ||||||||
| if (typeof parsed === 'object' && parsed !== null) { | ||||||||
| const indentation = indent ? ' ' : '' | ||||||||
| const jsonString = JSON.stringify(parsed, null, 4) | ||||||||
| return ( | ||||||||
| '\n' + | ||||||||
| jsonString | ||||||||
| .split('\n') | ||||||||
| .map((line) => | ||||||||
| line ? indentation + line : line, | ||||||||
| ) | ||||||||
| .join('\n') + | ||||||||
| '\n' | ||||||||
| ) | ||||||||
| } | ||||||||
| } catch { | ||||||||
|
||||||||
| } catch { | |
| } catch { | |
| // If JSON parsing fails, fall back to using the raw recommendedValue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation logic doesn't add the comment prefix (' * ') that's required for block comments. The blockComment function expects staleWarning to be formatted as a single line with the comment prefix already applied (see line 41 in blockComment). The current implementation adds indentation but not the ' * ' prefix needed for multi-line comment content. This will result in malformed JSDoc comments when the recommended value is a JSON object.