# terser-sync

> Execute Terser minify synchronously

Latest version **0.1.1** (published 2021-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install terser-sync
pnpm add terser-sync
yarn add terser-sync
bun add terser-sync
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-08-25 |
| First published | 2021-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 4 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Overlook Motel |
| Maintainers | overlookmotel |
| Keywords | terser, minify, sync |

## Links

- npm: https://www.npmjs.com/package/terser-sync
- Repository: https://github.com/overlookmotel/terser-sync
- Homepage: https://github.com/overlookmotel/terser-sync#readme
- Issues: https://github.com/overlookmotel/terser-sync/issues
- npm.io page: https://npm.io/package/terser-sync

## Dependencies (4)

- [terser](https://npm.io/package/terser.md) ^5.7.2
- [is-it-type](https://npm.io/package/is-it-type.md) ^5.0.0
- [source-map](https://npm.io/package/source-map.md) ^0.5.7
- [has-own-prop](https://npm.io/package/has-own-prop.md) ^2.0.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2021-08-25
- 0.1.0 — 2021-07-12

## README

[![NPM version](https://img.shields.io/npm/v/terser-sync.svg)](https://www.npmjs.com/package/terser-sync)
[![Build Status](https://img.shields.io/github/workflow/status/overlookmotel/terser-sync/Test.svg)](https://github.com/overlookmotel/terser-sync/actions)
[![Dependency Status](https://img.shields.io/david/overlookmotel/terser-sync.svg)](https://david-dm.org/overlookmotel/terser-sync)
[![Dev dependency Status](https://img.shields.io/david/dev/overlookmotel/terser-sync.svg)](https://david-dm.org/overlookmotel/terser-sync)
[![Coverage Status](https://img.shields.io/coveralls/overlookmotel/terser-sync/master.svg)](https://coveralls.io/r/overlookmotel/terser-sync)

# Execute Terser minify synchronously

## What is this?

A really hacky way of of getting [Terser](https://www.npmjs.com/package/terser) to run synchronously.

`terser.minify()` is async and returns a Promise. The reason for this is that Terser uses uses [source-map](https://www.npmjs.com/package/source-map) (which is implemented in WASM and is async) to parse input source maps. The entire rest of Terser's codebase is synchronous, but this one dependency forces Terser to be async too.

This package calls Terser with a specially crafted options object which tricks Terser into skipping over the async code and into using an older version of source-map (v0.5.7) which is pure JS and is synchronous.

`minifySync()` is born!

## Usage

This package is a drop-in replacement for Terser which adds a `minifySync()` method.

```js
const terser = require('terser-sync');

// Original async terser.minify()
const {code} = await terser.minify('() => {}');

// Sync version - options are exactly the same
const {code} = terser.minifySync('() => {}');
```

### Errors

If Terser throws an error, it's not possible to obtain it synchronously. `minifySync()` will throw an error synchronously and that error has a `.promise` property which will resolve to the error Terser threw.

```js
try {
  terser.minifySync( '() => {}', { nonExistentOption: true } );
} catch (e) {
  const err = await e.promise;
  // err.message === '`nonExistentOption` is not a supported option'
}
```

## Versioning

This module follows [semver](https://semver.org/). Breaking changes will only be made in major version updates.

All active NodeJS release lines are supported (v12+ at time of writing). After a release line of NodeJS reaches end of life according to [Node's LTS schedule](https://nodejs.org/en/about/releases/), support for that version of Node may be dropped at any time, and this will not be considered a breaking change. Dropping support for a Node version will be made in a minor version update (e.g. 1.2.0 to 1.3.0). If you are using a Node version which is approaching end of life, pin your dependency of this module to patch updates only using tilde (`~`) e.g. `~1.2.3` to avoid breakages.

## Tests

Use `npm test` to run the tests. Use `npm run cover` to check coverage.

## Changelog

See [changelog.md](https://github.com/overlookmotel/terser-sync/blob/master/changelog.md)

## Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/terser-sync/issues

## Contribution

Pull requests are very welcome. Please:

* ensure all tests pass before submitting PR
* add tests for new features
* document new functionality/API additions in README
* do not add an entry to Changelog (Changelog is created when cutting releases)

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