Skip to content

Commit 6d3bde3

Browse files
committed
Split up and document isLocal
1 parent 9832a9d commit 6d3bde3

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

lib/entry-points.js

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,13 +1277,43 @@ export async function initConfig(
12771277
return config;
12781278
}
12791279

1280+
/**
1281+
* Determines if `configPath` is explicitly local. That is, it starts with "./".
1282+
* A configuration file path that starts with "./" is always treated as a local path.
1283+
*
1284+
* @param configPath The path to test.
1285+
*/
1286+
function isRelativePath(configPath: string): boolean {
1287+
return configPath.startsWith("./");
1288+
}
1289+
1290+
/**
1291+
* Determines if `configPath` contains a '@' character.
1292+
*
1293+
* @param configPath The path to test.
1294+
*/
1295+
function containsAtRef(configPath: string): boolean {
1296+
return configPath.includes("@");
1297+
}
1298+
1299+
/**
1300+
* Determines if `configPath` refers to a local configuration file.
1301+
* This assumes the `OLD_REMOTE_ADDRESS_FORMAT` which must contain a '@'
1302+
* character for remote addresses.
1303+
*
1304+
* @param configPath The path to test.
1305+
* @returns True if it is local, or false otherwise.
1306+
*/
12801307
function isLocal(configPath: string): boolean {
1281-
// If the path starts with ./, look locally
1282-
if (configPath.indexOf("./") === 0) {
1308+
// If the path starts with "./", it is explicitly local.
1309+
// This allows local paths that would otherwise contain '@'
1310+
// to be used with a "./" prefix.
1311+
if (isRelativePath(configPath)) {
12831312
return true;
12841313
}
12851314

1286-
return configPath.indexOf("@") === -1;
1315+
// Otherwise, the path is also local if it does not contain '@'.
1316+
return !containsAtRef(configPath);
12871317
}
12881318

12891319
export function getLocalConfig(

0 commit comments

Comments
 (0)