{"id":13774409,"url":"https://github.com/frostney/rollup-plugin-named-directory","last_synced_at":"2025-04-14T21:21:32.837Z","repository":{"id":50414387,"uuid":"128671755","full_name":"frostney/rollup-plugin-named-directory","owner":"frostney","description":"Resolves modules to its directory names","archived":false,"fork":false,"pushed_at":"2018-04-09T04:42:50.000Z","size":56,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-29T09:26:13.356Z","etag":null,"topics":["directory","named","rollup-plugin"],"latest_commit_sha":null,"homepage":null,"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/frostney.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}},"created_at":"2018-04-08T18:50:38.000Z","updated_at":"2023-09-27T20:23:25.000Z","dependencies_parsed_at":"2022-09-23T13:02:56.485Z","dependency_job_id":null,"html_url":"https://github.com/frostney/rollup-plugin-named-directory","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Frollup-plugin-named-directory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Frollup-plugin-named-directory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Frollup-plugin-named-directory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frostney%2Frollup-plugin-named-directory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frostney","download_url":"https://codeload.github.com/frostney/rollup-plugin-named-directory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239841743,"owners_count":19705981,"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":["directory","named","rollup-plugin"],"created_at":"2024-08-03T17:01:26.460Z","updated_at":"2025-02-26T02:32:56.713Z","avatar_url":"https://github.com/frostney.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Modules"],"readme":"# rollup-plugin-named-directory\nProvide shortcuts for your modules\n\nIn most projects we will reach this point where we use directories to logically structure our JavaScript files. Let's take a look at this example:\n```\n.\n├── Button\n│   ├── Button.js\n│   ├── Caption.js\n│   └── Icon.js\n...\n```\n\nIn this scenario, `Button` is the module you would want to use most of the time. `Caption` and `Icon` are only being used inside of the scope of the `Button` file.\n\nWhenever you want to require a module from a file in a directory you will have two choices to import these files:\n1. Import the files directly like this `import Button from './Button/Button'`. Since it this case `Caption` and `Icon` should only be used for the scope for `Button`. We could strive for shorter import statement that would create the illusion of stronger coupling.\n2. Create an `index.js` file for each directory and mimic Node.js resolution behavior. While this shortens the import statement to `import Button from './Button'` increasing the coupling and decreasing moving parts, it creates additional files to maintain.\n\nIdeally, we would want short import statements without the need to create additional files that link to the file in question. And this is where `rollup-plugin-named-directory` comes in.\n\nIf you have been using Webpack before, this plugin is similar to https://github.com/shaketbaby/directory-named-webpack-plugin.\n\n## Usage\n```javascript\nimport namedDirectory from 'rollup-plugin-named-directory';\n\nrollup({\n  plugins: [\n    namedDirectory()\n  ]\n})\n```\n\n### Options\n#### `matchers`\nDefault value: `['\u003cdir\u003e/\u003cdir\u003e.js']`\n\nWhenever Rollup encounters `\u003cdir\u003e`, it will now look for `\u003cdir\u003e/\u003cdir\u003e.js` first. (Example: If the directory is `Button`, it will now look for `Button/Button.js` first)\nIf the plugin isn't able to find the file in question, it will continue with the typical resolution behavior as dictated by Rollup and other plugins.\n\nMake sure to provide the file extensions in.\n\nIt's possible to provide multiple strings which will be resolved in the order they have been defined.\n\n```javascript\nnamedDirectory({\n  matchers: ['\u003cdir\u003eCustomSuffix.js', '\u003cdir\u003e/\u003cdir\u003e.js']\n})\n```\n\n#### `filter`\nAllows to provide an optional filter function that will be called on each potential match from the `matchers` array.\nDefault value: `() =\u003e false`\n\n```javascript\nnamedDirectory({\n  filter: (name: string): boolean =\u003e {\n    // Name provides the relative path to the expanded module\n    // ./files/Button/Button.js\n  }\n})\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostney%2Frollup-plugin-named-directory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrostney%2Frollup-plugin-named-directory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrostney%2Frollup-plugin-named-directory/lists"}