refactor: replace JSON round-trip with explicit deepStripUndefined utility#7284
refactor: replace JSON round-trip with explicit deepStripUndefined utility#7284alfonso-noriega wants to merge 2 commits into
Conversation
The empty catch block in app-logs-polling.ts silently swallowed all errors during app logs setup, making failures invisible to developers. Added outputDebug logging so errors are captured in debug output instead of being silently discarded.
…ility The analytics payload builder used JSON.parse(JSON.stringify(payload)) to strip undefined fields. While functionally correct, the intent is non-obvious — it relies on a side-effect of JSON serialization. Added a dedicated deepStripUndefined() utility to cli-kit's object module with full test coverage, and replaced the JSON round-trip in analytics.ts. This makes the code self-documenting. Note: this is a readability improvement, not a performance one — the operation runs once per CLI command and takes ~2µs either way.
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/common/object.d.ts@@ -84,4 +84,12 @@ export declare function isEmpty(object: object): boolean;
* @param object - The object whose undefined will be deleted.
* @returns A copy of the object with the undefined elements deleted.
*/
-export declare function compact(object: object): object;
\ No newline at end of file
+export declare function compact(object: object): object;
+/**
+ * Recursively removes properties with values from an object.
+ * Arrays are traversed but not filtered. Non-object values are returned as-is.
+ *
+ * @param value - The value to strip undefined fields from.
+ * @returns A deep copy of the value with all undefined-valued keys removed.
+ */
+export declare function deepStripUndefined<T>(value: T): T;
\ No newline at end of file
packages/cli-kit/dist/public/node/node-package-manager.d.ts@@ -60,10 +60,6 @@ export declare class FindUpAndReadPackageJsonNotFoundError extends BugError {
export declare function packageManagerFromUserAgent(env?: NodeJS.ProcessEnv): PackageManager;
/**
* Returns the dependency manager used in a directory.
- * Walks upward from so workspace packages (e.g. )
- * still resolve to the repo root lockfile ().
- * If no lockfile is found, it falls back to the package manager from the user agent.
- * If the package manager from the user agent is unknown, it returns 'npm'.
* @param fromDirectory - The starting directory
* @returns The dependency manager
*/
packages/cli-kit/dist/public/node/upgrade.d.ts@@ -28,14 +28,11 @@ export declare function versionToAutoUpgrade(): string | undefined;
export declare function warnIfUpgradeAvailable(): Promise<void>;
/**
* Generates a message to remind the user to update the CLI.
- * For major version bumps, appends a link to the GitHub release notes so users
- * can review breaking changes before deciding to upgrade.
*
* @param version - The version to update to.
- * @param isMajor - Whether the version bump is a major version change.
* @returns The message to remind the user to update the CLI.
*/
-export declare function getOutputUpdateCLIReminder(version: string, isMajor?: boolean): string;
+export declare function getOutputUpdateCLIReminder(version: string): string;
/**
* Prompts the user to enable or disable automatic upgrades, then persists their choice.
*
packages/cli-kit/dist/private/node/ui/components/DangerousConfirmationPrompt.d.ts@@ -1,4 +1,3 @@
-import { InlineToken, TokenItem } from './TokenizedText.js';
import { InfoTableProps } from './Prompts/InfoTable.js';
import { AbortSignal } from '../../../../public/node/abort.js';
import { FunctionComponent } from 'react';
@@ -6,7 +5,6 @@ export interface DangerousConfirmationPromptProps {
message: string;
confirmation: string;
infoTable?: InfoTableProps['table'];
- warningItem?: TokenItem<InlineToken>;
onSubmit: (value: boolean) => void;
abortSignal?: AbortSignal;
}
|
|
This PR seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. |
3a69a9a to
fb3eac1
Compare

WHY are these changes introduced?
Fixes #0000
WHAT is this pull request doing?
How to test your changes?
Post-release steps
Checklist
pnpm changeset add