alias icon indicating copy to clipboard operation
alias copied to clipboard

incorrect path when resolve to the same or the sub folder

Open lake2 opened this issue 4 years ago • 2 comments

this test case will fail:

  ['should support wild card aliases']: {
    options: { config: { paths: { '@/*': ['./src/*'] } } },
    path: './src/pages/Page.ts',
    input: "import module from 'module'\nimport Component from '@/pages/components'",
    output: "import module from 'module'\nimport Component from './components'",
  },

lake2 avatar Nov 01 '21 10:11 lake2

please merge and release a new version

lake2 avatar Nov 19 '21 11:11 lake2

To help others, while #405 isn't merged, I'm changing de code inside node_modules without transpile.

Inside lib/index.js line 61

function resolveImports(file, imports, options) {
        //...code 
        
        const target = path_1.default.relative(base, resolved);
        let relative = path_1.default.relative(current, target).replace(/\\/g, '/');
        if (!relative.startsWith('..')) {
            // https://github.com/gulp-plugin/alias/issues/404
            // in the some folder or the sub folder
            relative = './' + relative
        }
        lines[imported.index] = line.replace(imported.import, relative);
        
        //...code
  }

ayelsew avatar Mar 04 '23 19:03 ayelsew