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

server-cli-only

v0.3.2

Published

The server-cli-only package is designed to restrict the import of modules exclusively to React Server Components or scripts running on the CLI.

Downloads

7,469

Readme

server-cli-only

This package is designed as a failsafe. All modules marked with import "server-cli-only" will throw an error on build-time if imported into a module running in the "browser" runtime (e.g., React Client Components). This package is an alternative to the server-only package, which permits the execution of React Server Components runtimes but doesn't allow using other server or edge runtimes. This package aims for the use with React but can also be used in other projects that follow this strategy.

Installation

npm i server-cli-only

Module Usage

Import server-cli-only at the beginning of a module that you want to protect from leaking to the front-end (browser):

import "server-cli-only";

Now, imports of your module importing server-cli-only into "browser" modules (e.g., React Client Components) will throw an error.

Command Line Usage

You can directly execute scripts in server runtimes like node, deno, and bun. For example:

node your-script.js

Or in your package.json:

{
  "scripts": {
    "your-cli-script": "node your-script.js"
  }
}

Context

This package tries to align with the guidelines in the React Server Module Conventions of RFC #227 but extends this guideline to also allow executions in other server and edge runtimes, not only the "react-server" runtime. The overarching goal is to restrict modules with sensitive data from being leaked to the front-end (browser) by using "conditional exports" in Node.js's package.json file. Doing so results in build-time errors for "browser" and unknown runtime modules. Following, all allowed and forbidden (error-throwing) runtimes.

Allowed Runtimes

| Key | Target | | ------------ | ----------------------- | | react-server | React Server Components | | node | Node.js runtime | | bun | Bun runtime | | deno | Deno runtime | | edge-light | Vercel edge | | netlify | Netlify edge | | workerd | Cloudflare edge |

Forbidden Runtimes (Error-Throwing)

| Key | Target | | ----------- | ----------------------- | | browser | React Client Components | | <unknown> | All unknown runtimes |

Lookout Places for Additional Runtime Keys in the Future

Proposed Specs concerning the different runtime keys available by the Web-interoperable Runtimes Community Group (WinterCG). And React-DOM's package.json "conditional exports" field.

License

MIT License.

Links

  • Source Code: https://github.com/destacks/core-ts/tree/main/packages/server-cli-only
  • Project Repo: https://github.com/destacks/core-ts
  • NPM Package: https://www.npmjs.com/package/server-cli-only