{"id":21937619,"url":"https://github.com/cap32/import-file","last_synced_at":"2026-04-13T21:32:10.395Z","repository":{"id":57272977,"uuid":"77770001","full_name":"Cap32/import-file","owner":"Cap32","description":"Import the closest file with loader","archived":false,"fork":false,"pushed_at":"2018-12-21T11:33:46.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-09T02:06:31.093Z","etag":null,"topics":["cli","filepath","import","interpret","loader","module","nodejs","require","resolver"],"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/Cap32.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-01T07:32:34.000Z","updated_at":"2023-03-04T05:34:31.000Z","dependencies_parsed_at":"2022-09-08T23:12:07.538Z","dependency_job_id":null,"html_url":"https://github.com/Cap32/import-file","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Cap32/import-file","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Fimport-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Fimport-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Fimport-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Fimport-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cap32","download_url":"https://codeload.github.com/Cap32/import-file/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cap32%2Fimport-file/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267793009,"owners_count":24144959,"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","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"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":["cli","filepath","import","interpret","loader","module","nodejs","require","resolver"],"created_at":"2024-11-29T01:20:48.178Z","updated_at":"2026-04-13T21:32:10.346Z","avatar_url":"https://github.com/Cap32.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# import-file\n\n[![Build Status](https://travis-ci.org/Cap32/import-file.svg?branch=master)](https://travis-ci.org/Cap32/import-file)\n\n  Import the closest file as a node module with loader.\n\n## What is it\n\nSay you're writing a CLI tool. You may want the following features:\n\n- Get the closest configure file\n- Automatically register module loader according to extension name\n\n`import-file` manages these for you.\n\n## Example\n\n###### /project/my_config.babel.js\n\n```js\nexport default {\n    name: 'awesome',\n};\n```\n\n###### /project/src/index.js\n\n```js\nconst importFile = require('import-file');\nconst config = importFile('my_config.babel.js');\nconsole.log(config.name);\n```\n\n```bash\n$ cd /project/src \u0026\u0026 node index\n# =\u003e `awesome`\n```\n\n## Usage\n\n#### importFile(filepath[, options])\n\nImport a file as a node module. Return a node module if the file exists, otherwise throw an error.\n\n###### Arguments\n\n1. `filepath` (String): Target file path. If not provide a extension name, it will automatically add extension and register module loader. For more detail of extensions and modules, please read [interpret](https://github.com/js-cli/js-interpret).\n2. `options` (Object): These are all the available options.\n    - `cwd` (String): The directory resolves from. Defaults to `process.cwd()`\n    - `useLoader` (Boolean): Enable automatically register module loader according to the adding extension name. Defaults to `true`\n    - `useFindUp` (Boolean): Find by walking up parent directories. Defaults to `true`\n    - `useCache` (Boolean): Cache imported file. The same behaviour with node.js `require`. Default to `true`.\n    - `useESDefault` (Boolean): Export `default` in ES module. Default to `true`.\n    - `resolvers` ([String]): Tell `importFile` what directories should be searched when resolving files\n    - `exts` ([String]): Extensions white list for loader. Only work if `useLoader` is `true`. Defaults to all [interpret](https://github.com/js-cli/js-interpret#extensions) extensions\n\n\n#### importFile.resolve(filepath[, options])\n\nThe same with `importFile()`, but just return the resolved filename. Throw an error if the file is not exists.\n\n## Installing\n\n```bash\n$ npm install import-file\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcap32%2Fimport-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcap32%2Fimport-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcap32%2Fimport-file/lists"}