Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/publishing.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -45,4 +46,4 @@
"engines": {
"node": ">=14.0.0"
}
}
}
18 changes: 12 additions & 6 deletions src/__tests__/stringifyCSSProperties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
3 changes: 2 additions & 1 deletion src/stringifyCSSProperties.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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};`
Expand Down
4 changes: 1 addition & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { type CSSProperties } from "react";

export type CSSSelector = string;

export type StyleMap = Record<CSSSelector, CSSProperties>;
export type StyleMap = Record<string, CSSProperties>;
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from "./camelToKebab";
export * from "./isUnitless";
export * from "./applyCssUnits";
export * from "./trimCssSelector";
export * from "./isCSSPropertyValue";
2 changes: 2 additions & 0 deletions src/utils/isCSSPropertyValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const isCSSPropertyValue = (value: unknown): value is number | string =>
typeof value === "number" || typeof value === "string";