{"id":21554545,"url":"https://github.com/ryoppippi/pkg-to-jsr","last_synced_at":"2025-04-10T09:26:18.267Z","repository":{"id":251917095,"uuid":"838833786","full_name":"ryoppippi/pkg-to-jsr","owner":"ryoppippi","description":"Zero-config tool that generates jsr.json from package.json","archived":false,"fork":false,"pushed_at":"2025-04-09T00:40:13.000Z","size":1203,"stargazers_count":25,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T01:29:35.010Z","etag":null,"topics":["cli","jsr","package-json","typescript","zero-config"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pkg-to-jsr","language":"TypeScript","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/ryoppippi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yaml","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},"funding":{"github":"ryoppippi"}},"created_at":"2024-08-06T12:39:44.000Z","updated_at":"2025-04-09T00:40:16.000Z","dependencies_parsed_at":"2024-08-23T23:47:29.383Z","dependency_job_id":"147e44b3-7d2c-46be-9749-528b5079b692","html_url":"https://github.com/ryoppippi/pkg-to-jsr","commit_stats":null,"previous_names":["ryoppippi/pkg-to-jsr"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryoppippi%2Fpkg-to-jsr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryoppippi%2Fpkg-to-jsr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryoppippi%2Fpkg-to-jsr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryoppippi%2Fpkg-to-jsr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryoppippi","download_url":"https://codeload.github.com/ryoppippi/pkg-to-jsr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247964313,"owners_count":21025175,"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":["cli","jsr","package-json","typescript","zero-config"],"created_at":"2024-11-24T07:15:22.544Z","updated_at":"2025-04-10T09:26:18.244Z","avatar_url":"https://github.com/ryoppippi.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ryoppippi"],"categories":[],"sub_categories":[],"readme":"# pkg-to-jsr 🚀\n\n[![npm version](https://img.shields.io/npm/v/pkg-to-jsr?color=yellow)](https://npmjs.com/package/pkg-to-jsr)\n[![npm downloads](https://img.shields.io/npm/dm/pkg-to-jsr?color=yellow)](https://npmjs.com/package/pkg-to-jsr)\n\npkg-to-jsr is a zero-config generator that creates a `jsr.json` file from your existing `package.json`.\n\nIt simplifies the process of preparing your package for publication on [JSR](https://jsr.io).\n\n## ✨ Features\n\n- 🔧 Zero configuration required - just run and go!\n- 🪄 Automatically generates `jsr.json` from `package.json`\n- 📦 Handles complex `exports` configurations with ease\n- 🎯 Supports `include` and `exclude` options for precise publishing control\n- 🚀 Streamlines your workflow for JSR publication\n\n## 📥 Installation\n\nYou can use pkg-to-jsr without installation using npx:\n\n```bash\nnpx pkg-to-jsr\n```\n\nAlternatively, you can use other package managers:\n\n```bash\n# Using Yarn\nyarn dlx pkg-to-jsr\n\n# Using pnpm\npnpm dlx pkg-to-jsr\n\n# Using Bun\nbunx pkg-to-jsr\n```\n\nFor global installation:\n\n```bash\nnpm install -g pkg-to-jsr\n```\n\n## 🚀 Usage\n\nRun the following command in your project directory:\n\n```bash\nnpx pkg-to-jsr\n```\n\nThis will generate a `jsr.json` file based on your `package.json`.\n\n### Options\n\n- `--root \u003cpath\u003e`: Specify the root directory containing the `package.json` file (default: current working directory)\n\n## 📚 Examples\n\nHere are some examples of how pkg-to-jsr transforms your `package.json` into `jsr.json`:\n\n### Basic Example\n\n**package.json**:\n\n```json\n{\n\t\"name\": \"package\",\n\t\"jsrName\": \"@scope/package\",\n\t\"version\": \"1.0.0\",\n\t\"exports\": \"./index.js\"\n}\n```\n\n**Generated jsr.json**:\n\n```json\n{\n\t\"name\": \"@scope/package\",\n\t\"version\": \"1.0.0\",\n\t\"exports\": {\n\t\t\".\": \"./index.js\"\n\t}\n}\n```\n\n### Complex Exports Example\n\n**package.json**:\n\n```json\n{\n\t\"name\": \"package\",\n\t\"author\": \"ryoppippi\",\n\t\"version\": \"1.0.0\",\n\t\"exports\": {\n\t\t\".\": {\n\t\t\t\"jsr\": \"./src/index.ts\",\n\t\t\t\"import\": \"./dist/index.js\",\n\t\t\t\"types\": \"./dist/index.d.ts\"\n\t\t},\n\t\t\"./utils\": {\n\t\t\t\"jsr\": \"./src/utils.ts\",\n\t\t\t\"import\": \"./dist/utils.js\",\n\t\t\t\"types\": \"./dist/utils.d.ts\"\n\t\t}\n\t},\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"!dist/**/*.test.js\"\n\t],\n\t\"jsrInclude\": [\n\t\t\"src\"\n\t],\n\t\"jsrExclude\": [\n\t\t\"src/**/*.test.ts\"\n\t]\n}\n```\n\n**Generated jsr.json**:\n\n```json\n{\n\t\"name\": \"@ryoppippi/package\",\n\t\"version\": \"1.0.0\",\n\t\"exports\": {\n\t\t\".\": \"./src/index.ts\",\n\t\t\"./utils\": \"./src/utils.ts\"\n\t},\n\t\"publish\": {\n\t\t\"include\": [\"dist\", \"src\"],\n\t\t\"exclude\": [\"dist/**/*.test.js\", \"src/**/*.test.ts\"]\n\t}\n}\n```\n\n## 🔧 How it works\n\npkg-to-jsr performs the following steps:\n\n1. 🔍 Locates your `package.json` file\n2. 📤 Extracts relevant information such as `name`, `version`, and `exports`\n3. ✍️ Generates a `jsr.json` file with the correct structure for JSR\n\nMore details on implementation can be found in the [source code](./src).\n\nYou can see example projects in the [tests](./tests).\n\n### Name Handling\n\npkg-to-jsr determines the package name for `jsr.json` using the following logic:\n\n1. 🏷️ If a `jsrName` field exists in `package.json` and is correctly formatted (`@scope/package-name`), it is used.\n2. 📦 If `jsrName` is not present, it checks the `name` field in `package.json`. If this is correctly formatted for JSR, it is used.\n3. 🔧 If `name` is not in JSR format, it combines the `name` and `author` fields. For example, if `name` is \"package\" and `author` is \"ryoppippi\", it generates `@ryoppippi/package`.\n4. ❌ If none of the above methods produce a valid name, an error is thrown.\n\nThis approach allows maximum flexibility while ensuring compliance with JSR naming conventions.\n\n### Exports handling\n\nThe tool intelligently handles various `exports` configurations:\n\n- 🧵 String exports are converted to object format\n- 🧩 Complex exports with `jsr`, `import`, and other conditions are handled\n- 🏆 If a `jsr` field is specified in the exports, it takes priority over other fields\n- ⚠️ Invalid or unsupported exports are warned about and skipped\n\n### Publish configuration\n\npkg-to-jsr generates the `publish.include` and `publish.exclude` fields in `jsr.json` by merging and filtering information from multiple sources:\n\n1. 📂 `jsrInclude` array in `package.json`: All entries are considered for inclusion\n2. 🚫 `jsrExclude` array in `package.json`: All entries are considered for exclusion\n3. 📁 `files` array in `package.json`:\n   - Files without a leading `!` are considered for inclusion\n   - Files with a leading `!` are considered for exclusion (with the `!` removed)\n\nThe final `include` and `exclude` lists in `jsr.json` are the result of merging and filtering these sources:\n\n- The `include` list combines unique entries from both `jsrInclude` and the positive entries in `files`, excluding any paths that are in `jsrExclude`\n- The `exclude` list combines unique entries from both `jsrExclude` and the negative entries in `files` (with `!` removed), excluding any paths that are in `jsrInclude`\n\nThis approach provides fine-grained control over what gets published to JSR while maintaining compatibility with existing `files` configurations and allowing for explicit inclusion and exclusion rules.\n\nExample:\n\n**package.json**:\n\n```json\n{\n\t\"files\": [\n\t\t\"dist\",\n\t\t\"src\",\n\t\t\"!dist/**/*.test.js\"\n\t],\n\t\"jsrInclude\": [\n\t\t\"src\",\n\t\t\"types\"\n\t],\n\t\"jsrExclude\": [\n\t\t\"src/**/*.test.ts\",\n\t\t\"dist\"\n\t]\n}\n```\n\n**Generated jsr.json**:\n\n```json\n{\n\t\"publish\": {\n\t\t\"include\": [\"src\", \"types\"],\n\t\t\"exclude\": [\"dist/**/*.test.js\", \"src/**/*.test.ts\"]\n\t}\n}\n```\n\nIn this example:\n\n- `src` is included because it's in both `files` and `jsrInclude`\n- `types` is included because it's in `jsrInclude`\n- `dist` is excluded because it's in `jsrExclude`, overriding its presence in `files`\n- Test files in both `dist` and `src` are excluded\n\nThis merged and filtered configuration ensures that all necessary files are included while respecting explicit inclusion and exclusion rules, providing precise control over the package contents for JSR publication.\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## 📄 License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryoppippi%2Fpkg-to-jsr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryoppippi%2Fpkg-to-jsr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryoppippi%2Fpkg-to-jsr/lists"}