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

mjscjs

v1.1.0

Published

Transform typescript output to .mjs and .cjs compatible code. One codebase to rule them all.

Downloads

92

Readme

mjscjs

Transform typescript output to .mjs and .cjs compatible code. One codebase to rule them all.

This simple utility will ensure you deliver packages using latest ES standards. It relies on two separate typescript tsconfig.json configurations to generate esnext and commonjs modules. After build, mjscjs will process all the generated files:

✅ Renames all your files to .mjs and .cjs respectively

✅ Renames all your sourcemaps to .mjs.map and .cjs.map

✅ Replaces all your imports to use .mjs and requires to use .cjs

✅ Replaces all your sourcemap references

✅ Replaces all your tsconfig.json paths aliases with relative imports and requires

Installation

npm install -D mjscjs

Usage

For mjscjs to work properly, please make sure your tsconfig.json specifies the following configuration options:

{
    "compilerOptions": {
        "outDir": "lib",
        "rootDir": "./src",
        "baseUrl": ".",
        "paths": {
            "@example/*": ["./src/*"]
        }
    }
}

1. Create .mjs specific configuration

Create a file called tsconfig.mjs.json.

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "esnext",
        "outDir": "lib-mjs"
    }
}

2. Create .cjs specific configuration

Create a file called tsconfig.cjs.json.

{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "module": "commonjs",
        "outDir": "lib-cjs"
    }
}

3. Run mjscjs against both configurations

When working with a typescript project, simply target the tsconfig.json file of your project.

npx tsc -d -p tsconfig.mjs.json
npx mjscjs -p tsconfig.mjs.json
npx tsc -d -p tsconfig.cjs.json
npx mjscjs -p tsconfig.cjs.json

Add to package scripts

To make things easier, add mjscjs to your package.json scripts and run the complete build using npm run build.

{
  "scripts": {
    "build": "npm run build:mjs && npm run build:cjs",
    "build:mjs": "tsc -d -p tsconfig.mjs.json && npm run build:mjs:transform",
    "build:mjs:transform": "mjscjs -p tsconfig.mjs.json",
    "build:cjs": "tsc -d -p tsconfig.cjs.json && npm run build:cjs:transform",
    "build:cjs:transform": "mjscjs -p tsconfig.cjs.json"
  }
}

Alternative Usage

Attention The non-typescript usage is work in progress and not properly tested. Contributions are welcome.

When working with a non-typescript project, you can specify the module type, build dir, and source dir separately.

npx mjscjs --target . --buildDir './build' --srcDir './src' --module esm
npx mjscjs -t . -b './build' -s './src' -m esm

Contributing

Contributions are welcome! Please raise an issue to discuss any problem or feature request.

Copyright and license

Code copyright 2022 Alex Grozav. Code released under the MIT License.