Skip to content

Commit aad3d45

Browse files
committedApr 11, 2022
Update dependencies, tests...
1 parent fdc7056 commit aad3d45

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed
 

Diff for: ‎lib/grunt/file.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ file.write = function(filepath, contents, options) {
292292
// Read a file, optionally processing its content, then write the output.
293293
// Or read a directory, recursively creating directories, reading files,
294294
// processing content, writing output.
295+
// Handles symlinks by coping them as files or directories.
295296
file.copy = function copy(srcpath, destpath, options) {
296-
if (file.isDir(srcpath)) {
297+
if (file._isSymbolicLink(srcpath)) {
298+
file._copySymbolicLink(srcpath, destpath);
299+
} else if (file.isDir(srcpath)) {
297300
// Copy a directory, recursively.
298301
// Explicitly create new dest directory.
299302
file.mkdir(destpath);
@@ -449,6 +452,24 @@ file.isPathCwd = function() {
449452
}
450453
};
451454

455+
file._isSymbolicLink = function() {
456+
var filepath = path.join.apply(path, arguments);
457+
return fs.lstatSync(filepath).isSymbolicLink();
458+
};
459+
460+
file._copySymbolicLink = function(srcpath, destpath) {
461+
var destdir = path.join(destpath, '..');
462+
var fileBase = path.basename(srcpath);
463+
// Use the correct relative path for the symlink
464+
if (!grunt.file.isPathAbsolute(srcpath)) {
465+
srcpath = path.relative(destdir, srcpath) || '.';
466+
}
467+
file.mkdir(destdir);
468+
var mode = grunt.file.isDir(srcpath) ? 'dir' : 'file';
469+
var destpath = path.join(destpath, fileBase);
470+
return fs.symlinkSync(srcpath, destpath, mode);
471+
};
472+
452473
// Test to see if a filepath is contained within the CWD.
453474
file.isPathInCwd = function() {
454475
var filepath = path.join.apply(path, arguments);

Diff for: ‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"exit": "~0.1.2",
4343
"findup-sync": "~0.3.0",
4444
"glob": "~7.1.6",
45-
"grunt-cli": "~1.4.2",
45+
"grunt-cli": "~1.4.3",
4646
"grunt-known-options": "~2.0.0",
4747
"grunt-legacy-log": "~3.0.0",
4848
"grunt-legacy-util": "~2.0.1",
@@ -56,7 +56,7 @@
5656
"devDependencies": {
5757
"difflet": "~1.0.1",
5858
"eslint-config-grunt": "~1.0.1",
59-
"grunt-contrib-nodeunit": "~3.0.0",
59+
"grunt-contrib-nodeunit": "~4.0.0",
6060
"grunt-contrib-watch": "~1.1.0",
6161
"grunt-eslint": "~18.1.0",
6262
"temporary": "~0.0.4",

Diff for: ‎test/grunt/file_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -893,5 +893,28 @@ exports.file = {
893893
test.ok(grunt.file.isPathInCwd(path.resolve('deep')), 'subdirectory is in cwd');
894894
test.done();
895895
},
896+
'symbolicLinkCopy': function(test) {
897+
test.expect(4);
898+
var srcfile = new Tempdir();
899+
fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(srcfile.path, 'octocat.png'), 'file');
900+
// test symlink copy for files
901+
var destdir = new Tempdir();
902+
grunt.file.copy(path.join(srcfile.path, 'octocat.png'), destdir.path);
903+
test.ok(fs.lstatSync(path.join(srcfile.path, 'octocat.png')).isSymbolicLink());
904+
test.ok(fs.lstatSync(path.join(destdir.path, 'octocat.png')).isSymbolicLink());
905+
906+
// test symlink copy for directories
907+
var srcdir = new Tempdir();
908+
var destdir = new Tempdir();
909+
var fixtures = path.resolve('test/fixtures');
910+
var symlinkSource = path.join(srcdir.path, path.basename(fixtures));
911+
console.log('symlinkSource', symlinkSource);
912+
fs.symlinkSync(fixtures, symlinkSource, 'dir');
913+
914+
grunt.file.copy(symlinkSource, destdir.path);
915+
test.ok(fs.lstatSync(symlinkSource).isSymbolicLink());
916+
test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink());
917+
test.done();
918+
},
896919
}
897920
};

0 commit comments

Comments
 (0)
Please sign in to comment.