Skip to content

Commit bc1b957

Browse files
author
Mariusz Pasinski
committed
feat: extract path normalization from determineModuleContext()
1 parent 7907855 commit bc1b957

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
@@ -118,10 +118,23 @@ export function determineModuleContext(
118118
packageNameCache.set(pkgDir, pkgName);
119119
}
120120
// Compute module-relative path
121-
const relPath = normalizeModulePath(path.relative(pkgDir, originalPath));
121+
const relPath = path.relative(pkgDir, originalPath);
122122
return { packageName: pkgName, relativePath: relPath };
123123
}
124124

125+
/**
126+
* Traverse the filesystem upward to find a name for the package that which contains a file.
127+
* This variant normalizes the module path.
128+
*/
129+
export function determineNormalizedModuleContext(
130+
modulePath: string,
131+
originalPath = modulePath
132+
): ModuleContext {
133+
const { packageName, relativePath } = determineModuleContext(modulePath, originalPath);
134+
const relPath = normalizeModulePath(relativePath);
135+
return { packageName, relativePath: relPath };
136+
}
137+
125138
export function normalizeModulePath(modulePath: string) {
126139
const dirname = path.normalize(path.dirname(modulePath));
127140
const basename = path.basename(modulePath);
@@ -137,7 +150,7 @@ export function escapePath(modulePath: string) {
137150
* Get the name of the library which will be used when the module is linked in.
138151
*/
139152
export function getLibraryName(modulePath: string, naming: NamingStrategy) {
140-
const { packageName, relativePath } = determineModuleContext(modulePath);
153+
const { packageName, relativePath } = determineNormalizedModuleContext(modulePath);
141154
return naming.stripPathSuffix
142155
? packageName
143156
: `${packageName}--${escapePath(relativePath)}`;

0 commit comments

Comments
 (0)