{"id":17472814,"url":"https://github.com/shinnn/import-package","last_synced_at":"2026-04-12T05:35:28.742Z","repository":{"id":65997851,"uuid":"157289894","full_name":"shinnn/import-package","owner":"shinnn","description":"Import an npm package from the disk","archived":false,"fork":false,"pushed_at":"2018-11-12T23:19:48.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T08:11:14.725Z","etag":null,"topics":["fallback","import","javascript","nodejs","npm","package","promise"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-12T23:09:25.000Z","updated_at":"2018-11-12T23:18:21.000Z","dependencies_parsed_at":"2023-06-05T17:00:14.597Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/import-package","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/shinnn/import-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fimport-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fimport-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fimport-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fimport-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/import-package/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fimport-package/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31705574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T05:11:36.334Z","status":"ssl_error","status_checked_at":"2026-04-12T05:11:27.332Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["fallback","import","javascript","nodejs","npm","package","promise"],"created_at":"2024-10-18T17:37:38.137Z","updated_at":"2026-04-12T05:35:28.727Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# import-package\n\n[![npm version](https://img.shields.io/npm/v/import-package.svg)](https://www.npmjs.com/package/import-package)\n[![Build Status](https://travis-ci.com/shinnn/import-package.svg?branch=master)](https://travis-ci.com/shinnn/import-package)\n[![Coverage Status](https://img.shields.io/coveralls/shinnn/import-package.svg)](https://coveralls.io/github/shinnn/import-package?branch=master)\n\nImport an [npm package](https://docs.npmjs.com/about-packages-and-modules#about-packages) from the disk\n\n```javascript\nconst importPackage = require('import-package');\n\n(async () =\u003e {\n  const tar = importPackage('tar');\n  //=\u003e {create: [Function], update: [Function], extract: [Function], ...}\n})();\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).\n\n```\nnpm install import-package\n```\n\n## API\n\n```javascript\nconst importPackage = require('import-package');\n```\n\n### importPackage(*id*)\n\n*id*: `string` (a module ID)  \nReturn: `Promise\u003cany\u003e`\n\nIt imports a module with the given module ID from either of the following directories:\n\n1. [`node_modules`](https://docs.npmjs.com/files/folders#node-modules) in the [current working directory](https://nodejs.org/api/process.html#process_process_cwd)\n2. `node_modules` in the directory where [`npm` CLI](https://github.com/npm/cli) is installed\n\nIf the module ins't installed in CWD but included in the [npm CLI dependencies](https://github.com/npm/cli/tree/v6.4.1/node_modules), it imports the module from npm CLI directory.\n\n```javascript\n// $ npm ls npm-packlist\n// \u003e └── (empty)\n\n(async () =\u003e {\n  // However, npm CLI contins `npm-packlist` package.\n  const npmPacklist = await importPackage('npm-packlist'); //=\u003e {[Function: walk], sync: [Function: walkSync], ...}\n})();\n```\n\nIf the module is not included in the npm CLI dependencies but installed in CWD, it imports the module from CWD.\n\n```javascript\n// $ npm ls eslint\n// \u003e └── eslint@5.9.0\n\n(async () =\u003e {\n  // npm CLI doesn't contain `eslint` package.\n  const eslint = await importPackage('eslint'); //=\u003e {Linter: [Function: Linter], ...}\n})();\n```\n\nIf the module exists in both directories, it compares their [package versions](https://docs.npmjs.com/files/package.json#version) and imports the newer one.\n\n```javascript\n// $ npm ls tar\n// \u003e └── tar@0.1.0\n\n(async () =\u003e {\n  // Loaded from the npm CLI directory as the CWD version is older\n  const tar = await importPackage('tar');\n})();\n```\n\nThe returned `Promise` will be fulfilled with the imported module, or rejected when it fails to find the module.\n\nEach imported modules are stored in the internal cache and they will be loaded faster at the next time on.\n\n### importPackage.preload(*id*)\n\n*id*: `string` (a module ID)  \nReturn: `boolean` (whether the package is already imported or not)\n\nTry to find the given package and store it to the internal cache when it exists.\n\nThis method is useful when a user knows which package will be needed and want it to be loaded faster when it's actually imported.\n\n```javascript\nconst importPackage = require('import-package');\n\nmodule.exports = function main() {\n  const uuid = await importPackage('uuid');\n  return uuid();\n}\n\n// The author know `uuid` package needs to be imported in the future.\nimportPackage.preload('uuid');\n```\n\n## License\n\n[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fimport-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fimport-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fimport-package/lists"}