-
Notifications
You must be signed in to change notification settings - Fork 283
LS function fix for single file input #1106
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
Azure Pipelines successfully started running 1 pipeline(s). |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Pull Request Overview
This PR fixes an issue where providing a single file as input to the ls() function returned an empty string. It introduces a two-phase processing approach that first handles files (extracting basenames) and then processes directories, and it updates the array flattening logic along with a minor version bump.
- Fix for single file input in ls() to correctly return file basenames.
- Separation of file and directory handling with dedicated processing logic.
- Introduces a custom flattenArray function for array flattening.
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
node/test/ls.ts | Adds a test to verify that single file paths are correctly handled. |
node/task.ts | Updates the ls() function to handle files separately and replaces Array.prototype.flat with a custom flattenArray function. |
node/package.json | Bumps package version to reflect the updates. |
Files not reviewed (1)
- node/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
node/task.ts:1143
- Consider adding a brief comment above flattenArray to document its purpose and recursive behavior, which can aid in future maintainability.
function flattenArray(arr: any[]): any[] {
while (paths.length > 0) { | ||
const pathEntry = resolve(paths.shift()); |
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.
Using paths.shift() repeatedly in a loop can lead to suboptimal performance for large arrays; consider refactoring to an index-based loop to improve efficiency.
while (paths.length > 0) { | |
const pathEntry = resolve(paths.shift()); | |
for (let i = 0; i < paths.length; i++) { | |
const pathEntry = resolve(paths[i]); |
Copilot uses AI. Check for mistakes.
Explanation of the fix we implemented in the
ls
function for the single file input issue:Issue
ls()
, it was returning an empty string because the relative path calculation was comparing the file path against itself.Fix Details
Key Changes
Benefits
Example
Now correctly adds the file to the archive with its proper name instead of an empty string.
Link to modified canary pipeline with specific file archiving tests.
This pipeline run is from my private organization which is run on archive file task linked locally to modified task-lib code. This includes new tests named
Test archive with specific file zip
for testing the changehttps://dev.azure.com/rishabhmalikOrg/Test%20Project/_build/results?buildId=1040&view=logs&j=1809f88b-43e1-5a25-3102-9dca9646ed63