feat(utils): add constants for Unicode and UCDJS API URLs#75
Conversation
* Introduced `constants.ts` to define base URLs for the Unicode API and UCDJS API. * Updated `package.json` to export the new `./constants` module.
🦋 Changeset detectedLatest commit: 2415c8e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
Caution Review failedThe pull request is closed. WalkthroughA new constants module was added to the Changes
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)
Possibly related PRs
Poem
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
packages/utils/src/constants.tsOops! 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. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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.tswith three exported URL constants and JSDoc defaults - Updated
tsdown.config.tsto bundleconstants.ts - Expanded
package.jsonexports to include./constantsand 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.tsto 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
./constantsin theexportsfield (e.g., add atypesentry pointing to./dist/constants.d.ts) to ensure TS consumers can resolve typings for the new module.
"./constants": "./dist/constants.js",
There was a problem hiding this comment.
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-friendlyImporting
envfromnode:processmakes 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 fromglobalThis.process?.env(or to inject the values at build time) and fall back whenprocessis absent.-import { env } from "node:process"; +const env = typeof process === "undefined" ? {} : process.env;
7-19: Normalise trailing slashes to avoid subtle double-slash bugsBecause 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_URLandUCDJS_API_BASE_URL..changeset/three-corners-fly.md (1)
5-5: Make the changeset message more descriptive for downstream changelogs
feat: export constantsis terse and loses context when viewed outside the repo. Something likefeat(utils): add Unicode & UCDJS API URL constantsgives immediate clarity.No code change required; edit if you agree.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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-entryAdding the file to
entryis correct; just ensuretsdownactually outputsdist/constants.d.tsbecausepackage.jsonnow exposes the file at a sub-path.
No change requested—flagging for build verification.packages/utils/package.json (1)
23-23: AddtypesVersionsor rely on TS5 “exports” resolutionNode will resolve
@ucdjs/utils/constantsvia the"exports"field, but older TypeScript versions (< 5.0 withmoduleResolution: "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.
* 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.
constants.tsto define base URLs for the Unicode API and UCDJS API.package.jsonto export the new./constantsmodule.Summary by CodeRabbit