payload icon indicating copy to clipboard operation
payload copied to clipboard

fix: support node subpath imports in importmap

Open rzeczkowskip opened this issue 10 months ago • 2 comments

What?

Support path aliases that start with #, when generating import map.

Why?

Nodejs allows to define "imports" field in package.json to create mappings - just like "paths" in tsconfig.json. Each import has to start with a #. This breaks existing implementation of parsePayloadComponent and leads to invalid importMap.js contents.

Payload splits path and export name using #. As. a result, the full import path might have 2 # characters.

How?

  1. By default, use payload component as path and "default" as export name.
  2. Check if there is # character in path and it's not at the beginning.
  3. If true, use part after last # as export name and rest of the string as path

rzeczkowskip avatar Feb 27 '25 07:02 rzeczkowskip

Oh wow! I thought this would be specific enough that there wouldn't be a PR yet... So I also made one, whoops. I did include a fix for the new jobs system too, which has the same problem: https://github.com/payloadcms/payload/pull/11471

Let me know if you include a fix for that case too here, then I'll close my PR.

SimonVreman avatar Mar 01 '25 12:03 SimonVreman

Oh wow! I thought this would be specific enough that there wouldn't be a PR yet... So I also made one, whoops. I did include a fix for the new jobs system too, which has the same problem: #11471

Let me know if you include a fix for that case too here, then I'll close my PR.

Sure, I'll include your changes.

If it wasn't for ~~to be~~just released erasableSyntaxOnly, there wouldn't be a PR tbh. I wanted to switch asap and keep import aliases.

rzeczkowskip avatar Mar 01 '25 18:03 rzeczkowskip