{"id":24143329,"url":"https://github.com/little-core-labs/tiny-module-compiler","last_synced_at":"2026-03-08T02:04:54.520Z","repository":{"id":35825667,"uuid":"219403958","full_name":"little-core-labs/tiny-module-compiler","owner":"little-core-labs","description":"Compile, archive, unpack, and load compiled modules leveraging v8 cached data.","archived":false,"fork":false,"pushed_at":"2021-11-11T21:53:16.000Z","size":200,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-25T00:56:52.415Z","etag":null,"topics":["cache","compiler","module","node","tiny","tinybox","v8"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/little-core-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-04T02:49:09.000Z","updated_at":"2024-01-14T00:00:34.000Z","dependencies_parsed_at":"2022-08-03T00:30:57.671Z","dependency_job_id":null,"html_url":"https://github.com/little-core-labs/tiny-module-compiler","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/little-core-labs/tiny-module-compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Ftiny-module-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Ftiny-module-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Ftiny-module-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Ftiny-module-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/little-core-labs","download_url":"https://codeload.github.com/little-core-labs/tiny-module-compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/little-core-labs%2Ftiny-module-compiler/sbom","scorecard":{"id":593004,"data":{"date":"2025-08-11","repo":{"name":"github.com/little-core-labs/tiny-module-compiler","commit":"5e85c16867897597ec3b3e70d0ecc6be7311ff04"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/little-core-labs/tiny-module-compiler/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/little-core-labs/tiny-module-compiler/nodejs.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:22","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T22:25:59.386Z","repository_id":35825667,"created_at":"2025-08-20T22:25:59.386Z","updated_at":"2025-08-20T22:25:59.386Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30242404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"online","status_checked_at":"2026-03-08T02:00:06.215Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","compiler","module","node","tiny","tinybox","v8"],"created_at":"2025-01-12T05:15:14.714Z","updated_at":"2026-03-08T02:04:54.486Z","avatar_url":"https://github.com/little-core-labs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/little-core-labs/tiny-module-compiler/blob/master/assets/cover.png\" alt=\"tiny module compiler\" /\u003e\n\n**_Compile, archive, unpack, and load compiled modules leveraging v8 cached data._**\n\n\u003ca name=\"toc\"\u003e\u003c/a\u003e\n## Table of Contents\n\n* [**Status**](#status)\n* [**Installation**](#installation)\n* [**Abstract**](#abstract)\n* [**Basic Usage**](#usage)\n* [**API**](#api)\n  * [`compile(target[, options], callback)`](#api-compile)\n  * [`archive(target, objects[, options], callback)`](#api-archive)\n  * [`load(target[, options], callback)`](#api-load)\n  * [`unpack(target[, options], callback)`](#api-unpack)\n  * [Class: `Compiler`](#api-class-compiler)\n    * [Constructor: `new Compiler([options])`](#api-class-compiler-constructor)\n    * [Accessor: `compiler.targets`](#api-class-compiler-targets)\n    * [`compiler.ready(callback)`](#api-class-compiler-ready)\n    * [`compiler.target(filename[, options], callback)`](#api-class-compiler-target)\n    * [`compiler.compile([options], callback)`](#api-class-compiler-target)\n  * [Class: `Archiver`](#api-class-archiver)\n    * [Constructor: `new Archiver([options])`](#api-class-archiver-constructor)\n    * [`archiver.ready(callback)`](#api-class-archiver-ready)\n    * [`archiver.archive(filename, objects[, options], callback)`](#api-class-archiver-archive)\n  * [Class: `Loader`](#api-class-loader)\n    * [Constructor: `new Loader([options])`](#api-class-loader-constructor)\n    * [`loader.ready(callback)`](#api-class-loader-ready)\n    * [`loader.load(filename[, options], callback)`](#api-class-loader-load)\n  * [Class: `Target`](#api-class-target)\n    * [Constructor: `new Target(filename[, options])`](#api-class-target-constructor)\n    * [Accessor: `target.fd`](#api-class-target-fd)\n    * [`target.stat(callback)`](#api-class-target-stat)\n    * [`target.read(offset, size, callback)`](#api-class-target-read)\n    * [`target.ready(callback)`](#api-class-target-ready)\n* [**Command Line Interface**](#cli)\n  * [**The `tmc(1)` Command**](#cli-tmc)\n  * [**Compiling Modules**](#cli-compiling)\n  * [**Archiving Compiled Modules**](#cli-archiving-modules)\n  * [**Copying Relocated Assets**](#cli-copying-assets)\n  * [**Archiving Relocated Assets**](#cli-archiving-assets)\n  * [**Unpacking Archives**](#cli-unpacking)\n  * [**Loading Modules \u0026 Archives**](#cli-loading)\n* [**Constraints**](#constraints)\n  * [**v8 Version**](#constraints-v8-version)\n  * [`Function.prototype.toString()`](#constraints-function-to-string)\n* [**See Also**](#see-also)\n* [**Prior Art**](#prior-art)\n* [**License**](#license)\n\n\u003ca name=\"status\"\u003e\u003c/a\u003e\n## Status\n\n\u003e **Stable/Documentation**\n\n\u003e [![Actions Status](https://github.com/little-core-labs/tiny-module-compiler/workflows/Node%20CI/badge.svg)](https://github.com/little-core-labs/tiny-module-compiler/actions)\n\n\u003ca name=\"installation\"\u003e\u003c/a\u003e\n## Installation\n\n```sh\n$ npm install tiny-module-compiler\n```\n\n\u003ca name=\"abstract\"\u003e\u003c/a\u003e\n## Abstract\n\nThe `tiny-module-compiler` module is small toolkit for compiling\nJavaScript CommonJs modules into standalone binaries that leverage that\nv8 cache data format exposed by the [`vm`](https://nodejs.org/api/vm.html)\nAPI. Compiled module objects can be archived into a single file based on the\n[TinyBox][tinybox] file format and then unpacked later to the file\nsystem.\n\nThis toolkit allows for the compilation of an entire project into a single\ncompiled binary object file. Multiple binary object files and various\nassets (`*.node`, `*.so`, etc) can be packaged into an archive and\nunpacked to file system for later use making it suitable as a delivery\nmechanism.\n\nCompiled modules objects can be loaded and executed but must be in a\nruntime that uses the same [version of v8](#constraints-v8-version).\n\n\u003ca name=\"usage\"\u003e\u003c/a\u003e\n## Basic Usage\n\n```js\nconst tmc = require('tiny-module-compiler')\n\nconst targets = '*.js'\nconst archiveName = 'modules.a'\n\n// compile module targets into compiled module objects\ntmc.compile(targets, (err, objects) =\u003e {\n  // archive objects into file specified by `archiveName`\n  tmc.archive(archiveName, objects, (err) =\u003e {\n    tmc.load(archiveName, (err, archive) =\u003e {\n      // `archive` contains a mapping of compiled module object\n      // filenames to loaded exports\n    })\n  })\n})\n```\n\n## API\n\nThe `tiny-module-compiler` module exports a public API described in this\nsection.\n\n\u003ca name=\"api-compile\"\u003e\u003c/a\u003e\n### `compile(target[, options], callback)`\n\nCompiles a file specified at `target`. The default behavior is to write\nthe output to a file of the same name as `target` with `.out` appended\nto the end. This behaviour can be configured by specifying an\n`options.output` option or `options.storage` as a custom\n[random-access-storage][ras] _factory function_.\n\nThe value of `options` is optional and can be:\n\n```js\n{\n  // current working directory for compilation\n  cwd: process.cwd(),\n\n  // output filename (single file compilation) or directory (multiple files)\n  output: target + '.out',\n\n  // custom storage factory function to return\n  // 'random-access-storage' compliant object\n  storage(filename) {\n    return require('random-access-file')(filename)\n  }\n}\n```\n\n#### Examples\n\n##### Simple Compilation\n\nA simple compilation example that compiles a target input file to an\noutput file.\n\n```js\nconst { compile } = require('tiny-module-compiler')\n\n// compile this file\nconst target = __filename\nconst output = __filename + '.out'\ncompile(target, { output }, (err) =\u003e {\n  // `target` compiled to `output`\n})\n```\n\n##### Simple Compilation to Memory\n\nA simple compilation example that compiles a target input file to an in\nmemory `random-access-memory` storage.\n\n```js\nconst { compile } = require('tiny-module-compiler')\nconst ram = require('random-access-memory')\n\n// compile this file\nconst target = __filename\nconst storage = ram()\ncompile(target, { storage: () =\u003e storage }, (err) =\u003e {\n  // `target` compiled and written to `storage`\n})\n```\n\n\u003ca name=\"api-archive\"\u003e\u003c/a\u003e\n### `archive(target, inputs[, options], callback)`\n\nArchives the entries found in a given `inputs` `Map` into `target`. The\ndefault behaviour is to enumerate the entries in `inputs` and write them\nto a [TinyBox][tinybox] instance specified at `target` where the keys\nand values of the entries are \"put\" into the TinyBox storage that lives\non the file system. This behaviour can be configured by specifying\n`options.storage` as a custom [random-access-storage][ras] _instance_.\n\nThe value of `options` is optional and can be:\n\n```js\n{\n  // if `false`, will not truncate archive storage\n  truncate: true,\n\n  // custom 'random-access-storage' compliant object\n  storage: require('random-access-file')(target)\n}\n```\n\n#### Examples\n\n##### Simple Archive\n\nA simple example that archives the compiled objects of a compiled file.\n\n```js\nconst { compile, archive } = require('tiny-module-compiler')\n\n// compile this file\nconst target = __filename\n\ncompile(target, (err, objects) =\u003e {\n  archive(__filename + '.a', objects, (err) =\u003e {\n    // `target` is compiled and then archived\n  })\n})\n```\n\n##### Simple Archive in Memory\n\nA simple example that archives the compiled objects of a compiled file\ninto an in memory `random-access-memory` storage.\n\n```js\nconst { compile, archive } = require('tiny-module-compiler')\nconst ram = require('random-access-memory')\n\n// compile this file\nconst target = __filename\ncompile(target, { storage: ram }, (err) =\u003e {\n  const storage = ram()\n  archive(__filename + '.a', objects, { storage}, (err) =\u003e {\n    // `target` is compiled and then archived\n    // `storage` contains archived objects\n  })\n})\n```\n\n\u003ca name=\"api-load\"\u003e\u003c/a\u003e\n### `load(target[, options], callback)`\n\nLoads the exports from a module or the entries in archive specified at\n`target`. The default behaviour is to load the contents of the file\nspecified at `target` as a compiled module and call `callback(err,\nexports)` upon success or error with the module exports. If `target` is\na path to an archive represented by a [TinyBox][tinybox], then the\nentries are loaded and `callback(err, archive)` is called upon success\nor error. The storage of the compiled module or archive can be\nexplicitly set by specifying `options.storage` as a custom\n[random-access-storage][ras] _instance_.\n\nThe value of `options` is optional and can be:\n\n```js\n{\n  // custom 'random-access-storage' compliant object\n  storage: require('random-access-file')(target),\n\n  // custom cache `Map` store for loaded modules\n  cache: new Map(),\n\n  // current working directory to load module in\n  cwd: process.cwd()\n}\n```\n\n#### Example\n\n##### Simple Compile and Load\n\nA simple compilation and load example that compiles a target input file to an\noutput file and then loads the exports.\n\n***file.js:***\n\n```js\nmodule.exports = {\n  hello() {\n    return 'world'\n  }\n}\n```\n\n***compile-and-load.js:***\n\n```js\nconst { compile, load } = require('tiny-module-compiler')\n\n// compile this file\nconst target = 'file.js'\nconst output = target + '.out'\ncompile(target, { output }, (err) =\u003e {\n  // `target` compiled to `output`\n  load(output, (err, exports) =\u003e {\n    // `exports` points to `module.exports` in `output`\n    console.log(exports.hello()) // 'world'\n  })\n})\n```\n\n##### Simple Compile and Load in Memory\n\nA simple compilation and load example that compiles a target input file to an\nin memory storage and then loads the exports from it.\n\n***file.js:***\n\n```js\nmodule.exports = {\n  hello() {\n    return 'world'\n  }\n}\n```\n\n***compile-and-load-in-memory.js:***\n\n```js\nconst { compile, load } = require('tiny-module-compiler')\nconst ram = require('random-access-memory')\n\n// compile this file\nconst target = 'file.js'\nconst storage = ram()\ncompile(target, { storage: () =\u003e storage }, (err) =\u003e {\n  // `target` compiled to `storage`\n  load('loaded from memory', { storage }, (err, exports) =\u003e {\n    // `exports` points to `module.exports` in `output`\n    console.log(exports.hello()) // 'world'\n  })\n})\n```\n\n\u003ca name=\"api-unpack\"\u003e\u003c/a\u003e\n### `unpack(target[, options], callback)`\n\nUnpacks `target` archive entries. The default behaviour is to enumerate\nthe entries in the archive specified at `target` and copy them to the\nfile system. This behaviour can be configured by specifying a `options.storage`\n[random-access-storage][ras] _factory function_ to provide custom\nstorage for the archive entries. If `target` is a [random-access-storage][ras]\ninstance, it will be used instead of reading from the file system.\n\nThe value of `options` is optional and can be:\n\n```js\n{\n  // output path for default storage\n  output: process.cwd(),\n\n  // custom storage factory function to return\n  // 'random-access-storage' compliant object\n  storage(filename) {\n    return require('random-access-file')(filename)\n  }\n}\n```\n\n#### Example\n\n##### Simple Unpack\n\nA simple example to unpack an archive's entries to file system.\n\n```js\nconst { unpack } = require('tiny-module-compiler')\n\nconst archive = '/path/to/archive'\nunpack(archive, (err, entries) =\u003e {\n  // `archive` entries unpacked to file system\n  console.log(entries) // array of unpacked file names\n})\n```\n\n##### Simple Unpack in Memory\n\nA simple example to unpack an archive's entries to an in memory file\nstore.\n\n```js\nconst { unpack } = require('tiny-module-compiler')\nconst ram = require('random-access-memory'\n\nconst archive = '/path/to/archive'\nconst files = new Map()\n\nunpack(archive, { storage: createStorage }, (err, entries) =\u003e {\n  // `archive` entries unpacked to file system\n  console.log(entries) // array of unpacked file names\n  for (const entry of entries) {\n    console.log(files[entry.filename])\n  }\n})\n\nfunction createStorage(filename) {\n  return files.set(filename, ram()).get(filename)\n}\n```\n\n\u003ca name=\"api-class-compiler\"\u003e\u003c/a\u003e\n### Class: `Compiler`\n\n* Extends: [`nanoresource-pool`][nanoresource-pool]\n\nThe `Compiler` class represents a container of compile targets\nthat can be compiled into a single binary file containing\nv8 cache data and header information about the compiled output.\n\n\u003ca name=\"api-class-compiler-constructor\"\u003e\u003c/a\u003e\n#### Constructor: `new Compiler([options])`\n\nCreates a new [`Compiler`](#api-class-compiler) instance where `options`\ncan be:\n\n```js\n{\n  // current working directory for compilation\n  cwd: process.cwd()\n}\n```\n\n##### Example\n\n```js\nconst compiler = new Compiler()\n```\n\n\u003ca name=\"api-class-compiler-targets\"\u003e\u003c/a\u003e\n#### Accessor: `compiler.targets`\n\n* `Array\u003cString\u003e`\n\nAll opened targets in the compiler.\n\n##### Example\n\n```js\nfor (const target of compiler.targets) {\n  // handle opened `target`\n}\n```\n\n\u003ca name=\"api-class-compiler-ready\"\u003e\u003c/a\u003e\n#### `compiler.ready(callback)`\n\nWaits for compiler to be ready and calls `callback()` upon success.\n\n##### Example\n\n```js\ncompiler.ready(() =\u003e {\n  // `compiler` is opened and ready\n})\n```\n\n\u003ca name=\"api-class-compiler-target\"\u003e\u003c/a\u003e\n#### `compiler.target(filename[, options], callback)`\n\nCreates and returns a new compile [target](#api-class-target) that is added\nto compiler pool calling `callback(err, target)` when the target resource\nis opened or an error occurs. The target will be compiled when\n[`compiler.compiler()`](#api-class-compiler-compile) is called.\n\nThe value of `options` can be:\n\n```js\n{\n  // the default output for a compilation target\n  output: target + '.out',\n\n  // custom storage factory function to return\n  // 'random-access-storage' compliant object\n  storage(filename) {\n    return require('random-access-file')(filename)\n  }\n}\n```\n\n##### Example\n\n```js\ncompiler.target('/path/to/file.js', (err, target) =\u003e {\n  // `target` is an opened `nanoresource`\n})\n```\n\n\u003ca name=\"api-class-compiler-compile\"\u003e\u003c/a\u003e\n#### `compiler.compile([options], callback)`\n\nCompiles all pending compile [targets](#api-class-compiler-target) calling\n`callback(err, objects, assets)` upon success or error. Callback will be\ngiven a `Map` of compiled objects and a `Map` of extracted assets that\nshould live with the compiled objects on the file system.\n\nThe value of `options` can be:\n\n```js\n{\n  // if `true`, will produce a source map stored in the `assets` map\n  map: false,\n\n  // if `false`, `ncc` will produce verbose output\n  quiet: true,\n\n  // if `true`, will use `ncc` cache for faster builds\n  cache: false,\n\n  // if `true`, will produce compiled javascript source debug output\n  debug: false,\n\n  // if `true`, will minify compiled javascript source before creating binary\n  optimize: false,\n\n  // an array of external modules that should _not_ be compiled\n  externals: [],\n}\n```\n\n##### Example\n\n```js\ncompiler.compile({ externals: ['sodium-native'] }, (err, objects, assets) =\u003e {\n  // `objects` is a `Map` mapping file names to compiled module objects\n  // `assets` is a `Map` mapping file names to assets that should be copied\n})\n```\n\n\u003ca name=\"api-class-archiver\"\u003e\u003c/a\u003e\n### Class: `Archiver`\n\n* Extends: [`nanoresource`][nanoresource]\n\nThe `Archiver` class represents an abstraction for storing\ncompiled objects into a [TinyBox][tinybox]\n\n\u003ca name=\"api-class-archiver-constructor\"\u003e\u003c/a\u003e\n#### Constructor: `new Archiver([options])`\n\nCreates a new [`Archiver`](#api-class-archiver) instance where `options`\ncan be:\n\n```js\n{\n  // default custom storage factory function to return\n  // 'random-access-storage' compliant object used in\n  // `archiver.archive()` calls. This storage can be overloaded\n  // by supplying a storage factory function to `archiver.archive()`\n  storage(filename) {\n    return require('random-access-file')(filename)\n  }\n}\n```\n\n##### Example\n\n```js\nconst ram = require('random-access-memory')\n\n// in memory archiver\nconst archiver = new Archiver({ storage: ram })\n```\n\n\u003ca name=\"api-class-archiver-ready\"\u003e\u003c/a\u003e\n#### `archiver.ready(callback)`\n\nWaits for archiver to be ready and calling `callback()` when it is.\n\n##### Example\n\n```js\narchiver.ready(() =\u003e {\n  // `archiver` is opened and ready\n})\n```\n\n\u003ca name=\"api-class-archiver-archive\"\u003e\u003c/a\u003e\n#### `archiver.archive(filename, inputs[, options], callback)`]\n\nArchives the entries found in a given `inputs` `Map` into `target`. The\nunderlying storage for `filename` can be given by `options.storage` or a\nnew one is created by the `storage` factory function given to the\n[`Archiver`](#api-class-archiver-constructor) class constructor.\n`callback(err)` is called upon success or error.\n\nThe value of `options` can be:\n\n```js\n{\n  // if `false`, will not truncate archive storage\n  truncate: true,\n\n  // custom 'random-access-storage' compliant object\n  // where `inputs` are archived to\n  storage: require('random-access-file')(filename)\n}\n```\n\n##### Example\n\n```js\nconst extend = require('map-extend')\n\ncompiler.compile((err, objects, assets) =\u003e {\n  // merge `objects` and `assets` and archive\n  archiver.archive('/path/to/archive', extend(objects, assets), (err) =\u003e {\n    // inputs should be archived\n  })\n```\n\n\u003ca name=\"api-class-loader\"\u003e\u003c/a\u003e\n### Class: `Loader`\n\n* Extends: [`nanoresource-pool`][nanoresource-pool]\n\nThe `Loader` class represents an abstraction for loading compiled\nmodule objects and JavaScript sources as node modules.\n\n\u003ca name=\"api-class-loader-constructor\"\u003e\u003c/a\u003e\n#### Constructor: `new Loader([options])`\n\nCreates a new [`Loader`](#api-class-loader) instance where `options`\ncan be:\n\n```js\n{\n  // custom cache `Map` store for loaded modules\n  cache: new Map()\n}\n```\n\n\u003ca name=\"api-class-loader-ready\"\u003e\u003c/a\u003e\n#### `loader.ready(callback)`\n\nWaits for loader to be ready and calling `callback()` when it is.\n\n##### Example\n\n```js\nloader.ready(() =\u003e {\n  // `loader` is opened and ready\n})\n```\n\n\u003ca name=\"api-class-loader-load\"\u003e\u003c/a\u003e\n#### `loader.load(filename[, options], callback)`\n\nLoads a compiled module object or JavaScript source module\nspecified at filename calling `callback(err, exports)` upon success\nor error. Success loads will cache resulting module for subsequent\nrequests to load the module.\n\nThe value of `options` can be:\n\n```js\n{\n  // custom 'random-access-storage' compliant object\n  // where module is loaded from\n  storage: require('random-access-file')(filename)\n}\n```\n\n##### Example\n\n```js\nloader.load('/path/to/compiled/module.js', (err, exports) =\u003e {\n  // `exports` points to `module.exports` of loaded module\n})\n```\n\n\u003ca name=\"api-class-target\"\u003e\u003c/a\u003e\n### Class: `Target`\n\n* Extends: [`nanoresource`][nanoresource]\n\nThe `Target` class represents a [`nanoresource`][nanoresource] to a target\nfile backed by a [`random-access-storage`][ras] instance.\n\n\u003ca name=\"api-class-target-constructor\"\u003e\u003c/a\u003e\n#### Constructor: `new Target(filename[, options])`\n\nCreates a new [`Target`](#api-class-target) instance where `filename`\nis the name of the target file and `options` can be:\n\n```js\n{\n  // custom 'random-access-storage' compliant object\n  // where file is loaded from\n  storage: require('random-access-file')(filename)\n}\n```\n\n***Note:*** _This class is intended for internal and advanced use. You\nwill most likely not use this directly._\n\n##### Example\n\n```js\nconst target = new Target('/path/to/file.js')\n```\n\n\u003ca name=\"api-class-target-fd\"\u003e\u003c/a\u003e\n#### Accessor: `target.fd`\n\n* `?(Number)`\n\nThe active file descriptor for the target resource. Will be `null`\nif not opened.\n\n\u003ca name=\"api-class-target-stat\"\u003e\u003c/a\u003e\n#### `target.stat(callback)`\n\nQueries for stats from the underlying target storage calling\n`callback(err, stats)` upon success or error.\n\n##### Example\n\n```js\ntarget.stat((err, stats) =\u003e {\n  console.log(stats.size)\n})\n```\n\n\u003ca name=\"api-class-target-read\"\u003e\u003c/a\u003e\n#### `target.read(offset, size, callback)`\n\nReads data from the underlying target storage at a specified `offset` and\n`size` calling `callback(err, buffer)` upon success or error.\n\n##### Example\n\n```js\ntaret.read(32, 64, (err, buffer) =\u003e {\n  console.log(buffer)\n})\n```\n\n\u003ca name=\"api-class-target-ready\"\u003e\u003c/a\u003e\n#### `target.ready(callback)`\n\nWaits for loader to be ready and calling `callback()` when it is.\n\n##### Example\n\n```js\ntarget.ready(() =\u003e {\n  // `target` is opened and ready\n})\n```\n\n\u003ca name=\"cli\"\u003e\u003c/a\u003e\n### Command Line Interface\n\nThe `tiny-module-compiler` exposes a command line interface through the\n`tmc` command that is suitable for compiling, archiving, and unpacking\ncompiled modules and their assets.\n\nThis section describes the command line interface and a few workflows\nfor making the best use of the `tmc` command.\n\n\u003ca name=\"cli-tmc\"\u003e\u003c/a\u003e\n#### The `tmc(1)` Command\n\nThe `tmc` command has a command line signature of the following:\n\n```sh\ntmc [-hV] [-acu] [-vCDMO] [options] ...input\n```\n\nWhere `options` can be:\n\n```sh\n  -a, --archive             If present, will archive input into \"tinybox\" format\n  -c, --compile             If present, will compile input into header prefixed v8 cached data\n    , --concurrency \u003cjobs\u003e  An alias for '--jobs'\n  -C, --copy-assets         If present, will copy assets to directory of output\n  -D, --debug               If present, will enable debug output (DEBUG=tiny-module-compiler)\n  -e, --external \u003cmodule\u003e   Specifies an external dependency that will be linked at runtime\n  -h, --help                If present, will print this message\n  -l, --load                If present, will load inputs\n  -j, --jobs \u003cjobs\u003e         Specifies the number of concurrent jobs for batch tasks (--load, --archive, --copy-assets)\n  -M, --source-map          If present, a source map will be generated\n  -o, --output \u003cpath\u003e       If present, will change the output path. Assumes directory if multiple inputs given\n  -O, --optimize            If present, will optimize output by minifying JavaScript source prior to compilation\n  -u, --unpack              If present, will treat input as an archive and will unpack files to path specified by '--output'\n  -v, --verbose             If present, will emit verbose output to stdout/stderr\n  -V, --version             If present, will print the version number\n  -x                        An alias for '--external'\n```\n\n\u003ca name=\"cli-compiling\"\u003e\u003c/a\u003e\n#### Compiling Modules\n\nThe simplest use of the `tmc` command is to compile a single file. By\ndefault, the `-c` (or `--compile`) is assumed if `-a` (or\n`--archive`) and `-u` (or `--unpack`) flags are **not present**.\n\n```sh\n$ tmc file.js ## will write ./file.js.out\n```\n\nThe output of the compiled file can be configured using the `-o` (or `--output`)\nflag to set the output name.\n\n```sh\n$ tmc file.js -o file.compiled.js\n```\n\nIf multiple inputs were given, then the output\nvalue will be a directory and the original file names are preserved.\n\n```sh\n$ tmc *.js -o build/\n```\n\n\u003ca name=\"cli-archiving-modules\"\u003e\u003c/a\u003e\n#### Archiving Compiled Modules\n\nAfter compiling modules it may be useful to archive them into a single\nfile. This is often beneficial if the compiled module contained static\nassets that need to live on the file system alongside the compiled\nmodule file during runtime.\n\nThe `tmc` command makes it easy to specify a number of files that\nshould be added to an archive by making use of the `-a` (or `--archive`)\nflag to indicate that inputs should be archived.\n\n```sh\n$ tmc -a modules.archive *.compiled.js ## archives all `*.compiled.js` files into `modules.archive`\n```\n\nAny asset can be added to an archive as well.\n\n```sh\n$ tmc -a modules.archive *.node ## archives all `*.node` files into `modules.archive`\n```\n\nThe `modules.archive` file contains an index of entries added to it by\nfile name. The archive can be [unpacked](#cli-unpacking) using the `tmc`\ncommand as well.\n\n\u003ca name=\"cli-unpacking\"\u003e\u003c/a\u003e\n#### Unpacking Archives\n\nCompiled modules and their assets living in an archive can be easily\nunpacked to the file system. The `tmc` command makes it easy to unpack\nentries in an archive.\n\n```sh\n$ tmc -u modules.archive\n```\n\nThe output of the entries can be specified with the `-o` (or `--output`)\nflag.\n\n```sh\n$ tmc -u modules.archive -o build/\n```\n\n\u003ca name=\"cli-loading\"\u003e\u003c/a\u003e\n#### Loading Modules \u0026 Archives\n\nCompiled modules and packed archives can be loaded at runtime in an\napplication. The `tmc` command provides a simple way to do this from the\ncommand line from array of inputs by making use of the `-l` (or\n`--load`) flag to indicate the inputs should be loaded.\n\n```sh\n$ tmc -l module.compiled.js\n```\n\nArchives can be loaded as well.\n\n```sh\n$ tmc -l modules.archive\n```\n\nRegular JavaScript files an be given as input.\n\n```sh\n$ tmc -l file.js\n```\n\nMultiple inputs can be loaded.\n\n```sh\n$ tmc -l modules.archive file.js module.compiled\n```\n\nThe load concurrency can be set by specifying the `-j` (or `--jobs` or\n`--concurrency`) flag to indicate the number of concurrent loads that\ncan occur when loading the inputs.\n\n```sh\n$ tmc -l -j1 modules.archive file.js module.compiled ## one at a time\n```\n\n\u003ca name=\"constraints\"\u003e\u003c/a\u003e\n## Constraints\n\nThe `tiny-module-compile` module ships with a few constrains due to the\nnature of how v8 cache data works. They are described in this section.\n\n\u003ca name=\"constraints-v8-version\"\u003e\u003c/a\u003e\n### v8 Version\n\nThe **v8 version** (`process.versions.v8`) in the runtime of `node` used\nto compile modules to v8 cache data must match the one used to load. The\nmodule will throw an error if the versions do not match as unexpected\nbehaviour may occur.\n\n\u003ca name=\"constraints-function-to-string\"\u003e\u003c/a\u003e\n### `Function.prototype.toString()`\n\nFor user-defined functions,\n[`Function.prototype.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)\nmay not work as expected or not at all because the string source code\nrepresentation of the function is lost after compilation.\n\n## See Also\n\n- [nanoresource-pool][nanoresource-pool]\n- [nanoresource][nanoresource]\n- [tinybox][tinybox]\n- [@zeit/ncc][ncc]\n- [glob][glob]\n\n## Prior Art\n\n- https://github.com/OsamaAbbas/bytenode\n- https://github.com/zertosh/v8-compile-cache\n- https://github.com/v8/v8/blob/master/src/snapshot/code-serializer.h\n- https://hackernoon.com/how-to-compile-node-js-code-using-bytenode-11dcba856fa9\n\n## License\n\nMIT\n\n[ras]: https://github.com/random-access-storage/random-access-storage\n[ncc]: https://github.com/zeit/ncc\n[glob]: https://github.com/isaacs/node-glob\n[tinybox]: https://github.com/hyperdivision/tinybox\n[nanoresource]: https://github.com/mafintosh/nanoresource\n[nanoresource-pool]: https://github.com/little-core-labs/nanoresource-pool\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Ftiny-module-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flittle-core-labs%2Ftiny-module-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flittle-core-labs%2Ftiny-module-compiler/lists"}