{"id":15493426,"url":"https://github.com/knightedcodemonkey/specifier","last_synced_at":"2025-04-22T19:47:54.669Z","repository":{"id":183603428,"uuid":"670439182","full_name":"knightedcodemonkey/specifier","owner":"knightedcodemonkey","description":"Node.js tool for parsing imports and rewriting specifiers.","archived":false,"fork":false,"pushed_at":"2025-04-15T15:35:43.000Z","size":282,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T16:43:51.889Z","etag":null,"topics":["cjs","esm","export","import","jsx","nodejs","require","specifier","typescript"],"latest_commit_sha":null,"homepage":"","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/knightedcodemonkey.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":"2023-07-25T04:06:46.000Z","updated_at":"2025-04-15T15:32:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8b7ea44-def8-4cf2-b991-1a64cb58f401","html_url":"https://github.com/knightedcodemonkey/specifier","commit_stats":null,"previous_names":["knightedcodemonkey/specifier"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knightedcodemonkey%2Fspecifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knightedcodemonkey%2Fspecifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knightedcodemonkey%2Fspecifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knightedcodemonkey%2Fspecifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knightedcodemonkey","download_url":"https://codeload.github.com/knightedcodemonkey/specifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250312368,"owners_count":21410022,"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":["cjs","esm","export","import","jsx","nodejs","require","specifier","typescript"],"created_at":"2024-10-02T08:06:39.433Z","updated_at":"2025-04-22T19:47:54.661Z","avatar_url":"https://github.com/knightedcodemonkey.png","language":"TypeScript","readme":"# [`@knighted/specifier`](https://www.npmjs.com/package/@knighted/specifier)\n\n![CI](https://github.com/knightedcodemonkey/specifier/actions/workflows/ci.yml/badge.svg)\n[![codecov](https://codecov.io/gh/knightedcodemonkey/specifier/branch/main/graph/badge.svg?token=5KS9ZB3XDK)](https://codecov.io/gh/knightedcodemonkey/specifier)\n[![NPM version](https://img.shields.io/npm/v/@knighted/specifier.svg)](https://www.npmjs.com/package/@knighted/specifier)\n\nNode.js tool for parsing imports to change ESM and CJS [specifiers](https://nodejs.org/api/esm.html#import-specifiers).\n\n- Rewrite specifier values.\n- Updates files or strings.\n- Read metadata about a specifier's [AST](https://www.npmjs.com/package/oxc-parser) node.\n- Parses `import`, `import()`, `import.meta.resolve()`, `export`, `require`, and `require.resolve()`.\n\n## Example\n\nGiven a file with some imports and exports:\n\n```ts\n// file.ts\n\nimport { someLib } from 'some-package'\nimport { foo } from './path/to/foo.js'\n\nexport { bar } from './path/to/bar.js'\n```\n\nYou can use `specifier` to change the values:\n\n```ts\nimport { specifier } from '@knighted/specifier'\n\nconst update = await specifier.update('file.ts', ({ value }) =\u003e {\n  if (value === 'some-package') {\n    return 'some-package/esm'\n  }\n\n  return value.replace('.js', '.mjs')\n})\n\nconsole.log(update)\n\n/*\nimport { someLib } from 'some-package/esm'\nimport { foo } from './path/to/foo.mjs'\n\nexport { bar } from './path/to/bar.mjs'\n*/\n```\n\nOr collect the AST nodes:\n\n```ts\nimport { type Spec, specifier } from '@knighted/specifier'\n\nconst nodes: { node: Spec['node']; parent: Spec['parent'] }[] = []\n\nawait specifier.update('file.ts', ({ parent, node }) =\u003e {\n  nodes.push({ node, parent })\n})\n\nnodes.forEach(({ node, parent }) =\u003e {\n  // Do something with the metadata\n})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknightedcodemonkey%2Fspecifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknightedcodemonkey%2Fspecifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknightedcodemonkey%2Fspecifier/lists"}