Skip to content
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

Type generating CLI #301

Draft
wants to merge 79 commits into
base: main
Choose a base branch
from
Draft

Type generating CLI #301

wants to merge 79 commits into from

Conversation

roncohen
Copy link
Contributor

@roncohen roncohen commented Jan 30, 2025

This is a two part PR with a CLI that generates a package _bucket and updates the browser/react SDK to optionally make use of the _bucket package.

It's a lot of added complexity, so any suggestions on simplifying would be greatly appreciated.

CLI

This introduces a new minimalistic CLI package which can:

  • bucket init: writes an almost empty bucket.config.json file
  • bucket features add: add a new feature to bucket.config.json and call features generate
  • bucket features generate: write the _bucket package out based off of bucket.config.json.

thanks to @Swiftwork for laying the ground work for the CLI!

Browser/React SDK

The goal here has been to keep the option to use both libraries without the generated _bucket package and CLI. There's no way to do try { import ... from "_bucket" } catch {} because there's no runtime importing going on. At compile-time there's a bundler that runs and resolves all the imported packages. If you import a package that imports from "_bucket" and that module doesn't exist, you'll get an error.

So, this introduces two sets of files, for each of the Browser and React SDKs:

  • a basic set which contains no reference to generated types but is generic so you can "just" fill in the generated types
  • a set which relies on a generated package, tentatively called _bucket. This set imports from the _bucket package and exposes a bunch the same classes/types but with the type arguments filled in.

Example:

  • BrowserSDK now has two entry points: @bucketco/browser-sdk and @bucketco/browser-sdk/configuredClient. @bucketco/browser-sdk exposes the generic version of the BucketClient: BucketClient<FeatureDefs> and doesn't use the _bucket package, while @bucketco/browser-sdk/configuredClient exposes a BucketClientConfigured which already has the types from the generated _bucket package inserted along with the list of features (the types get removed at compile time, but since we want the toolbar to show the list of features locally, we also need to include an actual list as opposed to just the types).

Similarly, in the ReactSDK we go on the assumption that people will be using the CLI workflow to generate types and this importing @bucketco/react-sdk will give you a BucketProvider which already has the types and the feature list loaded in from _bucket. It imports @bucketco/browser-sdk/configuredClient which does the hard work. You can still import @bucketco/react/baseBucketProvider to get a vanilla BucketProvider without the types/features loaded in.

Why _bucket

I started out with .bucket but unfortunately rollup refuses to resolve it. It works for Prisma because they rely on Node.js package resolving while we have to deal with bundlers. Other options could be @bucketco/_generated @bucketco/_generated-config or similar

UMD build

Unfortunately, vite doesn't support building a UMD when there are multiple entrypoints. We have multiple entrypoints to allow folks to use the libraries without the generated _bucket package. We can probably work around it if we think it's important.

Swiftwork and others added 30 commits January 10, 2025 13:44
…ample (#289)

Bumps [nanoid](https://github.com/ai/nanoid) from 3.3.7 to 3.3.8.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/ai/nanoid/blob/main/CHANGELOG.md">nanoid's
changelog</a>.</em></p>
<blockquote>
<h2>3.3.8</h2>
<ul>
<li>Fixed a way to break Nano ID by passing non-integer size (by <a
href="https://github.com/myndzi"><code>@​myndzi</code></a>).</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/ai/nanoid/commit/3044cd5e73f4cf31795f61f6e6b961c8c0a5c744"><code>3044cd5</code></a>
Release 3.3.8 version</li>
<li><a
href="https://github.com/ai/nanoid/commit/4fe34959c34e5b3573889ed4f24fe91d1d3e7231"><code>4fe3495</code></a>
Update size limit</li>
<li><a
href="https://github.com/ai/nanoid/commit/d643045f40d6dc8afa000a644d857da1436ed08c"><code>d643045</code></a>
Fix pool pollution, infinite loop (<a
href="https://redirect.github.com/ai/nanoid/issues/510">#510</a>)</li>
<li>See full diff in <a
href="https://github.com/ai/nanoid/compare/3.3.7...3.3.8">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nanoid&package-manager=npm_and_yarn&previous-version=3.3.7&new-version=3.3.8)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/bucketco/bucket-javascript-sdk/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This is a piece of infrastructure needed for local overrides. We will
likely need a few adjustments to this as we go about building the
toolbar on top, but this is a good base.
roncohen and others added 28 commits January 29, 2025 10:25
…config` option. (#285)

This PR introduces the `config`, which is an user-supplied JSON value
that matches a given feature context (similar to targeting). The
resolved configuration variant is then passed down to the client SDKs
for use.
Was missing in the previous alpha release, which meant that the value of
the `toolbar` prop wasn't correctly configured in the browser SDK.
This PR adds support for remote configuration to the node-sdk.
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.

6 participants