JSPM

  • Created
  • Published
  • Downloads 35
  • Score
    100M100P100Q76582F
  • License ISC

Enhanced sort-package-json with scripts and exports sorting / 增強版 sort-package-json,支援 scripts 和 exports 排序

Package Exports

  • sort-package-json3
  • sort-package-json3/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sort-package-json3) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sort-package-json3

Enhanced sort-package-json with scripts and exports sorting 增強版 sort-package-json,支援 scripts 和 exports 排序

NPM version License

Description / 描述

This module provides an enhanced sort-package-json function that:

  • Sorts package.json keys in a predefined order
  • Sorts scripts following npm lifecycle order
  • Sorts exports field with consistent key ordering

此模組提供增強的 sort-package-json 函式:

  • 按預定義順序排序 package.json 鍵
  • 按 npm 生命週期順序排序 scripts
  • 按一致的鍵值順序排序 exports 欄位

Installation / 安裝

# Using yarn
yarn add sort-package-json3

# Using yarn-tool
yarn-tool add sort-package-json3

# Using yt (yarn-tool alias)
yt add sort-package-json3

# Using npm
npm install sort-package-json3

Usage / 使用方式

import sortPackageJson from 'sort-package-json3';

const pkg = {
  version: '1.0.0',
  name: 'my-package',
  scripts: {
    test: 'jest',
    pretest: 'npm run lint',
    posttest: 'echo done',
  },
  exports: {
    '.': {
      import: './dist/index.esm.mjs',
      require: './dist/index.cjs',
      types: './dist/index.d.ts',
    },
  },
  dependencies: {
    lodash: '^4.17.21',
  },
};

const sorted = sortPackageJson(pkg);
// Returns:
// {
//   name: 'my-package',
//   version: '1.0.0',
//   exports: { '.': { types: '...', require: '...', import: '...' } },
//   scripts: { pretest: '...', test: '...', posttest: '...' },
//   dependencies: { lodash: '^4.17.21' }
// }

Features / 功能

  • Top-level Key Sorting: Sorts package.json keys in a logical order

  • Scripts Sorting: Sorts scripts following npm lifecycle order (pre, main, post)

  • betterScripts Sorting: Also sorts betterScripts field

  • Exports Sorting: Sorts exports field with consistent key ordering

  • 頂層鍵排序:按邏輯順序排序 package.json 鍵

  • Scripts 排序:按 npm 生命週期順序排序 scripts(pre、main、post)

  • betterScripts 排序:也排序 betterScripts 欄位

  • Exports 排序:按一致的鍵值順序排序 exports 欄位

License / 授權

ISC © bluelovers