MCPcopy Create free account
hub / github.com/R-js/libRmath.js / resolveAliasPaths

Function resolveAliasPaths

scripts/helpers.mjs:138–177  ·  view source on GitHub ↗
(path, pathsDictionary, base, exact, wildcard, possibleExtensions)

Source from the content-addressed store, hash-verified

136}
137
138function resolveAliasPaths(path, pathsDictionary, base, exact, wildcard, possibleExtensions){
139 const idxExact = exact.indexOf(path);
140 if (idxExact >= 0) {
141 return resolve(base, pathsDictionary[exact[idx]][0]);
142 }
143 const candidates = wildcard
144 .map(wc => path.startsWith(wc.slice(0, -1)) || path.startsWith(wc.slice(0, -2)) ? wc : null)
145 .filter (f => !!f); // remove nulls
146
147 for (const candidate of candidates) {
148 const noStar = candidate.slice(0, -1);
149 const noSlash = noStar.slice(0, -1);
150 const matchedString = path.startsWith(noStar) ? noStar : noSlash;
151
152 const possibleDirs = pathsDictionary[candidate];
153 // we have to resolve each array element untill we find it
154 for (const replace of possibleDirs) {
155 const dir = resolve(base, replace.slice(0, -1));
156 // must be a dir
157 let lstat;
158 try {
159 lstat = lstatSync(dir);
160 } catch (err) {
161 console.log(`lstat failed for ${replace} aliased by ${candidate}, with error ${String(err)}`);
162 continue;
163 }
164 if (!lstat.isDirectory()){
165 console.log(`${replace} aliased by ${candiate} is not a directory`);
166 continue;
167 }
168 // so we have a directory
169 // replace alias prefix with real full dir
170 const subPathElts = path.replace(matchedString, '').split('/');
171 const actual = walkDirPath(structuredClone(subPathElts), dir, possibleExtensions);
172 if (actual){
173 return actual;
174 }
175 }
176 }
177}
178
179export function resolveToFullPath(module, importStatement, base, pathsDictionary, exact, wildcard, forceExt, possibleExtensions) {
180 const node_m = 'node_modules';

Callers 1

resolveToFullPathFunction · 0.85

Calls 1

walkDirPathFunction · 0.85

Tested by

no test coverage detected