Registry / devops / prisma-schema-sorter

prisma-schema-sorter

JSON →
library1.5.0jsnpmunverified

A CLI and programmatic tool that alphabetically sorts Prisma schema elements, including models, enums, generators, and datasources. Version 1.5.0 (stable) requires Node.js >=18. It is zero-config, fast, lightweight, and ships TypeScript types. Unlike manual sorting or ad-hoc scripts, this tool provides a consistent, automated ordering that integrates into pre-commit hooks or CI pipelines. Released under MIT license on npm with weekly updates.

npm install prisma-schema-sorter
INSTALL
IMPORT
SIG · PRISMA-SCHEMA-SORT
P
prisma-schema-sorter
devopsjavascriptv1.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sortPrismaSchema
import { sortPrismaSchema } from 'prisma-schema-sorter'
const sortPrismaSchema = require('prisma-schema-sorter')
ESM-only since v1.0; CommonJS requires dynamic import or use async. The function returns a Promise.
default import
import { sortPrismaSchema } from 'prisma-schema-sorter'
import sortPrismaSchema from 'prisma-schema-sorter'
No default export exists; only named export `sortPrismaSchema` is available.
CLI command
npx prisma-schema-sorter sort --schema='./prisma/schema.prisma'
prisma-schema-sorter --input schema.prisma
CLI syntax expects the subcommand `sort` and option `--schema` with path string.

Demonstrates installation and both programmatic (ESM/CommonJS) and CLI usage to sort a Prisma schema file.

// 1. Install the package // npm install prisma-schema-sorter // 2. Programmatic usage (ESM/TypeScript) import { sortPrismaSchema } from 'prisma-schema-sorter'; const schemaPath = './prisma/schema.prisma'; try { await sortPrismaSchema(schemaPath); console.log('Schema sorted successfully!'); } catch (error) { console.error('Sorting failed:', error); } // 3. Alternatively, use CLI: // npx prisma-schema-sorter sort --schema='./prisma/schema.prisma' // 4. For CommonJS: // async function run() { // const { sortPrismaSchema } = await import('prisma-schema-sorter'); // await sortPrismaSchema('./prisma/schema.prisma'); // } // run();
Debug
Known issues
breakingUnrecognized CLI arguments cause exit code 1 without clear error.
fix
Use correct syntax: `prisma-schema-sorter sort --schema=./prisma/schema.prisma` (note: option value with equals sign is recommended).
affects: >=0.0.0
gotchaFunction throws an error if the file path does not exist.
fix
Check file existence before calling sortPrismaSchema. Use try/catch.
affects: >=0.0.0
deprecatedThe package name 'prisma-schema-sorter' may conflict with other tools; ensure correct spelling.
fix
Double-check npm package name and import path.
affects: >=0.0.0
gotchaIncorrect import (default instead of named) resolves to undefined at runtime.
fix
Use import { sortPrismaSchema } from 'prisma-schema-sorter'.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'prisma-schema-sorter'
Package not installed or not in node_modules.
fix
Run `npm install prisma-schema-sorter` and ensure CWD has node_modules.
TypeError: sortPrismaSchema is not a function
Imported incorrectly (default instead of named).
fix
Use `import { sortPrismaSchema } from 'prisma-schema-sorter'`.
Prisma schema not found at <path>
Provided path to sortPrismaSchema does not exist.
fix
Verify the path string points to an existing .prisma file.
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
prisma-schema-sorter — npm install prisma-schema-sorter · libregistry