{"id":21076104,"url":"https://github.com/shaack/modlib","last_synced_at":"2026-04-28T09:05:42.436Z","repository":{"id":57300608,"uuid":"143186824","full_name":"shaack/modlib","owner":"shaack","description":"Tool functions to use ES6 modules as npm packages without transpiling","archived":false,"fork":false,"pushed_at":"2023-04-01T09:53:17.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-01T10:08:28.021Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-08-01T17:20:34.000Z","updated_at":"2022-05-26T14:11:48.000Z","dependencies_parsed_at":"2022-09-10T21:10:54.185Z","dependency_job_id":null,"html_url":"https://github.com/shaack/modlib","commit_stats":null,"previous_names":["shaack/modrator","shaack/es6-npm-toolkit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shaack/modlib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fmodlib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fmodlib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fmodlib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fmodlib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaack","download_url":"https://codeload.github.com/shaack/modlib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fmodlib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32373549,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"online","status_checked_at":"2026-04-28T02:00:07.250Z","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":[],"created_at":"2024-11-19T19:26:37.336Z","updated_at":"2026-04-28T09:05:42.375Z","avatar_url":"https://github.com/shaack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ModLib\n\nUse ES6 modules from npm in webapps without transpiling.\n\nModLib is a tool class, to create a library out of the ES6 modules of `node_modules` packages\nto use them in web apps.\n\n## The problem with ES6 and npm in web projects\n\nLet's assume we have two ES6 projects. \"cm-main\" and \"cm-dependency\" with the following structure:\n`cm-main/src/Main.js` and `cm-dependency/src/Dependency.js`.\n\nWhen developing \"cm-main\" the import path from `src/Main.js` to `node_modules/cm-dependency/src/Dependency.js` would be `../node_modules/cm-dependency/src/Dependency.js` but later when both are npm packages, they are both in node_modules and then the import path will become `../../cm-dependency/Dependency.js`. Because of that importing files from node_modules does not work for ES6 web-projects.\n\n## The solution (without transpiling)\n\nWhen we copy `node_modules/cm-dependency/src/Dependency.js` to `lib/Dependency.js` on `npm install`, the include path for local development from `src/Main.js` will be `../lib/Dependency.js`. And later, when both are npm packages, the import path from `lib/Main.js` will remain `../lib/Dependency.js`. 👍\n\n## Usage\n\nModLib is mainly used in `postinstall.cjs`.\n\n```js\n// Create an instance of `ModLib` in your `postinstall.cjs`:\n\nconst modLib = new (require(\"modlib\"))\n\n// Then add modules from packages\n\nmodLib.add(\"npm-package-name-1\")\nmodLib.add(\"npm-package-name-2\")\n// [..]\n```\n\nThe module sources will be copied from the `node_modules/package/src/*` to the `lib/package/*` folder for easy handling of the relative import path from other ES6 modules.\n\nAuto execute `postinstall.cjs` on `npm install` with adding it to your `package.json` like so\n```json\n\"scripts\": {\n  \"postinstall\": \"node postinstall.cjs\"\n}\n```\n\n## Examples\n\nIt works in these plain ES6 module based apps and components, which must not be transpiled or compiled to run. They work out of the box without transpiling, without babel.\n\n- [cm-chess](https://github.com/shaack/cm-chess)\n- [cm-fen-editor](https://github.com/shaack/cm-fen-editor)\n- [chess-console](https://github.com/shaack/chess-console)\n- [chess-console-stockfish](https://github.com/shaack/chess-console-stockfish)\n\n## API\n\n### constructor\n\n```js\n/**\n * @param projectRoot Your project root, mostly `__dirname`\n * @param props Configuration properties\n */\nconstructor(projectRoot = __dirname, props = {})\n```\n\nDefault props\n\n```js\nprops = {\n    nodeModulesPath: path.resolve(__dirname, '../../'), // path to `node_modules`\n    libraryFolder: \"lib\", // library folder where the module sources are linked/copied to\n    mode: \"copy\" // set to \"symlink\" to symlink sources instead of copying\n}\n```\n\n### method `add` to a package to the library\n\n```js\n/**\n * Add the modules of a node package to the library\n * @param packageName Name of the nmp package\n * @param projectSourceRoot The source root inside the package folder\n * @param fileOrFolder The module source folder or file inside the 'projectSourceRoot'\n */\nadd(packageName, projectSourceRoot = \"src\", fileOrFolder = packageName)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaack%2Fmodlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaack%2Fmodlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaack%2Fmodlib/lists"}