https://github.com/ntnyq/sync-npm-packages
:package: Sync released npm packages to a mirror site.
https://github.com/ntnyq/sync-npm-packages
npm-mirror npm-package npmmirror sync
Last synced: 5 months ago
JSON representation
:package: Sync released npm packages to a mirror site.
- Host: GitHub
- URL: https://github.com/ntnyq/sync-npm-packages
- Owner: ntnyq
- License: mit
- Created: 2025-01-06T03:10:33.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-21T07:09:06.000Z (6 months ago)
- Last Synced: 2025-04-22T21:55:18.274Z (6 months ago)
- Topics: npm-mirror, npm-package, npmmirror, sync
- Language: TypeScript
- Homepage:
- Size: 206 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sync-npm-packages
[](https://github.com/ntnyq/sync-npm-packages/actions)
[](https://www.npmjs.com/package/sync-npm-packages)
[](https://www.npmjs.com/package/sync-npm-packages)
[](https://github.com/ntnyq/sync-npm-packages/blob/main/LICENSE)Sync released npm packages to a mirror site. e.g: [npmmirror](https://npmmirror.com/)
## Without installation
```shell
npx sync-npm-packages --target npmmirror
``````shell
yarn dlx sync-npm-packages --target npmmirror
``````shell
pnpm dlx sync-npm-packages --target npmmirror
```## Install
```shell
npm install sync-npm-packages -D
``````shell
yarn add sync-npm-packages -D
``````shell
pnpm add sync-npm-packages -D
```## Usage
```ts
import { syncNpmPackages, syncNpmPackagesAuto } from 'sync-npm-packages'// single package
await syncNpmPackages('package-foobar', { target: 'npmmirror' })// multiple packages
await syncNpmPackages(['package-foo', 'package-bar'], { target: 'npmmirror' })// auto detect package.json and sync
await syncNpmPackagesAuto({ target: 'npmmirror' })// auto sync with options
await syncNpmPackagesAuto({
cwd: './packages',
ignore: ['**/themes/**', '**/tools/**'],
target: 'npmmirror',
})
```## Config file
`sync-npm-packages` uses [antfu-collective/unconfig](https://github.com/antfu-collective/unconfig) as the config loader, it will resolve files below by order:
- `sync.config.mts`
- `sync.config.cts`
- `sync.config.ts`
- `sync.config.mjs`
- `sync.config.cjs`
- `sync.config.js`
- `sync.config.json`
- `.syncrc.json`All properties of `Options` are supported and optional.
JSON schema for json format config
### .syncrc.json
Config in `.syncrc.json`
```json
{
"$schema": "https://unpkg.com/sync-npm-packages/schemas/syncrc.json"
}
```
Example:
```ts
// sync.config.ts
import { defineConfig } from 'sync-npm-packages'export default defineConfig({
target: 'npmmirror',
defaultIgnore: false,
})
```> [!NOTE]
> When both config file and cli options are provided, cli options would take a higher priority.## Cli
In package.json, if installed as a devDependency, `npx` can be emited.
```json
{
"scripts": {
"release": "npm publish && npx sync-npm-packages --target npmmirror"
}
}
```## GitHub Action
Run `npx sync-npm-packages` after publishing packages to npm.
```yaml
name: Releasepermissions:
contents: writeon:
push:
tags:
- 'v*'jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0# publish packages to npm
- run: npx sync-npm-packages --target npmmirror
```## API
### syncNpmPackages
**Type**: `(input: string | string[], options: SyncOptions) => Promise`
Sync npm packages release to a mirror site.
#### Parameters
**input**
The package name or package names to sync.
- **Type**: `string | string[]`
**options**
Sync options.
- **Type**: `SyncOptions`
### syncNpmPackagesAuto
**Type**: `(options?: SyncOptions & DetectOptions) => Promise`
Auto detect and sync npm packages release to a mirror site.
#### Parameters
**options**
The sync options.
- **Type**: `SyncOptions & DetectOptions`
## Interfaces
```ts
export interface DetectOptions {
/**
* Current working directory for glob
*
* @default process.cwd()
*/
cwd?: string/**
* Use built-in default ignore patterns
*
* @default true
*/
defaultIgnore?: boolean/**
* Exclude packages from being synced
*
* @default []
*/
exclude?: string | string[]/**
* Ignore package.json glob pattern
*
* @default []
*/
ignore?: string | string[]/**
* Additional packages to sync
*
* @default []
*/
include?: string | string[]/**
* With `optionalDependencies` in `package.json`
*
* @default false
*/
withOptional?: boolean
}export interface SyncOptions {
/**
* Sync target mirror set
*
* @requires
*/
target: 'npmmirror'/**
* Enable debug mode
*
* @default false
*/
debug?: boolean
}
```## Additional
### Default ignore patterns
- `**/node_modules/**`
- `**/.git/**`
- `**/docs/**`
- `**/tests/**`
- `**/examples/**`
- `**/fixtures/**`
- `**/playground/**`Use `--no-default-ignore` in cli or `defaultIgnore: false` in NodeJS API to disable all default ignore patterns except \***\*/node_modules/\*\***.
## Credits
- Idea from [vuepress/ecosystem](https://github.com/vuepress/ecosystem/blob/main/scripts/syncNpmmirror.ts)
## License
[MIT](./LICENSE) License © 2025-PRESENT [ntnyq](https://github.com/ntnyq)