From 0c0c2cc3d72c0e7f7865381b1238d669d437e590 Mon Sep 17 00:00:00 2001 From: Artem Karlov Date: Thu, 15 May 2025 10:22:54 +0200 Subject: [PATCH 1/2] fix: handle explicit undefined values in CSS props --- src/__tests__/stringifyCSSProperties.test.ts | 18 ++++++++++++------ src/stringifyCSSProperties.ts | 3 ++- src/types.ts | 4 +--- src/utils/index.ts | 1 + src/utils/isCSSPropertyValue.ts | 2 ++ 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 src/utils/isCSSPropertyValue.ts diff --git a/src/__tests__/stringifyCSSProperties.test.ts b/src/__tests__/stringifyCSSProperties.test.ts index 92859b7..5e1516f 100644 --- a/src/__tests__/stringifyCSSProperties.test.ts +++ b/src/__tests__/stringifyCSSProperties.test.ts @@ -25,13 +25,19 @@ describe("stringifyCSSProperties", () => { ); }); - it("throws error for wrong CSS-value", () => { - expect(() => + it("skips CSS properties with wrong CSS value", () => { + const expected = "padding:5px 10px;color:teal;"; + const actual = stringifyCSSProperties({ //@ts-ignore - stringifyCSSProperties({ color: { color: "teal" } }) - ).toThrowError( - "Invalid input: value of 'cssProperties' must be string or number." - ); + margin: { top: 10 }, + padding: "5px 10px", + background: undefined, + color: "teal", + //@ts-ignore + border: null, + }); + + expect(actual).toBe(expected); }); it("doesn't change string CSS-value", () => { diff --git a/src/stringifyCSSProperties.ts b/src/stringifyCSSProperties.ts index 456d261..a2b147b 100644 --- a/src/stringifyCSSProperties.ts +++ b/src/stringifyCSSProperties.ts @@ -1,5 +1,5 @@ import { type CSSProperties } from "react"; -import { applyCssUnits, camelToKebab } from "./utils"; +import { applyCssUnits, camelToKebab, isCSSPropertyValue } from "./utils"; /** * Converts a CSSProperties object into a CSS string. @@ -20,6 +20,7 @@ export function stringifyCSSProperties( const important = isImportant ? "!important" : ""; return Object.entries(cssProperties) + .filter(([_, value]) => isCSSPropertyValue(value)) .map( ([key, value]) => `${camelToKebab(key)}:${applyCssUnits(key, value)}${important};` diff --git a/src/types.ts b/src/types.ts index e55618a..6a2697c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,3 @@ import { type CSSProperties } from "react"; -export type CSSSelector = string; - -export type StyleMap = Record; +export type StyleMap = Record; diff --git a/src/utils/index.ts b/src/utils/index.ts index 63b3aaa..cd678c8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,3 +2,4 @@ export * from "./camelToKebab"; export * from "./isUnitless"; export * from "./applyCssUnits"; export * from "./trimCssSelector"; +export * from "./isCSSPropertyValue"; diff --git a/src/utils/isCSSPropertyValue.ts b/src/utils/isCSSPropertyValue.ts new file mode 100644 index 0000000..8f1a057 --- /dev/null +++ b/src/utils/isCSSPropertyValue.ts @@ -0,0 +1,2 @@ +export const isCSSPropertyValue = (value: unknown): value is number | string => + typeof value === "number" || typeof value === "string"; From 7903e1877f0f653a898edec6416fef2b53a92add Mon Sep 17 00:00:00 2001 From: Artem Karlov Date: Thu, 15 May 2025 11:02:59 +0200 Subject: [PATCH 2/2] docs: add publishing reminder --- docs/publishing.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +++-- 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 docs/publishing.md diff --git a/docs/publishing.md b/docs/publishing.md new file mode 100644 index 0000000..5ca8fc8 --- /dev/null +++ b/docs/publishing.md @@ -0,0 +1,52 @@ +# Manual Package Publishing Flow + +1. ✅ Make code changes + +Create a branch from `main`, commit and push your changes, then open a Pull Request. +Merge the PR into `main` after it's reviewed and tests pass. + +2. 🔄 Switch to the `main` branch + +Ensure you're on the latest `main` branch: + +```bash +git checkout main +git pull origin main +``` + +3. 🔖 Bump the version using npm + +Use [semver](https://semver.org/) to choose the correct bump type: + +```bash +npm version patch # or minor / major +``` + +4. 🚀 Push changes and tags + +```bash +git push +git push origin vX.Y.Z +``` + +5. ✅ Run tests (before build) + +```bash +npm test +``` + +6. 🧱 Build the package + +```bush +npm run build +``` + +7. 📦 Publish to npm + +```bush +npm publish +``` + +8. 📝 (Optional) Add release notes + +Create or edit a release on GitHub for the new tag and describe the changes. diff --git a/package.json b/package.json index 284ae98..133b9b6 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ }, "scripts": { "build": "tsup", - "test": "vitest --config vitest.config.ts" + "test": "vitest run --config vitest.config.ts", + "test:watch": "vitest --config vitest.config.ts" }, "dependencies": { "@emotion/unitless": "^0.10.0" @@ -45,4 +46,4 @@ "engines": { "node": ">=14.0.0" } -} +} \ No newline at end of file