Skip to content

Commit 3eda6ae

Browse files
authoredApr 11, 2022
Merge pull request #1740 from gruntjs/update-deps-22-10
Update dependencies, tests...
2 parents fdc7056 + 47d32de commit 3eda6ae

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed
 

‎.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
node: [10, 12, 14]
16+
node: [12, 14, 16]
1717
os: [ubuntu-latest, windows-latest]
1818

1919
steps:

‎lib/grunt/file.js

+26-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,28 @@ 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+
if (fs.existsSync(destpath)) {
471+
// skip symlink if file already exists
472+
return;
473+
}
474+
return fs.symlinkSync(srcpath, destpath, mode);
475+
};
476+
452477
// Test to see if a filepath is contained within the CWD.
453478
file.isPathInCwd = function() {
454479
var filepath = path.join.apply(path, arguments);

‎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",

‎test/grunt/file_test.js

+22
Original file line numberDiff line numberDiff line change
@@ -893,5 +893,27 @@ 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+
fs.symlinkSync(fixtures, symlinkSource, 'dir');
912+
913+
grunt.file.copy(symlinkSource, destdir.path);
914+
test.ok(fs.lstatSync(symlinkSource).isSymbolicLink());
915+
test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink());
916+
test.done();
917+
},
896918
}
897919
};

0 commit comments

Comments
 (0)
Please sign in to comment.