fix(cli): init command loading non-existing package.json#11947
Conversation
User descriptionDescription of changePull-Request Checklist
PR TypeBug fix Description
Diagram Walkthroughflowchart LR
A["gulpfile.ts"] -->|removes unused task| B["movePackageJsonReferenceLevelUp"]
A -->|removes task from pipeline| C["packagePublish task"]
|
| Relevant files | |||
|---|---|---|---|
| Bug fix |
|
PR Code Suggestions ✨Latest suggestions up to f578bf7
Previous suggestionsSuggestions up to commit 4cd2668
Suggestions
|
|||||||||||||||||||||||||||
commit: |
PR Code Suggestions ✨
|
|||||||||
Code Review by Qodo
1. Missing test for init command fix
|
| .pipe(replace(/\.\.\/package.json/g, "package.json")) | ||
| .pipe(gulp.dest("./build/package/commands")); | ||
| } | ||
|
|
There was a problem hiding this comment.
1. No test added for init fix 📘 Rule violation ⛯ Reliability
• The PR fixes an init issue (closes #11945) but does not add or update any tests in test/functional. • Compliance rule 3 requires issue fixes to add or update tests in test/functional with an issue reference. • Without tests, there's no verification that the fix works correctly or prevents regression.
Agent prompt
## Issue description
The PR fixes an init command issue (#11945) by removing a build step that was adjusting package.json references. However, no tests were added to verify this fix works correctly or prevent future regressions.
## Issue Context
The removed task `movePackageJsonReferenceLevelUp` was replacing `../package.json` with `package.json` in the built InitCommand.js file. The fix removes this task, suggesting the source code now uses the correct path. Per project compliance rules, issue fixes should include functional tests with issue references.
## Fix Focus Areas
- test/functional/commands[1-1] (create new test file for init command)
- Add test that verifies InitCommand can read package.json correctly
- Include comment referencing issue #11945
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Code Review by Qodo
1. Broken package.json path in InitCommand
|
| "packagePreparePackageFile", | ||
| "packageCopyReadme", | ||
| "packageCopyShims", | ||
| "movePackageJsonReferenceLevelUp" |
There was a problem hiding this comment.
1. Broken package.json path in initcommand 🐞 Bug ✓ Correctness
• The removal of the movePackageJsonReferenceLevelUp task breaks the InitCommand functionality by leaving an incorrect relative path reference • After compilation and file movement, the path ../package.json in InitCommand.js will point to a non-existent location instead of the actual package.json file • This will cause runtime failures when users run the init command, as the file read operation will fail with a file-not-found error
Agent prompt
# Issue Description
The removal of the `movePackageJsonReferenceLevelUp` gulp task causes InitCommand to fail at runtime because it attempts to read package.json using a relative path that becomes invalid after the build process moves compiled files.
# Issue Context
The build process:
1. Compiles TypeScript files to `./build/package/src/commands/InitCommand.js`
2. Runs `packageMoveCompiledFiles` which moves files from `./build/package/src/**` to `./build/package`
3. The compiled InitCommand.js ends up at `./build/package/commands/InitCommand.js`
4. The code contains `__dirname + '/../package.json'` which now points to the wrong location
The removed task was specifically designed to fix this by replacing `../package.json` with `package.json` after the move.
# Fix Focus Areas
**Option 1: Restore the build task**
- gulpfile.ts[192-200] - Restore the removed task
- gulpfile.ts[220-220] - Restore the task invocation in the build pipeline
**Option 2: Fix the source code path resolution**
- src/commands/InitCommand.ts[682-682] - Change the path resolution logic to work correctly after build (e.g., use a different approach to locate package.json that doesn't rely on relative paths that change during build)
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Persistent review updated to latest commit 4cd2668 |
| .pipe(gulp.dest("./build/package")); | ||
| } | ||
|
|
||
| /** | ||
| * Move reference to package.json one level up | ||
| */ | ||
| @Task() | ||
| movePackageJsonReferenceLevelUp() { | ||
| return gulp.src("./build/package/commands/InitCommand.js") | ||
| .pipe(replace(/\.\.\/package.json/g, "package.json")) | ||
| .pipe(gulp.dest("./build/package/commands")); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a package that can be published to npm. | ||
| */ |
There was a problem hiding this comment.
1. Missing test for issue 11946 📘 Rule violation ⛯ Reliability
• This PR fixes issue #11946 but does not add any tests to verify the fix. • The compliance checklist requires issue fixes to add or update tests in test/functional with an issue reference. • Without tests, there is no automated verification that the init command now correctly resolves package.json from the parent directory.
Agent prompt
## Issue description
The PR fixes issue #11946 by removing a gulp task that incorrectly modified package.json path references, but no tests were added to verify the fix works correctly.
## Issue Context
The init command was failing because it was looking for package.json in the wrong location. The fix removes the movePackageJsonReferenceLevelUp task from gulpfile.ts. Per compliance requirements, issue fixes should add or update tests in test/functional with an issue reference.
## Fix Focus Areas
- test/functional/commands/[new test file for init command]
- Add test that verifies InitCommand correctly resolves package.json from ../package.json
- Include comment referencing issue #11946
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| "packagePreparePackageFile", | ||
| "packageCopyReadme", | ||
| "packageCopyShims", | ||
| "movePackageJsonReferenceLevelUp" |
There was a problem hiding this comment.
2. Build transformation task removed without source update 🐞 Bug ✓ Correctness
• The removed movePackageJsonReferenceLevelUp task was designed to transform the package.json path
reference in the compiled InitCommand.js from '../package.json' to 'package.json'
• The source file InitCommand.ts (line 682) still contains the relative path
${__dirname}/../package.json which was intended to be modified during build
• Removing this transformation without updating the source code or verifying the new behavior breaks
the intended build pipeline logic and creates maintenance issues
• This could lead to runtime errors if the build directory structure changes or if the path
resolution doesn't work as expected in the final package
Agent prompt
## Issue Description
The build task `movePackageJsonReferenceLevelUp` was removed from the gulpfile.ts without updating the source code that depends on the transformation it performed. This task was responsible for replacing '../package.json' with 'package.json' in the compiled InitCommand.js file.
## Issue Context
- The removed task performed a string replacement on the compiled InitCommand.js
- The source file InitCommand.ts still contains a relative path reference that was meant to be transformed
- The build process compiles files to build/package/ and then moves them, affecting path resolution
- The package.json is copied to build/package/package.json by the packagePreparePackageFile task
## Fix Focus Areas
Option 1 - Restore the transformation task:
- gulpfile.ts[192-200] (restore the removed task)
- gulpfile.ts[220-220] (restore the task invocation)
Option 2 - Update the source code:
- src/commands/InitCommand.ts[682-682] (update the path to work without transformation)
Option 3 - Verify and document:
- Test that the current path resolution works correctly in the final package
- Add comments explaining why the transformation is no longer needed
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Persistent review updated to latest commit f578bf7 |
Description of change
The npx typeorm init command failed because it was looking for package.json in the wrong
location within the published package. This was caused by a build task in gulpfile.ts named
movePackageJsonReferenceLevelUp that incorrectly modified the path in InitCommand.js from
../package.json to package.json.
I have fixed this by removing the movePackageJsonReferenceLevelUp task from gulpfile.ts. This
ensures that InitCommand.js correctly resolves package.json from the parent directory
(.../typeorm/package.json) instead of looking for it in .../typeorm/commands/package.json
(which does not exist).
Pull-Request Checklist
masterbranch