Skip to content

chore(setup): add SDK init/injection library and templates - #751

Open
ffantl-ld wants to merge 1 commit into
ffantl/setup-ld/2-installerfrom
ffantl/setup-ld/3-initializer
Open

chore(setup): add SDK init/injection library and templates#751
ffantl-ld wants to merge 1 commit into
ffantl/setup-ld/2-installerfrom
ffantl/setup-ld/3-initializer

Conversation

@ffantl-ld

@ffantl-ld ffantl-ld commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Describe the solution you've provided

Third layer of the guided setup command: SDK initialization. Renders per-SDK code snippets from embedded templates and injects them into the project (Initializer, RenderTemplate, InjectIntoFile), plus docs-URL helpers. Ships the sdk_init_templates/ for the supported SDKs.

Independent library layer.

Related issues

Part of the setup-ld feature. Stacked PR — base is ffantl/setup-ld/2-installer.

Requirements

  • I have added test coverage for new or changed functionality

Note

Medium Risk
Append-safe paths write to user-specified files (create or modify), so callers must pass correct paths; guidance-only paths avoid corrupting compiled/framework projects.

Overview
Adds an SDK initialization layer for guided setup: embedded per-SDK templates render init code from InitConfig (SDK key, client-side ID, mobile key, flag key), and InjectIntoFile either writes into the project or returns copy-paste guidance.

In-place injection is limited to append-safe interpreted entrypoints (Node, Python, Ruby): imports are prepended and init code appended, with // --- init --- / # --- init --- stripped from output. Go, Java, C#, Swift, Android, React, and React Native never modify files—InitResult returns Success: false with a Snippet and DocsURL so callers do not treat broken appended code as done. SDKs without templates only get documentation links via a broad sdkDocsPaths map and GetDocsURL.

Ships 11 sdk_init_templates/*.tmpl files plus unit tests covering rendering, injection, guidance-only paths, and docs fallbacks.

Reviewed by Cursor Bugbot for commit c56c506. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ffantl-ld
ffantl-ld marked this pull request as ready for review July 27, 2026 17:23
@ffantl-ld
ffantl-ld requested review from Vadman97 and erangeles July 27, 2026 17:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c56c506. Configure here.

// --- init ---
const ldClient = new LDClient();
const context = { kind: 'user', key: 'example-user-key', name: 'Example User' };
await ldClient.configure({ mobileKey: '{{.MobileKey}}' }, context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Native template API mismatch

High Severity

The React Native init snippet imports @launchdarkly/react-native-client-sdk (v10) but uses the v9 LDClient default export and configure() API. That package exposes ReactNativeLDClient instead, so the guidance snippet does not run against the imported SDK.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.

"python-server-sdk": "sdk/server-side/python",
"react-client-sdk": "sdk/client-side/react",
"react-native": "sdk/client-side/react-native",
"react-native-client-sdk": "sdk/client-side/react-native",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect React Native docs URL

Medium Severity

sdkDocsPaths maps react-native and react-native-client-sdk to sdk/client-side/react-native, but the live docs live at sdk/client-side/react/react-native. GetDocsURL therefore returns a dead link for those IDs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.


content := string(existing)
if importSection != "" {
content = importSection + "\n" + content

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import prepend breaks shebang

High Severity

For append-safe SDKs, InjectIntoFile always prepends the import section at byte 0 of an existing file. That displaces a leading shebang and Python encoding cookies, so common entry points like manage.py stop being directly executable.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.

@@ -0,0 +1,12 @@
import * as LDClient from 'launchdarkly-js-client-sdk';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS client package name mismatch

Medium Severity

The JS client init template imports launchdarkly-js-client-sdk, but the stacked installer layer installs @launchdarkly/js-client-sdk for the same SDK ID. After a successful install, the rendered snippet’s import does not resolve to the installed package.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.

@ffantl-ld
ffantl-ld requested review from a team and removed request for Vadman97 July 28, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant