microsoft / TypeScript-Website

The Website and web infrastructure for learning TypeScript
https://www.typescriptlang.org
Creative Commons Attribution 4.0 International
2.21k stars 1.36k forks source link

@typescript/ata JSR registry support #3202

Open nicu-chiciuc opened 1 month ago

nicu-chiciuc commented 1 month ago

I understand this is not a critical issue. I've already tried to make some changes and open a PR but I think the issue might need some more thought put in.

I was trying to figure out a way to be able to allow imports of JSR packages in the monaco editor.

@typescript/ata relies on jsdelivr so the JSR packages aren't available there.

Issues I've encountered

1. Not clear how imports should work. In Deno it's possible to do it like this:

import { something } from 'jsr:@scope/package';

For Node, (https://jsr.io/docs/npm-compatibility), it's necessary to add a new registry https://npm.jsr.io/ and the name of the package gets transformed to

import {} from '@jsr/scope__package'

or packages.json can be updated like this:

 // package.json
 {
   "type": "module",
   "dependencies": {
-    "@jsr/luca__cases": "1"
+    "@luca/cases": "npm:@jsr/luca__cases@1"
   }
 }

2. Where to import the files from

Initially I tried querying jsr.io directly: https://jsr.io/@luca/flag/meta.json based on https://jsr.io/docs/api

Then I figured it'd be better to use the npm compatibility layer so I get well formed ESM instead of Typescript. I've used things like https://npm.jsr.io/@jsr/tscu__dependent

The issue now is that I don't get access to specific files, but to a tarball of a specific version.


At this point it's not clear what solution should be correct. I figured maybe I'll open a discussion on this.

orta commented 1 month ago

Before even cosindering syntax etc, the thing that makes ATA possible (reasonably cheaply time/resources wise) via jsdelivr is that they have an API which returns a list of the file tree we can work from. Then it's a matter of grabbing all the .d.ts files and re-implementing that in the vfs.

Without going back to a version of ATA which reads and parses every file to incrementally learn the shape of the file/dep graph, which this version of ATA probably doesn't want to do (as it's focused on web/playground)

You'd probably be better off asking the jsdelivr folks if they are interested in covering jsr (or asking jsr if they are interested in making a 'tree' like API)

jakebailey commented 1 month ago

The issue now is that I don't get access to specific files, but to a tarball of a specific version.

I'm pretty sure the original files are accessible via paths like https://jsr.io/@luca/flag/1.0.0/main.ts (the API page indicates so).

nicu-chiciuc commented 1 month ago

I'm pretty sure the original files are accessible via paths like https://jsr.io/@luca/flag/1.0.0/main.ts (the API page indicates so).

Yes, but that's available only for the original files. I guess I could continue trying going in this direction. I was afraid this would get messy if the packages had other JSR deps.

examples: https://jsr.io/@luca/flag/1.0.1_meta.json https://jsr.io/@luca/flag/1.0.1/main.ts