···1414- Rather than requiring you to use a compiler and bundler, unpm downloads files that you can serve directly with no build step.
1515- Rather forcing you to install your dependencies over and over, unpm is designed for you to just commit them to your repo.
16161717+## Installation
1818+1919+unpm requires [Go](https://go.dev/dl/). Once Go is installed, run:
2020+2121+```sh
2222+go install tangled.org/jakelazaroff.com/unpm/cmd/unpm@latest
2323+```
2424+1725## Getting started
18261927After installing unpm, create an `unpm.json` file at the root of your project:
···62706371That's it! Your dependencies will now work unbundled in a browser.
64726565-## Static types
7373+## TypeScript types
66746775unpm can get TypeScript types in a few different ways:
68766977- If a JavaScript file includes JSDoc comments, [TypeScript can already check it](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html)!
7078- If the response for a vendored file includes the header `x-typescript-types`, unpm will download the type definition file at that URL.
7179- If a file has a "sidecar" `.d.ts` file next to it, unpm will download it.
7272-- Finally, you can just point unpm at a TypeScript file and it'll compile it! (Although note that your unpm.json file will no longer be a working import map.)
8080+- Finally, you can add a [`types`](#types) object to `unpm.json` with the URLs of type definition files.
73817482You'll need to tell TypeScript where to find any vendored type definitions. You can do that by having your `jsconfig.json` extend the one that unpm generates:
7583···144152145153`imports` is a [module specifier map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#module_specifier_map) that maps between module specifiers and URLs. It's a bit stricter than actual import maps: you can only use ["bare modules"](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap#bare_modules), meaning each property must resolve to a JavaScript file rather than a directory. In addition, each value must be a full URL.
146154155155+```json
156156+{
157157+ "imports": {
158158+ "mylib": "https://example.com/mylib.js"
159159+ }
160160+}
161161+```
162162+147163Unlike most package managers, unpm doesn't rely on an external package repository like npm or JSR. You can install packages from any URL on the Internet.
164164+165165+### types
166166+167167+`types` is a map from import specifiers to URLs of TypeScript type definition files. It's the highest-priority way to attach types to a dependency (overriding both the `x-typescript-types` response header and any sidecar `.d.ts` files).
168168+169169+```json
170170+{
171171+ "imports": {
172172+ "mylib": "https://example.com/mylib.js"
173173+ },
174174+ "types": {
175175+ "mylib": "https://example.com/mylib.d.ts"
176176+ }
177177+}
178178+```
179179+180180+Each key must match a key in `imports`. You should only need to add entries here when auto-detection doesn't work.
148181149182### unpm
150183