question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

gulp.src does not copy subdirs within symlink

See original GitHub issue
$ gulp -v
CLI version 1.2.2
Local version 4.0.0-alpha.2

Directory structure of images and symlink’ed directory (shared-assets):

├── images
│   └── branding -> ../shared-assets/branding/     (this is a symlink)
├── shared-assets
│   ├── branding
│   │   ├── img1.png
│   │   ├── img2.png
│   │   └── dir1
│   │       ├── img3.png
│   │       └── img4.png
gulp.src('..../images/**/*.{.jpg,.png}').pipe(gulp.dest('dist/images'))

Produces:

├── images
│   ├── branding
│   │   ├── img1.png
│   │   └── img2.png
gulp.src('..../images/**/*').pipe(gulp.dest('dist/images'))  // matches all files

Produces:

├── images
│   ├── branding
│   │   ├── img1.png
│   │   └── img2.png
│   └── dir1  (empty dir)

I expected dir1 and its contents to be in the output. To further clarify, I do want gulp to copy the contents (vs copying the symlink) which it does correctly with img1.png, img2.png, just not with subdirs or their contents img3.png, img4.png.

Is this expected behavior? Bug? I don’t feel like it’s a fault of my glob string, since I can use /**/*.{jpg,png} for any number of subdirs of any depth that aren’t symlinked.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
phatedcommented, Aug 26, 2016

followSymlinks turns symbolic links into hard files (reads the contents of the linked file and creates duplicate files in the output, etc). It might be a poor name for what it actually does, but that’s what we have right now. follow does something different, in which it follows symlinks throughout a tree, and isn’t enabled by default in node-glob because it breaks on circular links. Those 2 behaviors are mutually exclusive so we can’t force follow on if followSymlinks is set to true.

It’s a frustrating state of naming but imagine followSymlinks as convertToFile and you’d have { follow: true, convertToFile: true } (notice how they are very different with better naming).

I’m going to close this and chalk it up to a documentation problem (which have multiple issues open), but I’ll open an issue on vinyl-fs to revisit the naming of the followSymlinks option. Thanks for bringing this up!

1reaction
mabarcommented, Aug 11, 2016

There is an option follow, which can help you. gulp.src('..../images/**/*', { follow: true })

But be aware of cyclic links. That kind of mistake maybe cause delete of all files.

Optionally, you can use workaround too

var vfs = require('vinyl-fs');

gulp.task('myTask', [], function() {
  vfs.src'..../images/**/*')
  .pipe(vfs.dest('dist/images'))
)};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp giving error on symlinks in gulp.src() - Stack Overflow
src () uses node-glob, which doesn't crawl symlinks: ** If a "globstar" is alone in a path portion, then it matches zero or...
Read more >
gulp-rsync - npm
Enables files or directories matching the pattern(s) provided to be excluded from the transfer. This is probably most useful when recursive is ......
Read more >
rollup.js
During this step, Rollup will build the module graph and perform tree-shaking, but will not generate any output. On a bundle object, you...
Read more >
Sass to CSS > Gulp! Refreshment for Your Frontend Assets
I do have a project-specific CSS file, but it's missing from here. The problem is that it's not a CSS file at all...
Read more >
Nixpkgs 22.11 manual - NixOS
Nix expressions describe how to build packages from source and are collected in the nixpkgs repository. Also included in the collection are Nix...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found