-
-
Notifications
You must be signed in to change notification settings - Fork 19
chore: add warning for mismatched versions during zen generate
#660
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
e22b2de
832616c
971325e
1076be2
846883b
8f807ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,3 +156,47 @@ export function getOutputPath(options: { output?: string }, schemaFile: string) | |
| return path.dirname(schemaFile); | ||
| } | ||
| } | ||
| export async function getZenStackPackages(projectPath: string): Promise<Array<{ pkg: string; version: string | undefined }>> { | ||
| let pkgJson: { | ||
| dependencies: Record<string, unknown>; | ||
| devDependencies: Record<string, unknown>; | ||
| }; | ||
| const resolvedPath = path.resolve(projectPath); | ||
| try { | ||
| pkgJson = ( | ||
| await import(path.join(resolvedPath, 'package.json'), { | ||
| with: { type: 'json' }, | ||
| }) | ||
| ).default; | ||
| } catch { | ||
| return []; | ||
| } | ||
|
|
||
| const packages = Array.from( | ||
| new Set( | ||
| [...Object.keys(pkgJson.dependencies ?? {}), ...Object.keys(pkgJson.devDependencies ?? {})].filter( | ||
| (p) => p.startsWith('@zenstackhq/') || p === 'zenstack', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'zenstack' package name is not used anymore. |
||
| ), | ||
| ), | ||
| ).sort(); | ||
|
|
||
| const result = await Promise.all( | ||
| packages.map(async (pkg) => { | ||
| try { | ||
| const depPkgJson = ( | ||
| await import(`${pkg}/package.json`, { | ||
| with: { type: 'json' }, | ||
| }) | ||
| ).default; | ||
| if (depPkgJson.private) { | ||
| return undefined; | ||
| } | ||
| return { pkg, version: depPkgJson.version as string }; | ||
| } catch { | ||
| return { pkg, version: undefined }; | ||
| } | ||
| }), | ||
| ); | ||
|
|
||
| return result.filter((p) => !!p); | ||
| } | ||
|
Comment on lines
+159
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Find all package.json files and check engines field
echo "=== Checking Node.js engine requirements ==="
fd -t f 'package.json' --max-depth 1 | xargs jq -r '.engines.node // "Not specified"' 2>/dev/null
echo -e "\n=== Checking root package.json for engines ==="
jq '.engines // "No engines field"' package.json 2>/dev/null || echo "package.json not found"
# Check if import attributes (with syntax) are used elsewhere
echo -e "\n=== Searching for import attributes syntax (with keyword) ==="
rg 'import\s*\([^)]*\)\s*with\s*\{' --type ts --type js -g '!node_modules' | head -20
# Also check for assert syntax (older form)
echo -e "\n=== Searching for import assert syntax (older form) ==="
rg 'import\s*\([^)]*\)\s*assert\s*\{' --type ts --type js -g '!node_modules' | head -20Repository: zenstackhq/zenstack-v3 Length of output: 311 🏁 Script executed: #!/bin/bash
# Check the specific file and lines mentioned
echo "=== Checking the actual code in action-utils.ts ==="
cat -n packages/cli/src/actions/action-utils.ts | sed -n '159,202p'Repository: zenstackhq/zenstack-v3 Length of output: 1819 🏁 Script executed: #!/bin/bash
# Check for TypeScript version and compiler options
echo "=== Checking TypeScript config for target ==="
if [ -f tsconfig.json ]; then
jq '.compilerOptions.target' tsconfig.json 2>/dev/null || echo "No target found"
fi
# Look for .nvmrc or similar Node version specifiers
echo -e "\n=== Checking for Node version specifiers ==="
ls -la | grep -E '\.(nvmrc|node-version|tool-versions)' || echo "No Node version file found"
if [ -f .nvmrc ]; then cat .nvmrc; fiRepository: zenstackhq/zenstack-v3 Length of output: 184 Remove import attributes or add explicit Node.js ≥22 requirement. The
Additionally, line 194's 🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ymc9 how should I handle this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai do you know if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
// For project package.json:
const pkgJson = require(path.join(resolvedPath, 'package.json'));
// For dependency package.json:
const depPkgJson = require(`${pkg}/package.json`);Benefits of using
The main change would be wrapping the require calls in try-catch blocks (which you're already doing with the import). This approach avoids the Node ≥22 requirement entirely while keeping the same functionality. 🧠 Learnings used |
||
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.
This currently assumes the "zen" command is run at the root of the project. I think it's more flexible if we call the
findUputility to search upward for the nearest package.json file and then analyze its dependencies, so the logic would work if "zen" is run in a subfolder.If so, the
projectPathis thensearchStartPath.What do you think @sanny-io ?