Skip to content

fix(cli): init command loading non-existing package.json#11947

Merged
gioboa merged 3 commits into
typeorm:masterfrom
gioboa:fix/11946
Jan 31, 2026
Merged

fix(cli): init command loading non-existing package.json#11947
gioboa merged 3 commits into
typeorm:masterfrom
gioboa:fix/11946

Conversation

@gioboa
Copy link
Copy Markdown
Collaborator

@gioboa gioboa commented Jan 26, 2026

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

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Jan 26, 2026

User description

Description of change

Pull-Request Checklist


PR Type

Bug fix


Description

  • Removes unused movePackageJsonReferenceLevelUp task from build pipeline

  • Eliminates unnecessary package.json reference path manipulation

  • Simplifies gulpfile build process by removing dead code


Diagram Walkthrough

flowchart LR
  A["gulpfile.ts"] -->|removes unused task| B["movePackageJsonReferenceLevelUp"]
  A -->|removes task from pipeline| C["packagePublish task"]
Loading

File Walkthrough

Relevant files
Bug fix
gulpfile.ts
Remove unused package.json reference task                               

gulpfile.ts

  • Removes the movePackageJsonReferenceLevelUp task method that replaced
    package.json references
  • Removes the task from the packagePublish task dependencies array
  • Eliminates unnecessary path manipulation logic for InitCommand.js
+2/-10   

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Jan 26, 2026

PR Code Suggestions ✨

Latest suggestions up to f578bf7

CategorySuggestion                                                                                                                                    Impact
Possible issue
Verify package.json path in InitCommand

Verify that InitCommand.js can still correctly locate package.json after the
removal of the movePackageJsonReferenceLevelUp gulp task to prevent potential
runtime failures.

gulpfile.ts [207-210]

 packagePreparePackageFile() {
     const packageJsonContents = require("./package.json");
     return gulp.src("./package.json")
         .pipe(replace(/"private": true,/, '"private": false,'))
         .pipe(gulp.dest("./build/package"));
 }
+// Verify InitCommand.js correctly locates package.json after build

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies a potential runtime issue where the init command might fail due to the removal of the movePackageJsonReferenceLevelUp task. It rightly asks for verification that this change is safe, which is important for ensuring the command's functionality.

Low
  • More

Previous suggestions

Suggestions up to commit 4cd2668
CategorySuggestion                                                                                                                                    Impact
Possible issue
Verify package.json path references

Verify that the path to package.json in InitCommand.js is correct, as the gulp
task movePackageJsonReferenceLevelUp that previously updated it has been
removed.

gulpfile.ts [187-190]

 packageCopyShims() {
     return gulp.src(["./extra/typeorm-model-shim.js", "./extra/typeorm-class-transformer-shim.js"])
         .pipe(gulp.dest("./build/package"));
 }
 
+// Verify InitCommand.js uses correct package.json path for the build output structure
+
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that removing the movePackageJsonReferenceLevelUp task could lead to a runtime error if the path to package.json in InitCommand.js is not updated elsewhere, making this a valuable verification check.

Medium
Suggestions
CategorySuggestion                                                                                                                                    Impact
Possible issue
Verify package.json reference handling

Verify that the path to package.json in InitCommand.js is correct after the
removal of the movePackageJsonReferenceLevelUp build task.

gulpfile.ts [187-190]

 packageCopyShims() {
     return gulp.src(["./extra/typeorm-model-shim.js", "./extra/typeorm-class-transformer-shim.js"])
         .pipe(gulp.dest("./build/package"));
 }
 
+// Verify InitCommand.js handles package.json path correctly
+
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential runtime issue in InitCommand.js due to the removal of the movePackageJsonReferenceLevelUp task, which could leave an incorrect path to package.json.

Medium
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 26, 2026

commit: f578bf7

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
Possible issue
Verify package.json reference handling

Verify that the path to package.json in InitCommand.js is correct after the
removal of the movePackageJsonReferenceLevelUp build task.

gulpfile.ts [187-190]

 packageCopyShims() {
     return gulp.src(["./extra/typeorm-model-shim.js", "./extra/typeorm-class-transformer-shim.js"])
         .pipe(gulp.dest("./build/package"));
 }
 
+// Verify InitCommand.js handles package.json path correctly
+

[To ensure code accuracy, apply this suggestion manually]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential runtime issue in InitCommand.js due to the removal of the movePackageJsonReferenceLevelUp task, which could leave an incorrect path to package.json.

