New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pkg-typescript

Package Overview
Dependencies
Maintainers
1
Versions
324
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pkg-typescript

[![npm version](https://badge.fury.io/js/pkg-typescript.svg)](https://badge.fury.io/js/pkg-typescript) [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC) [![TypeScript](https://img.shields.io/badge/%3

latest
npmnpm
Version
0.7.0
Version published
Weekly downloads
54
2600%
Maintainers
1
Weekly downloads
 
Created
Source

pkg-ts 📦

npm version License: ISC TypeScript

Use a TypeScript file for your package.json with full type safety and enhanced developer experience! 🚀

✨ Features

  • 🔒 Type Safety: Define your package configuration with full TypeScript type checking
  • 🎯 IntelliSense: Get autocomplete and validation for all package.json fields
  • 🔄 Version Sync: Keep your TypeScript config and package.json versions in sync
  • 🧩 Plugin System: Extend functionality with reusable plugins
  • 📦 Multiple Packages: Build and manage multiple packages from a single configuration
  • CLI Tools: Powerful command-line interface for package management

🚀 Installation

# Using yarn (recommended)
yarn add -D pkg-typescript

# Using npm
npm install --save-dev pkg-typescript

📖 Quick Start

  • Create a package.ts file in your project root:
import { PackageConfig } from 'pkg-typescript'

const config: PackageConfig = {
  name: 'my-awesome-package',
  version: '1.0.0',
  scripts: {
    dev: 'vite dev',
    build: 'vite build',
    pre: {
      build: 'echo "Starting build..."',
    },
    post: {
      build: 'echo "Build complete!"',
    },
  },
  dependencies: {
    react: [18, 0, 0],
    lodash: ['github', 'lodash/lodash'],
  },
  devDependencies: {
    typescript: [5, 0, 0],
    vite: [4, 0, 0],
  },
}

export default config
  • Generate your package.json:
npx pkg-ts build

🛠️ CLI Commands

pkg-ts build

Generate package.json from your TypeScript configuration:

# Build single package
pkg-ts build

# Build specific package file
pkg-ts build --config my-package.ts

# Build all packages in directory
pkg-ts build --all

pkg-ts sync

Sync version between package.json and your TypeScript config:

# Sync version from package.json to package.ts
pkg-ts sync

# Sync specific config file
pkg-ts sync --config my-package.ts

pkg-ts add-plugin

Add a plugin to your package configuration:

pkg-ts add-plugin my-plugin

pkg-ts update

Update package configurations:

pkg-ts update

📋 Configuration

PackageConfig Interface

The PackageConfig interface provides full type safety for your package configuration:

export type PackageConfig<T = any> = {
  name: string
  version: string
  license?: string
  type?: 'plugin'
  plugins?: string[]
  private?: boolean
  scripts: {
    dev?: string
    build?: string
    start?: string
    pre?: PreScripts
    post?: PostScripts
    [key: string]: string | undefined | PreScripts | PostScripts
  }
  dependencies?: Record<string, Dependency>
  devDependencies?: Record<string, Dependency>
  config?: T
}

Dependency Types

Define dependencies using semantic versioning arrays or GitHub sources:

// Semantic version [major, minor, patch]
dependencies: {
  'react': [18, 2, 0],
  'lodash': [4, 17, 21]
}

// GitHub source
dependencies: {
  'my-package': ['github', 'username/repo']
}

// Latest version
dependencies: {
  'some-package': 1
}

Pre/Post Scripts

Define scripts that run before or after main scripts:

scripts: {
  build: 'webpack build',
  pre: {
    build: 'rm -rf dist',
    version: 'npm run test'
  },
  post: {
    build: 'npm run deploy',
    version: 'git push --tags'
  }
}

🧩 Plugin System

Create reusable plugins to extend functionality:

// my-plugin.ts
import { PluginFunction } from 'pkg-typescript'

interface MyPluginConfig {
  feature: boolean
}

const myPlugin: PluginFunction<MyPluginConfig> = (config) => {
  return {
    scripts: {
      'my-command': 'echo "Plugin command"',
    },
    dependencies: {
      'plugin-dep': [1, 0, 0],
    },
  }
}

export default myPlugin

Use plugins in your package configuration:

import myPlugin from './my-plugin'

const config: PackageConfig = {
  name: 'my-package',
  version: '1.0.0',
  plugins: ['my-plugin'],
  // ... rest of config
}

🔌 Available Plugins

Extend pkg-ts functionality with these official plugins:

🚀 Next.js Plugin

Pre-configured setup for Next.js applications with optimized scripts and dependencies.

💅 Prettier Plugin

Automatic code formatting configuration with Prettier integration.

🗄️ Prisma Plugin

Database toolkit integration with Prisma ORM setup and scripts.

🗄️ Mantine Plugin

Mantine UI library integration with Mantine UI setup and scripts.

⚙️ Scripts Plugin

Scripts integration with scripts setup and scripts.

Using Plugins

Install and use plugins in your package configuration:

npx pkg-ts add-plugin prisma
npx pkg-ts add-plugin prettier
import { PackageConfig } from 'pkg-typescript'
import nextjsPlugin from 'pkg-ts-plugin-nextjs'

const config: PackageConfig = {
  name: 'my-nextjs-app',
  version: '1.0.0',
  plugins: ['pkg-ts-plugin-nextjs'],
  // Plugin configuration will be automatically applied
}

export default config

🎯 Use Cases

  • Monorepos: Manage multiple packages with shared configuration
  • Type Safety: Catch configuration errors at compile time
  • Plugin Development: Create reusable package configurations
  • CI/CD: Automate package.json generation in build pipelines
  • Team Collaboration: Share typed package configurations

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m '✨ add amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

📄 License

This project is licensed under the ISC License - see the LICENSE file for details.

Made with ❤️ and TypeScript

FAQs

Package last updated on 25 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts