0.3.2 • Published 13 days ago

server-cli-only v0.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
13 days ago

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

KeyTarget
react-serverReact Server Components
nodeNode.js runtime
bunBun runtime
denoDeno runtime
edge-lightVercel edge
netlifyNetlify edge
workerdCloudflare edge

Forbidden Runtimes (Error-Throwing)

KeyTarget
browserReact 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

0.3.2

13 days ago

0.3.1

13 days ago

0.3.0

14 days ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago