Skip to content

Commit 717625f

Browse files
authored
[BUG] What is utils::path-cache::getAAP() doing? (#160)
Fixes #155
1 parent e391a04 commit 717625f

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

projects/project1/src/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import * as data from 'myproject/data.json';
66

77
export { DATA as XYZ } from '@commons';
88

9+
console.log(DATA);
10+
11+
if (DATA !== 'mydata') {
12+
throw new Error('Bad resolution');
13+
}
14+
915
console.log(DATA);
1016
console.log(CUSTOM_MODULE);
1117
console.log(EXTRA);

projects/project1/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"resolveJsonModule": true,
1111
"paths": {
1212
"myproject/*": ["./*"],
13-
"@commons": ["lib/commons/index.ts"],
13+
"@commons": ["libo/commo/index-1.ts", "lib/commons/index.ts"],
1414
"custom/*": ["custom_modules/*", "custom_modules/modules/*"],
1515
"extra": ["../../project2/index"]
1616
}

src/helpers/path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function findBasePathOfAlias(config: IProjectConfig) {
115115
* folder in the output folder (outDir).
116116
*/
117117
if (aliasPath.path.match(/^(\.\/|)node_modules/g)) {
118-
aliasPath.basePath = resolve(config.baseUrl, aliasPath.path);
118+
aliasPath.basePath = resolve(config.baseUrl, 'node_modules');
119119
aliasPath.isExtra = false;
120120
return aliasPath;
121121
}

src/replacers/base-url.replacer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default function replaceBaseUrlImport({
3636
let relativePath: string = normalizePath(
3737
relative(
3838
dirname(file),
39-
config.pathCache.getAbsoluteAliasPath(config.outPath, '')
39+
config.pathCache
40+
.getAbsoluteAliasPath(config.outPath, '')
41+
.replace('---', '')
4042
)
4143
);
4244
if (!relativePath.startsWith('.')) {

src/replacers/default.replacer.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function replaceImportStatement({
5656

5757
if (isAlias) {
5858
for (let i = 0; i < alias.paths.length; i++) {
59-
const absoluteAliasPath = config.pathCache.getAbsoluteAliasPath(
59+
let absoluteAliasPath = config.pathCache.getAbsoluteAliasPath(
6060
alias.paths[i].basePath,
6161
alias.paths[i].path
6262
);
@@ -65,6 +65,14 @@ export default function replaceImportStatement({
6565
absoluteAliasPath
6666
);
6767

68+
if (absoluteAliasPath.startsWith('---')) {
69+
if (i === alias.paths.length - 1) {
70+
absoluteAliasPath = absoluteAliasPath.replace('---', '');
71+
} else {
72+
continue;
73+
}
74+
}
75+
6876
// Check if path is valid.
6977
if (
7078
!config.pathCache.existsResolvedAlias(

src/utils/path-cache.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,20 @@ export class PathCache {
9797

9898
let aliasPathPart = aliasPathParts.shift() || '';
9999

100-
let pathExists: boolean;
100+
let pathExists = false;
101+
101102
while (
102103
!(pathExists = this.exists(join(basePath, aliasPathPart))) &&
103104
aliasPathParts.length
104105
) {
105106
aliasPathPart = aliasPathParts.shift();
106107
}
107108

108-
return join(
109-
basePath,
110-
pathExists ? aliasPathPart : '',
111-
aliasPathParts.join('/')
112-
);
109+
if (pathExists) {
110+
return join(basePath, aliasPathPart, aliasPathParts.join('/'));
111+
}
112+
113+
return '---' + join(basePath, aliasPathParts.join('/'));
113114
}
114115

115116
/**

0 commit comments

Comments
 (0)