Skip to content

Commit 0ed5259

Browse files
author
Mariusz Pasinski
committed
feat: extract path normalization from determineModuleContext()
1 parent 8bb3e77 commit 0ed5259

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/react-native-node-api-modules/src/node/path-utils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,23 @@ export function determineModuleContext(
134134
packageNameCache.set(pkgDir, pkgName);
135135
}
136136
// Compute module-relative path
137-
const relPath = normalizeModulePath(path.relative(pkgDir, originalPath));
137+
const relPath = path.relative(pkgDir, originalPath);
138138
return { packageName: pkgName, relativePath: relPath };
139139
}
140140

141+
/**
142+
* Traverse the filesystem upward to find a name for the package that which contains a file.
143+
* This variant normalizes the module path.
144+
*/
145+
export function determineNormalizedModuleContext(
146+
modulePath: string,
147+
originalPath = modulePath
148+
): ModuleContext {
149+
const { packageName, relativePath } = determineModuleContext(modulePath, originalPath);
150+
const relPath = normalizeModulePath(relativePath);
151+
return { packageName, relativePath: relPath };
152+
}
153+
141154
export function normalizeModulePath(modulePath: string) {
142155
const dirname = path.normalize(path.dirname(modulePath));
143156
const basename = path.basename(modulePath);
@@ -154,7 +167,7 @@ export function escapePath(modulePath: string) {
154167
* Get the name of the library which will be used when the module is linked in.
155168
*/
156169
export function getLibraryName(modulePath: string, naming: NamingStrategy) {
157-
const { packageName, relativePath } = determineModuleContext(modulePath);
170+
const { packageName, relativePath } = determineNormalizedModuleContext(modulePath);
158171
return naming.stripPathSuffix
159172
? packageName
160173
: `${packageName}--${escapePath(relativePath)}`;

0 commit comments

Comments
 (0)