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

Array of sources for an alias #98

Open
danielmitchell opened this issue May 4, 2023 · 2 comments
Open

Array of sources for an alias #98

danielmitchell opened this issue May 4, 2023 · 2 comments

Comments

@danielmitchell
Copy link

danielmitchell commented May 4, 2023

Some of my path aliases are an array of sources, which is supported by typescript and webpack but unfortunately not by this package. Only the first source is used and the rest are ignored which breaks my build.

It would be great if this package supported an array of sources. It seems like this should be an easy fix since I was able to get it working by making a couple of changes:

function configPaths(configPath = '', confUndoc) {
    ...
    const targets = Array.isArray(value) ? value : [value]
    a[path.replace(/\/\*$/,'')] = targets.map(t => t.replace(/\/\*$/,''))
    ...
}
function aliasWebpack(options) {
  const aliasMap = defaultOptions(options).aliasMap
  const aliasLocal = Object.keys(aliasMap).reduce( (a,i) => {
    a[i] = (Array.isArray(aliasMap[i]) ? aliasMap[i] : [aliasMap[i]]).map(p => path.resolve(paths.appPath, p))
    return a
  }, {})
  ...
}
function expandPluginsScope(plugins, dirs, files) {
    ...
    plugins[pluginPos] = new ModuleScopePlugin(dirs.flat(), files.flat())
  }
}
function aliasMapForJest(baseUrl, aliasMap) {
  return Object.keys(aliasMap).reduce((a, i) => {
    const restr = i.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
    const alias = `^${restr}/(.*)$`

    const targets = Array.isArray(aliasMap[i]) ? aliasMap[i] : [aliasMap[i]]

    return {
      ...a,
      [alias]: targets.map(t =>
        isOutsideOfRoot(t) ? path.resolve(baseUrl, t) + '/$1' : `<rootDir>/${t}/$1`,
      ),
    }
  }, {})
}
@oklas
Copy link
Owner

oklas commented May 6, 2023

Looks good. You would have done a pr right away, we would have seen that the tests pass.

@oklas
Copy link
Owner

oklas commented May 6, 2023

Check lines length no more 80 or 100, at your second snippet a[i] = ....

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