{"id":13565989,"url":"https://github.com/jspm/import-map","last_synced_at":"2025-04-03T23:30:49.705Z","repository":{"id":45972142,"uuid":"388618406","full_name":"jspm/import-map","owner":"jspm","description":"Import Map Utility","archived":false,"fork":false,"pushed_at":"2024-07-07T20:32:04.000Z","size":61,"stargazers_count":44,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T04:30:06.504Z","etag":null,"topics":[],"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/jspm.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},"funding":{"github":["jspm"],"patreon":null,"open_collective":"jspm","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-07-22T22:53:56.000Z","updated_at":"2024-10-24T09:29:37.000Z","dependencies_parsed_at":"2023-09-22T07:08:42.925Z","dependency_job_id":"966c41b5-ba9d-4e1a-b339-cd51c7d85e94","html_url":"https://github.com/jspm/import-map","commit_stats":{"total_commits":55,"total_committers":6,"mean_commits":9.166666666666666,"dds":0.1636363636363637,"last_synced_commit":"f293320be5971f64a347cd0c2c00bd4bbff49097"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspm%2Fimport-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspm%2Fimport-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspm%2Fimport-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspm%2Fimport-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jspm","download_url":"https://codeload.github.com/jspm/import-map/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246759385,"owners_count":20829095,"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-08-01T13:01:59.552Z","updated_at":"2025-04-03T23:30:48.946Z","avatar_url":"https://github.com/jspm.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jspm","https://opencollective.com/jspm"],"categories":["JavaScript"],"sub_categories":[],"readme":"# Import Map Utility\n\nGeneric ImportMap class utility for the manipulation and resolution of import maps, used by JSPM.\n\n## Getting Started\n\n### Installation\n\nNode.js:\n```\nnpm install @jspm/import-map\n```\n\n### Usage\n\n`@jspm/import-map` only ships as an ES module.\n\nexample.mjs\n```js\nimport { ImportMap } from '@jspm/import-map';\n\nconst mapUrl = import.meta.url;\n\nconst map = new ImportMap({\n  mapUrl, // optional\n  map: {\n    imports: {\n      react: 'https://cdn.com/react.js'\n    },\n    scopes: {\n      'https://site.com/': {\n        react: 'https://cdn.com/react2.js'\n      }\n    },\n    integrity: {\n      'https://cdn.com/react.js': 'sha384-...'\n    }\n  }\n});\n\n// Use the map resolver\nmap.resolve('react') === 'https://cdn.com/react.js';\nmap.resolve('react', 'https://site.com/') === 'https://cdn.com/react2.js';\n\n// Supports normal URL resolution behaving a browser-compatible ES module resolver\nmap.resolve('./hello.js', 'https://site.com/') === 'https://site.com/hello.js';\n\n// Mutate the map\nmap.set('react', './custom-react.js');\nmap.resolve('react') === new URL('./custom-react.js', mapUrl).href;\n\n// Mutate the map inside a custom scope\nmap.set('react', './custom-react2.js', 'https://another.com/');\nmap.resolve('react', 'https://another.com/') === new URL('./custom-react2.js', mapUrl).href;\n\n// Get the map JSON\nconsole.log(JSON.stringify(map.toJSON(), null, 2));\n// {\n//   \"imports\": {\n//     \"react\": \"./custom-react.js\"\n//   },\n//   \"scopes\": {\n//     \"https://site.com/\": {\n//       \"react\": \"https://cdn.com/react2.js\"\n//     },\n//     \"https://another.com/\": {\n//       \"react\": \"./custom-react2.js\"\n//     }\n//   },\n//   \"integrity\": {\n//     \"https://cdn.com/react.js\": \"sha384-...\"\n//   }\n// }\n\n// Rebase the map\nmap.rebase('./map/');\nconsole.log(JSON.stringify(map.toJSON(), null, 2));\n// {\n//   \"imports\": {\n//     \"react\": \"../custom-react.js\"\n//   },\n//   \"scopes\": {\n//     \"https://site.com/\": {\n//       \"react\": \"https://cdn.com/react2.js\"\n//     },\n//     \"https://another.com/\": {\n//       \"react\": \"../custom-react2.js\"\n//     }\n//   },\n//   \"integrity\": {\n//     \"https://cdn.com/react.js\": \"sha384-...\"\n//   }\n// }\n\n// Flatten the import map (removes unnecessary scope redundancy)\nmap.set('react', '../custom-react.js', 'https://site.com/');\nmap.flatten();\nconsole.log(JSON.stringify(map.toJSON(), null, 2));\n// {\n//   \"imports\": {\n//     \"react\": \"../custom-react.js\"\n//   },\n//   \"scopes\": {\n//     \"https://another.com/\": {\n//       \"react\": \"../custom-react2.js\"\n//     }\n//   },\n//   \"integrity\": {\n//     \"https://cdn.com/react.js\": \"sha384-...\"\n//   }\n// }\n\n// Replace URLs in the map\nmap.replace('https://cdn.com/', 'https://cdn-mirror.com/');\nmap.replace('https://another.com/', 'https://another-site.com/');\nconsole.log(JSON.stringify(map.toJSON(), null, 2));\n// {\n//   \"imports\": {\n//     \"react\": \"../custom-react.js\"\n//   },\n//   \"scopes\": {\n//     \"https://another-site.com/\": {\n//       \"react\": \"../custom-react2.js\"\n//     }\n//   },\n//   \"integrity\": {\n//     \"https://another.com/react.js\": \"sha384-...\"\n//   }\n// }\n\n// Combine subpaths in the map\n// This is only supported for scopes and not top-level imports,\n// to avoid losing dependency information from imports.\n// (all non-returning methods support chaining)\nconsole.log(new ImportMap({\n  map: {\n    scopes: {\n      \"/\": {\n        \"pkg/a.js\": \"/pkg/a.js\",\n        \"pkg/b.js\": \"/pkg/b.js\"\n      }\n    }\n  }\n}).combineSubpaths().toJSON());\n// {\n//   \"imports\": {},\n//   \"scopes\": {\n//     \"/\": {\n//       \"pkg/\": \"/pkg/\"\n//     }\n//   }\n//  }\n```\n\n## API\n\nSee [src/map.ts](https://github.com/jspm/import-map/blob/main/src/map.ts).\n\nSupport is also provided for conditional maps supporting a way to manage generic maps for multiple environment targets, before serializing or resolving for exact environment targets.\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjspm%2Fimport-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjspm%2Fimport-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjspm%2Fimport-map/lists"}