# sol-merger

> Merges all import files into single file.

Latest version **4.4.2** (published 2025-04-03) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install sol-merger
pnpm add sol-merger
yarn add sol-merger
bun add sol-merger
```

Provides the command `sol-merger`.

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.4.2 |
| Published | 2025-04-03 |
| First published | 2017-09-01 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 7 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 154 |
| Author | Valery Aligorsky |
| Maintainers | ryuugan |
| Keywords | smartcontract, sol, merger, solidity, solidity-merger, analyzer, smart contract |

## Links

- npm: https://www.npmjs.com/package/sol-merger
- Repository: https://github.com/RyuuGan/sol-merger
- Homepage: https://github.com/RyuuGan/sol-merger#readme
- Issues: https://github.com/RyuuGan/sol-merger/issues
- npm.io page: https://npm.io/package/sol-merger

## Dependencies (7)

- [glob](https://npm.io/package/glob.md) ^7.1.7
- [debug](https://npm.io/package/debug.md) ^4.3.4
- [antlr4ts](https://npm.io/package/antlr4ts.md) ^0.5.0-alpha.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [commander](https://npm.io/package/commander.md) ^4.0.1
- [picocolors](https://npm.io/package/picocolors.md) ^1.1.1
- [strip-json-comments](https://npm.io/package/strip-json-comments.md) ^3.0.1

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 4.4.2 (latest) — 2025-04-03
- 4.4.1 — 2023-12-10
- 4.4.0 — 2023-04-15
- 4.3.0 — 2023-02-24
- 4.2.0 — 2023-02-04
- 4.1.1 — 2022-04-03
- 4.1.0 — 2022-04-03
- 4.0.0 — 2022-02-22
- 3.1.0 — 2020-06-26
- 3.0.1 — 2020-05-17
- 3.0.0 — 2020-05-17
- 2.0.1 — 2020-02-07
- 2.0.0 — 2020-02-05
- 1.2.2 — 2020-01-07
- 1.1.1 — 2019-10-22
- … 11 more at https://npm.io/package/sol-merger/versions

## README

### Build status

![Build status](https://github.com/RyuuGan/sol-merger/actions/workflows/node.js.yml/badge.svg)

### Quick Usage

```javascript
const { merge } = require('sol-merger');

// Get the merged code as a string
const mergedCode = await merge('./contracts/MyContract.sol');
// Print it out or write it to a file etc.
console.log(mergedCode);
```

### CLI Usage

Right now it only works with solidity files that are in `node_modules`
or relative to your solidity file.

Simple usage:

```sh
npm i --save-dev sol-merger
```

Then add following line to your `package.json`.

```json
{
  "scripts": {
    "build-contracts": "sol-merger \"./contracts/*.sol\" ./build"
  }
}
```

This will allow you to use `npm run build-contracts` in your project directory.

Note that contracts glob should be surrounded with `"`

If no output file specified then output file will be created at the same
directory and appended with `_merged` (by default), i.e. `MyContract_merged.sol`. You can also
change this behaviour by specifying `--append` option:

```sh
sol-merger --append _me "./contracts/*.sol"
sol-merger -a _me "./contracts/*.sol"
```

You may need to use `npm run` to invoke the program standalone, as in `npm run sol-merger`.

You can also get help via `--help` command

```sh
sol-merger -h
sol-merger --help
```

More info about `glob` available at [node-glob repository](https://github.com/isaacs/node-glob)

See tests for more examples.

# Post processing support

It is possible right now to write your own plugins to process exports.
Currently state is not used in plugins. To see available plugins
[take a look plugins page](https://github.com/RyuuGan/sol-merger/tree/develop/lib/plugins).

All default plugins are available via shortcut syntax using filename:

```
sol-merger --export-plugin SPDXLicenseRemovePlugin "test/contracts/*.sol" compiled
```

It is also possible to use external plugins via relative path to plugin
or path relative to `node_modules`:

```sh
sol-merger --export-plugin ./dist/lib/plugins/SPDXLicenseRemovePlugin.js "test/contracts/*.sol" compiled

sol-merger --export-plugin sol-merger/lib/plugins/SPDXLicenseRemovePlugin.js "test/contracts/*.sol" compiled
```

Note that file extension is required for plugin to be loaded.

# Additional root folders for searching contracts

By default, `sol-merger` only searches for contracts in the `node_modules` folder.
However, you can include additional root folders to search for contracts.
This can be done by passing a CLI argument or a parameter through the code.

If additional root folders are specified, `sol-merger` will first search for
the contract in the `node_modules` folder and then in the additional root folders.
Multiple folders can be included by passing a CLI argument multiple times.

Example of usage in CLI:

```sh
sol-merger --additional-root "./test/contracts/imports" "test/contracts/ImportWithAdditionalRoot.sol" compiled
```

Example of usage in code:

```ts
const merger = new Merger({
  delimeter: '\n\n',
  additionalRoots: ['./test/contracts/imports'],
});
```

# Debuging

It is possible to setup environment variable to see what is happening under the hood
when contracts are being compiled:

```sh
export DEBUG="sol-merger*"
```

# Plugin for VSCode

I created a plugin for `VSCode` so you can use it instead of `sol-merger`: [Solidity Contracts Merger](https://marketplace.visualstudio.com/items?itemName=RyuuGan.sol-merger-vscode).

Hope you will like it.

---
_Source: https://npm.io/package/sol-merger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
