### Install Publint locally Source: https://publint.dev/docs Add the package as a development dependency to your project. ```bash npm install --save-dev publint ``` ```bash pnpm add --save-dev publint ``` ```bash yarn add --dev publint ``` -------------------------------- ### Run Publint on Current Directory Source: https://publint.dev/docs/cli Execute publint on the current working directory. No additional setup is required. ```bash publint ``` -------------------------------- ### Configure Publint Pack Manager Source: https://publint.dev/docs/cli Specify the package manager to use for packing with the --pack flag. This example forces the use of npm. ```bash publint --pack npm ``` -------------------------------- ### Configure Publint Level Source: https://publint.dev/docs/cli Control the verbosity of publint output by setting the --level flag. This example ignores suggestions, showing only warnings and errors. ```bash publint --level warning ``` -------------------------------- ### Run Publint via CLI Source: https://publint.dev/docs Execute the linter directly using your preferred package manager. ```bash npx publint ``` ```bash pnpm dlx publint ``` ```bash yarn dlx publint ``` -------------------------------- ### Basic usage in Node.js Source: https://publint.dev/docs/javascript-api Run publint on a local package directory. ```javascript import { publint } from 'publint' const result = await publint({ pkgDir: './packages/mylib' }) ``` -------------------------------- ### Execute local Publint script Source: https://publint.dev/docs Run the configured linting script using your package manager. ```bash npm run lint:package ``` ```bash pnpm lint:package ``` ```bash yarn lint:package ``` -------------------------------- ### Configure Publint in package.json Source: https://publint.dev/docs Define a script in your package.json to execute the linter. ```json { "scripts": { "lint:package": "publint" } } ``` -------------------------------- ### publint() Function Source: https://publint.dev/docs/javascript-api The main entry point for running publint programmatically. It returns an object containing linting messages and package information. ```APIDOC ## publint(options) ### Description Executes the publint process based on the provided configuration options. ### Parameters #### Request Body - **pkgDir** (string) - Optional - Path to the package directory containing package.json. Defaults to process.cwd() in Node.js. - **level** ('suggestion' | 'warning' | 'error') - Optional - The severity level of messages to log. Defaults to 'suggestion'. - **pack** (string | object | boolean) - Optional - Configuration for how to pack the package. Supports 'auto', package manager names, tarball buffers/streams, or manual file arrays. - **strict** (boolean) - Optional - If true, reports warnings as errors. ### Response #### Success Response (200) - **messages** (Array) - An array of message objects describing issues. - **pkg** (Object) - The parsed package.json content. ``` -------------------------------- ### CLI Command: publint Source: https://publint.dev/docs/cli The primary command for running publint on a target path with various configuration options. ```APIDOC ## publint [path] [options] ### Description Lint a specific directory or a tarball file to ensure package correctness. ### Parameters #### Path Parameters - **path** (string) - Optional - The directory path or tarball file path to lint. Defaults to the current directory. #### Options - **--level** (string) - Optional - Level of messages to log. Options: 'suggestion', 'warning', 'error'. Default: 'suggestion'. - **--pack** (string) - Optional - Package manager to use for packing. Options: 'auto', 'npm', 'yarn', 'pnpm', 'bun', false. Default: 'auto'. - **--strict** (boolean) - Optional - Report warnings as errors. Default: false. ### Request Example ```bash # Run publint on a specific directory publint ./dir # Run publint on a tarball publint ./mylib-1.0.0.tgz # Treat warnings as errors publint --strict ``` ``` -------------------------------- ### Configure Publint Strict Mode Source: https://publint.dev/docs/cli Enable strict mode with the --strict flag to treat all warnings as errors. This is useful for enforcing stricter quality standards. ```bash publint --strict ``` -------------------------------- ### Run Publint on Tarball Source: https://publint.dev/docs/cli Lint a tarball file by providing its path as an argument to publint. ```bash publint ./mylib-1.0.0.tgz ``` -------------------------------- ### Run Publint on Specific Directory Source: https://publint.dev/docs/cli Lint a specific directory by providing its path as an argument to publint. ```bash publint ./dir ``` -------------------------------- ### Run publint programmatically Source: https://publint.dev/docs/javascript-api Basic execution of the publint function to retrieve linting messages. ```javascript import { publint } from 'publint' const { messages } = await publint({ // options... }) ``` -------------------------------- ### Define pack options Source: https://publint.dev/docs/javascript-api Configuration types for the pack option, defining how the package is prepared for linting. ```typescript | 'auto' | 'npm' | 'yarn' | 'pnpm' | 'bun' | { tarball: ArrayBuffer | ReadableStream } | { files: PackFile[] } | false ``` -------------------------------- ### Lint a remote tarball Source: https://publint.dev/docs/javascript-api Fetch and lint a package tarball directly from a registry. ```javascript import { publint } from 'publint' // Fetch tarball const response = await fetch('https://registry.npmjs.org/mylib/-/mylib-1.0.0.tgz') if (!response.body) throw new Error('Failed to fetch tarball') const result = await publint({ pack: { tarball: response.body } }) ``` -------------------------------- ### Lint manually unpacked files Source: https://publint.dev/docs/javascript-api Unpack a tarball manually using @publint/pack and pass the resulting files to publint. ```javascript import { publint } from 'publint' import { unpack } from '@publint/pack' // Fetch tarball const response = await fetch('https://registry.npmjs.org/mylib/-/mylib-1.0.0.tgz') if (!response.body) throw new Error('Failed to fetch tarball') const { rootDir, files } = await unpack(response.body) // Do something with `files` if needed const result = await publint({ pkgDir: rootDir, pack: { files } }) ``` -------------------------------- ### Lint a local tarball Source: https://publint.dev/docs/javascript-api Read a local tarball file into a buffer and pass it to publint. ```javascript import fs from 'node:fs/promises' import { publint } from 'publint' const nodeBuffer = await fs.readFile('./mylib-1.0.0.tgz') const tarballBuffer = nodeBuffer.buffer.slice( nodeBuffer.byteOffset, nodeBuffer.byteOffset + nodeBuffer.byteLength ) +const result = await publint({ pack: { tarball: tarballBuffer } }) ``` -------------------------------- ### Format publint messages Source: https://publint.dev/docs/javascript-api Use the formatMessage utility to convert message objects into human-readable strings. ```javascript import { publint } from 'publint' import { formatMessage } from 'publint/utils' const { messages, pkg } = await publint({ // options... }) for (const message of messages) { console.log(formatMessage(message, pkg)) } ``` -------------------------------- ### formatMessage() Utility Source: https://publint.dev/docs/javascript-api A utility function to format raw message objects into human-readable strings. ```APIDOC ## formatMessage(message, pkg) ### Description Converts a message object returned by publint into a formatted string for logging. ### Parameters - **message** (Object) - The message object from the publint result. - **pkg** (Object) - The package object from the publint result. ``` -------------------------------- ### Specify package manager for packing Source: https://publint.dev/docs/troubleshooting Use these commands to override the default package manager detection if the packing process hangs or to work around Yarn 1 limitations. ```bash publint --pack ``` ```javascript pack: '' ``` ```bash publint --pack npm ``` ```bash publint ./mylib-1.0.0.tgz ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.