From 6679e840e006cd5590c30d96ae3010048ac7dad7 Mon Sep 17 00:00:00 2001 From: Mariusz Pasinski Date: Tue, 17 Jun 2025 18:16:05 +0200 Subject: [PATCH] fix: escape package name (see #127) This change fixes [#127](https://github.com/callstackincubator/react-native-node-api/issues/127) by simply escaping (i.e. replacing) all non-alphanumeric characters with `-` (including `-` itself). While the `escapePath()` is overly strict (e.g. does not allow a valid `_` character) it does not need relaxing for now. Lifting limitations is always backwards-compatible; introducing them is not. --- packages/host/src/node/path-utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/host/src/node/path-utils.ts b/packages/host/src/node/path-utils.ts index ec93df86..179688ce 100644 --- a/packages/host/src/node/path-utils.ts +++ b/packages/host/src/node/path-utils.ts @@ -148,9 +148,10 @@ export function escapePath(modulePath: string) { */ export function getLibraryName(modulePath: string, naming: NamingStrategy) { const { packageName, relativePath } = determineModuleContext(modulePath); + const escapedPackageName = escapePath(packageName); return naming.stripPathSuffix - ? packageName - : `${packageName}--${escapePath(relativePath)}`; + ? escapedPackageName + : `${escapedPackageName}--${escapePath(relativePath)}`; } export function prettyPath(p: string) {