An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Overview

modern-npm-package

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format (CJS). It can be used in Node.js and browser applications.

Get Started

  1. Run npm install in your terminal
  2. Then run npm run build
  3. Update the package.json file "name" field with your own package name. Example @username/package-name
  4. Create an account with npm if you don't have one already. Also be sure to enable two-factor authentication
  5. Sign in to your npm account in your terminal with npm login
  6. Run npm publish --access=public to publish your package

Testing

  1. Install developer dependencies using the following command in your terminal npm i -D mocha @type/mocha chai @types/chai ts-node
  2. Create a new file .mocharc.json in the root directory with the following contents:
    {
      "extension": ["ts"],
      "spec": "./**/*.spec.ts",
      "require": "ts-node/register"
    }
  3. Create a tests folder
  4. Create an index.spec.ts file in the tests folder
  5. Write unit tests in the index.spec.ts file to test the code in index.ts
  6. Add a "test" property in the package.json file and give it a value of "mocha"
  7. Run npm test in your terminal from the root folder of the project
Comments
  • The automated release is failing 🚨

    The automated release is failing 🚨

    :rotating_light: The automated release from the main branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here are some links that can help you:

    If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


    No npm token specified.

    An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

    Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


    Good luck with your project ✨

    Your semantic-release bot :package::rocket:

    semantic-release 
    opened by github-actions[bot] 4
  • [BUG]: The tutorial on https://snyk.io/blog/best-practices-create-modern-npm-package/ has not working repo link

    [BUG]: The tutorial on https://snyk.io/blog/best-practices-create-modern-npm-package/ has not working repo link

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Description of the bug

    There is info on the website https://snyk.io/blog/best-practices-create-modern-npm-package/ to clone this https://github.com/snyk-labs/simple-npm-package.git repo, but such repo doesn't exists, instead this one exists https://github.com/snyk-labs/modern-npm-package.git.

    I think that this can be a bug 😉

    Steps To Reproduce

    Try to: git clone https://github.com/snyk-labs/simple-npm-package.git

    Additional Information

    No response

    bug 
    opened by rrakso 0
  • [BUG]: Small typo in README.md

    [BUG]: Small typo in README.md

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Description of the bug

    That's a small type in README.md:

    Install developer dependencies using the following command in your terminal npm i -D mocha @type/mocha chai @types/chai ts-node

    It should be:

    Install developer dependencies using the following command in your terminal npm i -D mocha @types/mocha chai @types/chai ts-node

    Steps To Reproduce

    Just check the file 🙂

    Additional Information

    No response

    bug 
    opened by zaerl 0
  • [BUG]: Wrong imports defined in `tests/index.spec.ts`

    [BUG]: Wrong imports defined in `tests/index.spec.ts`

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Description of the bug

    First of all, thank you very much for that repo, it's very useful.

    I noticed that some of the imports located in the index.spec.ts are wrong. See https://github.com/snyk-labs/modern-npm-package/blob/main/tests/index.spec.ts#L5

    Indeed, I guess it should be

    import { helloWorld, goodBye } from '../src';
    import commonPackage from '../src';
    
    // instead of 
    
    import { helloWorld, goodBye } from '../index';
    import npmPackage from '../index';
    

    Steps To Reproduce

    • Follow the installation guidelines from the README.md
    • Run npm test
    • Will results into the following error tests/index.spec.ts:5:27 - error TS2307: Cannot find module '../index' or its corresponding type declarations.

    Additional Information

    No response

    bug 
    opened by JUNNNI 0
  • fix: test script fail due to move index to src folder commit

    fix: test script fail due to move index to src folder commit

    When running npm run test, I got this result

    
    > @snyk-labs/[email protected] test
    > mocha
    
    
    TSError: ⨯ Unable to compile TypeScript:
    tests/index.spec.ts:4:37 - error TS2307: Cannot find module '../index' or its corresponding type declarations.
    
    4 import { helloWorld, goodBye } from '../index';
                                          ~~~~~~~~~~
    tests/index.spec.ts:5:24 - error TS2307: Cannot find module '../index' or its corresponding type declarations.
    
    5 import npmPackage from '../index';
                             ~~~~~~~~~~
    
        at createTSError (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:859:12)
        at reportTSError (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:863:19)
        at getOutput (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:1077:36)
        at Object.compile (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:1433:41)
        at Module.m._compile (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:1617:30)
        at Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/ts-node/src/index.ts:1621:12)
        at Module.load (node:internal/modules/cjs/loader:975:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Module.require (node:internal/modules/cjs/loader:999:19)
        at require (node:internal/modules/cjs/helpers:102:18)
        at Object.exports.requireOrImport (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/mocha/lib/nodejs/esm-utils.js:49:16)
        at async Object.exports.loadFilesAsync (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
        at async singleRun (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/mocha/lib/cli/run-helpers.js:125:3)
        at async Object.exports.handler (/Users/naach/dev/sandbox2/modern-npm-package/node_modules/mocha/lib/cli/run.js:370:5)
    

    Expected

    
    > @snyk-labs/[email protected] test
    > mocha
    
    
    
      NPM Package
        ✔ should be an object
        ✔ should have a helloWorld property
    
      Hello World Function
        ✔ should be a function
        ✔ should return the hello world message
    
      Goodbye Function
        ✔ should be a function
        ✔ should return the goodbye message
    
    
      6 passing (9ms)
    

    cause by this change https://github.com/snyk-labs/modern-npm-package/commit/09130ce9a2d74fad9c9a1af054846ab7474d6342

    tested on node v17.6.0

    opened by SuperCipher 0
  • [FEAT]: dev mode

    [FEAT]: dev mode

    Is there an existing feature request for this?

    • [X] I have searched the existing feature requests

    Description

    how to use dev

    "dev": "tsc -w ./config/tsconfig.esm.json",
    

    Is that right?

    Additional Information

    No response

    enhancement 
    opened by mahaoming 0
Owner
Snyk Labs
Continuously find & fix vulnerabilities in dependencies pulled from npm, Maven, RubyGems, PyPI and more
Snyk Labs
Minimal utility to convert to or from any timezone. Deno/Node/Browser. ESM/CommonJS.

minitz Features Convert dates between any timezone supported by the system. Parses ISO8601 time strings. MIT licensed, use the library any way you wan

Hexagon 14 Oct 10, 2022
Node.js loader for compiling ESM & TypeScript modules to CommonJS

cjs-loader Node.js require() hook to instantaneously transform ESM & TypeScript to CommonJS on demand using esbuild. Features Transforms ESM & TypeScr

esbuild kit 40 Dec 13, 2022
Universal importer for CommonJS and ESM in Node.js

ModuleImporter by Nicholas C. Zakas If you find this useful, please consider supporting my work with a donation. Description A utility for seamlessly

Human Who Codes 18 Dec 2, 2022
Project developed in typescript with clean architecture + tdd for demonstration purposes.

Description Project developed in typescript with clean architecture + tdd for demonstration purposes in Usystem. Installation $ yarn Running the app #

USystem - Desenvolvimento Ágil de Softwares 1 Oct 5, 2022
Babel plugin and helper functions for interoperation between Node.js native ESM and Babel ESM

babel-plugin-node-cjs-interop and node-cjs-interop: fix the default import interoperability issue in Node.js The problem to solve Consider the followi

Masaki Hara 15 Nov 6, 2022
📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs

pkgroll Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single command! Features Zero conf

hiroki osame 153 Dec 23, 2022
📦 🍣 Zero-config JS bundler for ESM, CommonJS, and .d.ts outputs. (Forked from pkgroll)

?? ?? puild (A fork of pkgroll) Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single com

ʀᴀʏ 6 Sep 6, 2022
Recursively publish ESM packages as CommonJS!

Commonify.js For us who are still relying on CommonJS, or using Electron which does not support ESM. ?? See also build-electron I made this tool that

Mikael Finstad 31 Dec 29, 2022
A simple NFT trading and breeding platform for demonstration purposes.

?? boxyz I know it sounds strange, but maybe these boxes can breed and have children. They can be sold as well. boxyz is a fun project to trade and br

cetin 8 Dec 12, 2022
Demonstration of how you build full-stack, typed, NPM packages, the right way

NPM Packages - The Right way This repository aims to demonstrate how to build NPM packages the right way. my-package should import the shared code, bu

VulcanJS 61 Nov 27, 2022
Babel-plugin-amd-checker - Module format checking plugin for Babel usable in both Node.js the web browser environments.

babel-plugin-amd-checker A Babel plugin to check the format of your modules when compiling your code using Babel. This plugin allows you to abort the

Ferdinand Prantl 1 Jan 6, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
npm i uuid, npm i nodemon, npm i commander

goit-nodejs-hw-01 Получаем и выводим весь список контактов в виде таблицы (console.table) node index.js --action list Получаем контакт по id node inde

Oksana Banshchykova 3 Jul 5, 2022
This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build some javascript library which consumes the output of this library.

@albanian-xrm/dataverse-odata This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you

AlbanianXrm 3 Oct 22, 2022
Elven Tools Dapp - Elrond blockckchain frontend dapp demo. Primarily for NFT minting, but it can be used for other purposes.

Elven Tools Dapp Docs: elven.tools/docs/landing-page.html Demo: dapp-demo.elven.tools Sneak peek: youtu.be/ATSxD3mD4dc The Dapp is built using Nextjs

Elven Tools 24 Jan 1, 2023
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
Node.js loader for compiling TypeScript modules to ESM

esm-loader Node.js import hook to instantaneously transform TypeScript to ESM on demand using esbuild. Features Transforms TypeScript to ESM on demand

esbuild kit 90 Jan 4, 2023