diff --git a/mocks/jsconfig.json b/mocks/jsconfig.json index 7ac4649..0952d71 100644 --- a/mocks/jsconfig.json +++ b/mocks/jsconfig.json @@ -6,7 +6,14 @@ "@dir/*": ["./src/dir/*"], "@dir2/*": ["././src/dir2/*"], "$dir3/*": ["src/dir3/*", "src/dir3"], - "my-package": ["./node_modules/some-package", "./node_modules/some-package/*"], + "my-package": [ + "./node_modules/some-package", + "./node_modules/some-package/*" + ], + "external-package": [ + "/absolute_path/external-package", + "/absolute_path/external-package/*" + ], "@material-ui": ["node_modules/@material-ui/ie-10/ie-10.js"] } } diff --git a/mocks/tsconfig.paths.json b/mocks/tsconfig.paths.json index 0faa7cc..0952d71 100644 --- a/mocks/tsconfig.paths.json +++ b/mocks/tsconfig.paths.json @@ -6,7 +6,14 @@ "@dir/*": ["./src/dir/*"], "@dir2/*": ["././src/dir2/*"], "$dir3/*": ["src/dir3/*", "src/dir3"], - "my-package": ["./node_modules/some-package/*", "./node_modules/some-package"], + "my-package": [ + "./node_modules/some-package", + "./node_modules/some-package/*" + ], + "external-package": [ + "/absolute_path/external-package", + "/absolute_path/external-package/*" + ], "@material-ui": ["node_modules/@material-ui/ie-10/ie-10.js"] } } diff --git a/plugin/extract-aliases/index.js b/plugin/extract-aliases/index.js index e34e1a0..735ac71 100644 --- a/plugin/extract-aliases/index.js +++ b/plugin/extract-aliases/index.js @@ -28,7 +28,7 @@ const extractAliases = ({ pluginOptions, context: { paths } }) => { const { appPath } = paths const { baseUrl } = options - const absoluteBaseUrl = path.join(appPath, baseUrl) + const absoluteBaseUrl = path.resolve(appPath, baseUrl) if (options.source === 'jsconfig') return extractAliasesFromConfig({ diff --git a/plugin/extract-aliases/index.test.js b/plugin/extract-aliases/index.test.js index e127cd1..94fedb2 100644 --- a/plugin/extract-aliases/index.test.js +++ b/plugin/extract-aliases/index.test.js @@ -3,8 +3,8 @@ const extractAliases = require('.') describe('extract-aliases', () => { const appPath = path.resolve(__dirname, '../..') - const appJsConfig = path.join(appPath, 'mocks/jsconfig.json') - const tsConfigPath = path.join(appPath, 'mocks/tsconfig.paths.json') + const appJsConfig = path.resolve(appPath, 'mocks/jsconfig.json') + const tsConfigPath = path.resolve(appPath, 'mocks/tsconfig.paths.json') const context = { paths: { @@ -24,6 +24,7 @@ describe('extract-aliases', () => { '@dir2': '././src/dir2/', '$dir3': 'src/dir3', 'my-package': './node_modules/some-package', + 'external-package': '/absolute_path/external-package', '@material-ui': 'node_modules/@material-ui/ie-10/ie-10.js', }, }, @@ -45,13 +46,17 @@ describe('extract-aliases', () => { } const result = { - '@file': path.join(appPath, './src/file.js'), - '@file2': path.join(appPath, './src/file2.js'), - '@dir': path.join(appPath, './src/dir'), - '@dir2': path.join(appPath, './src/dir2'), - '$dir3': path.join(appPath, './src/dir3'), - 'my-package': path.join(appPath, './node_modules/some-package'), - '@material-ui': path.join( + '@file': path.resolve(appPath, './src/file.js'), + '@file2': path.resolve(appPath, './src/file2.js'), + '@dir': path.resolve(appPath, './src/dir'), + '@dir2': path.resolve(appPath, './src/dir2'), + '$dir3': path.resolve(appPath, './src/dir3'), + 'my-package': path.resolve(appPath, './node_modules/some-package'), + 'external-package': path.resolve( + appPath, + '/absolute_path/external-package' + ), + '@material-ui': path.resolve( appPath, './node_modules/@material-ui/ie-10/ie-10.js' ), diff --git a/plugin/extract-aliases/normalize-aliases.js b/plugin/extract-aliases/normalize-aliases.js index 330dda6..149e4a9 100644 --- a/plugin/extract-aliases/normalize-aliases.js +++ b/plugin/extract-aliases/normalize-aliases.js @@ -8,7 +8,7 @@ const normalizeAliases = ({ absoluteBaseUrl, aliases }) => { const cleanAlias = aliases[aliasName].replace(/\/$/, '') // make alias path absolute - result[aliasName] = path.join(absoluteBaseUrl, cleanAlias) + result[aliasName] = path.resolve(absoluteBaseUrl, cleanAlias) } return result diff --git a/plugin/extract-aliases/normalize-aliases.test.js b/plugin/extract-aliases/normalize-aliases.test.js index a578637..3c935c4 100644 --- a/plugin/extract-aliases/normalize-aliases.test.js +++ b/plugin/extract-aliases/normalize-aliases.test.js @@ -9,7 +9,7 @@ describe('normalize-aliases', () => { test('should correctly normalize aliases', () => { expect( normalizeAliases({ - absoluteBaseUrl: path.join(appPath, '.'), + absoluteBaseUrl: path.resolve(appPath, '.'), aliases: { '@file': './src/file.js', '@file2': 'src/file2.js', @@ -17,17 +17,22 @@ describe('normalize-aliases', () => { '@dir2': '././src/dir2/', '$dir3': 'src/dir3', 'my-package': './node_modules/some-package', + 'external-package': '/absolute_path/external-package', '@material-ui': 'node_modules/@material-ui/ie-10/ie-10.js', }, }) ).toEqual({ - '@file': path.join(appPath, './src/file.js'), - '@file2': path.join(appPath, './src/file2.js'), - '@dir': path.join(appPath, './src/dir'), - '@dir2': path.join(appPath, './src/dir2'), - '$dir3': path.join(appPath, './src/dir3'), - 'my-package': path.join(appPath, './node_modules/some-package'), - '@material-ui': path.join( + '@file': path.resolve(appPath, './src/file.js'), + '@file2': path.resolve(appPath, './src/file2.js'), + '@dir': path.resolve(appPath, './src/dir'), + '@dir2': path.resolve(appPath, './src/dir2'), + '$dir3': path.resolve(appPath, './src/dir3'), + 'my-package': path.resolve(appPath, './node_modules/some-package'), + 'external-package': path.resolve( + appPath, + '/absolute_path/external-package' + ), + '@material-ui': path.resolve( appPath, './node_modules/@material-ui/ie-10/ie-10.js' ), @@ -35,7 +40,7 @@ describe('normalize-aliases', () => { expect( normalizeAliases({ - absoluteBaseUrl: path.join(appPath, './src'), + absoluteBaseUrl: path.resolve(appPath, './src'), aliases: { '@file': './file.js', '@file2': 'file2.js', @@ -45,11 +50,11 @@ describe('normalize-aliases', () => { }, }) ).toEqual({ - '@file': path.join(appPath, './src/file.js'), - '@file2': path.join(appPath, './src/file2.js'), - '@dir': path.join(appPath, './src/dir'), - '@dir2': path.join(appPath, './src/dir2'), - '$dir3': path.join(appPath, './src/dir3'), + '@file': path.resolve(appPath, './src/file.js'), + '@file2': path.resolve(appPath, './src/file2.js'), + '@dir': path.resolve(appPath, './src/dir'), + '@dir2': path.resolve(appPath, './src/dir2'), + '$dir3': path.resolve(appPath, './src/dir3'), }) }) })