serverless/lib/utils/fs/copyDirContentsSync.js
Stephane Seng 5952712085 fix(GITHUB-6525-5172): Rewrite copyDirContentsSyncAllow to call fs-extra::copySync() on the directories instead of calling it on the files to copy individually.
The main motivation behind these changes is to rely on
https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md as
much as possible in order to avoid having to do the
`fullFilePath.replace(srcDir, '')` operation because this operation can be
error-prone.

Doing so fixes the following issues because the user-submitted file paths are
now correctly interpreted by fs-extra, closing both #6525 and #5172.
2019-08-12 23:09:23 +02:00

17 lines
412 B
JavaScript

'use strict';
const fs = require('fs');
const fse = require('./fse');
const isNotSymbolicLink = src => !fs.lstatSync(src).isSymbolicLink();
function copyDirContentsSync(srcDir, destDir, { noLinks = false } = {}) {
const copySyncOptions = {
dereference: true,
filter: noLinks ? isNotSymbolicLink : null,
};
fse.copySync(srcDir, destDir, copySyncOptions);
}
module.exports = copyDirContentsSync;