Publish TypeScript SDKs manually

View as Markdown

This guide covers publishing TypeScript SDKs manually. For information on automating TypeScript SDK publishing, see Publish TypeScript SDKs automatically.

To share your generated TypeScript SDK with the community, you can publish it to npm. This enables other developers to easily install it using npm. Follow the steps below.

Prerequisites

To publish your SDK to npm, you need the following:

  • An npm account. You can create it at npmjs.com.
  • npm CLI installed. You can install it with Node.js from nodejs.org.
  • A unique package name. You can check availability using the npm search your-package-name command.

Publish your TypeScript SDK to npm

  1. Configure package.json. Ensure these fields are set correctly:

    1{
    2 "name": "@your-org/your-sdk",
    3 "version": "1.0.0",
    4 "description": "SDK for Your API",
    5 "main": "dist/index.js",
    6 "types": "dist/index.d.ts",
    7 "files": [
    8 "dist",
    9 "README.md",
    10 "LICENSE"
    11 ],
    12 "repository": {
    13 "type": "git",
    14 "url": "https://github.com/your-org/your-sdk"
    15 },
    16 "keywords": ["api", "sdk", "your-api"],
    17 "author": "Your Name",
    18 "license": "MIT"
    19}
  2. Build the SDK.

    $npm install
    $npm run build
    $npm test
  3. Sign in to npm.

    $npm login
  4. Publish the package.

    • For public packages, use:

      $npm publish --access public
    • For scoped private packages, use:

      $npm publish
  5. Verify publication:

    $npm info @your-org/your-sdk

Publish updates

To publish an updated SDK, update the version in the package.json following the semantic versioning:

  • Patch: 1.0.01.0.1 (bug fixes)
  • Minor: 1.0.01.1.0 (new features, backward compatible)
  • Major: 1.0.02.0.0 (breaking changes)

Alternatively, you can use the npm version command:

$npm version patch # or minor, or major
$npm publish

Best practices for publishing TypeScript SDKs

Use the following best practices when publishing your TypeScript SDK to npm:

  • Use .npmignore to exclude unnecessary files.
  • Include a comprehensive README.md.
  • Add a LICENSE file.
  • Tag releases in Git: git tag v1.0.0 && git push --tags.
  • Set up CI/CD for automated publishing.
  • Consider using np tool for streamlined publishing: npx np.