Skip to content

Array of sources for an alias #98

@danielmitchell

Description

@danielmitchell

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`,
      ),
    }
  }, {})
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions