# @fwoosh/virtual-file

> Utility function to help create virtual files for fwoosh. Enables authoring in TS but being loaded in a virtual files as plain JS.

Latest version **0.0.126** (published 2023-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fwoosh/virtual-file
pnpm add @fwoosh/virtual-file
yarn add @fwoosh/virtual-file
bun add @fwoosh/virtual-file
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.126 |
| Published | 2023-02-21 |
| First published | 2023-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Andrew Lisowski |
| Maintainers | alisowski |

## Links

- npm: https://www.npmjs.com/package/@fwoosh/virtual-file
- Repository: https://github.com/hipstersmoothie/fwoosh
- Homepage: https://github.com/hipstersmoothie/fwoosh#readme
- Issues: https://github.com/hipstersmoothie/fwoosh/issues
- npm.io page: https://npm.io/package/@fwoosh/virtual-file

## Dependencies (1)

- [esbuild](https://npm.io/package/esbuild.md) ^0.17.7

## Recent versions

- 0.0.126 (latest) — 2023-02-21
- 0.0.127--canary.b23f4f1.0 (canary) — 2023-08-05
- 0.0.126--canary.78.79db14d.0 — 2023-02-21
- 0.0.126--canary.78.44c3e91.0 — 2023-02-21
- 0.0.126--canary.78.19a91ae.0 — 2023-02-20
- 0.0.126--canary.2f17ddd.0 — 2023-02-20
- 0.0.126--canary.78.57c4714.0 — 2023-02-20
- 0.0.126--canary.78.089e333.0 — 2023-02-20
- 0.0.126--canary.02f5198.0 — 2023-02-20
- 0.0.126--canary.78.8abe2ab.0 — 2023-02-19
- 0.0.126--canary.78.1a36e7f.0 — 2023-02-19
- 0.0.126--canary.78.b24a189.0 — 2023-02-19
- 0.0.125 — 2023-02-18
- 0.0.125--canary.78.fb4b692.0 — 2023-02-18
- 0.0.124 — 2023-02-18
- … 97 more at https://npm.io/package/@fwoosh/virtual-file/versions

## README

# `@fwoosh/virtual-file`

Utility function to help create virtual files for fwoosh. Enables authoring in TS but being loaded in a virtual files as plain JS.

## Usage

The following will load the contents of `my-file.ts` as ESM JS.

```js example.js
import { loadVirtualFile } from "@fwoosh/virtual-file";
import { createRequire } from "module";

const require = createRequire(import.meta.url);

// NOTE: Use the .js extension even if it's .ts
await loadVirtualFile(require.resolve("./my-file.js"));
```

## Variables

You can inject variables into loaded files by using `process.env.YOUR_VARIABLE` in your file.

Give this file:

```tsx my-file.ts
export function getVariable() {
  return process.env.YOUR_VARIABLE;
}
```

And this usage:

```tsx my-usage.ts
await loadVirtualFile(require.resolve("./my-file.js"), {
  YOUR_VARIABLE: 1000,
});
```

The virtual file will be:

```tsx output.ts
export function getVariable() {
  return 1000;
}
```

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