Skip to content

Fix create-app package names for path targets#11

Open
xusd320 wants to merge 2 commits into
mainfrom
codex/find-user-experience-issues-in-evjs
Open

Fix create-app package names for path targets#11
xusd320 wants to merge 2 commits into
mainfrom
codex/find-user-experience-issues-in-evjs

Conversation

@xusd320
Copy link
Copy Markdown
Contributor

@xusd320 xusd320 commented May 15, 2026

Motivation

  • The project scaffolder wrote raw path-like project names (e.g. /tmp/my-app) into package.json.name, producing invalid npm package metadata and breaking first-run DX.
  • The change ensures scaffolded projects receive a valid package name derived from the target directory while preserving scoped package names like @scope/app.

Description

  • Add derivePackageName utility at packages/create-app/src/project-name.ts that returns a scoped name unchanged or the basename of the resolved targetDir for path-like names.
  • Use derivePackageName in packages/create-app/src/index.ts to compute packageName and set projPkg.name = packageName when post-processing template package.json files.
  • Add a unit test in packages/create-app/tests/scaffold.test.ts to cover simple names, absolute/nested path inputs, and scoped package names to prevent regressions.
  • Keep existing dependency sync logic intact (update @evjs/* versions from workspace to ^pkg.version).

Testing

  • Ran npm run build --workspace @evjs/create-app, which completed successfully.
  • Scaffolded a project and validated the generated package.json name with node packages/create-app/dist/index.js /tmp/evjs-dx-real-app-fixed --template basic and node -e "console.log(JSON.parse(require('fs').readFileSync('/tmp/evjs-dx-real-app-fixed/package.json','utf8')).name)", which showed the expected basename value.
  • npm run test --workspace @evjs/create-app failed in this environment because vitest is not available (sh: 1: vitest: not found).
  • Lint invocation failed in this environment because biome is not installed (sh: 1: biome: not found).

Codex Task

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a derivePackageName utility to handle package name generation from project names or paths, including support for scoped packages. It updates the scaffolding logic to use this utility when writing to package.json and adds relevant unit tests. Feedback suggests trimming the project name input and ensuring derived package names are lowercased to meet NPM standards.

@@ -67,6 +68,7 @@ program
const projectName = response.projectName || name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Trimming the projectName ensures that leading or trailing whitespace from user input doesn't result in unexpected directory names or invalid package metadata. This improves the robustness of the scaffolding process.

Suggested change
const projectName = response.projectName || name;
const projectName = (response.projectName || name).trim();

const trimmedName = inputName.trim();

if (scopedPackagePattern.test(trimmedName)) {
return trimmedName.replace("\\", "/");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

NPM package names must be lowercase. Lowercasing the scoped name here ensures that the generated package.json adheres to NPM naming requirements, even if the user provided uppercase characters in the input.

Suggested change
return trimmedName.replace("\\", "/");
return trimmedName.replace("\\", "/").toLowerCase();

return trimmedName.replace("\\", "/");
}

return path.basename(path.resolve(targetDir));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to scoped names, the basename of the target directory should be lowercased to ensure a valid NPM package name. This prevents issues where a directory named with uppercase letters would otherwise produce an invalid package.json.

Suggested change
return path.basename(path.resolve(targetDir));
return path.basename(path.resolve(targetDir)).toLowerCase();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant