@alessiofrittoli/node-scripts

中文文档
4.2.0发布于 2026/10/24MITTypeScriptESM + CJS零依赖近 30 天下载 3644

Utility library with common Node.js scripts

原始使用文档
文档目录6 节
  1. Utility library with common Node.js scripts
  2. Table of Content
  3. Getting started
  4. Development
  5. API Reference
  6. Made with ☕

Node.js Scripts 🫧

Utility library with common Node.js scripts

Latest version Test coverage Socket Security score npm downloads Dependencies Dependencies status

minified minizipped Tree shakable

Fund this package

Table of Content


Getting started

Run the following command to start using node-scripts in your projects:

npm i @alessiofrittoli/node-scripts

or using pnpm

pnpm i @alessiofrittoli/node-scripts

Development

Run the following to start development

nvm use

pnpm i

Local development

Run the following

pnpm dev

This will generate unminified output code, sourcemaps and will enable source file watcher.


Production build

Run the following to create a local production build

pnpm build

This will generate minified output code without sourcemaps.


Unit tests

Run all the defined test suites by running the following:

# Run tests and watch file changes.
pnpm test:watch

# Run tests in a CI environment.
pnpm test:ci

Run tests with coverage

An HTTP server is then started to serve coverage files from ./coverage folder.

⚠️ You may see a blank page the first time you run this command. Simply refresh the browser to see the updates.

pnpm test:coverage:serve

Contributing

Contributions are truly welcome!

Please refer to the Contributing Doc for more information on how to start contributing to this project.

Help keep this project up to date with GitHub Sponsor.

GitHub Sponsor


Security

If you believe you have found a security vulnerability, we encourage you to responsibly disclose this and NOT open a public issue. We will investigate all legitimate reports. Email [email protected] to disclose any security vulnerabilities.


API Reference

Post-Install scripts

TypeScript Type Reference Management

The addTypesReference function allows you to create and manage TypeScript reference files and update the related tsconfig.json file for a project installing your node module.

Below are the detailed descriptions of the interfaces and functions included.

Type Reference Interfaces
CommonOptions
Properties
PropertyTypeDescription
rootstringThe root directory of the project which is installing your node module.
namestringThe name of your node module.
outputFilestringThe output file name.

AddTypesReferenceOptions
Properties
PropertyTypeDefaultDescription
namestring-The project name currently executing the script.
scopesstring[]-An array of scopes references used over package name.
outputFilestring'globals.d.ts'The *.d.ts output file name.

Type Reference Functions
createReferenceFile

Creates or updates a reference file with type definitions for a project.

Parameters
ParameterTypeDescription
optionsCommonOptionsCommon options for the reference file creation.

Throws

Error - Throws an error if there is an issue creating or updating the file.


updateTsConfig

Updates the tsconfig.json file by adding the specified output file to the include array.

Parameters
ParameterTypeDescription
optionsCommonOptionsCommon options for the reference file creation.

Throws
  • Error - Throws an error if the tsconfig.json file cannot be read or updated.

addTypesReference

Adds a TypeScript reference file and updates the tsconfig.json for the project installing your node module.

If the options.outputFile already exists, it will be updated with the new package reference if not already in there.

Parameters
ParameterTypeDescription
optionsAddTypesReferenceOptionsThe options for adding the types reference.

Error

Exit the process with code 1 on failure.


Add Types Reference Example usage

Add the postinstall script in your package.json file which will execute the script once your package get installed in an external project.

{
  // ...
  "files": [
    // ...,
    "my-scripts" // ensure folder is published to `npm`
  ],
  "scripts": {
    // ...
    "postinstall": "node my-scripts/ts-setup.ts"
  }
}

Then in your ts-setup.ts file simply import the script and execute it with a few options.

// my-scripts/ts-setup.ts
import { addTypesReference } from '@alessiofrittoli/node-scripts/postinstall'
import packageJson from '../package.json'

addTypesReference({
  name: packageJson.name,
  outputFile: `${packageJson.name}.d.ts`, // optional
})

Or you can statically pass a outputFile to add all your scoped packages in a single file.

// my-scripts/ts-setup.ts
import { addTypesReference } from '@alessiofrittoli/node-scripts/postinstall'
import packageJson from '../package.json'

addTypesReference({
  name: packageJson.name,
  outputFile: 'my-package-scope-env.d.ts',
})

Add custom types references
// my-scripts/ts-setup.ts
import { addTypesReference } from '@alessiofrittoli/node-scripts/postinstall'
import packageJson from '../package.json'

addTypesReference({
  name: packageJson.name,
  types: [`${packageJson.name}/globals`, `${packageJson.name}/globals-2`],
  outputFile: `${packageJson.name}.d.ts`, // optional
})

Release scripts

release

The release function automates the process of building, tagging, and optionally releasing a project to npm.

This function either works with process options (passed via CLI) or function arguments (function arguments takes precedence over process options).

Arguments
ArgumentTypeDefaultDescription
versionstring--version process option or package.json.The version to release.
Retrieved from --version process option or package.json if omitted.
buildstring'build'A custom build command that will build your project before publish.
Retrieved from --build process option or fallback to build if omitted.
verbosebooleanfalseEnables detailed logging.
Retrieved from --verbose process option or fallback to false if omitted.
originstring'origin'The Git origin name used for pushing version tags.
Retrieved from --origin or --o process option or fallback to origin if omitted.
npmbooleanfalseIndicates whether to publish the package to npm.
Retrieved from --npm process option or fallback to false if omitted.
accesspublic|restricted'public'Sets npm package access level.
Retrieved from --access process option or fallback to public if omitted.

Process Options - CLI
OptionTypeDefaultDescription
--versionstringValue from package.jsonThe version to release. Retrieved from package.json if omitted.
Retrieved from package.json if omitted.
--buildstringbuildA custom build command that will build your project before publish.
--verbosebooleanfalseEnables detailed logging.
--origin, -ostring'origin'The Git origin name used for pushing version tags.
--npmbooleanfalseIndicates whether to publish the package to npm.
--accesspublic|restricted'public'Sets npm package access level.

Performed steps
  1. Retrieve package.json:
    • Attempts to load and parse the package.json file.
    • Exits the process with code "1" if the file is unavailable or invalid.
    • Retrieve the version to use as fallback if no --version option has been provided.
  2. Parse Options:
    • Retrieves CLI options using getProcessOptions().
    • Validates critical parameters such as version and access.
  3. Prepare Git and Build:
    • Stashes any uncommitted changes with a stash name (pre-release).
    • Executes the npm run build or pnpm build command (if pnpm is globally installed).
    • Create the Git Tag as v{version}
    • Push the Git Tag the the specified origin or to the default Git Repository Remote.
  4. Publish to npm (Optional):
    • Publishes the package using npm publish if the --npm flag is set.
  5. Restore Stash:
    • Restores the stashed changes if any were saved during the process.
  6. Verbose Logging:
    • Logs details of the release process if the --verbose flag is set.

Example usage
Using function arguments

Add the release script in your package.json file so you can easly run from your terminal.

{
  // ...
  "scripts": {
    // ...
    "release": "node my-scripts/release.ts"
  }
}

Then in your release.ts file simply import the script and execute it.

⚠️ Remember to add this file to .npmignore so it won't be published within you package.

// my-scripts/release.ts
import { release } from '@alessiofrittoli/node-scripts/release'

release({
  verbose: true,
  npm: true,
  access: 'restricted',
})

Using CLI options

Add the release script in your package.json file so you can easly run from your terminal.

{
  // ...
  "scripts": {
    // ...
    "release": "node my-scripts/release.ts --verbose --npm --access restricted"
  }
}

Then in your release.ts file simply import the script and execute it.

⚠️ Remember to add this file to .npmignore so it won't be published within you package.

// my-scripts/release.ts
import { release } from '@alessiofrittoli/node-scripts/release'

release()

Made with ☕

avatar
Alessio Frittoli
https://alessiofrittoli.it | [email protected]

版本与发布记录

@alessiofrittoli/node-scripts 共发布 33 个版本,首次发布于 2024/12/25;过去 12 个月发布了 11 个版本。

版本发布日期距今
4.2.0latest2026/10/2414 天前
4.1.02026/10/1623 天前
4.0.02026/10/1028 天前
4.0.0-alpha.5alpha2026/10/071 个月前
4.0.0-alpha.32026/10/061 个月前
4.0.0-alpha.22026/10/061 个月前

关于 @alessiofrittoli/node-scripts 的常见问题

@alessiofrittoli/node-scripts 是什么?

Utility library with common Node.js scripts

如何安装 @alessiofrittoli/node-scripts?

在项目目录运行 npm install @alessiofrittoli/node-scripts,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@alessiofrittoli/tsconfig(^1.0.0)、@alessiofrittoli/typed-map(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@alessiofrittoli/node-scripts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@alessiofrittoli/node-scripts 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@alessiofrittoli/node-scripts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.15.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@alessiofrittoli/node-scripts 可以商用吗?

@alessiofrittoli/node-scripts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alessiofrittoli/node-scripts 的下载量有多少?

根据 npm 官方下载统计,@alessiofrittoli/node-scripts 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,644 次,日均约 121 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alessiofrittoli/node-scripts 还在维护吗?

最新版本 4.2.0 发布于 2026/10/24(14 天前);至今共发布 33 个版本,其中过去 12 个月发布了 11 个;首次发布于 2024/12/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。