MCPcopy
hub / github.com/angular/angular-cli / buildRelativePath

Function buildRelativePath

packages/schematics/angular/utility/find-module.ts:130–159  ·  view source on GitHub ↗
(from: string, to: string)

Source from the content-addressed store, hash-verified

128 * Build a relative path from one file path to another file path.
129 */
130export function buildRelativePath(from: string, to: string): string {
131 from = normalize(from);
132 to = normalize(to);
133
134 // Convert to arrays.
135 const fromParts = from.split('/');
136 const toParts = to.split('/');
137
138 // Remove file names (preserving destination)
139 fromParts.pop();
140 const toFileName = toParts.pop();
141
142 const relativePath = relative(
143 normalize(fromParts.join('/') || '/'),
144 normalize(toParts.join('/') || '/'),
145 );
146 let pathPrefix = '';
147
148 // Set the path prefix for same dir or child dir, parent dir starts with `..`
149 if (!relativePath) {
150 pathPrefix = '.';
151 } else if (!relativePath.startsWith('.')) {
152 pathPrefix = `./`;
153 }
154 if (pathPrefix && !pathPrefix.endsWith('/')) {
155 pathPrefix += '/';
156 }
157
158 return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
159}

Callers 3

buildRelativeModulePathFunction · 0.90
addDeclarationToNgModuleFunction · 0.90

Calls 3

normalizeFunction · 0.90
relativeFunction · 0.90
popMethod · 0.80

Tested by

no test coverage detected