0.3.2 • Published 4 months ago

inlinable v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Inlinable

Quickstart

First, add the package as dev dependency:

npm install -D inlinable

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

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:

$ inlinable replace lib/**/*.js

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

  "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:

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.

0.3.2

4 months ago

0.3.0

5 months ago

0.2.8

5 months ago

0.3.1

5 months ago

0.2.7

8 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.2.6

10 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.5

11 months ago

0.2.4

11 months ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago