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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow symlink support for readdirp #5082

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions packages/@ionic/utils-fs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,16 @@ export interface WalkerOptions {
* @return `true` to include file path, otherwise it is excluded
*/
readonly pathFilter?: (p: string) => boolean;

/**
* Follow symlinks during walk.
*
* Additionally, the `IONIC_UTILS_FS_FOLLOW_SYMLINKS` environment variable can
* be used to set this option as `true` or `false`.
*
* @default false
*/
readonly followSymlinks?: boolean;
}

export interface Walker extends stream.Readable {
Expand All @@ -360,14 +370,18 @@ export class Walker extends stream.Readable {

_read() {
const p = this.paths.shift();
const { pathFilter } = this.options;
const { pathFilter, followSymlinks } = this.options;

if (!p) {
this.push(null);
return;
}

fs.lstat(p, (err, stats) => {
const envFollowSymlinks = process.env.IONIC_UTILS_FS_FOLLOW_SYMLINKS &&
process.env.IONIC_UTILS_FS_FOLLOW_SYMLINKS === 'true' ||
process.env.IONIC_UTILS_FS_FOLLOW_SYMLINKS === '1';
const finalPath = (followSymlinks || envFollowSymlinks) ? fs.realpathSync(p) : p;
fs.lstat(finalPath, (err, stats) => {
if (err) {
this.emit('error', err);
return;
Expand Down