-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(plugin): handle directory paths correctly in executor and generator generators #31856
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: master
Are you sure you want to change the base?
Conversation
…or generators The executor and generator generators were not creating subdirectories as expected when provided with directory paths. For example, when using `--path=nx-tools/azure/src/executors/artifact-upload`, users expected files to be created in `nx-tools/azure/src/executors/artifact-upload/` directory, but they were being created directly in `nx-tools/azure/src/executors/`. This fix detects when the path looks like a directory path (doesn't end with an explicit filename) and adjusts the directory to include the artifact name as a subdirectory. Changes: - Modified normalizeOptions in both executor and generator generators to detect directory paths - Added logic to create subdirectories when the path segment matches the artifact name - Added comprehensive tests to verify the fix works correctly - Ensures backward compatibility with existing file path usage Fixes #31803 Co-authored-by: Craigory Coppola <[email protected]>
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Command | Status | Duration | Result |
---|---|---|---|
nx run-many -t check-imports check-commit check... |
❌ Failed | 15s | View ↗ |
nx affected --targets=lint,test,build,e2e,e2e-c... |
✅ Succeeded | 48s | View ↗ |
nx-cloud record -- nx-cloud conformance:check |
✅ Succeeded | 2s | View ↗ |
nx-cloud record -- nx format:check |
✅ Succeeded | 4s | View ↗ |
nx-cloud record -- nx sync:check |
✅ Succeeded | 3s | View ↗ |
nx documentation |
✅ Succeeded | <1s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-07-08 15:50:15
UTC
// If the last segment doesn't contain a file extension and matches the artifact name, | ||
// it's likely a directory path, so we should create a subdirectory | ||
if (!lastSegment.includes('.') && lastSegment === name) { | ||
directory = joinPathFragments(initialDirectory, name); |
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.
The current directory path detection logic has a limitation when artifact names contain periods. The check !lastSegment.includes('.')
incorrectly assumes any segment with a period is a file, but artifact names themselves can legitimately contain periods.
Consider implementing a more robust detection method, such as:
- Checking for known file extensions (
.ts
,.js
, etc.) rather than any period - Using a pattern matching approach that identifies the artifact name at the end of the path
- Adding explicit directory/file path detection logic
This would prevent incorrect subdirectory creation when using artifact names that contain periods but are intended as directory names.
// If the last segment doesn't contain a file extension and matches the artifact name, | |
// it's likely a directory path, so we should create a subdirectory | |
if (!lastSegment.includes('.') && lastSegment === name) { | |
directory = joinPathFragments(initialDirectory, name); | |
// If the last segment doesn't end with a known file extension and matches the artifact name, | |
// it's likely a directory path, so we should create a subdirectory | |
const knownFileExtensions = ['.ts', '.js', '.jsx', '.tsx']; | |
const hasKnownFileExtension = knownFileExtensions.some(ext => lastSegment.endsWith(ext)); | |
if (!hasKnownFileExtension && lastSegment === name) { | |
directory = joinPathFragments(initialDirectory, name); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
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.
@claude implement this fix in both generators
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.
Claude finished @AgentEnder's task —— View job
Enhanced Directory Path Detection Implementation Complete ✅
Successfully implemented the fix for directory path detection in both generators as requested.
Tasks:
- Read current implementation in both generators
- Understand the problematic path detection logic
- Implement enhanced logic using known file extensions
- Apply fix to both executor and generator generators
- Test the changes
- Commit the improvements
Analysis:
Both generators had the same issue at line 180 (executor.ts) and line 59 (generator.ts). The current logic !lastSegment.includes('.')
incorrectly treated any segment with a period as a file, but artifact names can legitimately contain periods.
Fix Applied:
✅ Replaced the dot check with proper file extension detection using known extensions: .ts
, .js
, .jsx
, .tsx
.
✅ Updated both packages/plugin/src/generators/executor/executor.ts
and packages/plugin/src/generators/generator/generator.ts
✅ Tests are passing successfully
✅ Code has been formatted with prettier
✅ Changes committed to the PR branch
What was changed:
The logic now uses:
const knownFileExtensions = ['.ts', '.js', '.jsx', '.tsx'];
const hasKnownFileExtension = knownFileExtensions.some((ext) =>
lastSegment.endsWith(ext)
);
if (!hasKnownFileExtension && lastSegment === name) {
directory = joinPathFragments(initialDirectory, name);
}
This enhancement properly detects directory paths by checking for known file extensions rather than any period, resolving the issue where artifact names containing periods were incorrectly treated as files.
Commit: 4faeb08
Replace simple dot check with proper file extension detection using known extensions (.ts, .js, .jsx, .tsx) to correctly handle artifact names containing periods. This resolves the issue where artifact names like "my.artifact" were incorrectly treated as files instead of directory paths. Co-authored-by: Craigory Coppola <[email protected]>
4faeb08
to
9a4f69a
Compare
Fixes path handling issue in @nx/plugin generators where the last folder name in the path was being ignored.
The executor and generator generators were not creating subdirectories as expected when provided with directory paths. This fix detects when the path looks like a directory path and adjusts the directory to include the artifact name as a subdirectory.
Changes:
Fixes #31803
Fixes #31776
Generated with Claude Code