@ui5/fs
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -5,4 +5,10 @@ # Changelog | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v3.0.0...HEAD). | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v3.0.1...HEAD). | ||
<a name="v3.0.1"></a> | ||
## [v3.0.1] - 2023-02-16 | ||
### Dependency Updates | ||
- Bump minimatch from 6.1.8 to 6.2.0 [`20e9311`](https://github.com/SAP/ui5-fs/commit/20e931149ce87d374e607f0f4e4357ae0abe3f97) | ||
<a name="v3.0.0"></a> | ||
@@ -155,2 +161,3 @@ ## [v3.0.0] - 2023-02-09 | ||
- **AbstractAdapter:** Fix normalization of globstar [`6d484e8`](https://github.com/SAP/ui5-fs/commit/6d484e847b62aa0829641f25a76dcc89b0840d44) | ||
[v3.0.1]: https://github.com/SAP/ui5-fs/compare/v3.0.0...v3.0.1 | ||
[v3.0.0]: https://github.com/SAP/ui5-fs/compare/v2.0.6...v3.0.0 | ||
@@ -157,0 +164,0 @@ [v2.0.6]: https://github.com/SAP/ui5-fs/compare/v2.0.5...v2.0.6 |
@@ -63,3 +63,3 @@ import path from "node:path/posix"; | ||
*/ | ||
_byGlob(virPattern, options = {nodir: true}, trace) { | ||
async _byGlob(virPattern, options = {nodir: true}, trace) { | ||
const excludes = this._excludesNegated; | ||
@@ -73,32 +73,30 @@ | ||
virPattern = Array.prototype.concat.apply(virPattern, excludes); | ||
let patterns = virPattern.map(this._normalizePattern, this); | ||
patterns = Array.prototype.concat.apply([], patterns); | ||
if (patterns.length === 0) { | ||
return []; | ||
} | ||
return Promise.all(virPattern.map(this._normalizePattern, this)).then((patterns) => { | ||
patterns = Array.prototype.concat.apply([], patterns); | ||
if (patterns.length === 0) { | ||
return []; | ||
} | ||
if (!options.nodir) { | ||
for (let i = patterns.length - 1; i >= 0; i--) { | ||
const idx = this._virBaseDir.indexOf(patterns[i]); | ||
if (patterns[i] && idx !== -1 && idx < this._virBaseDir.length) { | ||
const subPath = patterns[i]; | ||
return Promise.resolve([ | ||
this._createResource({ | ||
statInfo: { // TODO: make closer to fs stat info | ||
isDirectory: function() { | ||
return true; | ||
} | ||
}, | ||
source: { | ||
adapter: "Abstract" | ||
}, | ||
path: subPath | ||
}) | ||
]); | ||
} | ||
if (!options.nodir) { | ||
for (let i = patterns.length - 1; i >= 0; i--) { | ||
const idx = this._virBaseDir.indexOf(patterns[i]); | ||
if (patterns[i] && idx !== -1 && idx < this._virBaseDir.length) { | ||
const subPath = patterns[i]; | ||
return [ | ||
this._createResource({ | ||
statInfo: { // TODO: make closer to fs stat info | ||
isDirectory: function() { | ||
return true; | ||
} | ||
}, | ||
source: { | ||
adapter: "Abstract" | ||
}, | ||
path: subPath | ||
}) | ||
]; | ||
} | ||
} | ||
return this._runGlob(patterns, options, trace); | ||
}); | ||
} | ||
return await this._runGlob(patterns, options, trace); | ||
} | ||
@@ -134,72 +132,70 @@ | ||
* @param {string} virPattern glob pattern for virtual directory structure | ||
* @returns {Promise<string[]>} Promise resolving to list of normalized glob patterns | ||
* @returns {string[]} A list of normalized glob patterns | ||
*/ | ||
_normalizePattern(virPattern) { | ||
return Promise.resolve().then(() => { | ||
const that = this; | ||
const mm = new minimatch.Minimatch(virPattern); | ||
const that = this; | ||
const mm = new minimatch.Minimatch(virPattern); | ||
const basePathParts = this._virBaseDir.split("/"); | ||
const basePathParts = this._virBaseDir.split("/"); | ||
function matchSubset(subset) { | ||
let i; | ||
for (i = 0; i < basePathParts.length; i++) { | ||
const globPart = subset[i]; | ||
if (globPart === undefined) { | ||
log.verbose("Ran out of glob parts to match (this should not happen):"); | ||
if (that._project) { // project is optional | ||
log.verbose(`Project: ${that._project.getName()}`); | ||
} | ||
log.verbose(`Virtual base path: ${that._virBaseDir}`); | ||
log.verbose(`Pattern to match: ${virPattern}`); | ||
log.verbose(`Current subset (tried index ${i}):`); | ||
log.verbose(subset); | ||
return {idx: i, virtualMatch: true}; | ||
function matchSubset(subset) { | ||
let i; | ||
for (i = 0; i < basePathParts.length; i++) { | ||
const globPart = subset[i]; | ||
if (globPart === undefined) { | ||
log.verbose("Ran out of glob parts to match (this should not happen):"); | ||
if (that._project) { // project is optional | ||
log.verbose(`Project: ${that._project.getName()}`); | ||
} | ||
const basePathPart = basePathParts[i]; | ||
if (typeof globPart === "string") { | ||
if (globPart !== basePathPart) { | ||
return null; | ||
} else { | ||
continue; | ||
} | ||
} else if (globPart === minimatch.GLOBSTAR) { | ||
return {idx: i}; | ||
} else { // Regex | ||
if (!globPart.test(basePathPart)) { | ||
return null; | ||
} else { | ||
continue; | ||
} | ||
log.verbose(`Virtual base path: ${that._virBaseDir}`); | ||
log.verbose(`Pattern to match: ${virPattern}`); | ||
log.verbose(`Current subset (tried index ${i}):`); | ||
log.verbose(subset); | ||
return {idx: i, virtualMatch: true}; | ||
} | ||
const basePathPart = basePathParts[i]; | ||
if (typeof globPart === "string") { | ||
if (globPart !== basePathPart) { | ||
return null; | ||
} else { | ||
continue; | ||
} | ||
} else if (globPart === minimatch.GLOBSTAR) { | ||
return {idx: i}; | ||
} else { // Regex | ||
if (!globPart.test(basePathPart)) { | ||
return null; | ||
} else { | ||
continue; | ||
} | ||
} | ||
if (subset.length === basePathParts.length) { | ||
return {rootMatch: true}; | ||
} | ||
return {idx: i}; | ||
} | ||
if (subset.length === basePathParts.length) { | ||
return {rootMatch: true}; | ||
} | ||
return {idx: i}; | ||
} | ||
const resultGlobs = []; | ||
for (let i = 0; i < mm.set.length; i++) { | ||
const match = matchSubset(mm.set[i]); | ||
if (match) { | ||
let resultPattern; | ||
if (match.virtualMatch) { | ||
resultPattern = basePathParts.slice(0, match.idx).join("/"); | ||
} else if (match.rootMatch) { // matched one up | ||
resultPattern = ""; // root "/" | ||
} else { // matched at some part of the glob | ||
resultPattern = mm.globParts[i].slice(match.idx).join("/"); | ||
if (resultPattern.startsWith("/")) { | ||
resultPattern = resultPattern.substr(1); | ||
} | ||
const resultGlobs = []; | ||
for (let i = 0; i < mm.set.length; i++) { | ||
const match = matchSubset(mm.set[i]); | ||
if (match) { | ||
let resultPattern; | ||
if (match.virtualMatch) { | ||
resultPattern = basePathParts.slice(0, match.idx).join("/"); | ||
} else if (match.rootMatch) { // matched one up | ||
resultPattern = ""; // root "/" | ||
} else { // matched at some part of the glob | ||
resultPattern = mm.globParts[i].slice(match.idx).join("/"); | ||
if (resultPattern.startsWith("/")) { | ||
resultPattern = resultPattern.substr(1); | ||
} | ||
if (mm.negate) { | ||
resultPattern = "!" + resultPattern; | ||
} | ||
resultGlobs.push(resultPattern); | ||
} | ||
if (mm.negate) { | ||
resultPattern = "!" + resultPattern; | ||
} | ||
resultGlobs.push(resultPattern); | ||
} | ||
return resultGlobs; | ||
}); | ||
} | ||
return resultGlobs; | ||
} | ||
@@ -206,0 +202,0 @@ |
{ | ||
"name": "@ui5/fs", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "UI5 Tooling - File System Abstraction", | ||
@@ -129,3 +129,3 @@ "author": { | ||
"micromatch": "^4.0.5", | ||
"minimatch": "^6.1.6", | ||
"minimatch": "^6.2.0", | ||
"pretty-hrtime": "^1.0.3", | ||
@@ -143,8 +143,8 @@ "random-int": "^3.0.0" | ||
"docdash": "^2.0.1", | ||
"eslint": "^8.33.0", | ||
"eslint": "^8.34.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-plugin-ava": "^14.0.0", | ||
"eslint-plugin-jsdoc": "^39.8.0", | ||
"eslint-plugin-jsdoc": "^40.0.0", | ||
"esmock": "^2.1.0", | ||
"jsdoc": "^4.0.0", | ||
"jsdoc": "^4.0.1", | ||
"nyc": "^15.1.0", | ||
@@ -151,0 +151,0 @@ "open-cli": "^7.1.0", |
133784
2901
Updatedminimatch@^6.2.0