https://github.com/snyk-snippets/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. It can be used in Node.js and browser applications.
https://github.com/snyk-snippets/modern-npm-package
Last synced: 4 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/snyk-snippets/modern-npm-package
- Owner: snyk-snippets
- License: mit
- Created: 2022-08-12T22:23:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T17:38:23.000Z (over 1 year ago)
- Last Synced: 2024-04-14T12:56:55.791Z (about 1 year ago)
- Language: TypeScript
- Size: 116 KB
- Stars: 93
- Watchers: 3
- Forks: 26
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - snyk-snippets/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. It can be used in Node.js and browser applications. (TypeScript)
README
# modern-npm-package
An npm package for demonstration purposes using TypeScript to build for the ECMAScript Module format (i.e. ESM or ES Module). It can be used in Node.js and browser applications. Refer to the [Snyk blog post](https://snyk.co/uhYgM) for a full tutorial.
> If you're reading/coming from the Snyk blog post that discusses both ESM and CommonJS go to the [v2022-2024](https://github.com/snyk-snippets/modern-npm-package/tree/v2022-2024) branch
## Get Started
1. Run `npm install` in your terminal
1. Then run `npm run build`
1. Update the `package.json` file "name" field with your own package name. Example `@username/package-name`
1. Create an account with [npm](https://www.npmjs.com/signup) if you don't have one already. Also be sure to enable [two-factor authentication](https://docs.npmjs.com/configuring-two-factor-authentication)
1. Sign in to your npm account in your terminal with `npm login`
1. Run `npm publish --access=public` to publish your package### Testing
1. Install developer dependencies using the following command in your terminal `npm i -D typescript @types/node`
1. Create a `tests` folder
1. Create an `index.test.ts` file in the `tests` folder
1. Write unit tests in the `index.test.ts` file to test the code in `index.ts`
1. Add a `"test"` property in the `package.json` file `"scripts"` object and give it a value of `"node --experimental-strip-types --test"`
1. Run `npm test` in your terminal from the root folder of the project