# inlinable

> JavaScript code inlining utilities

Latest version **0.8.2** (published 2025-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install inlinable
pnpm add inlinable
yarn add inlinable
bun add inlinable
```

Provides the command `inlinable`.

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads; pre 1.0.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 0.8.2 |
| Published | 2025-04-25 |
| First published | 2023-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 9 |
| Unpacked size | 32.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthieu Monsch |
| Maintainers | mtth |
| Keywords | inline |

## Links

- npm: https://www.npmjs.com/package/inlinable
- Repository: https://github.com/mtth/sdk.ts
- Homepage: https://github.com/mtth/sdk.ts#readme
- Issues: https://github.com/mtth/sdk.ts/issues
- npm.io page: https://npm.io/package/inlinable

## Dependencies (9)

- [ora](https://npm.io/package/ora.md) ^8.0.1
- [glob](https://npm.io/package/glob.md) ^10.4.1
- [acorn](https://npm.io/package/acorn.md) ^8.11.3
- [recast](https://npm.io/package/recast.md) ^0.23.7
- [ast-types](https://npm.io/package/ast-types.md) ^0.14.2
- [commander](https://npm.io/package/commander.md) ^12.1.0
- [@mtth/stl-utils](https://npm.io/package/@mtth/stl-utils.md) 0.8.2
- [@mtth/stl-errors](https://npm.io/package/@mtth/stl-errors.md) 0.8.2
- [inlinable-runtime](https://npm.io/package/inlinable-runtime.md) 0.8.2

## Recent versions

- 0.8.2 (latest) — 2025-04-25
- 0.8.1 — 2025-04-25
- 0.8.0 — 2025-04-24
- 0.7.1 — 2025-03-29
- 0.7.0 — 2025-03-15
- 0.6.0 — 2025-02-15
- 0.5.0 — 2025-02-15
- 0.4.2 — 2025-02-15
- 0.4.1 — 2025-02-15
- 0.4.0 — 2025-02-15
- 0.3.5 — 2024-11-20
- 0.3.4 — 2024-08-03
- 0.3.3 — 2024-05-25
- 0.3.2 — 2024-01-21
- 0.3.1 — 2023-11-30
- … 22 more at https://npm.io/package/inlinable/versions

## README

# Inlinable

## Quickstart

First, add the package as dev dependency:

```sh
npm install -D inlinable
```

Then use the default export in any JavaScript module to flag an expression as
candidate for inlining:

```typescript
import __inlinable from 'inlinable';

// Inline the contents of `resources/METADATA`
const metadata = __inlinable((ctx) => {
  const path = ctx.enclosing(import.meta.url).resourcePath('METADATA');
  return ctx.readTextFile(path);
});
```

Then run the command below to inline all candidates found in matching files:

```sh
$ inlinable replace lib/**/*.js
```

This works best when run automatically after TypeScript compilation within a
`package.json` script:

```javascript
  "scripts": {
    "build": "tsc -p src && inlinable replace"
    // ...
  }
```

## How does it work?

In the simple case, `inlinable replace` runs each inlinable function as if it
was an [IIFE][] and substitutes the original value with its JSONified return
value. Additionally, the `inlinable` import is removed. In the example above,
the final code will look like:

```typescript
const metadata = "...METADATA contents...";
```

It's also possible to run the code directly. `__inlinable` is guaranteed to
produce the same result as the inlined version when the inlined functions do not
rely on side-effects. This is typically useful for running tests.

[IIFE]: https://developer.mozilla.org/en-US/docs/Glossary/IIFE

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