MCPcopy
hub / github.com/QwikDev/qwik / resolve

Function resolve

packages/qwik/src/optimizer/src/path.ts:118–168  ·  view source on GitHub ↗
(...paths: string[])

Source from the content-addressed store, hash-verified

116
117 // path.resolve([from ...], to)
118 const resolve = function resolve(...paths: string[]) {
119 let resolvedPath = '';
120 let resolvedAbsolute = false;
121 let cwd;
122
123 for (let i = paths.length - 1; i >= -1 && !resolvedAbsolute; i--) {
124 let path;
125 if (i >= 0) {
126 path = paths[i];
127 } else {
128 if (cwd === undefined) {
129 if (opts && typeof opts.cwd === 'function') {
130 cwd = opts.cwd();
131 } else if (typeof process !== 'undefined' && typeof process.cwd === 'function') {
132 cwd = process.cwd();
133 } else {
134 cwd = '/';
135 }
136 }
137 path = cwd;
138 }
139
140 assertPath(path);
141
142 // Skip empty entries
143 if (path.length === 0) {
144 continue;
145 }
146
147 resolvedPath = path + '/' + resolvedPath;
148 resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/;
149 }
150
151 // At this point the path should be resolved to a full absolute path, but
152 // handle relative paths to be safe (might happen when process.cwd() fails)
153
154 // Normalize the path
155 resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
156
157 if (resolvedAbsolute) {
158 if (resolvedPath.length > 0) {
159 return '/' + resolvedPath;
160 } else {
161 return '/';
162 }
163 } else if (resolvedPath.length > 0) {
164 return resolvedPath;
165 } else {
166 return '.';
167 }
168 };
169
170 const normalize = function normalize(path: string) {
171 assertPath(path);

Callers 12

qwikloader.unit.tsFile · 0.90
preloader.unit.tsFile · 0.90
resolveRelativeDirFunction · 0.90
eslint-docs.tsFile · 0.90
vite.config.tsFile · 0.90
getTmpDirSyncFunction · 0.90
loadPlatformBindingFunction · 0.70
relativeFunction · 0.70
rollup.unit.tsFile · 0.50
plugin.unit.tsFile · 0.50
vite.unit.tsFile · 0.50

Calls 2

assertPathFunction · 0.85
normalizeStringPosixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…