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

[EDU-1816] - Add NPM Workspaces to examples #2419

Merged

Conversation

GregHolmes
Copy link
Contributor

@GregHolmes GregHolmes commented Feb 5, 2025

This is a trial to see if this implementation of NPM Workspaces would work.
I have carried this out for pub-sub-connection-state. To test it. You would:

  • In /examples/ run yarn install
  • mv /examples/.env.example /examples/.env.local
  • Update the ENV variables in .env.local
  • In /examples/ run yarn workspace pub-sub-connection-state-react dev for react or run yarn workspace pub-sub-connection-state-javascript dev for javascript.

Summary by CodeRabbit

  • New Features

    • Enhanced environment configuration for real-time messaging support.
  • Chores

    • Introduced a new project configuration for the React sample.
    • Rebranded and streamlined workspace setups by removing outdated dependency declarations.
  • Documentation

    • Updated instructions and navigation commands to streamline the process of launching development servers.

@GregHolmes GregHolmes self-assigned this Feb 5, 2025
Copy link

coderabbitai bot commented Feb 5, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces new Ably environment variables in the main examples configuration and a new React package configuration via a comprehensive package.json. In the pub-sub-connection-state subdirectories for both JavaScript and React, environment variables for Ably are removed, package names are updated, and dependency sections are eliminated. Additionally, navigation and startup commands in README files are revised to reflect the new workspace structure. A new Next.js configuration file with dotenv support is added, replacing an older configuration file, and the Vite configuration is enhanced with dotenv integration and minor formatting adjustments.

Changes

File(s) Summary
examples/.env.example Added VITE_PUBLIC_ABLY_KEY and NEXT_PUBLIC_ABLY_KEY for Ably configuration.
examples/pub-sub-connection-state/react/.env.example
examples/pub-sub-connection-state/javascript/.env.example
Removed unused Ably environment variables (NEXT_PUBLIC_ABLY_KEY from React and VITE_PUBLIC_ABLY_KEY from JavaScript).
examples/package.json New React project configuration with workspaces, dependencies, and devDependencies defined.
examples/pub-sub-connection-state/react/package.json
examples/pub-sub-connection-state/javascript/package.json
Updated package names to pub-sub-connection-state-react and pub-sub-connection-state-javascript respectively; removed dependencies and devDependencies.
examples/pub-sub-connection-state/react/README.md
examples/pub-sub-connection-state/javascript/README.md
examples/pub-sub-connection-state/page.md
Updated directory navigation and development server commands to align with the new workspace structure.
examples/pub-sub-connection-state/javascript/vite.config.ts Introduced dotenv configuration from a shared .env.local file and reformatted CSS configuration syntax.
examples/pub-sub-connection-state/react/next.config.mjs
examples/pub-sub-connection-state/react/next.config.ts
Added new Next.js configuration with dotenv support in next.config.mjs and removed the obsolete next.config.ts file.

Poem

Hopping through the code, I cheer,
New keys and configs now appear.
With workspaces aligned and paths refined,
My byte-sized carrots are perfectly designed.
I, the rabbit, dance with glee—
A joyous leap in our repository! 🐰🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ably-ci ably-ci temporarily deployed to ably-docs-edu-1816-crea-t8xdpr February 5, 2025 14:08 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-edu-1816-crea-t8xdpr February 6, 2025 14:05 Inactive
Copy link
Member

@jamiehenson jamiehenson left a comment

Choose a reason for hiding this comment

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

@GregHolmes - nice, I like it. Looks pretty clean from a first go of it. To go further though I need VITE_PUBLIC_ABLY_KEY and NEXT_PUBLIC_ABLY_KEY - where can I get those? (sorry, new to examples testing)

As an aside here I would change the dev command for the main docs to be yarn dev (instead of develop) so that it aligns with the conventions here and everywhere else. Tbh though, I have ideas to push for changing the package manager to pnpm across web repos since Yarn 1 is a bit long in the tooth, not sure if you have any views on that. It would be a trivial migration from a workspace perspective (not suggesting we do this now, it's a medium term thing).

I'm also just going to kick off a bot review to see if that sees anything outside of the fairly standard convention I see here

@jamiehenson
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Feb 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
examples/pub-sub-connection-state/page.md (1)

88-90: Environment Variable Name Inconsistency
There is an inconsistency in the JavaScript section: step 4 instructs updating VITE_PUBLIC_API_KEY while the JavaScript README uses VITE_PUBLIC_ABLY_KEY. This mismatch may confuse users. Please confirm the intended variable name and update to ensure consistency across documentation.

Suggested diff (if VITE_PUBLIC_ABLY_KEY is intended):

-4. In `.env.local` update the value of `VITE_PUBLIC_API_KEY` to be your Ably API key.
+4. In `.env.local` update the value of `VITE_PUBLIC_ABLY_KEY` to be your Ably API key.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2977771 and f96bb29.

⛔ Files ignored due to path filters (2)
  • examples/pub-sub-connection-state/javascript/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
  • examples/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (12)
  • examples/.env.example (1 hunks)
  • examples/package.json (1 hunks)
  • examples/pub-sub-connection-state/javascript/.env.example (0 hunks)
  • examples/pub-sub-connection-state/javascript/README.md (2 hunks)
  • examples/pub-sub-connection-state/javascript/package.json (1 hunks)
  • examples/pub-sub-connection-state/javascript/vite.config.ts (1 hunks)
  • examples/pub-sub-connection-state/page.md (4 hunks)
  • examples/pub-sub-connection-state/react/.env.example (0 hunks)
  • examples/pub-sub-connection-state/react/README.md (2 hunks)
  • examples/pub-sub-connection-state/react/next.config.mjs (1 hunks)
  • examples/pub-sub-connection-state/react/next.config.ts (0 hunks)
  • examples/pub-sub-connection-state/react/package.json (1 hunks)
💤 Files with no reviewable changes (3)
  • examples/pub-sub-connection-state/react/.env.example
  • examples/pub-sub-connection-state/javascript/.env.example
  • examples/pub-sub-connection-state/react/next.config.ts
✅ Files skipped from review due to trivial changes (4)
  • examples/.env.example
  • examples/pub-sub-connection-state/react/package.json
  • examples/pub-sub-connection-state/javascript/package.json
  • examples/package.json
🔇 Additional comments (11)
examples/pub-sub-connection-state/react/README.md (2)

16-17: Directory Navigation Update Looks Good
The change to use cd /examples/ simplifies navigation and aligns with the new workspace structure.


36-37: Updated Server Startup Command is Clear
The updated command yarn workspace pub-sub-connection-state-react dev clearly reflects the new workspace setup for the React example.

examples/pub-sub-connection-state/javascript/README.md (2)

16-17: Consistent Directory Command
Changing to cd /examples/ streamlines the instructions and matches the React example.


36-37: Updated Workspace Command for JavaScript
The change to yarn workspace pub-sub-connection-state-javascript dev is properly aligned with the new workspace structure.

examples/pub-sub-connection-state/page.md (4)

44-45: Unified Navigation for React & JavaScript
The updated command cd /examples/ in the React section simplifies directory navigation and is consistent with the individual README files.


64-65: Updated React Server Command in Page Documentation
Using yarn workspace pub-sub-connection-state-react dev clearly indicates the correct workspace command for the React example.


80-81: Consistent JavaScript Directory Instruction
The change to cd /examples/ in the JavaScript section maintains consistency with other documentation.


100-101: Updated JavaScript Workspace Command is Correct
The new command yarn workspace pub-sub-connection-state-javascript dev accurately reflects the workspace structure for the JavaScript example.

examples/pub-sub-connection-state/react/next.config.mjs (2)

1-4: LGTM! Environment variable loading is properly implemented.

The implementation correctly loads environment variables from the shared .env.local file in the examples root directory, which aligns with the NPM workspace structure.


6-11: Verify the environment variable configuration.

The configuration looks good with React strict mode enabled. However, ensure that the Ably key is properly set in the shared .env.local file.

❌ Verification inconclusive

🏁 Script executed:

#!/bin/bash
# Description: Verify the environment variable configuration

# Check if .env.example exists and contains the required variable
echo "Checking .env.example for NEXT_PUBLIC_ABLY_KEY..."
if ! rg "NEXT_PUBLIC_ABLY_KEY" "examples/.env.example"; then
  echo "Warning: NEXT_PUBLIC_ABLY_KEY not found in examples/.env.example"
fi

Length of output: 178


Environment variable configuration is declared correctly in the code, but please double-check your shared .env.local file.

  • The next.config.mjs file properly sources NEXT_PUBLIC_ABLY_KEY from process.env.
  • The execution of the script shows that examples/.env.example contains NEXT_PUBLIC_ABLY_KEY=, which is typical for a template file.
  • Verify that the actual Ably key (a non‑empty value) is set in your shared .env.local file to ensure it’s available at runtime.
examples/pub-sub-connection-state/javascript/vite.config.ts (1)

1-5: LGTM! Environment variable loading is properly implemented.

The implementation correctly loads environment variables from the shared .env.local file in the examples root directory, which aligns with the NPM workspace structure.

@GregHolmes GregHolmes force-pushed the EDU-1816-Create-an-NPM-workspace-usage-for-one-example branch from f96bb29 to 600c0ec Compare February 11, 2025 10:21
@GregHolmes GregHolmes temporarily deployed to ably-docs-edu-1816-crea-t8xdpr February 11, 2025 10:21 Inactive
@GregHolmes GregHolmes temporarily deployed to ably-docs-edu-1816-crea-t8xdpr February 11, 2025 12:30 Inactive
@jamiehenson
Copy link
Member

Hey @GregHolmes just checking in on this - this PR looks okay to me and I approve of workspaces here in general, but there's a matter of how we want to proceed with this, given that you say this is a trial in the description. Is your intention to merge this in and then do the other examples in separate PRs in turn, or start another PR that isn't a trial?

@GregHolmes
Copy link
Contributor Author

given that you say this is a trial in the description. Is your intention to merge this in and then do the other examples in separate PRs in turn, or start another PR

I will update the description as you're happy with this and roll out the changes throughout in this PR just to simplify the release.

Copy link
Member

@jamiehenson jamiehenson left a comment

Choose a reason for hiding this comment

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

Just a comment about the extra scripts in the top level package.json, and need to squash up the fixup commits, then we'll be away

"pub-sub-connection-state/react",
"pub-sub-connection-state/javascript"
],
"scripts": {
Copy link
Member

Choose a reason for hiding this comment

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

The README materials for the language examples reference yarn workspace pub-sub-connection-state-javascript dev directly and I can't see these scripts used anywhere - so we should either remove these extra scripts, or update the READMEs (unless they're used in another place I'm not aware of)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not too sure what you mean by this.

These scripts: pub-sub-connection-state-javascript and pub-sub-connection-state-react are referenced in the /examples/pub-sub-connection-state/react and /examples/pub-sub-connection-state/javascript READMEs. As well as in the page.md file in /examples/pub-sub-connection-state/ directory.

These scripts are run in the main /examples/ directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have left the chat-room-history/ ones in the workspaces. But they'll be added as soon as you're happy with this PR showing one example.

@GregHolmes GregHolmes force-pushed the EDU-1816-Create-an-NPM-workspace-usage-for-one-example branch 3 times, most recently from 0d4c490 to 0b8810e Compare February 20, 2025 14:27
@GregHolmes GregHolmes requested a review from m-hulbert February 21, 2025 11:51
@GregHolmes GregHolmes force-pushed the EDU-1816-Create-an-NPM-workspace-usage-for-one-example branch 4 times, most recently from 543b2be to ce59333 Compare February 24, 2025 11:41
Copy link
Contributor

@m-hulbert m-hulbert left a comment

Choose a reason for hiding this comment

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

Spotted a couple of places that don't make sense in the instructions, or were missed 🙂

Comment on lines 31 to +34
5. In a new tab, change directory:

```sh
cd /examples/auth-generate-jwt/server/
cd /examples/
Copy link
Contributor

Choose a reason for hiding this comment

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

You're already in this directory with the workspace changes. I think the auth ones will need rewording as you just need to update the .env files rather than messing around changing directories now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but if you run yarn run auth-generate-jwt-javascript you're then opening a second terminal to run the server command, which means you'll likely have to navigate to that directory again.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point 🤦

```

5. In a new tab, change directory:

```sh
cd /examples/auth-request-token/server/
cd /examples/
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as for JWT.

@GregHolmes GregHolmes force-pushed the EDU-1816-Create-an-NPM-workspace-usage-for-one-example branch from 4f4277d to 97ad0c1 Compare February 25, 2025 14:27
@GregHolmes GregHolmes requested a review from m-hulbert February 25, 2025 15:33
@GregHolmes GregHolmes merged commit b913a98 into main Feb 25, 2025
5 checks passed
@GregHolmes GregHolmes deleted the EDU-1816-Create-an-NPM-workspace-usage-for-one-example branch February 25, 2025 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants