Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Fix absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kdziamura authored and Evgeny Zakharov committed May 23, 2021
1 parent 12071df commit 57463ea
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
9 changes: 8 additions & 1 deletion mocks/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
Expand Down
9 changes: 8 additions & 1 deletion mocks/tsconfig.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/extract-aliases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
23 changes: 14 additions & 9 deletions plugin/extract-aliases/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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',
},
},
Expand All @@ -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'
),
Expand Down
2 changes: 1 addition & 1 deletion plugin/extract-aliases/normalize-aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions plugin/extract-aliases/normalize-aliases.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,38 @@ 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',
'@dir': './src/dir',
'@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'
),
})

expect(
normalizeAliases({
absoluteBaseUrl: path.join(appPath, './src'),
absoluteBaseUrl: path.resolve(appPath, './src'),
aliases: {
'@file': './file.js',
'@file2': 'file2.js',
Expand All @@ -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'),
})
})
})

0 comments on commit 57463ea

Please sign in to comment.