Skip to content

fix: sort project files alphabetically on pull to preserve sidebar order - #181

Open
aronsysdone wants to merge 1 commit into
leonhartX:masterfrom
aronsysdone:patch-1
Open

fix: sort project files alphabetically on pull to preserve sidebar order#181
aronsysdone wants to merge 1 commit into
leonhartX:masterfrom
aronsysdone:patch-1

Conversation

@aronsysdone

Copy link
Copy Markdown

Summary

Fixes an issue where pulling modified files from GitHub/SCM alters file ordering in Google Apps Script projects.

Cause

During a pull, modified files are concatenated ahead of unchanged files (updatedFiles.concat(remainedFiles)), placing modified items at the top of the project payload array.

Because Google Apps Script uses this internal array sequence for both IDE sidebar rendering and top-level evaluation order, scrambling the array index is not just cosmetic—it can cause runtime errors (such as ReferenceError when global scope code depends on files expected to load first).

Fix

Sorts the concatenated files array alphabetically before sending the PUT request, keeping the appsscript manifest at index 0 to ensure deterministic execution order and consistent sidebar layout.

const files = updatedFiles.concat(remainedFiles);

// Sort files alphabetically while keeping 'appsscript' manifest at index 0
files.sort((a, b) => {
  if (a.name === 'appsscript') return -1;
  if (b.name === 'appsscript') return 1;
  return a.name.localeCompare(b.name);
});

Fixes an issue where pulling modified files from GitHub/SCM alters the file ordering in Google Apps Script.

During a pull, modified files are concatenated ahead of unchanged files (`updatedFiles.concat(remainedFiles)`), placing modified items at the top of the array payload. Because Google Apps Script renders the IDE sidebar strictly based on array index position in the manifest, updated files were permanently pushed to the top of the sidebar.

This change sorts the concatenated `files` array alphabetically before sending the PUT request, keeping the `appsscript` manifest at index 0.
@aronsysdone

Copy link
Copy Markdown
Author

Note for the maintainer: The CircleCI build failure is purely infrastructural and completely unrelated to the changes in this patch.

The build failed at the initial environment setup step during git clone (Permission denied (publickey)) because CircleCI restricts SSH deploy key access on PRs submitted from external forks. No code checks, linting, or tests were executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant