davestewart / alias-hq

The end-to-end solution for configuring, refactoring, maintaining and using path aliases
https://davestewart.co.uk/projects/open-source/alias-hq/
MIT License
330 stars 11 forks source link

Rollup integration uses `name`, `path` instead of `find`, `replacement` #32

Closed IanVS closed 2 years ago

IanVS commented 2 years ago

This seems like a very cool tool, and I'm getting started using it, but having some trouble with rollup.

I'm building my app with vite, which allows a resolve.alias setting (https://vitejs.dev/config/#resolve-alias) that is passed to @rollup/plugin-alias. However, when I run hq.get('rollup'), I get an array like this:

[
  { name: '@api', path: '/path/to/src/api' },
  {
    name: '@components',
    path: '/path/to/src/components'
  }
]

But rollup wants the objects to have keys of find and replacement. Debugging via the cli results in the right thing, just not hq.get(). Am I doing something incorrectly? Thanks!

Edit: I just found that hq.get('rollup', { format: 'object' }) will meet my needs, but I'll leave this open in case you'd like to look into it.

davestewart commented 2 years ago

Hey Ian,

Thanks for letting me know!

Actually, I've just come back to this project after about a year and it wasn't easy to find that information.

I outline all the options here:

I'm not sure why, but it's not easy to find if you just come to GitHub!

I'll see what I can do about that now.

Cheers, Dave

IanVS commented 2 years ago

Thanks, I see two issues:

1) the array format produces incorrect keys for rollup 2) the docs indicate that object is the default format, but it is not, array is the default.

I'd be happy to submit a PR if you like.

davestewart commented 2 years ago

I've just spent some time looking into this, didn't quite understand what you're alluding to, but I think I finally got there.

The problem is here:

https://github.com/davestewart/alias-hq/blob/master/src/plugins/rollup/index.js#L9

The merging of defaults should actually be done here:

https://github.com/davestewart/alias-hq/blob/master/src/plugins/rollup/index.js#L29

Otherwise, if you skip passing options, the main function returns the array format – as you said.

Thanks for flagging! I'll get this fixed up and published in the next hour or so.

davestewart commented 2 years ago

OK, looking good:

image

About to publish.

davestewart commented 2 years ago

OK! Fixes published as 5.1.7:

https://www.npmjs.com/package/alias-hq

Thanks for the flagging.