mem-fs-editor
Advanced tools
Comparing version 9.5.0 to 9.6.0
@@ -19,26 +19,30 @@ 'use strict'; | ||
options = options || {}; | ||
const fromGlob = util.globify(from); | ||
let diskFiles = []; | ||
let files = []; | ||
if (options.noGlob) { | ||
const fromFiles = Array.isArray(fromGlob) ? fromGlob : [fromGlob]; | ||
diskFiles = fromFiles.filter((filepath) => fs.existsSync(filepath)); | ||
const fromFiles = Array.isArray(from) ? from : [from]; | ||
files = fromFiles.filter( | ||
(filepath) => this.store.existsInMemory(filepath) || fs.existsSync(filepath) | ||
); | ||
} else { | ||
const fromGlob = util.globify(from); | ||
const globOptions = { ...options.globOptions, nodir: true }; | ||
diskFiles = globby.sync(fromGlob, globOptions).map((file) => path.resolve(file)); | ||
const diskFiles = globby | ||
.sync(fromGlob, globOptions) | ||
.map((file) => path.resolve(file)); | ||
const storeFiles = []; | ||
this.store.each((file) => { | ||
// The store may have a glob path and when we try to copy it will fail because not real file | ||
if ( | ||
!diskFiles.includes(file.path) && | ||
!globby.hasMagic(normalize(file.path)) && | ||
multimatch([file.path], fromGlob).length !== 0 | ||
) { | ||
storeFiles.push(file.path); | ||
} | ||
}); | ||
files = diskFiles.concat(storeFiles); | ||
} | ||
const storeFiles = []; | ||
this.store.each((file) => { | ||
// The store may have a glob path and when we try to copy it will fail because not real file | ||
if ( | ||
!globby.hasMagic(normalize(file.path)) && | ||
multimatch([file.path], fromGlob).length !== 0 && | ||
!diskFiles.includes(file.path) | ||
) { | ||
storeFiles.push(file.path); | ||
} | ||
}); | ||
const files = diskFiles.concat(storeFiles); | ||
let generateDestination = () => to; | ||
@@ -56,3 +60,3 @@ if ( | ||
const processDestinationPath = options.processDestinationPath || ((path) => path); | ||
const root = util.getCommonPath(from); | ||
const root = options.fromBasePath || util.getCommonPath(from); | ||
generateDestination = (filepath) => { | ||
@@ -59,0 +63,0 @@ const toFile = path.relative(root, filepath); |
{ | ||
"name": "mem-fs-editor", | ||
"version": "9.5.0", | ||
"version": "9.6.0", | ||
"description": "File edition helpers working on top of mem-fs", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -78,3 +78,4 @@ # mem-fs-editor | ||
Copy a file from the `from` path to the `to` path. | ||
Copy file(s) from the `from` path to the `to` path. | ||
When passing array, you should pass `options.fromBasePath` to be used to calculate the `to` relative path. The common directory will be detected and used as `fromBasePath` otherwise. | ||
@@ -81,0 +82,0 @@ Optionally, pass an `options.process` function (`process(contents)`) returning a string or a buffer who'll become the new file content. The process function will take a single contents argument who is the copied file contents as a `Buffer`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31176
684
156