{"id":17034568,"url":"https://github.com/caub/micro-require","last_synced_at":"2025-03-22T22:18:01.292Z","repository":{"id":151002975,"uuid":"64530798","full_name":"caub/micro-require","owner":"caub","description":"lazy-loaded isomorphic commonjs implementation for development with stable hooks support","archived":false,"fork":false,"pushed_at":"2016-03-16T18:49:56.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T02:11:14.693Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"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/caub.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}},"created_at":"2016-07-30T06:52:17.000Z","updated_at":"2017-12-25T10:44:29.000Z","dependencies_parsed_at":"2023-05-30T04:45:37.031Z","dependency_job_id":null,"html_url":"https://github.com/caub/micro-require","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fmicro-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fmicro-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fmicro-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caub%2Fmicro-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caub","download_url":"https://codeload.github.com/caub/micro-require/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245026042,"owners_count":20549073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-10-14T08:43:59.028Z","updated_at":"2025-03-22T22:18:01.261Z","avatar_url":"https://github.com/caub.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## micro-require\n\nthis is an isomorphic commonjs implementation. it uses synchronous XHR in the browser, and `readFileSync` in node. it is only for development.\nit supports loading from node modules.\n\nin the browser, loading heavily distributed node modules like react and virtual-dom etc. could take a lot of time (specially in FireFox), so better to require their dist files instead.\n\ntake a look at the `tests` folder and `index.html` to see how to set roots and add hooks etc.\n\nI use it as a lazily-loaded browserify, giving me a workflow with 0 build time lag. It obviously won't scale well for large and hefty projects.\n\nFF dev edition and Chrome Dev edition already support like most of the ES6, so I don't need any build at all in dev.\n\n### how it works\n\nthe flow of things along with caching is documented here for future me and anyone interested.\n\nthere is one internal main function called `realRequire`\n\n`realRequire` is passed two things:\n\n- path of the directory where the calling module resides (`__dirname` of the calling module)\n- the exact string literal which the caller required as module identifier\n\n`realRequire` uses an internal operation `requirablePaths`, which passed the above two things verbatim, returns an iterator.\nthe iterator is a lazy sequence of paths which we will try accessing until a valid module is found.\n\nif `./foo` was requested from `/bar/`, the following paths are traversed:\n\n```\n/bar/foo\n/bar/foo.js\n/bar/foo.json\n/bar/foo/index.js\n/bar/foo/index.json\n```\nif those fail, then `/bar/foo/package.json` is requested and parsed to json, and the `main` field is extracted. then `/bar/foo/${main}` is requested\n\nif that fails as well, `node_modules` are traversed from each directory going up the tree with the same resolution algorithm above followed with single depth.\n\nthe internal `fetchSource` operation is passed the above paths in sequence, and it tries to get the content from that location relative to the `_root` internal variable (overridable by `require.setRoot` function on the main `require` instance).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fmicro-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaub%2Fmicro-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaub%2Fmicro-require/lists"}