Skip to content

Commit 096add6

Browse files
committed
Fix gyp-to-cmake project name escaping
1 parent 6729b9d commit 096add6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/gyp-to-cmake/src/cli.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export type TransformOptions = Omit<GypToCmakeListsOptions, "gyp"> & {
2424
export function generateProjectName(gypPath: string) {
2525
const packagePath = packageDirectorySync({ cwd: path.dirname(gypPath) });
2626
assert(packagePath, "Expected the binding.gyp file to be inside a package");
27-
const packageJson = readPackageSync({ cwd: packagePath });
28-
return packageJson.name;
27+
const { name } = readPackageSync({ cwd: packagePath });
28+
return name
29+
.replace(/^@/g, "")
30+
.replace(/\//g, "--")
31+
.replace(/[^a-zA-Z0-9_]/g, "_");
2932
}
3033

3134
export function transformBindingGypFile(

packages/gyp-to-cmake/src/transformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function escapeSpaces(source: string) {
2828
}
2929

3030
function escapeBundleIdentifier(identifier: string) {
31-
return identifier.replace(/[^A-Za-z0-9.-]/g, "-");
31+
return identifier.replaceAll("__", ".").replace(/[^A-Za-z0-9.-_]/g, "-");
3232
}
3333

3434
/**

0 commit comments

Comments
 (0)