tsc-alias
tsc-alias copied to clipboard
baseUrl value is not accurately recognized
There is an error in not parsing the path accurately, depending on the baseUrl value in tsconfig.json.
Error Case
tsconfig.json
{
...
"compilerOptions": {
"baseUrl": "./src/jslib",
"paths": { "@/crypto/*": ["crypto/*"], "@/utils/*": ["utils/*"] }
"outDir": "./build"
}
...
}
Problem found with debug
Correctly find the file to replace and read the baseUrl and path values in tsconfig.json correctly.
However, the .replace('---', '') function does not seem to work.
tsc-alias debug: default replacer - absoluteAliasPath: '---/Users/rhiemh/Workspace/@demo/test-sandbox/build'
tsc-alias debug: default replacer - Invalid path
tsc-alias debug: base-url replacer - requiredModule: '@/utils/math'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/index.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/crypto/decrypt.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/crypto/encrypt.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/utils/math.js'
Success Case
tsconfig.json
{
...
"compilerOptions": {
"baseUrl": "./",
"paths": { "@/crypto/*": ["./src/jslib/crypto/*"], "@/utils/*": ["./src/jslib/utils/*"] },
"outDir": "./build"
}
...
}
Debug result
tsc-alias debug: default replacer - absoluteAliasPath: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/utils'
tsc-alias debug: default replacer - relativeAliasPath: './jslib/utils'
tsc-alias debug: default replacer - newImportScript: 'require("./jslib/utils/math")'
tsc-alias debug: default replacer - modulePath: './jslib/utils/math'
tsc-alias debug: base-url replacer - requiredModule: './jslib/utils/math'
tsc-alias debug: base-url replacer - already resolved
tsc-alias debug: replaced file with changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/index.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/utils/math.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/crypto/decrypt.js'
tsc-alias debug: replaced file without changes: '/Users/rhiemh/Workspace/@demo/test-sandbox/build/src/jslib/crypto/encrypt.js'
Issue Conclusion
As you can see, both 'Error Case' and 'Success Case' have the same path, but they behave differently depending on the combination of baseUrl and path.
Am I doing something wrong or is it a bug?
Thanks!
Best regards.