Skip to content

Commit

Permalink
Update dependnecies and some more readme
Browse files Browse the repository at this point in the history
  • Loading branch information
thokra-nav committed Nov 28, 2023
1 parent c008973 commit 7885aaf
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 98 deletions.
48 changes: 9 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,20 @@ Check out the [Storybook](https://nais.io/ds-svelte-community) for examples of h

---

## Developing this package
## Development

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
We use [Bun](https://bun.sh) and [asdf](https://asdf-vm.com) to manage dependencies and run scripts.

```bash
npm run storbyook # or
npm run dev
Run `asdf install` to install the correct version of `bun`. (You might need to run `asdf plugin add bun` first.)

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.

## Building

To build your library:
### Packages

```bash
npm run package
```

To create a production version of your showcase app:

```bash
npm run build
```
The library is split into multiple packages in the `packages` directory. Each package has its own `README.md` with more information.

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
## Publishing

The package is hosted on Google Artifact Registry. To publish a new version:

Update the version in `package.json` and commit the change.

Then run:

```bash
npm run gar-login
npm run publish
```
| Package | Description |
| -------------------------------- | ------------------------------------------------------------------- |
| `ds-svelte-community` | The actual component library, including icons. |
| `ds-svelte-community-preprocess` | A preprocessing step that optimizes usage of the component library. |

## GitHub copilot in use

Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/ds-svelte-community-preprocess-svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
A Svelte preprocessor for [ds-svelte-community](../ds-svelte-community-preprocess-svelte)

This is heavily inspired by [carbon-preprocess-svelte](https://github.com/carbon-design-system/carbon-preprocess-svelte)

## Development

When there's new/removed components in `ds-svelte-community`, you need to run `bun run update-components` in this package to update the components tree.
7 changes: 4 additions & 3 deletions packages/ds-svelte-community-preprocess-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
},
"exports": {
".": {
"bun": "./src/index.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"default": "./dist/index.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"typesVersions": {
">4.0": {
"index.d.ts": [
Expand All @@ -51,7 +50,9 @@
"dist/**/*",
"dist/__snapshots__/**/*",
"!dist/**/*.test.*",
"!dist/**/*.spec.*"
"!dist/**/*.spec.*",
"src/*.ts",
"!src/**/*.test.*"
],
"peerDependencies": {
"svelte": "^3.59.0 || ^4.0.0-0"
Expand Down
105 changes: 105 additions & 0 deletions packages/ds-svelte-community/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# ds-svelte-community

## Developing this package

Once you've created a project and installed dependencies with `bun install`, start a development server:

> [!TIP]
> You might need to build [`ds-svlete-community-preprocess`](../ds-svelte-community-preprocess-svelte/) first.
> `cd ../ds-svelte-community-preprocess-svelte && bun run build && cd ../ds-svelte-community`
```bash
bun run storbyook # or
bun test
```

Everything inside `src/lib` is part of the library, everything inside `src/routes` can be used as a showcase or preview app.

## Adding new components

In general, we try to create components that behave like the components in the [React version](https://github.com/navikt/aksel/tree/main/%40navikt/core/react), with a few exceptions:

- Default user facing texts are in English, not Norwegian.
- We try to make the components feel more like Svelte components, and less like React components.

We stribe to generate HTML equal to the HTML generated by the React version of the component library.

We ensure this by adding a test for each component, that renders the component and compares the HTML to the HTML generated by the React version.

```typescript
import { bunmatch } from "$testlib/bunmatch";
import { Loader as ReactLoader } from "@navikt/ds-react";
import { cleanup, render } from "@testing-library/svelte";
import { afterEach, describe, expect, it } from "bun:test";
import Loader from "./Loader.svelte";
import type { Props } from "./type";

describe("Loader", () => {
it("renders with HTML similar to ds-react", async () => {
// Often we can define one structure with props, used by both components.
// If there's differences, we should pass separate props to each component.
const props: Props = {
title: "Loading",
};
expect(
// bunmatch is a custom matcher that returns true if they are similar.
// bunmatch will do some alterations to the HTML, e.g. sort attributes, classes and format the html.
// The API is a bit of a hack until Bun supports custom matchers.
// The first argument is the Svelte component, the second is the React component.
// The third argument is an object with props and options.
await bunmatch(render(Loader, props), ReactLoader, {
props: {
// Spread the props object, so we can add more props if needed.
...props,
},
opts: {
// There's a few functions that alters the HTML. E.g. this one removes any attribute where the function returns false.
compareAttrs(node, attr) {
const tagName = node.tagName.toLowerCase();
// Title ids are unique
if (tagName == "svg" && ["aria-labelledby"].includes(attr)) {
return false;
}

if (tagName == "title" && attr == "id") {
return false;
}
return true;
},
},
}),
).toBeTrue(); // bunmatch returns true if the HTML is similar.
});

afterEach(cleanup);
});
```

## Building

To build the library:

```bash
bun run package
```

To create a production version of the showcase app:

```bash
bun run build
```

## Publishing

The package is hosted on Google Artifact Registry. To publish a new version:

Update the version in `package.json` and commit the change.

Then run:

```bash
# From root of project
bun run gar-login
# From this directory
bun run publish
```
6 changes: 3 additions & 3 deletions packages/ds-svelte-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"storybook": "storybook dev -p 6006 --no-open",
"storybook": "svelte-kit sync && storybook dev -p 6006 --no-open",
"build:storybook": "storybook build",
"storybook:docs": "storybook dev --docs",
"generate-icons": "./hack/generate-icons.sh",
Expand Down Expand Up @@ -116,8 +116,8 @@
"@testing-library/svelte": "^4.0.5",
"@types/diff": "^5.0.8",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"autoprefixer": "^10.4.16",
"bun-types": "^1.0.14",
"clsx": "^2.0.0",
Expand Down
106 changes: 53 additions & 53 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 9531A7AB5E9516C9-d105cb7df85c36f0-81CA2064F31D2B55-4f6aeafe25308437
# bun ./bun.lockb --hash: 7F89746ED4AC5A8F-fad6ba8493faef90-AA3203AD9ACFADEE-480fa315328d1f54


"@aashutoshrathi/word-wrap@^1.2.3":
Expand Down Expand Up @@ -1590,8 +1590,8 @@
"@testing-library/svelte" "^4.0.5"
"@types/diff" "^5.0.8"
"@types/react-dom" "^18.2.17"
"@typescript-eslint/eslint-plugin" "^6.12.0"
"@typescript-eslint/parser" "^6.12.0"
"@typescript-eslint/eslint-plugin" "^6.13.1"
"@typescript-eslint/parser" "^6.13.1"
autoprefixer "^10.4.16"
bun-types "^1.0.14"
clsx "^2.0.0"
Expand Down Expand Up @@ -3436,32 +3436,32 @@
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.2.tgz"
integrity sha512-5qcvofLPbfjmBfKaLfj/+f+Sbd6pN4zl7w7VSVI5uz7m9QZTuB2aZAa2uo1wHFBNN2x6g/SoTkXmd8mQnQF2Cw==

"@typescript-eslint/eslint-plugin@^6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.12.0.tgz"
integrity sha512-XOpZ3IyJUIV1b15M7HVOpgQxPPF7lGXgsfcEIu3yDxFPaf/xZKt7s9QO/pbk7vpWQyVulpJbu4E5LwpZiQo4kA==
"@typescript-eslint/eslint-plugin@^6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.13.1.tgz"
integrity sha512-5bQDGkXaxD46bPvQt08BUz9YSaO4S0fB1LB5JHQuXTfkGPI3+UUeS387C/e9jRie5GqT8u5kFTrMvAjtX4O5kA==
dependencies:
"@eslint-community/regexpp" "^4.5.1"
"@typescript-eslint/scope-manager" "6.12.0"
"@typescript-eslint/type-utils" "6.12.0"
"@typescript-eslint/utils" "6.12.0"
"@typescript-eslint/visitor-keys" "6.12.0"
"@typescript-eslint/scope-manager" "6.13.1"
"@typescript-eslint/type-utils" "6.13.1"
"@typescript-eslint/utils" "6.13.1"
"@typescript-eslint/visitor-keys" "6.13.1"
debug "^4.3.4"
graphemer "^1.4.0"
ignore "^5.2.4"
natural-compare "^1.4.0"
semver "^7.5.4"
ts-api-utils "^1.0.1"

"@typescript-eslint/parser@^6.0.0 || ^6.0.0-alpha", "@typescript-eslint/parser@^6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.12.0.tgz"
integrity sha512-s8/jNFPKPNRmXEnNXfuo1gemBdVmpQsK1pcu+QIvuNJuhFzGrpD7WjOcvDc/+uEdfzSYpNu7U/+MmbScjoQ6vg==
"@typescript-eslint/parser@^6.0.0 || ^6.0.0-alpha", "@typescript-eslint/parser@^6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.13.1.tgz"
integrity sha512-fs2XOhWCzRhqMmQf0eicLa/CWSaYss2feXsy7xBD/pLyWke/jCIVc2s1ikEAtSW7ina1HNhv7kONoEfVNEcdDQ==
dependencies:
"@typescript-eslint/scope-manager" "6.12.0"
"@typescript-eslint/types" "6.12.0"
"@typescript-eslint/typescript-estree" "6.12.0"
"@typescript-eslint/visitor-keys" "6.12.0"
"@typescript-eslint/scope-manager" "6.13.1"
"@typescript-eslint/types" "6.13.1"
"@typescript-eslint/typescript-estree" "6.13.1"
"@typescript-eslint/visitor-keys" "6.13.1"
debug "^4.3.4"

"@typescript-eslint/[email protected]":
Expand All @@ -3472,21 +3472,21 @@
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"

"@typescript-eslint/scope-manager@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.12.0.tgz"
integrity sha512-5gUvjg+XdSj8pcetdL9eXJzQNTl3RD7LgUiYTl8Aabdi8hFkaGSYnaS6BLc0BGNaDH+tVzVwmKtWvu0jLgWVbw==
"@typescript-eslint/scope-manager@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.13.1.tgz"
integrity sha512-BW0kJ7ceiKi56GbT2KKzZzN+nDxzQK2DS6x0PiSMPjciPgd/JRQGMibyaN2cPt2cAvuoH0oNvn2fwonHI+4QUQ==
dependencies:
"@typescript-eslint/types" "6.12.0"
"@typescript-eslint/visitor-keys" "6.12.0"
"@typescript-eslint/types" "6.13.1"
"@typescript-eslint/visitor-keys" "6.13.1"

"@typescript-eslint/type-utils@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.12.0.tgz"
integrity sha512-WWmRXxhm1X8Wlquj+MhsAG4dU/Blvf1xDgGaYCzfvStP2NwPQh6KBvCDbiOEvaE0filhranjIlK/2fSTVwtBng==
"@typescript-eslint/type-utils@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.13.1.tgz"
integrity sha512-A2qPlgpxx2v//3meMqQyB1qqTg1h1dJvzca7TugM3Yc2USDY+fsRBiojAEo92HO7f5hW5mjAUF6qobOPzlBCBQ==
dependencies:
"@typescript-eslint/typescript-estree" "6.12.0"
"@typescript-eslint/utils" "6.12.0"
"@typescript-eslint/typescript-estree" "6.13.1"
"@typescript-eslint/utils" "6.13.1"
debug "^4.3.4"
ts-api-utils "^1.0.1"

Expand All @@ -3495,10 +3495,10 @@
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.62.0.tgz"
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==

"@typescript-eslint/types@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.12.0.tgz"
integrity sha512-MA16p/+WxM5JG/F3RTpRIcuOghWO30//VEOvzubM8zuOOBYXsP+IfjoCXXiIfy2Ta8FRh9+IO9QLlaFQUU+10Q==
"@typescript-eslint/types@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.13.1.tgz"
integrity sha512-gjeEskSmiEKKFIbnhDXUyiqVma1gRCQNbVZ1C8q7Zjcxh3WZMbzWVfGE9rHfWd1msQtPS0BVD9Jz9jded44eKg==

"@typescript-eslint/[email protected]":
version "5.62.0"
Expand All @@ -3513,13 +3513,13 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/typescript-estree@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.12.0.tgz"
integrity sha512-vw9E2P9+3UUWzhgjyyVczLWxZ3GuQNT7QpnIY3o5OMeLO/c8oHljGc8ZpryBMIyympiAAaKgw9e5Hl9dCWFOYw==
"@typescript-eslint/typescript-estree@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.13.1.tgz"
integrity sha512-sBLQsvOC0Q7LGcUHO5qpG1HxRgePbT6wwqOiGLpR8uOJvPJbfs0mW3jPA3ujsDvfiVwVlWUDESNXv44KtINkUQ==
dependencies:
"@typescript-eslint/types" "6.12.0"
"@typescript-eslint/visitor-keys" "6.12.0"
"@typescript-eslint/types" "6.13.1"
"@typescript-eslint/visitor-keys" "6.13.1"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
Expand All @@ -3540,17 +3540,17 @@
eslint-scope "^5.1.1"
semver "^7.3.7"

"@typescript-eslint/utils@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.12.0.tgz"
integrity sha512-LywPm8h3tGEbgfyjYnu3dauZ0U7R60m+miXgKcZS8c7QALO9uWJdvNoP+duKTk2XMWc7/Q3d/QiCuLN9X6SWyQ==
"@typescript-eslint/utils@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.13.1.tgz"
integrity sha512-ouPn/zVoan92JgAegesTXDB/oUp6BP1v8WpfYcqh649ejNc9Qv+B4FF2Ff626kO1xg0wWwwG48lAJ4JuesgdOw==
dependencies:
"@eslint-community/eslint-utils" "^4.4.0"
"@types/json-schema" "^7.0.12"
"@types/semver" "^7.5.0"
"@typescript-eslint/scope-manager" "6.12.0"
"@typescript-eslint/types" "6.12.0"
"@typescript-eslint/typescript-estree" "6.12.0"
"@typescript-eslint/scope-manager" "6.13.1"
"@typescript-eslint/types" "6.13.1"
"@typescript-eslint/typescript-estree" "6.13.1"
semver "^7.5.4"

"@typescript-eslint/[email protected]":
Expand All @@ -3561,12 +3561,12 @@
"@typescript-eslint/types" "5.62.0"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/visitor-keys@6.12.0":
version "6.12.0"
resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.12.0.tgz"
integrity sha512-rg3BizTZHF1k3ipn8gfrzDXXSFKyOEB5zxYXInQ6z0hUvmQlhaZQzK+YmHmNViMA9HzW5Q9+bPPt90bU6GQwyw==
"@typescript-eslint/visitor-keys@6.13.1":
version "6.13.1"
resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.13.1.tgz"
integrity sha512-NDhQUy2tg6XGNBGDRm1XybOHSia8mcXmlbKWoQP+nm1BIIMxa55shyJfZkHpEBN62KNPLrocSM2PdPcaLgDKMQ==
dependencies:
"@typescript-eslint/types" "6.12.0"
"@typescript-eslint/types" "6.13.1"
eslint-visitor-keys "^3.4.1"

"@ungap/structured-clone@^1.2.0":
Expand Down

0 comments on commit 7885aaf

Please sign in to comment.