Skip to content
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

picklist:unrestrict handle every objects paths #137

Merged
merged 2 commits into from
Jan 4, 2024

Conversation

nabondance
Copy link
Contributor

Proposal to fix the issue #134

@FabienTaillon
Copy link
Member

Maybe the "official" way would be to parse sfdx-project.json and read the different path under packageDirectories to find all possible project paths.
Would that work for you ?
I need to have a look but maybe there is something doing that in SfProjectJson from @salesforce/core.

@nabondance
Copy link
Contributor Author

Maybe the "official" way would be to parse sfdx-project.json and read the different path under packageDirectories to find all possible project paths. Would that work for you ? I need to have a look but maybe there is something doing that in SfProjectJson from @salesforce/core.

indeed it can be done this way too, it should solve the issue

@nabondance
Copy link
Contributor Author

I thought about it some more and that's my outputs:

  • using the sfdx-project to check only packages paths is great to avoid finding unwanted objects paths
  • even with a known package path (/my-package for exemple), the objects folder can be anywhere in it:
    • /my-package/main/objects
    • /my-package/force-app/main/objects
    • /my-package/objects
    • /my-package/anything/somethingelse/objects

The solution can be to use both:

  • find a way to get all packages paths
  • inside theses paths, search for objects folders

unrestrict.ts

// Get packages paths
const packagesPaths: string[] = getPackagesPaths(); // command to find/develop
// Get all the objects folder paths inside the package ones
for (const recType of findObjectsFolders(packagesPaths, EXCLUDED_DIRS)) {
  objectsFolderPaths.push(recType);
}

sfdxProjectFolder.ts

export function findObjectsFolders(startPaths: string[], excludedDirs: string[] = []): string[] {
  const result: string[] = [];
  for (const iPath of startPaths) { // the new loop on the new startPaths parameter
    const filesAndDirs = fs.readdirSync(startPath);

    for (const fileOrDir of filesAndDirs) {
      const fullPath = path.join(startPath, fileOrDir);

      if (fs.statSync(fullPath).isDirectory()) {
        // If the directory is in the exclusion list, skip it.
        if (excludedDirs.includes(fileOrDir)) {
          continue;
        }

        if (fileOrDir === 'objects') {
          result.push(fullPath);
        }

        result.push(...findObjectsFolders(fullPath, excludedDirs));
      }
    }
  }

  return result;
}

@nabondance
Copy link
Contributor Author

I updated the PR to add the use of SfProject

export async function getPackagesPaths(): Promise<string[]> {
  try {
    const project: SfProject = await SfProject.resolve();
    const packageDirectories: NamedPackageDir[] = project.getPackageDirectories();

    return packageDirectories.map((dir) => dir.path);
  } catch (error) {
    /* eslint-disable no-console */
    console.error('Error retrieving package paths: ', error);
    return [];
  }
}

@FabienTaillon FabienTaillon merged commit 121ab31 into texei:master Jan 4, 2024
@FabienTaillon
Copy link
Member

Thank you !

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.

2 participants