11'use strict' ;
22
3- var path = require ( 'path' ) ;
4-
5- var fs = require ( 'graceful-fs' ) ;
63var pumpify = require ( 'pumpify' ) ;
7- var through = require ( 'through2' ) ;
84var lead = require ( 'lead' ) ;
95var mkdirpStream = require ( 'fs-mkdirp-stream' ) ;
106var createResolver = require ( 'resolve-options' ) ;
117
12- var fo = require ( '../file-operations' ) ;
13-
148var config = require ( './options' ) ;
159var prepare = require ( './prepare' ) ;
10+ var linkFile = require ( './link-file' ) ;
1611
1712var folderConfig = {
1813 outFolder : {
@@ -24,59 +19,6 @@ function symlink(outFolder, opt) {
2419 var optResolver = createResolver ( config , opt ) ;
2520 var folderResolver = createResolver ( folderConfig , { outFolder : outFolder } ) ;
2621
27- function linkFile ( file , enc , callback ) {
28- // Fetch the path as it was before prepare.dest()
29- var srcPath = file . history [ file . history . length - 2 ] ;
30-
31- var isDirectory = file . isDirectory ( ) ;
32-
33- // This option provides a way to create a Junction instead of a
34- // Directory symlink on Windows. This comes with the following caveats:
35- // * NTFS Junctions cannot be relative.
36- // * NTFS Junctions MUST be directories.
37- // * NTFS Junctions must be on the same file system.
38- // * Most products CANNOT detect a directory is a Junction:
39- // This has the side effect of possibly having a whole directory
40- // deleted when a product is deleting the Junction directory.
41- // For example, JetBrains product lines will delete the entire
42- // contents of the TARGET directory because the product does not
43- // realize it's a symlink as the JVM and Node return false for isSymlink.
44- var useJunctions = optResolver . resolve ( 'useJunctions' , file ) ;
45-
46- var symDirType = useJunctions ? 'junction' : 'dir' ;
47- var symType = isDirectory ? symDirType : 'file' ;
48- var isRelative = optResolver . resolve ( 'relative' , file ) ;
49-
50- // This is done inside prepareWrite to use the adjusted file.base property
51- if ( isRelative && ! useJunctions ) {
52- srcPath = path . relative ( file . base , srcPath ) ;
53- }
54-
55- // Because fs.symlink does not allow atomic overwrite option with flags, we
56- // delete and recreate if the link already exists and overwrite is true.
57- var flag = optResolver . resolve ( 'flag' , file ) ;
58- if ( flag === 'w' ) {
59- // TODO What happens when we call unlink with windows junctions?
60- fs . unlink ( file . path , onUnlink ) ;
61- } else {
62- fs . symlink ( srcPath , file . path , symType , onSymlink ) ;
63- }
64-
65- function onUnlink ( unlinkErr ) {
66- if ( fo . isFatalUnlinkError ( unlinkErr ) ) {
67- return callback ( unlinkErr ) ;
68- }
69- fs . symlink ( srcPath , file . path , symType , onSymlink ) ;
70- }
71-
72- function onSymlink ( symlinkErr ) {
73- if ( fo . isFatalOverwriteError ( symlinkErr , flag ) ) {
74- return callback ( symlinkErr ) ;
75- }
76- callback ( null , file ) ;
77- }
78- }
79-
8022 function dirpath ( file , callback ) {
8123 var dirMode = optResolver . resolve ( 'dirMode' , file ) ;
8224
@@ -86,7 +28,7 @@ function symlink(outFolder, opt) {
8628 var stream = pumpify . obj (
8729 prepare ( folderResolver , optResolver ) ,
8830 mkdirpStream . obj ( dirpath ) ,
89- through . obj ( linkFile )
31+ linkFile ( optResolver )
9032 ) ;
9133
9234 // Sink the stream to start flowing
0 commit comments