@ui5/fs
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
@@ -5,4 +5,7 @@ # Changelog | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v3.0.0-beta.2...HEAD). | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v3.0.0-beta.3...HEAD). | ||
<a name="v3.0.0-beta.3"></a> | ||
## [v3.0.0-beta.3] - 2022-11-11 | ||
<a name="v3.0.0-beta.2"></a> | ||
@@ -198,2 +201,3 @@ ## [v3.0.0-beta.2] - 2022-11-07 | ||
[v3.0.0-beta.3]: https://github.com/SAP/ui5-fs/compare/v3.0.0-beta.2...v3.0.0-beta.3 | ||
[v3.0.0-beta.2]: https://github.com/SAP/ui5-fs/compare/v3.0.0-beta.1...v3.0.0-beta.2 | ||
@@ -200,0 +204,0 @@ [v3.0.0-beta.1]: https://github.com/SAP/ui5-fs/compare/v3.0.0-alpha.7...v3.0.0-beta.1 |
@@ -5,3 +5,3 @@ import randomInt from "random-int"; | ||
/** | ||
* Abstract resource locator | ||
* Abstract resource locator implementing the general API for <b>reading</b> resources | ||
* | ||
@@ -18,9 +18,20 @@ * @abstract | ||
* @public | ||
* @param {string} name Name of the reader. Typically used for tracing purposes | ||
*/ | ||
constructor() { | ||
constructor(name) { | ||
if (new.target === AbstractReader) { | ||
throw new TypeError("Class 'AbstractReader' is abstract"); | ||
} | ||
this._name = name; | ||
} | ||
/* | ||
* Returns the name of the reader instance. This can be used for logging/tracing purposes. | ||
* | ||
* @returns {string} Name of the reader | ||
*/ | ||
getName() { | ||
return this._name || `<unnamed ${this.constructor.name} Reader>`; | ||
} | ||
/** | ||
@@ -85,2 +96,3 @@ * Locates resources by matching glob patterns. | ||
async filter(callback) { | ||
console.warn("DEPRECATED CALL TO AbstractReader#filter - THIS FUNCTION WILL BE REMOVED IN THE NEXT RELEASE"); | ||
const {default: Filter} = await import("./readers/Filter.js"); | ||
@@ -94,18 +106,2 @@ return new Filter({ | ||
/** | ||
* Create a [Transformer-Reader]{@link @ui5/fs/readers/Transformer} from the current reader. | ||
* | ||
* @private | ||
* @param {@ui5/fs/readers/Transformer~callback} callback | ||
* Callback to check and eventually transform any resource passed through the reader | ||
* @returns {Promise<@ui5/fs/readers/Transformer>} Promise resolving with transformer instance | ||
*/ | ||
async transform(callback) { | ||
const {default: Transformer} = await import("./readers/Transformer.js"); | ||
return new Transformer({ | ||
reader: this, | ||
callback | ||
}); | ||
} | ||
/** | ||
* Create a [Link-Reader]{@link @ui5/fs/readers/Link} where all requests are prefixed with | ||
@@ -122,2 +118,3 @@ * <code>/resources/<namespace></code>. | ||
async flatten(namespace) { | ||
console.warn("DEPRECATED CALL TO AbstractReader#flatten - THIS FUNCTION WILL BE REMOVED IN THE NEXT RELEASE"); | ||
const {default: Link} = await import("./readers/Link.js"); | ||
@@ -124,0 +121,0 @@ return new Link({ |
import AbstractReader from "./AbstractReader.js"; | ||
/** | ||
* Abstract resource locator | ||
* Abstract resource locator implementing the general API for <b>reading and writing</b> resources | ||
* | ||
@@ -17,10 +17,20 @@ * @abstract | ||
* @public | ||
* @param {string} name Name of the reader/writer. Typically used for tracing purposes | ||
*/ | ||
constructor() { | ||
constructor(name) { | ||
if (new.target === AbstractReaderWriter) { | ||
throw new TypeError("Class 'AbstractReaderWriter' is abstract"); | ||
} | ||
super(); | ||
super(name); | ||
} | ||
/* | ||
* Returns the name of the reader/writer instance. This can be used for logging/tracing purposes. | ||
* | ||
* @returns {string} Name of the reader/writer | ||
*/ | ||
getName() { | ||
return this._name || `<unnamed ${this.constructor.name} Reader/Writer>`; | ||
} | ||
/** | ||
@@ -27,0 +37,0 @@ * Writes the content of a resource to a path. |
@@ -26,4 +26,4 @@ import logger from "@ui5/logger"; | ||
super({virBasePath, project, excludes}); | ||
this._virFiles = {}; // map full of files | ||
this._virDirs = {}; // map full of directories | ||
this._virFiles = Object.create(null); // map full of files | ||
this._virDirs = Object.create(null); // map full of directories | ||
} | ||
@@ -30,0 +30,0 @@ |
@@ -23,3 +23,3 @@ import AbstractReaderWriter from "./AbstractReaderWriter.js"; | ||
constructor({reader, writer, name = ""}) { | ||
super(); | ||
super(name); | ||
this._reader = reader; | ||
@@ -29,3 +29,3 @@ this._writer = writer; | ||
this._combo = new ReaderCollectionPrioritized({ | ||
name: name, | ||
name: `${name} - ReaderCollectionPrioritized`, | ||
readers: [ | ||
@@ -32,0 +32,0 @@ writer, |
@@ -20,4 +20,3 @@ import AbstractReader from "./AbstractReader.js"; | ||
constructor({name, readers}) { | ||
super(); | ||
this._name = name; | ||
super(name); | ||
this._readers = readers; | ||
@@ -24,0 +23,0 @@ } |
@@ -21,4 +21,3 @@ import AbstractReader from "./AbstractReader.js"; | ||
constructor({readers, name}) { | ||
super(); | ||
this._name = name; | ||
super(name); | ||
this._readers = readers; | ||
@@ -41,3 +40,3 @@ } | ||
})).then((result) => { | ||
const files = {}; | ||
const files = Object.create(null); | ||
const resources = []; | ||
@@ -44,0 +43,0 @@ // Prefer files found in preceding resource locators |
@@ -8,3 +8,2 @@ import AbstractReader from "../AbstractReader.js"; | ||
* @class | ||
* @hideconstructor | ||
* @alias @ui5/fs/readers/Filter | ||
@@ -26,4 +25,5 @@ * @extends @ui5/fs/AbstractReader | ||
* | ||
* @public | ||
* @param {object} parameters Parameters | ||
* @param {@ui5/fs/AbstractReader} parameters.reader The resource reader to wrap | ||
* @param {@ui5/fs/AbstractReader} parameters.reader The resource reader or collection to wrap | ||
* @param {@ui5/fs/readers/Filter~callback} parameters.callback | ||
@@ -30,0 +30,0 @@ * Filter function. Will be called for every resource read through this reader. |
@@ -8,7 +8,6 @@ import AbstractReader from "../AbstractReader.js"; | ||
/** | ||
* A reader that allows modification of all resources passed through it. | ||
* A reader that allows removing paths segments from all resources passed through it. | ||
* | ||
* @public | ||
* @class | ||
* @hideconstructor | ||
* @alias @ui5/fs/readers/Link | ||
@@ -21,6 +20,6 @@ * @extends @ui5/fs/AbstractReader | ||
* | ||
* @private | ||
* @public | ||
* @typedef {object} @ui5/fs/readers/Link/PathMapping | ||
* @property {string} linkPath Input path to rewrite | ||
* @property {string} targetPath Path to rewrite to | ||
* @property {string} linkPath Path to match and replace in the requested path or pattern | ||
* @property {string} targetPath Path to use as a replacement in the request for the source reader | ||
*/ | ||
@@ -31,5 +30,5 @@ | ||
* | ||
* @private | ||
* @public | ||
* @param {object} parameters Parameters | ||
* @param {@ui5/fs/AbstractReader} parameters.reader The resource reader to wrap | ||
* @param {@ui5/fs/AbstractReader} parameters.reader The resource reader or collection to wrap | ||
* @param {@ui5/fs/readers/Link/PathMapping} parameters.pathMapping | ||
@@ -36,0 +35,0 @@ */ |
@@ -371,8 +371,8 @@ import stream from "node:stream"; | ||
getPathTree() { | ||
const tree = {}; | ||
const tree = Object.create(null); | ||
let pointer = tree[this._path] = {}; | ||
let pointer = tree[this._path] = Object.create(null); | ||
for (let i = this._collections.length - 1; i >= 0; i--) { | ||
pointer = pointer[this._collections[i]] = {}; | ||
pointer = pointer[this._collections[i]] = Object.create(null); | ||
} | ||
@@ -379,0 +379,0 @@ |
@@ -10,2 +10,4 @@ import path from "node:path"; | ||
import WriterCollection from "./WriterCollection.js"; | ||
import Filter from "./readers/Filter.js"; | ||
import Link from "./readers/Link.js"; | ||
@@ -165,2 +167,55 @@ /** | ||
/** | ||
* Create a [Filter-Reader]{@link @ui5/fs/readers/Filter} with the given reader. | ||
* The provided callback is called for every resource that is retrieved through the | ||
* reader and decides whether the resource shall be passed on or dropped. | ||
* | ||
* @public | ||
* @param {object} parameters | ||
* @param {@ui5/fs/AbstractReader} parameters.reader Single reader or collection of readers | ||
* @param {@ui5/fs/readers/Filter~callback} parameters.callback | ||
* Filter function. Will be called for every resource passed through this reader. | ||
* @returns {@ui5/fs/readers/Filter} Reader instance | ||
*/ | ||
export function createFilterReader(parameters) { | ||
return new Filter(parameters); | ||
} | ||
/** | ||
* Create a [Link-Reader]{@link @ui5/fs/readers/Filter} with the given reader. | ||
* The provided path mapping allows | ||
* | ||
* @public | ||
* @param {object} parameters | ||
* @param {@ui5/fs/AbstractReader} parameters.reader Single reader or collection of readers | ||
* @param {@ui5/fs/readers/Link/PathMapping} parameters.pathMapping | ||
* @returns {@ui5/fs/readers/Link} Reader instance | ||
*/ | ||
export function createLinkReader(parameters) { | ||
return new Link(parameters); | ||
} | ||
/** | ||
* Create a [Link-Reader]{@link @ui5/fs/readers/Link} where all requests are prefixed with | ||
* <code>/resources/<namespace></code>. | ||
* | ||
* This simulates "flat" resource access, which is for example common for projects of type | ||
* "application". | ||
* | ||
* @public | ||
* @param {object} parameters | ||
* @param {@ui5/fs/AbstractReader} parameters.reader Single reader or collection of readers | ||
* @param {string} parameters.namespace Project namespace | ||
* @returns {@ui5/fs/readers/Link} Reader instance | ||
*/ | ||
export function createFlatReader({reader, namespace}) { | ||
return new Link({ | ||
reader: reader, | ||
pathMapping: { | ||
linkPath: `/`, | ||
targetPath: `/resources/${namespace}/` | ||
} | ||
}); | ||
} | ||
/** | ||
* Normalizes virtual glob patterns by prefixing them with | ||
@@ -167,0 +222,0 @@ * a given virtual base directory path |
@@ -32,3 +32,3 @@ const tagNamespaceRegExp = /^[a-z][a-z0-9]+$/; // part before the colon | ||
this._pathTags = tags || {}; | ||
this._pathTags = tags || Object.create(null); | ||
} | ||
@@ -42,3 +42,3 @@ | ||
if (!this._pathTags[resourcePath]) { | ||
this._pathTags[resourcePath] = {}; | ||
this._pathTags[resourcePath] = Object.create(null); | ||
} | ||
@@ -45,0 +45,0 @@ this._pathTags[resourcePath][tag] = value; |
@@ -24,3 +24,3 @@ import logger from "@ui5/logger"; | ||
this._pathCalls = 0; | ||
this._collections = {}; | ||
this._collections = Object.create(null); | ||
summaryTrace.traceStarted(); | ||
@@ -27,0 +27,0 @@ } |
@@ -32,4 +32,3 @@ import AbstractReaderWriter from "./AbstractReaderWriter.js"; | ||
constructor({name, writerMapping}) { | ||
super(); | ||
this._name = name; | ||
super(name); | ||
@@ -36,0 +35,0 @@ if (!writerMapping) { |
{ | ||
"name": "@ui5/fs", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"description": "UI5 Tooling - File System Abstraction", | ||
@@ -26,2 +26,3 @@ "author": { | ||
"./fsInterface": "./lib/fsInterface.js", | ||
"./readers/*": "./lib/readers/*.js", | ||
"./ReaderCollection": "./lib/ReaderCollection.js", | ||
@@ -35,3 +36,3 @@ "./ReaderCollectionPrioritized": "./lib/ReaderCollectionPrioritized.js", | ||
"engines": { | ||
"node": ">= 16.13.2", | ||
"node": "^16.18.0 || >=18.0.0", | ||
"npm": ">= 8" | ||
@@ -125,9 +126,9 @@ }, | ||
"dependencies": { | ||
"@ui5/logger": "^3.0.1-beta.0", | ||
"clone": "^2.1.0", | ||
"@ui5/logger": "^3.0.1-beta.1", | ||
"clone": "^2.1.2", | ||
"escape-string-regexp": "^5.0.0", | ||
"globby": "^13.1.2", | ||
"graceful-fs": "^4.2.9", | ||
"graceful-fs": "^4.2.10", | ||
"make-dir": "^3.1.0", | ||
"micromatch": "^4.0.4", | ||
"micromatch": "^4.0.5", | ||
"minimatch": "^5.1.0", | ||
@@ -140,3 +141,3 @@ "pretty-hrtime": "^1.0.3", | ||
"ava": "^5.0.1", | ||
"chai": "^4.3.4", | ||
"chai": "^4.3.7", | ||
"chai-fs": "^2.0.0", | ||
@@ -147,12 +148,12 @@ "chokidar-cli": "^3.0.0", | ||
"docdash": "^1.2.0", | ||
"eslint": "^8.26.0", | ||
"eslint": "^8.27.0", | ||
"eslint-config-google": "^0.14.0", | ||
"eslint-plugin-ava": "^13.2.0", | ||
"eslint-plugin-jsdoc": "^37.6.3", | ||
"eslint-plugin-jsdoc": "^37.9.7", | ||
"esmock": "^2.0.7", | ||
"jsdoc": "^3.6.7", | ||
"jsdoc": "^3.6.11", | ||
"nyc": "^15.1.0", | ||
"open-cli": "^7.1.0", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^14.0.1", | ||
"sinon": "^14.0.2", | ||
"tap-nyan": "^1.1.0", | ||
@@ -159,0 +160,0 @@ "tap-xunit": "^2.4.1" |
124899
26
2678
Updated@ui5/logger@^3.0.1-beta.1
Updatedclone@^2.1.2
Updatedgraceful-fs@^4.2.10
Updatedmicromatch@^4.0.5