Skip to content

Commit

Permalink
[INTERNAL] FS Adapter: Stop passing byGlob options directly to globby
Browse files Browse the repository at this point in the history
Currently the only possible option should be "nodir".

This resolves possible inconsistencies when calling FileSystem and
Memory adapters with identical options containing more than "nodir".
Before, FS passed options to the glob module as a whole while Memory
only passed certain options.

This will also make it easier to upgrade to globby 8.x.
  • Loading branch information
RandomByte committed Jan 9, 2019
1 parent e12cd88 commit c92a3b3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 66 deletions.
5 changes: 3 additions & 2 deletions lib/adapters/AbstractAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class AbstractAdapter extends AbstractReaderWriter {
* @private
* @param {string|Array} virPattern GLOB pattern as string or an array of
* glob patterns for virtual directory structure
* @param {Object} options GLOB options
* @param {Object} [options={}] GLOB options
* @param {boolean} [options.nodir=true] Do not match directories
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/
_byGlob(virPattern, options, trace) {
_byGlob(virPattern, options = {nodir: true}, trace) {
if (!(virPattern instanceof Array)) {
virPattern = [virPattern];
}
Expand Down
16 changes: 8 additions & 8 deletions lib/adapters/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const log = require("@ui5/logger").getLogger("resources:adapters:FileSystem");
const path = require("path");
const fs = require("graceful-fs");
const glob = require("globby");
const defaults = require("defaults");
const clone = require("clone");
const makeDir = require("make-dir");
const Resource = require("../Resource");
const AbstractAdapter = require("./AbstractAdapter");
Expand Down Expand Up @@ -33,16 +31,18 @@ class FileSystem extends AbstractAdapter {
*
* @private
* @param {Array} patterns Array of GLOB patterns
* @param {Object} [options] GLOB options
* @param {Object} [options={}] GLOB options
* @param {boolean} [options.nodir=true] Do not match directories
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/
_runGlob(patterns, options, trace) {
_runGlob(patterns, options = {nodir: true}, trace) {
return new Promise((resolve, reject) => {
const opt = defaults(clone(options), { // Clone needed to prevent side effects
cwd: this._fsBasePath, // (todo: maybe make this a module itself)
dot: true
});
const opt = {
cwd: this._fsBasePath,
dot: true,
nodir: options.nodir
};

trace.globCall();
glob(patterns, opt).then((matches) => {
Expand Down
5 changes: 3 additions & 2 deletions lib/adapters/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ class Memory extends AbstractAdapter {
*
* @private
* @param {Array} patterns array of GLOB patterns
* @param {Object} [options] GLOB options
* @param {Object} [options={}] GLOB options
* @param {boolean} [options.nodir=true] Do not match directories
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/
_runGlob(patterns, options, trace) {
_runGlob(patterns, options = {nodir: true}, trace) {
if (patterns[0] === "" && !options.nodir) { // Match virtual root directory
return Promise.resolve([
new Resource({
Expand Down
67 changes: 14 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
"dependencies": {
"@ui5/logger": "^0.2.2",
"clone": "^2.1.0",
"defaults": "^1.0.3",
"globby": "^7.1.1",
"graceful-fs": "^4.1.15",
"make-dir": "^1.1.0",
Expand Down

0 comments on commit c92a3b3

Please sign in to comment.