From aad3d4521c3098fb255fb2db8f2e1d691a033665 Mon Sep 17 00:00:00 2001 From: Vlad Filippov Date: Sun, 10 Apr 2022 23:16:06 -0400 Subject: [PATCH 1/4] Update dependencies, tests... --- lib/grunt/file.js | 23 ++++++++++++++++++++++- package.json | 4 ++-- test/grunt/file_test.js | 23 +++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/grunt/file.js b/lib/grunt/file.js index 7e0e2fb7b..21f4ef29d 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -292,8 +292,11 @@ file.write = function(filepath, contents, options) { // Read a file, optionally processing its content, then write the output. // Or read a directory, recursively creating directories, reading files, // processing content, writing output. +// Handles symlinks by coping them as files or directories. file.copy = function copy(srcpath, destpath, options) { - if (file.isDir(srcpath)) { + if (file._isSymbolicLink(srcpath)) { + file._copySymbolicLink(srcpath, destpath); + } else if (file.isDir(srcpath)) { // Copy a directory, recursively. // Explicitly create new dest directory. file.mkdir(destpath); @@ -449,6 +452,24 @@ file.isPathCwd = function() { } }; +file._isSymbolicLink = function() { + var filepath = path.join.apply(path, arguments); + return fs.lstatSync(filepath).isSymbolicLink(); +}; + +file._copySymbolicLink = function(srcpath, destpath) { + var destdir = path.join(destpath, '..'); + var fileBase = path.basename(srcpath); + // Use the correct relative path for the symlink + if (!grunt.file.isPathAbsolute(srcpath)) { + srcpath = path.relative(destdir, srcpath) || '.'; + } + file.mkdir(destdir); + var mode = grunt.file.isDir(srcpath) ? 'dir' : 'file'; + var destpath = path.join(destpath, fileBase); + return fs.symlinkSync(srcpath, destpath, mode); +}; + // Test to see if a filepath is contained within the CWD. file.isPathInCwd = function() { var filepath = path.join.apply(path, arguments); diff --git a/package.json b/package.json index 444f03d96..167372f8b 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "exit": "~0.1.2", "findup-sync": "~0.3.0", "glob": "~7.1.6", - "grunt-cli": "~1.4.2", + "grunt-cli": "~1.4.3", "grunt-known-options": "~2.0.0", "grunt-legacy-log": "~3.0.0", "grunt-legacy-util": "~2.0.1", @@ -56,7 +56,7 @@ "devDependencies": { "difflet": "~1.0.1", "eslint-config-grunt": "~1.0.1", - "grunt-contrib-nodeunit": "~3.0.0", + "grunt-contrib-nodeunit": "~4.0.0", "grunt-contrib-watch": "~1.1.0", "grunt-eslint": "~18.1.0", "temporary": "~0.0.4", diff --git a/test/grunt/file_test.js b/test/grunt/file_test.js index b192cad9a..20c4aed44 100644 --- a/test/grunt/file_test.js +++ b/test/grunt/file_test.js @@ -893,5 +893,28 @@ exports.file = { test.ok(grunt.file.isPathInCwd(path.resolve('deep')), 'subdirectory is in cwd'); test.done(); }, + 'symbolicLinkCopy': function(test) { + test.expect(4); + var srcfile = new Tempdir(); + fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(srcfile.path, 'octocat.png'), 'file'); + // test symlink copy for files + var destdir = new Tempdir(); + grunt.file.copy(path.join(srcfile.path, 'octocat.png'), destdir.path); + test.ok(fs.lstatSync(path.join(srcfile.path, 'octocat.png')).isSymbolicLink()); + test.ok(fs.lstatSync(path.join(destdir.path, 'octocat.png')).isSymbolicLink()); + + // test symlink copy for directories + var srcdir = new Tempdir(); + var destdir = new Tempdir(); + var fixtures = path.resolve('test/fixtures'); + var symlinkSource = path.join(srcdir.path, path.basename(fixtures)); + console.log('symlinkSource', symlinkSource); + fs.symlinkSync(fixtures, symlinkSource, 'dir'); + + grunt.file.copy(symlinkSource, destdir.path); + test.ok(fs.lstatSync(symlinkSource).isSymbolicLink()); + test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink()); + test.done(); + }, } }; From 04b960e27151869312dd7e5686a7d39baa85ed0d Mon Sep 17 00:00:00 2001 From: Vlad Filippov Date: Sun, 10 Apr 2022 23:16:46 -0400 Subject: [PATCH 2/4] Remove console log --- test/grunt/file_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/grunt/file_test.js b/test/grunt/file_test.js index 20c4aed44..b24870c7b 100644 --- a/test/grunt/file_test.js +++ b/test/grunt/file_test.js @@ -908,7 +908,6 @@ exports.file = { var destdir = new Tempdir(); var fixtures = path.resolve('test/fixtures'); var symlinkSource = path.join(srcdir.path, path.basename(fixtures)); - console.log('symlinkSource', symlinkSource); fs.symlinkSync(fixtures, symlinkSource, 'dir'); grunt.file.copy(symlinkSource, destdir.path); From 2e9161caa25c430fa8423cc14f5b67733c402bcd Mon Sep 17 00:00:00 2001 From: Vlad Filippov Date: Sun, 10 Apr 2022 23:19:28 -0400 Subject: [PATCH 3/4] More updates --- lib/grunt/file.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/grunt/file.js b/lib/grunt/file.js index 21f4ef29d..ce268d041 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -467,6 +467,10 @@ file._copySymbolicLink = function(srcpath, destpath) { file.mkdir(destdir); var mode = grunt.file.isDir(srcpath) ? 'dir' : 'file'; var destpath = path.join(destpath, fileBase); + if (fs.existsSync(destpath)) { + // skip symlink if file already exists + return; + } return fs.symlinkSync(srcpath, destpath, mode); }; From 47d32de552e9d8445f2b50f2dcf764510e84d24b Mon Sep 17 00:00:00 2001 From: Vlad Filippov Date: Sun, 10 Apr 2022 23:22:39 -0400 Subject: [PATCH 4/4] Update testing matrix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a90a190b5..821633742 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - node: [10, 12, 14] + node: [12, 14, 16] os: [ubuntu-latest, windows-latest] steps: