Skip to content

feat(utils): add constants for Unicode and UCDJS API URLs#75

Merged
luxass merged 4 commits intomainfrom
add-constants
Jun 25, 2025
Merged

feat(utils): add constants for Unicode and UCDJS API URLs#75
luxass merged 4 commits intomainfrom
add-constants

Conversation

@luxass
Copy link
Copy Markdown
Member

@luxass luxass commented Jun 25, 2025

  • Introduced constants.ts to define base URLs for the Unicode API and UCDJS API.
  • Updated package.json to export the new ./constants module.

Summary by CodeRabbit

  • New Features
    • Added new constants for Unicode and UCDJS API endpoints, now available for import from the package.
  • Chores
    • Updated package configuration to export the new constants module for easier access.
    • Documented the feature addition and version update in the release notes.

* Introduced `constants.ts` to define base URLs for the Unicode API and UCDJS API.
* Updated `package.json` to export the new `./constants` module.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: 2415c8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@ucdjs/utils Minor
@ucdjs/ucd-store Patch
@ucdjs/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@luxass luxass requested a review from Copilot June 25, 2025 16:54
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 25, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new constants module was added to the @ucdjs/utils package, exporting three API-related URL constants. The package's exports and build configuration were updated to include and expose this new module. Additionally, a changeset was created to document and trigger a minor version release for this feature.

Changes

File(s) Change Summary
.changeset/three-corners-fly.md Added a changeset documenting a minor version bump for @ucdjs/utils with a new "export constants" feature.
packages/utils/package.json Added a subpath export for ./constants to expose dist/constants.js.
packages/utils/src/constants.ts Introduced and exported three API URL constants, each configurable via environment variables.
packages/utils/tsdown.config.ts Included src/constants.ts as an entry point for the tsdown documentation/build process.

Sequence Diagram(s)

sequenceDiagram
    participant Consumer as Package Consumer
    participant Utils as @ucdjs/utils
    participant Constants as constants.ts

    Consumer->>Utils: import { UNICODE_API_BASE_URL } from '@ucdjs/utils/constants'
    Utils->>Constants: Expose constants
    Constants-->>Consumer: Provide API URL constants (using env or defaults)
Loading

Possibly related PRs

Poem

Three new constants, shiny and bright,
URLs for APIs, set just right.
Exposed for all with a config tweak,
Now importing them is easy-peasy sleek!
🐇✨
Hopping along, our utils grow,
With every new export, onward we go!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/utils/src/constants.ts

Oops! Something went wrong! :(

ESLint: 9.28.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 59dee88 and 2415c8e.

📒 Files selected for processing (1)
  • packages/utils/src/constants.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new constants.ts module defining base URLs for the Unicode and UCDJS APIs, updates build and package exports to include it, and records the change in a changeset.

  • Added constants.ts with three exported URL constants and JSDoc defaults
  • Updated tsdown.config.ts to bundle constants.ts
  • Expanded package.json exports to include ./constants and added a changeset entry

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/utils/tsdown.config.ts Added ./src/constants.ts to the build entry
packages/utils/src/constants.ts New module exporting Unicode/UCDJS URLs
packages/utils/package.json Exported ./constants in package exports
.changeset/three-corners-fly.md Recorded the new export in a minor changeset
Comments suppressed due to low confidence (2)

packages/utils/src/constants.ts:1

  • Consider adding unit tests for constants.ts to verify both the default URL values and the overrides via environment variables. This will help ensure the constants behave as expected in different environments.
import { env } from "node:process";

packages/utils/package.json:23

  • If your package publishes TypeScript type definitions, consider adding a corresponding types export for ./constants in the exports field (e.g., add a types entry pointing to ./dist/constants.d.ts) to ensure TS consumers can resolve typings for the new module.
    "./constants": "./dist/constants.js",

Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (3)
packages/utils/src/constants.ts (2)

1-1: Consider environment-agnostic import to keep the utils package browser-friendly

Importing env from node:process makes the file unambiguously Node-only. If consumers ever tree-shake or bundle this file for browser usage it will force a Node polyfill (or crash in pure ESM runtimes such as Deno).
A safer pattern is to read directly from globalThis.process?.env (or to inject the values at build time) and fall back when process is absent.

-import { env } from "node:process";
+const env = typeof process === "undefined" ? {} : process.env;

7-19: Normalise trailing slashes to avoid subtle double-slash bugs

Because the constants can be overridden, downstream code may end up concatenating UNICODE_API_BASE_URL + "/endpoint" and accidentally produce // when the env var already ends with /. Consider stripping a trailing slash once up-front:

-export const UNICODE_API_BASE_URL = env.UNICODE_API_BASE_URL || "https://unicode-api.luxass.dev/api/v1";
+export const UNICODE_API_BASE_URL =
+  (env.UNICODE_API_BASE_URL || "https://unicode-api.luxass.dev/api/v1").replace(/\/$/, "");

Same normalisation can be applied to UNICODE_PROXY_URL and UCDJS_API_BASE_URL.

.changeset/three-corners-fly.md (1)

5-5: Make the changeset message more descriptive for downstream changelogs

feat: export constants is terse and loses context when viewed outside the repo. Something like feat(utils): add Unicode & UCDJS API URL constants gives immediate clarity.

No code change required; edit if you agree.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between dceca51 and 59dee88.

📒 Files selected for processing (4)
  • .changeset/three-corners-fly.md (1 hunks)
  • packages/utils/package.json (1 hunks)
  • packages/utils/src/constants.ts (1 hunks)
  • packages/utils/tsdown.config.ts (1 hunks)
🔇 Additional comments (2)
packages/utils/tsdown.config.ts (1)

7-7: Verify tsdown generates typings for the new sub-entry

Adding the file to entry is correct; just ensure tsdown actually outputs dist/constants.d.ts because package.json now exposes the file at a sub-path.
No change requested—flagging for build verification.

packages/utils/package.json (1)

23-23: Add typesVersions or rely on TS5 “exports” resolution

Node will resolve @ucdjs/utils/constants via the "exports" field, but older TypeScript versions (< 5.0 with moduleResolution: "bundler" | "node16" ) won’t. If supporting older TS, add:

"typesVersions": {
  "*": {
    "constants": ["dist/constants.d.ts"]
  }
}

If the package already mandates TS ≥ 5 in bundler/Node16 mode you can ignore this.

luxass added 2 commits June 25, 2025 18:57
* Prevents potential errors when `process` is undefined.
* Ensures compatibility in environments where Node.js globals are not available.
* Changed the default value of `UNICODE_API_BASE_URL` to remove the API version from the URL.
* This aligns the URL with the intended base endpoint for the Unicode API.
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.

2 participants