{"id":16256517,"url":"https://github.com/janniks/basetag","last_synced_at":"2025-03-16T13:30:49.680Z","repository":{"id":47265684,"uuid":"256748022","full_name":"janniks/basetag","owner":"janniks","description":"⚾️ A better way to import local NodeJS modules","archived":false,"fork":false,"pushed_at":"2022-11-30T22:16:28.000Z","size":41,"stargazers_count":36,"open_issues_count":7,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-05T23:39:15.529Z","etag":null,"topics":["base","basetag","import","local","nodejs","require","tag"],"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/janniks.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":"2020-04-18T12:27:22.000Z","updated_at":"2025-03-04T15:22:36.000Z","dependencies_parsed_at":"2022-09-05T13:02:07.937Z","dependency_job_id":null,"html_url":"https://github.com/janniks/basetag","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/janniks%2Fbasetag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2Fbasetag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2Fbasetag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2Fbasetag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janniks","download_url":"https://codeload.github.com/janniks/basetag/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243815578,"owners_count":20352194,"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":["base","basetag","import","local","nodejs","require","tag"],"created_at":"2024-10-10T15:45:26.477Z","updated_at":"2025-03-16T13:30:49.404Z","avatar_url":"https://github.com/janniks.png","language":"JavaScript","readme":"\u003ch1 align=\"center\" style=\"font-weight: bold !important\"\u003ebasetag ⚾️\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003ebasetag\u003c/strong\u003e lets you use local modules relative to your Node.js project base path\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/janniks/basetag/actions\"\u003e\n    \u003cimg src=\"https://github.com/janniks/basetag/workflows/build/badge.svg\" alt=\"Build status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/basetag\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/basetag.svg\" alt=\"Package version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/basetag?minimal=true\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/basetag.svg\" alt=\"Downloads per month\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://npmcharts.com/compare/basetag?minimal=true\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dt/basetag.svg\" alt=\"Total downloads\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/janniks/basetag/blob/master/LICENSE\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"MIT license\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://twitter.com/intent/follow?screen_name=jnnksbrt\"\u003e\n    \u003cimg src=\"https://img.shields.io/twitter/follow/jnnksbrt.svg?label=Follow%20@jnnksbrt\" alt=\"Follow @jnnksbrt on Twitter\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003e\n  \u003ca href=\"#usage-\"\u003eUsage\u003c/a\u003e\n  \u003cspan\u003e · \u003c/span\u003e\n  \u003ca href=\"#docs-\"\u003eDocs\u003c/a\u003e\n  \u003cspan\u003e · \u003c/span\u003e\n  \u003ca href=\"#why-%EF%B8%8F\"\u003eWhy?\u003c/a\u003e\n  \u003cspan\u003e · \u003c/span\u003e\n  \u003ca href=\"#how-\"\u003eHow?\u003c/a\u003e\n  \u003cspan\u003e · \u003c/span\u003e\n  \u003ca href=\"#license-%EF%B8%8F\"\u003eLicense\u003c/a\u003e\n\u003c/h3\u003e\n\n`basetag` creates a `$` symlink in your local `node_modules` so that you can:\n\n😓 Turn _this_:\n\n```js\nconst balls = require('../../../../baseball/balls'); // ❌\n```\n\n🤯 Into _this_:\n\n```js\nconst balls = require('$/baseball/balls'); // ✅\n```\n\n## Usage 🛠\n\nInstall as a **dev** dependency:\n\n```bash\nnpm install --save-dev basetag\n```\n\nCreate a `$` symlink in your local `node_modules` by running:\n\n```bash\nnpx basetag link --hook\n```\n\nUpgrade existing `require`s and `import`s to the basetag way:\n\n```bash\n# require('../../baseball') =\u003e require('$/baseball')\nnpx basetag rebase\n```\n\n---\n\n\u003e ⚠️ Unfortunately, npm does not like basetag very much\n\u003e\n\u003e npm will remove the `$` on every `npm install \u003cpackage\u003e`\n\n_To fix this issue there are some solutions:_\n\n### Fix #1\n\nUse the `postinstall` script to run basetag after every `npm install`\n\n`package.json`\n\n```\n\"scripts\": {\n  \"postinstall\": \"npx basetag link\"\n}\n```\n\n### Fix #2\n\nUse the `--hook` flag (which sets up an npm hook that runs basetag after every `npm install \u003cpackage\u003e`\n\n\u003e You only have to do this once (unless you delete your `node_modules` folder).\n\u003e But, you can also use this in connection with Fix #1.\n\n```\nnpx basetag link --hook\n```\n\n## Docs 📚\n\nbasetag has a few commands that can be run via `npx basetag \u003ccommand\u003e`\n\n- `link [--absolute] [--hook]` — creates a relative `$` symlink\n  - `--absolute` creates an absolute symlink rather than relative\n  - `--hook` sets up basetag to run after every `npm install ...`\n- `rebase` - upgrades `require`s and `import`s to use the package-relative `$/`\n- **_TODO_** `debase` - downgrades `require`s and `import`s to use file-relative `../`s\n\n## Why? ⚡️\n\n**What does `basetag` solve?**\n\nIn Node.js applications we sometimes want to import local modules that are in different far away subdirectories.\nThis can lead to very messy looking `require` statements.\nUsing basetag you can import modules with `$/` as the project base path.\nIf you're not convinced, check out the example below...\n\n🤯 _The modern **basetag** way:_\n\n```js\nconst balls = require('$/baseball/balls'); // ✅\n```\n\n😓 _The traditional (often messy) way:_\n\n```js\nconst balls = require('../../../../baseball/balls'); // ❌\n```\n\n## How? 💭\n\n### How do I use `basetag`?\n\nIt's really all described above and there's not much to it.\nLook at the code in [`test/example/`](test/example/) for an executable example.\nA larger project can have many nested subfolders as shown in the directory structure below.\nOf course a _real_ project would have more files in those subdirectories but for simplicity we'll leave those out.\nUsing basetag you can reference modules from the base `example/` path, rather than using relative directories (i.e. `../../..`).\n\n```\nexample/\n├── its/\n│   └── baseballs/\n│       └── all/\n│           └── the/\n│               └── way/\n│                   └── down.js\n├── somewhere/\n│   └── deep/\n│       └── and/\n│           └── random.js\n└── index.js\n```\n\n### How does `basetag` work?\n\nIt's rather simple.\nBy running basetag, a symlink is created that points from `node_modules/$` to your project base path.\nEverytime you use a `require` with `$/…` Node.js will look inside the `$` package (i.e. our new symlink).\nThe lookup is routed natively to your project files.\n\nTo Node.js, both methods of requiring look the same, because the files are literally the same files.\nBoth methods can be used in the same project and Node.js will cache imports correctly.\n\n## Compatibility\n\n`basetag` supports macOS, Linux, and Windows as of version `1.1.0`.\n\n## License ⚖️\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanniks%2Fbasetag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanniks%2Fbasetag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanniks%2Fbasetag/lists"}