Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand package entrypoints utility - want to reuse #225

Open
jorenbroekema opened this issue Feb 27, 2023 · 2 comments
Open

Expand package entrypoints utility - want to reuse #225

jorenbroekema opened this issue Feb 27, 2023 · 2 comments

Comments

@jorenbroekema
Copy link

Hey! I am looking for some advice/guidance with regards to creating import maps from package entrypoints. I have tried @jspm/generator package. It works, generally speaking, but instead of choosing a single subpath, I want to build an import map that installs all possible subpaths of a package. I could loop over my exports entrypoints and do so, however, I have entrypoints with wildstar subpaths, so I'd have to expand those first.

I can write a util that does this, but I prefer using something that already exists and is more battle-tested.

I noticed that on JSPM CDN, my package's package.json "exports" map is expanded --> https://ga.jspm.io/npm:@lion/[email protected]/package.json versus another CDN like unpkg where it only has the original exports with wildstars in them (not expanded) --> https://unpkg.com/browse/@lion/[email protected]/package.json

I was wondering if someone could point me in the right direction, I'd love to reuse the logic that's used for JSPM CDN to expand package entrypoints (resolving those * chars in paths).

Basically going from:

{
  "exports": {
    "./*": {
      "types": "./dist-types/exports/*",
      "default": "./exports/*"
    },
    "./calendar-translations/*": "./components/calendar/translations/*"
  }
}

to:

{
  "exports": {
    "./accordion.d.ts.map": {
      "types": "./dist-types/exports/accordion.d.ts.map"
    },
    "./button.d.ts.map": {
      "types": "./dist-types/exports/button.d.ts.map"
    },
    "./calendar-test-helpers.d.ts.map": {
      "types": "./dist-types/exports/calendar-test-helpers.d.ts.map"
    },
    "./accordion.js": {
      "default": "./exports/accordion.js"
    },
    "./button.js": {
      "default": "./exports/button.js"
    },
    "./calendar-test-helpers.js": {
      "default": "./exports/calendar-test-helpers.js"
    },
    "./calendar-translations/en-GB.js": "./components/calendar/translations/en-GB.js",
    "./calendar-translations/nl-NL.js": "./components/calendar/translations/nl-NL.js"
  }
}
@guybedford
Copy link
Member

This expansion is done by the CDN itself not the import map generation tooling. We did have an option to generate the "full map" in earlier versions of the generator but this is not currently exposed functionality since installing all subpaths quickly generated a very large map. Instead we treat the map as a specific traced subset always and encourage tracing the app each time through traceInstall. This is especially important since the import map is blocking on the main critical load path of the page.

We could certainly reenable full map generation though.

@jorenbroekema
Copy link
Author

Yeah that would be great if such a feature could be exposed. For my use case these full import maps wouldn't be used on runtime but moreso for analysis reasons.

Even if the full map option is not public, could you share the utility for expanding the export map/subpaths?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants