{"id":17750562,"url":"https://github.com/nuintun/bundler","last_synced_at":"2026-01-11T01:34:39.518Z","repository":{"id":37789373,"uuid":"118860568","full_name":"nuintun/bundler","owner":"nuintun","description":"An async file dependency bundle parser","archived":false,"fork":false,"pushed_at":"2024-09-26T08:36:46.000Z","size":230,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-27T05:19:54.416Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuintun.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-01-25T04:06:52.000Z","updated_at":"2024-09-26T08:36:50.000Z","dependencies_parsed_at":"2024-03-05T07:30:22.907Z","dependency_job_id":"08799360-4abf-4acf-9d2f-6e674d2d2ce0","html_url":"https://github.com/nuintun/bundler","commit_stats":{"total_commits":173,"total_committers":5,"mean_commits":34.6,"dds":0.1502890173410405,"last_synced_commit":"7678c23ca6de2094856e8923eb9da8fbdcf96a5e"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fbundler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fbundler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fbundler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Fbundler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuintun","download_url":"https://codeload.github.com/nuintun/bundler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222515842,"owners_count":16996253,"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-26T12:22:37.365Z","updated_at":"2026-01-11T01:34:39.491Z","avatar_url":"https://github.com/nuintun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bundler\n\n\u003c!-- prettier-ignore --\u003e\n\u003e An async file dependency bundle parser\n\u003e\n\u003e [![NPM Version][npm-image]][npm-url]\n\u003e [![Download Status][download-image]][npm-url]\n\u003e ![Node Version][node-image]\n\u003e [![License][license-image]][license-url]\n\n### interface\n\n```ts\ninterface ParsedMeta\u003cT\u003e {\n  contents?: T;\n  dependencies?: string[];\n}\n\ninterface Parse\u003cT\u003e {\n  (path: string): ParsedMeta\u003cT\u003e | void;\n  (path: string): Promise\u003cParsedMeta\u003cT\u003e | void\u003e;\n}\n\ninterface OnCycle {\n  (path: string, referrer: string): void | never;\n}\n\ninterface Resolve {\n  (src: string, referrer?: string): string;\n  (src: string, referrer?: string): Promise\u003cstring\u003e;\n}\n\nexport interface File\u003cT\u003e {\n  path: string;\n  contents: T | null;\n  dependencies: string[];\n}\n\nexport interface Options\u003cT\u003e {\n  parse: Parse\u003cT\u003e;\n  resolve: Resolve;\n  oncycle?: OnCycle;\n}\n\nexport declare class Bundler\u003cT\u003e {\n  constructor(options: Options\u003cT\u003e);\n  /**\n   * @public\n   * @method parse\n   * @param {string} input\n   * @description Get the list of dependent files of input file.\n   */\n  parse(input: string): Promise\u003cFile\u003cT\u003e[]\u003e;\n}\n```\n\n### API\n\n\u003e #### new Bundler\\\u003cT\\\u003e(options: Options) =\u003e Bundler\\\u003cT\\\u003e\n\u003e\n\u003e options?.oncycle: (path: string, referrer: string) =\u003e void\n\u003e\n\u003e - found circularly dependency callback function\n\u003e\n\u003e options.resolve(path: string, referrer: string) =\u003e string\n\u003e\n\u003e options.resolve(path: string, referrer: string) =\u003e Promise\\\u003cstring\\\u003e\n\u003e\n\u003e - path resolve function, support async function\n\u003e\n\u003e options.parse(path: string) =\u003e { contents?: T, dependencies?: string[] }\n\u003e\n\u003e options.parse(path: string) =\u003e Promise\\\u003c{ contents?: T, dependencies?: string[] }\\\u003e\n\u003e\n\u003e - file dependencies parse function, support async function\n\u003e\n\u003e #### new Bundler(options: Options).parse(input: string) =\u003e Promise\\\u003cFile[]\\\u003e\n\u003e\n\u003e input: string\n\u003e\n\u003e - path of input file\n\n### Examples\n\n```js\nimport { Bundler } from '@nuintun/bundler';\n\nconst files = {\n  '/src/1.js': { contents: 'file 1', dependencies: ['2.js', '4.js'] },\n  '/src/2.js': { contents: 'file 2', dependencies: ['./3.js', './5.js'] },\n  '/src/3.js': { contents: 'file 3', dependencies: ['/src/4.js', '/src/6.js'] },\n  '/src/4.js': { contents: 'file 4', dependencies: ['5.js', './7.js'] },\n  '/src/5.js': { contents: 'file 5', dependencies: ['6.js', '/src/8.js'] },\n  '/src/6.js': { contents: 'file 6', dependencies: ['./7.js', '/src/9.js'] },\n  '/src/7.js': { contents: 'file 7', dependencies: ['8.js'] },\n  '/src/8.js': { contents: 'file 8', dependencies: ['./9.js'] },\n  '/src/9.js': { contents: 'file 9', dependencies: [] }\n};\n\nconst bunder = new Bundler({\n  resolve(path, referrer) {\n    if (/^\\//.test(path)) return path;\n\n    const dirname = referrer.replace(/\\/[^\\/]+$/, '');\n\n    return `${dirname}/${path}`.replace(/(\\.\\/)+/g, '');\n  },\n  parse(path) {\n    return new Promise(resolve =\u003e {\n      const delay = 20;\n\n      setTimeout(() =\u003e resolve(files[path]), delay);\n\n      console.log(`Read: %o, Waiting: %oms`, path, delay);\n    });\n  }\n});\n\nasync function parse(input) {\n  try {\n    console.log(await bunder.parse(input));\n  } catch (error) {\n    console.error(error);\n  }\n}\n\nparse('/src/1.js');\n\n// Output: [\n//  {\n//    path: '/src/9.js',\n//    contents: 'file 9',\n//    dependencies: []\n//  },\n//  {\n//    path: '/src/8.js',\n//    contents: 'file 8',\n//    dependencies: ['./9.js']\n//  },\n//  {\n//    path: '/src/7.js',\n//    contents: 'file 7',\n//    dependencies: ['8.js']\n//  },\n//  {\n//    path: '/src/6.js',\n//    contents: 'file 6',\n//    dependencies: ['./7.js', '/src/9.js']\n//  },\n//  {\n//    path: '/src/5.js',\n//    contents: 'file 5',\n//    dependencies: ['6.js', '/src/8.js']\n//  },\n//  {\n//    path: '/src/4.js',\n//    contents: 'file 4',\n//    dependencies: ['5.js', './7.js']\n//  },\n//  {\n//    path: '/src/3.js',\n//    contents: 'file 3',\n//    dependencies: ['/src/4.js', '/src/6.js']\n//  },\n//  {\n//    path: '/src/2.js',\n//    contents: 'file 2',\n//    dependencies: ['./3.js', './5.js']\n//  },\n//  {\n//    path: '/src/1.js',\n//    contents: 'file 1',\n//    dependencies: ['2.js', '4.js']\n//  }\n//]\n```\n\n[npm-image]: https://img.shields.io/npm/v/@nuintun/bundler.svg?style=flat-square\n[node-image]: https://img.shields.io/node/v/@nuintun/bundler.svg?style=flat-square\n[download-image]: https://img.shields.io/npm/dm/@nuintun/bundler?style=flat-square\n[npm-url]: https://www.npmjs.org/package/@nuintun/bundler\n[license-image]: https://img.shields.io/github/license/nuintun/bundler?style=flat-square\n[license-url]: https://github.com/nuintun/bundler/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Fbundler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuintun%2Fbundler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Fbundler/lists"}