-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(cli/init): pick dependencies versions from our own package.json #11705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a Gulp task that rewrites ../../package.json references to package.json and includes it in the package sequence; enables TypeScript JSON imports; reads dependency versions from local package.json in InitCommand; adds @google-cloud/spanner as a devDependency. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev
participant Gulp as Gulp Tasks
participant Pkg as Packaging Pipeline
participant FS as File System
Dev->>Gulp: run package
Gulp->>Pkg: execute sequence
Pkg->>Pkg: packageCopyShims
Note over Pkg: New step
Pkg->>FS: movePackageJsonReferenceLevelUp<br/>(rewrite ../../package.json -> package.json)
Pkg->>Pkg: remaining packaging steps
Pkg-->>Dev: packaged output
sequenceDiagram
autonumber
participant User as CLI User
participant Init as InitCommand
participant JSON as local package.json
User->>Init: run init
Init->>JSON: import versions (requires resolveJsonModule)
Note over Init,JSON: Use local dependency versions for generated files
Init->>Init: build dependency maps (TypeScript, reflect-metadata, TypeORM, DB drivers)
Init-->>User: initialized project files with synced versions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (4)
gulpfile.ts (1)
229-237: LGTM with minor suggestion for comment clarity.The regex pattern correctly transforms
../../package.jsonto../package.json, which is the correct relative path frombuild/package/commands/InitCommand.jstobuild/package/package.jsonin the published package structure.Consider clarifying the comment to better describe the transformation:
- /** - * Move reference to package.json one level up - */ + /** + * Adjusts package.json import path for the packaged structure. + * Transforms "../../package.json" to "../package.json" in compiled InitCommand. + */Additionally, verify that no other commands import package.json:
#!/bin/bash # Check for other imports of package.json in commands directory rg -n --type=ts 'from.*package\.json' src/commands/src/commands/InitCommand.ts (3)
9-9: LGTM with recommendations for robustness.The import correctly sources dependency versions from the local
package.json, centralizing version management as intended.Consider adding validation to ensure required properties exist, preventing silent failures if
package.jsonstructure changes:import ourPackageJson from "../../package.json" + +// Validate required package.json properties +const requiredDevDeps = ["@types/node", "ts-node", "typescript", "mysql2", "pg", "sqlite3", "better-sqlite3", "oracledb", "mssql", "mongodb", "@google-cloud/spanner"]; +const requiredDeps = ["reflect-metadata"]; +const missingDevDeps = requiredDevDeps.filter(dep => !ourPackageJson.devDependencies?.[dep]); +const missingDeps = requiredDeps.filter(dep => !ourPackageJson.dependencies?.[dep]); +if (missingDevDeps.length > 0 || missingDeps.length > 0) { + throw new TypeORMError( + `Missing required dependencies in package.json: ${[...missingDevDeps, ...missingDeps].join(", ")}` + ); +}
685-687: Consider consistent property access notation.The code mixes bracket notation (
ourPackageJson.devDependencies["@types/node"]) and dot notation (ourPackageJson.devDependencies.typescript). While both are valid, bracket notation is safer for keys with special characters and provides consistency.Apply this diff for consistency:
packageJson.devDependencies = { - "@types/node": ourPackageJson.devDependencies["@types/node"], - "ts-node": ourPackageJson.devDependencies["ts-node"], - typescript: ourPackageJson.devDependencies.typescript, + "@types/node": ourPackageJson.devDependencies["@types/node"], + "ts-node": ourPackageJson.devDependencies["ts-node"], + typescript: ourPackageJson.devDependencies["typescript"], ...packageJson.devDependencies, }
701-732: LGTM with validation recommendation.Database driver versions are correctly sourced from
ourPackageJson.devDependencies, including the newly added@google-cloud/spanner.To prevent silent failures if a driver dependency is missing from
package.json, consider the validation suggested in the earlier comment on line 9.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
gulpfile.ts(2 hunks)package.json(1 hunks)src/commands/InitCommand.ts(2 hunks)tsconfig.json(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: tests-linux (20) / better-sqlite3
- GitHub Check: tests-linux (20) / sqljs
- GitHub Check: tests-linux (20) / mysql_mariadb_latest
- GitHub Check: tests-linux (20) / mysql_mariadb
- GitHub Check: tests-linux (20) / sap
- GitHub Check: tests-linux (18) / sap
- GitHub Check: tests-linux (18) / sqljs
- GitHub Check: tests-linux (18) / mysql_mariadb_latest
- GitHub Check: tests-linux (18) / postgres (14)
- GitHub Check: tests-linux (18) / better-sqlite3
- GitHub Check: tests-linux (18) / sqlite
- GitHub Check: tests-linux (18) / postgres (17)
- GitHub Check: tests-linux (18) / mysql_mariadb
- GitHub Check: tests-linux (18) / mssql
- GitHub Check: tests-linux (18) / oracle
- GitHub Check: tests-linux (18) / mongodb
- GitHub Check: tests-windows / sqljs
- GitHub Check: tests-windows / sqlite
- GitHub Check: tests-windows / better-sqlite3
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
tsconfig.json (1)
17-17: LGTM!Enabling
resolveJsonModuleis necessary to support importingpackage.jsonas a module inInitCommand.ts. The change is correct and minimal.src/commands/InitCommand.ts (1)
694-695: LGTM!Sourcing
reflect-metadataand the TypeORM version fromourPackageJsoncorrectly centralizes version management.gulpfile.ts (1)
256-257: EnsuremovePackageJsonReferenceLevelUpruns afterpackageMoveCompiledFiles
The task is currently grouped in the final parallel array withpackageCopyShims, so it may execute before compiled files are moved. Confirm that nested arrays map to parallel execution in your gulp sequence API and, if so, relocatemovePackageJsonReferenceLevelUpto its own step immediately afterpackageMoveCompiledFiles.
gioboa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great idea 💡
naorpeled
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🔥
Description of change
Instead of manually updating peer dependencies version generated via
initcommand, we could pull them from our owndependenciesanddevDependenciesdefined inpackage.json, which would lower maintenance effort on our side (single place to update, consistency in testing environment when bugs are reported).Pull-Request Checklist
masterbranchFixes #00000Summary by CodeRabbit
New Features
Chores