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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cather/kwc-module-resolver

v1.0.0

Published

Resolves paths for KWC components

Downloads

4

Readme

@cather/kwc-module-resolver

Implements the KWC module resolver algorithm.

Installation

npm install --save-dev @cather/kwc-module-resolver

APIs

resolveModule(specifier, importer, options)

Synchronously resolves an KWC module specifier from an import path.

import { resolveModule } from '@cather/kwc-module-resolver';

const result = resolveModule('x/foo', './index.js');
console.log(result);

If the resolver processes an invalid configuration, it throws an error with the KWC_CONFIG_ERROR error code. If the resolver can't locate the module, it throws an error with the NO_KWC_MODULE_FOUND error code.

import { resolveModule } from '@cather/kwc-module-resolver';

let result;
try {
    result = resolveModule('x/foo', './index.js');
} catch (err) {
    if (err.code === 'KWC_CONFIG_ERROR') {
        console.error(`The request module can't be resolved due to an invalid configuration`, err);
    } else if (err.code === 'NO_KWC_MODULE_FOUND') {
        console.error(`The requested module doesn't exists. `, err);
    } else {
        throw err;
    }
}

console.log(result);

Parameters:

  • specifier (string, required): The module specifier to resolve.
  • importer (string, required): The file from where the resolution starts.
  • options (object, optional):
    • modules (ModuleRecord[], optional, default: []): Injects module records to the resolved configuration.
    • rootDir (string, optional, default: process.cwd()): Use only when the modules option is set. Modules overrides are resolved from this directory.

Return value:

A RegistryEntry representing the resolved module with the following properties:

  • entry (string): The absolute path of the module entry point.
  • specifier (string): The resolved module specifier.
  • scope (string): The absolute path from where the module has been resolved.

Module resolution

The KWC compiler uses a custom resolution algorithm to resolve KWC modules. To configure module resolution, use the kwc.config.json file or the kwc key in the package.json file. The modules key accepts an array of module records. The resolver iterates through the modules array and returns the first module that matches the requested module specifier. There are three types of module record:

// kwc.config.json
{
    "modules": [
        {
            "name": "ui/button",
            "path": "src/modules/ui/button/button.js"
        },
        {
            "dir": "src/modules"
        },
        {
            "npm": "@ui/components"
        }
    ]
}

Module record types

Alias module record

An alias module record maps a module specifier to a file path. An alias module record is defined by two keys:

  • name (string, required): The KWC module specifier.
  • path (string, required): The file path to resolve.

In this example, the ui/button KWC module specifier is resolved from the src/modules/ui/button/button.js path.

{
    "modules": [
        {
            "name": "ui/button",
            "path": "src/modules/ui/button/button.js"
        }
    ]
}

Directory module record

A directory module record specifies a folder path where KWC modules are resolved. A directory module record is defined by one key:

  • dir (string, required): The directory path containing the modules.
{
    "modules": [
        {
            "dir": "src/modules"
        }
    ]
}

The directory module record uses an opinionated folder structure to resolve KWC modules. The directory path can contain one or multiple folders representing the KWC modules namespace. Each of those namespace folders can contain one or multiple folders representing the different KWC modules in the namespace. The name of the folder defines the KWC module name. For a module to be resolved, the KWC module folder must have a file matching the KWC module name, this file is the KWC module entry point.

In this example, if the dir key is set src/modules, the following KWC modules can be resolved: ui/button, ui/icons, shared/utils.

src
└── modules/
    ├── ui/
    │   ├── button/
    │   │   ├── button.js
    │   │   └── button.html
    │   └── icon/
    │       └── icon.js
    └── shared/
        └── utils/
            └── utils.js

NPM package module record

An NPM package module record tells the resolver that a given NPM package exposes resolvable KWC modules. More details about how to expose KWC modules out of an NPM package can be found in this section. An NPM package module record is defined by one key:

  • npm (string, required): The NPM package name exposing the KWC modules.

In this example, the resolver is told to look into the @ui/components NPM package to look up KWC modules.

{
    "modules": [
        {
            "npm": "@ui/components"
        }
    ]
}

Exposing KWC modules via NPM packages

To distribute an KWC module publicly via an NPM package, the package should follow the same the KWC module resolution rules. The NPM package should either have the kwc.config.json file in its root directory or the kwc key in its package.json describing how KWC modules are resolved relative to this package.

By default, an KWC module is not exposed outside of an NPM package. The KWC configuration must explicitly list the public KWC modules on the expose key.

In this example, the package makes the ui/button and ui/icon KWC modules public.

{
    "modules": [
        {
            "dir": "src/modules"
        }
    ],
    "expose": ["ui/button", "ui/icon"]
}