Medium
  • More
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented Jan 26, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Missing test for init command fix 📘 Rule violation ⛯ Reliability
Description
• The PR fixes a bug in the init command (issue #11946) but does not add any tests to verify the fix
• According to the compliance rule, issue fixes should add or update tests in test/functional with
  an issue reference
• Without tests, there is no automated verification that the bug is fixed or that it won't regress
  in the future
Code

gulpfile.ts[R192-194]

    /**
     * Creates a package that can be published to npm.
     */
Evidence
The PR removes a build task that was causing the init command to fail by looking for package.json in
the wrong location. This is a bug fix for issue #11946. The compliance checklist requires that issue
fixes should add or update tests in test/functional with an issue reference. A search for '11946' in
the test directory found no results, and there is no test/github-issues/11946 directory. While there
is a test/functional/commands directory with tests for other commands (migration-generate,
migration-create), no test was added for the init command fix.

Rule 3: Prefer functional tests over per-issue tests

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The init command fix lacks test coverage to verify that package.json is correctly resolved from the parent directory after the build process.

## Issue Context
This PR fixes issue #11946 where the init command failed because a build task was incorrectly modifying the package.json path. The compliance checklist requires that issue fixes add or update tests in test/functional with an issue reference.

## Fix Focus Areas
- test/functional/commands[1-1000] - Add a new test file for the init command that verifies package.json resolution works correctly

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Previous review results

Review updated until commit f578bf7

Results up to commit 4cd2668


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider
Action required
1. Missing test for issue 11946 📘 Rule violation ⛯ Reliability
Description
• 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.
Code

gulpfile.ts[R189-194]

            .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.
     */
Evidence
The PR removes the movePackageJsonReferenceLevelUp task to fix issue #11946, but no tests were added
to test/functional/commands or anywhere else to verify this fix. The compliance rule requires issue
fixes to add or update tests in test/functional with an issue reference in the test comment when
applicable.

Rule 3: Prefer functional tests over per-issue tests

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


2. Build transformation task removed without source update 🐞 Bug ✓ Correctness
Description
• 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
Code

gulpfile.ts[220]

-                "movePackageJsonReferenceLevelUp"
Evidence
The removed task at lines 192-200 in gulpfile.ts was explicitly designed to replace
'../package.json' with 'package.json' in the compiled InitCommand.js. The source file InitCommand.ts
at line 682 contains the code await CommandUtils.readFile('${__dirname}/../package.json') which
this task was meant to transform. The build process compiles TypeScript files from src/ to
build/package/, then moves them up one level via packageMoveCompiledFiles (line 121-124), placing
InitCommand.js at build/package/commands/InitCommand.js. The removed transformation was part of the
build pipeline (line 220) and its removal without corresponding source code changes or alternative
handling indicates an incomplete refactoring.

src/commands/InitCommand.ts[682-682]
gulpfile.ts[121-124]
gulpfile.ts[167-171]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Results up to commit 9bd2934


🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0)

Grey Divider
Action required
1. No test added for init fix 📘 Rule violation ⛯ Reliability
Description
• 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.
Code

gulpfile.ts[192]

+
Evidence
The PR description states this fixes issue #11945 related to init functionality. The compliance
checklist requires issue fixes to add or update tests in test/functional (PR Compliance ID 3). A
search for test files related to issues 11945 or 11946 found no matches, and no tests were added in
the diff. The removed task movePackageJsonReferenceLevelUp was related to the InitCommand, but no
functional tests verify the fix works correctly.

Rule 3: Prefer functional tests over per-issue tests

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Qodo Logo
Comment thread gulpfile.ts Outdated
.pipe(replace(/\.\.\/package.json/g, "package.json"))
.pipe(gulp.dest("./build/package/commands"));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

1. Broken package.json path in InitCommand 🐞 Bug ✓ Correctness
Description
• 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
Code

gulpfile.ts[220]

-                "movePackageJsonReferenceLevelUp"
Evidence
The InitCommand source code uses ${__dirname}/../package.json to read the package.json file. The
build process compiles TypeScript files to ./build/package/src/commands/InitCommand.js, then the
packageMoveCompiledFiles task moves files from ./build/package/src/** to ./build/package,
flattening the directory structure. The removed task was specifically designed to adjust this path
after the move, replacing ../package.json with package.json. Without this adjustment, the
compiled code will attempt to read from the wrong location.

src/commands/InitCommand.ts[682-682]
gulpfile.ts[121-123]
gulpfile.ts[192-200]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

# 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



ⓘ The new review experience is currently in Beta. Learn more

Qodo Logo

Comment thread gulpfile.ts
"packagePreparePackageFile",
"packageCopyReadme",
"packageCopyShims",
"movePackageJsonReferenceLevelUp"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

@gioboa gioboa requested review from G0maa, alumni and naorpeled January 26, 2026 21:50
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Persistent review updated to latest commit 4cd2668

Comment thread gulpfile.ts
Comment on lines 189 to 194
.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.
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

Comment thread gulpfile.ts
"packagePreparePackageFile",
"packageCopyReadme",
"packageCopyShims",
"movePackageJsonReferenceLevelUp"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

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

@gioboa gioboa changed the title fix: fix up init issue fix: fix up CLI init issue Jan 30, 2026
@alumni alumni changed the title fix: fix up CLI init issue fix(cli): init command loading non-existing package.json Jan 30, 2026
@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Persistent review updated to latest commit f578bf7

@gioboa gioboa merged commit abd0b0c into typeorm:master Jan 31, 2026
13 checks passed
@gioboa gioboa deleted the fix/11946 branch January 31, 2026 19:34
kranners pushed a commit to kranners/typeorm that referenced this pull request Feb 2, 2026
@gioboa gioboa mentioned this pull request Feb 10, 2026
18 tasks
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
@pkuczynski pkuczynski added this to the 1.0 milestone Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants