@file-services/commonjs

v9.4.1
Isomorphic, fs-agnostic implementation of the Node commonjs module system.

@file-services/commonjs

npm version package size

Isomorphic, fs-agnostic implementation of Node's CommonJS module system.

Getting started

Install library in project:

npm i @file-services/commonjs

Then, use the programmatic API:

import { createCjsModuleSystem } from "@file-services/commonjs";
import { createMemoryFs } from "@file-services/memory";

const fs = createMemoryFs({
  "some-folder": {
    "index.js": `module.exports = 'exported value'`,
  },
});

const moduleSystem = createCjsModuleSystem({ fs });

const evaluated = moduleSystem.requireModule("/some-folder/index.js");
// evaluated === 'exported value'

License

MIT

npm i @file-services/commonjs

Metadata

  • MIT
  • Whatever
  • Unknown
  • released 8/4/2024

Downloads