Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, tests... #1740

Merged
merged 4 commits into from Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [10, 12, 14]
node: [12, 14, 16]
os: [ubuntu-latest, windows-latest]

steps:
Expand Down
27 changes: 26 additions & 1 deletion lib/grunt/file.js
Expand Up @@ -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);
Expand Down Expand Up @@ -449,6 +452,28 @@ 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);
if (fs.existsSync(destpath)) {
// skip symlink if file already exists
return;
}
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);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions test/grunt/file_test.js
Expand Up @@ -893,5 +893,27 @@ 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));
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();
},
}
};