npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@greenbone/ui

v1.5.2-alpha38

Published

Greenbone UI Components

Downloads

93

Readme

Greenbone Logo

GitHub releases Build

Component-Library

About

This TypeScript project contains all React components for the new corporate design. This project uses SWC for production builds and SWC for test compilation.

For documentation, Storybook is used. A published version can be found on https://storybook.greenbone.io.

Prerequisites

Install npm dependencies npm install

Build

To create a production build use npm run build:source and npm run build:types.

  • npm run build:source transpiles and bundles the ./src files into ./lib
    • For this SWC is used
    • Configuration for SWC is located at
      • ./swcrc/./swcrc.production for transpilation and minification
      • ./spack.config.js for bundling
  • npm run build:types generated Type definition from ./src into ./types
    • For this TSC is used.
      • ./tsconfig[.XXX].json is used

Why SWC?

SWC is 20x faster than Babel on a single thread and 70x faster on four cores.

Test

To tun all tests run npm run test.

To simulate the pipeline process npm run pipeline

Storybook

To start the storybook use npm run storybook.

Development

Development inside component library

For isolated component development inside the library, you can run storybook and edit the component's files.

npm run storybook

Use the local development version in other projects

Common situation: Edit library component which is used in another frontend.

Hot reload

This will not reload the changed TypeScript types. It will just rebuild and bundle the files. The FE will instantly replace the components inside the browser using HMR.

UI lib

Start a file watcher, that automatically rebuilds once a file changes npm run build:watch. This simply rebuilds the ./lib folder.

CAUTION: This does NOT rebuild the types. Intellisense and other autocompletion features of your IDE won't work correctly for the changed components.

FE

The given snippet works with vite. If you use another building/development framework, please visit the documentation and see if aliases can be set. This shouldn't be a problem for rollup based bundlers.

Add this snipped to the vite.config.ts in the root of the FE project. Adjust the relative path if needed

const alias = (mode: string) =>
    mode === "local-ui" ? { "@greenbone/ui": `${process.cwd()}/../ui` } : {}

This basically tells vite/rollup to exchange the import path "@greenbone/ui" with the local path to the UI lib repo

Adjust the export to be a function (If you currently just exported the config object)

export default ({ mode }) => { <<<< This
    process.env = {
        ...process.env,
        ...loadEnv(mode, process.cwd()),
    }
    .
    .
    .

Add the alias property to the actual config export (resolve.alias)

        resolve: {
            preserveSymlinks: true,
        >>> alias: alias(mode),
            dedupe: [
                "react-i18next",
                "@mantine/*",
                "@mantine/core",
                "react",
                "react-dom",
            ],
        },

Add an npm script shortcut to start with the local-ui mode

    "dev": "vite",
    "dev:ui": "vite --mode local-ui", <<<< This
    "build": "tsc -p tsconfig.prod.json && vite build",

Now you can run npm run dev:ui to start the frontend with the local version of your UI lib. Keep in mind that before using this, you should run the build watcher or a simple build in the UI library.

Correct types

Providing locally adjusted types is more tricky as TypeScript cannot leave the root of the project. To achieve instant type safety and autocompletion, we have to link the local UI library into the FE dependencies using npm link ../ui. Adjust the path if necessary.

NOTE: This will change the dependencies in your FE project. Reset all links before you push your changes. To reset all links run npm install. Also, having locally linked dependencies might crash unit tests.

You can validate a successful linking by either checking the node_modules manually or check if you see the changes in the FE

HMR and Types

finally you can use the HMR and Typing technique together by:

  • [FE] Linking the local UI lib npm link ../ui
  • [UI lib terminal 1] npm run build:watch
  • [UI lib terminal 2] npm run build:types keep in mind to run this everytime you change the types
  • [FE] npm run dev:ui

UI lib

After you adjusted the types, make sure to run npm run build:types to rebuild the types.

Troubleshooting

No visible changes

Vite caches the dependencies. To flush the cache, either delete the node_modules/.vite folder or start the service with the --force flag e.g npm run dev -- --force. The -- is a must to pass the args to the script shortcut (in this case vite)

Type duplications

If you run into typescript errors. Try to remove the node_modules/@types module from the UI libs node_modules.

This might happen because the modules imported from node_modules/@greenbone/ui use the types from node_modules/@greenbone/ui/node_modules/@types. This can cause duplication errors when using different type versions

Credits

| Dependency | License | Source-code location | |----------------|-----------|----------------------| | caniuse-lite | CC-BY-4.0 | caniuse.com |