Skip to content

Commit 42a635e

Browse files
committed
Use the filesystem to determine package name.
1 parent cbad1e3 commit 42a635e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

scripts/lib/bashy-node/node-project/fix-package-json

+12-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ function do-fix {
9090
local filePath="$1"
9191
local fileDir="${filePath%/*}"
9292

93+
local packageName="${fileDir}"
94+
if [[ ${packageName} =~ /@(.*)$ ]]; then
95+
# The directory structure has the form `@<project>/<name>`.
96+
packageName="${BASH_REMATCH[2]}"
97+
else
98+
# No `@<project>`, so just use the final directory name, and assume it's
99+
# in `@this`.
100+
packageName="@this/${packageName##*/}"
101+
fi
102+
93103
local oldDeps
94104
oldDeps="$(jval <"${filePath}" --input=read '.dependencies // {}')" \
95105
|| return "$?"
@@ -124,11 +134,12 @@ function do-fix {
124134
hasExportTesting:json="${hasExportTesting}" \
125135
hasPrivateDir:json="${hasPrivateDir}" \
126136
hasTestsDir:json="${hasTestsDir}" \
137+
packageName="${packageName}" \
127138
deps:json="${finalDeps}" '
128139
(.scripts // {}) as $scripts
129140
|
130141
{
131-
name: .name,
142+
name: $packageName,
132143
version: .version,
133144
type: "module",
134145
private: true,

0 commit comments

Comments
 (0)