Socket
Socket
Sign inDemoInstall

@ui5/fs

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ui5/fs - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

42

CHANGELOG.md

@@ -5,23 +5,24 @@ # Changelog

A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v0.2.0...HEAD).
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-fs/compare/v1.0.0...HEAD).
<a name="v1.0.0"></a>
## [v1.0.0] - 2019-01-10
### Breaking Changes
- **index.js export:** Remove top-level access to adapters [`f1f7831`](https://github.com/SAP/ui5-fs/commit/f1f7831ae9e908731a57f9d67952a61431c69d21)
### Dependency Updates
- Pin dir-glob to v2.0.0 [`b921fbc`](https://github.com/SAP/ui5-fs/commit/b921fbceaa4f200737b8c6cf45eaf2d9bc3e1df2)
- Bump [@ui5](https://github.com/ui5)/logger from 0.2.2 to 1.0.0 ([#72](https://github.com/SAP/ui5-fs/issues/72)) [`4077f19`](https://github.com/SAP/ui5-fs/commit/4077f19251dee72933de0747de09a6eec5cb75cc)
### BREAKING CHANGE
Adapters "AbstractAdapter", "FileSystem" and "Memory" used to be accessible via the top-level export of index.js (example: require("[@ui5](https://github.com/ui5)/project").FileSystem). This is no longer possible. Adapters are now grouped in the top-level object "adapters" and can be accessed from there (example: require("[@ui5](https://github.com/ui5)/project").adapters.FileSystem).
<a name="v0.2.0"></a>
## [v0.2.0] - 2018-07-11
### Internal Changes
- package.json: Define files to publish [`e533d82`](https://github.com/SAP/ui5-fs/commit/e533d822119d50b4ce6182c6f758df3f71f8b5d7)
- Update min Node.js version to >=8.5 [`b141ddc`](https://github.com/SAP/ui5-fs/commit/b141ddcdde37455b7df4d8ab495abf4429424080)
<a name="v0.1.0"></a>
## [v0.1.0] - 2018-06-26
### Internal Changes
- Update ui5-logger dependency [`97aadf6`](https://github.com/SAP/ui5-fs/commit/97aadf60e04244822461c27feca7ea47f0e25c2e)
- Add coveralls and dm-badges [`8bd7d9e`](https://github.com/SAP/ui5-fs/commit/8bd7d9ee3c93aac56d2c14bca79355c792700d3c)
- Update package-lock with correct UI5 tooling deps [`c9f032b`](https://github.com/SAP/ui5-fs/commit/c9f032b85c77e898a8317662e401c8e334f89fa8)
- **CHANGELOG:** Fix GitHub release template [`35f9297`](https://github.com/SAP/ui5-fs/commit/35f92979c7a3f37fa51dc50eb01978527f280f02)
- **README:** Pre-Alpha -> Alpha [`7abadbb`](https://github.com/SAP/ui5-fs/commit/7abadbb8637df4698fd9a44d3b77a5187e2246d0)
- **README:** Fix links [`87ee658`](https://github.com/SAP/ui5-fs/commit/87ee65881ee80b7eb504b3a14b8d7913dba0f817)
- **resourceFactory:** Also provide project reference to source-locator ([#11](https://github.com/SAP/ui5-fs/issues/11)) [`836731c`](https://github.com/SAP/ui5-fs/commit/836731cca54c7ef67fa66b9d2013d18d8c23f9ba)
<a name="v0.0.1"></a>

@@ -32,16 +33,5 @@ ## v0.0.1 - 2018-06-06

### Internal Changes
- Prepare npm release [`08b4f56`](https://github.com/SAP/ui5-fs/commit/08b4f5669d11e864c13fc2e6d4575d338f17558c)
- Update .editorconfig [`c5d9708`](https://github.com/SAP/ui5-fs/commit/c5d970880373a0b12d3ba6cd6e54d47ef83e7bc1)
- Add chglog config + npm release scripts [`171ab78`](https://github.com/SAP/ui5-fs/commit/171ab78c0cc374adf1cd1f69504d58c3ac80e008)
- Update dependencies [`0036872`](https://github.com/SAP/ui5-fs/commit/0036872dedd932fc676b8c48e1ca00316e7dda45)
- Update jsdoc [`a458ac3`](https://github.com/SAP/ui5-fs/commit/a458ac32651ad44e748d876864981e45aad9b431)
- Add travis CI badge + package.json cleanup [`3ee1a19`](https://github.com/SAP/ui5-fs/commit/3ee1a19af8b46c66b9f960738b9886d71654effb)
- Fix links to CONTRIBUTING.md file [`f5ca860`](https://github.com/SAP/ui5-fs/commit/f5ca860b8f00c19b34d6174bc6066bffab2a0eee)
- **ESLint:** Activate no-console [`d8c8f50`](https://github.com/SAP/ui5-fs/commit/d8c8f501eacaf9c8bc47699f39ae7bd933a13784)
- **ESLint:** Activate no-var rule [`4470f28`](https://github.com/SAP/ui5-fs/commit/4470f28bb983b21ca17689cb5f8dd00fd223085c)
- **Travis:** Add node.js 10 to test matrix [`78e0d47`](https://github.com/SAP/ui5-fs/commit/78e0d47ef310286bcf04ec0f7c7a7a5b6362dfd4)
[v1.0.0]: https://github.com/SAP/ui5-fs/compare/v0.2.0...v1.0.0
[v0.2.0]: https://github.com/SAP/ui5-fs/compare/v0.1.0...v0.2.0
[v0.1.0]: https://github.com/SAP/ui5-fs/compare/v0.0.1...v0.1.0

@@ -1,5 +0,17 @@

const ui5Fs = {
AbstractAdapter: require("./lib/adapters/AbstractAdapter"),
FileSystem: require("./lib/adapters/FileSystem"),
Memory: require("./lib/adapters/Memory"),
/**
* @module @ui5/fs
* @public
*/
module.exports = {
/**
* @public
* @see module:@ui5/fs.adapters.AbstractAdapter
* @see module:@ui5/fs.adapters.FileSystem
* @see module:@ui5/fs.adapters.Memory
*/
adapters: {
AbstractAdapter: require("./lib/adapters/AbstractAdapter"),
FileSystem: require("./lib/adapters/FileSystem"),
Memory: require("./lib/adapters/Memory")
},
AbstractReader: require("./lib/AbstractReader"),

@@ -14,3 +26,1 @@ AbstractReaderWriter: require("./lib/AbstractReaderWriter"),

};
module.exports = ui5Fs;
{
"tags": {
"allowUnknownTags": true
"allowUnknownTags": false
},
"source": {
"include": ["README.md"],
"include": ["README.md", "index.js"],
"includePattern": ".+\\.js$",

@@ -16,8 +16,46 @@ "excludePattern": "(node_modules(\\\\|/))"

"recurse": true,
"verbose": true
"verbose": true,
"access": "public"
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false
"monospaceLinks": false,
"default": {
"useLongnameInNav": true
}
},
"openGraph": {
"title": "UI5 Build and Development Tooling - API Reference",
"type": "website",
"image": "https://sap.github.io/ui5-tooling/docs/images/UI5_logo_wide.png",
"site_name": "UI5 Build and Development Tooling - API Reference",
"url": "https://sap.github.io/ui5-tooling/"
},
"docdash": {
"sectionOrder": [
"Modules",
"Namespaces",
"Classes",
"Externals",
"Events",
"Mixins",
"Tutorials",
"Interfaces"
],
"meta": {
"title": "UI5 Build and Development Tooling - API Reference - UI5 FS",
"description": "UI5 Build and Development Tooling - API Reference - UI5 FS",
"keyword": "openui5 sapui5 ui5 build development tool api reference"
},
"search": true,
"wrap": true,
"menu": {
"GitHub": {
"href": "https://github.com/SAP/ui5-fs",
"target": "_blank",
"class": "menu-item",
"id": "github_link"
}
}
}
}

@@ -7,3 +7,5 @@ const randomInt = require("random-int");

*
* @public
* @abstract
* @memberof module:@ui5/fs
*/

@@ -13,2 +15,4 @@ class AbstractReader {

* The constructor.
*
* @public
*/

@@ -30,9 +34,10 @@ constructor() {

*
* @public
* @param {string|Array} virPattern GLOB pattern as string or array of glob patterns for virtual directory structure
* @param {Object} [options={}] GLOB options
* @param {boolean} [options.nodir=true] Do not match directories
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/
byGlob(virPattern, options = {nodir: true}) {
let trace = new Trace(virPattern);
const trace = new Trace(virPattern);
return this._byGlob(virPattern, options, trace).then(function(result) {

@@ -45,4 +50,4 @@ trace.printReport();

// Swap the first object with a randomly chosen one
let x = 0;
let y = randomInt(0, resources.length - 1);
const x = 0;
const y = randomInt(0, resources.length - 1);
// Swap object at index "x" with "y"

@@ -58,12 +63,13 @@ resources[x] = [resources[y], resources[y]=resources[x]][0];

*
* @public
* @param {string} virPath Virtual path
* @param {Object} options Options
* @param {boolean} [options.nodir=true] Do not match directories
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/
byPath(virPath, options = {nodir: true}) {
let trace = new Trace(virPath);
return this._byPath(virPath, options, trace).then(function(result) {
const trace = new Trace(virPath);
return this._byPath(virPath, options, trace).then(function(resource) {
trace.printReport();
return result;
return resource;
});

@@ -79,4 +85,4 @@ }

* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/

@@ -94,4 +100,4 @@ _byGlob(virPattern, options, trace) {

* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/

@@ -108,4 +114,4 @@ _runGlob(pattern, options, trace) {

* @param {string} virPath Virtual path
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/

@@ -112,0 +118,0 @@ _byPath(virPath, trace) {

@@ -6,4 +6,6 @@ const AbstractReader = require("./AbstractReader");

*
* @public
* @abstract
* @augments AbstractReader
* @memberof module:@ui5/fs
* @augments module:@ui5/fs.AbstractReader
*/

@@ -13,2 +15,4 @@ class AbstractReaderWriter extends AbstractReader {

* The constructor.
*
* @public
*/

@@ -25,3 +29,4 @@ constructor() {

*
* @param {Resource} resource The Resource to write
* @public
* @param {module:@ui5/fs.Resource} resource The Resource to write
* @returns {Promise<undefined>} Promise resolving once data has been written

@@ -38,3 +43,3 @@ */

* @protected
* @param {Resource} resource The Resource to write
* @param {module:@ui5/fs.Resource} resource The Resource to write
* @returns {Promise<undefined>} Promise resolving once data has been written

@@ -41,0 +46,0 @@ */

@@ -9,3 +9,5 @@ const log = require("@ui5/logger").getLogger("resources:adapters:AbstractAdapter");

* @abstract
* @augments AbstractReaderWriter
* @public
* @memberof module:@ui5/fs.adapters
* @augments module:@ui5/fs.AbstractReaderWriter
*/

@@ -16,2 +18,3 @@ class AbstractAdapter extends AbstractReaderWriter {

*
* @public
* @param {Object} parameters Parameters

@@ -35,8 +38,10 @@ * @param {string} parameters.virBasePath Virtual base path

* @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 {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @param {string|Array} virPattern GLOB pattern as string or an array of
* glob patterns for virtual directory structure
* @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)) {

@@ -65,3 +70,3 @@ virPattern = [virPattern];

let basePathParts = this._virBaseDir.split("/");
const basePathParts = this._virBaseDir.split("/");

@@ -101,3 +106,3 @@ function matchSubset(subset) {

for (let i = 0; i < mm.set.length; i++) {
let matchIdx = matchSubset(mm.set[i]);
const matchIdx = matchSubset(mm.set[i]);
let resultPattern;

@@ -104,0 +109,0 @@ if (matchIdx !== -42) {

@@ -5,4 +5,2 @@ const log = require("@ui5/logger").getLogger("resources:adapters:FileSystem");

const glob = require("globby");
const defaults = require("defaults");
const clone = require("clone");
const makeDir = require("make-dir");

@@ -15,3 +13,5 @@ const Resource = require("../Resource");

*
* @augments AbstractAdapter
* @public
* @alias module:@ui5/fs.adapters.FileSystem
* @augments module:@ui5/fs.adapters.AbstractAdapter
*/

@@ -36,12 +36,14 @@ class FileSystem extends AbstractAdapter {

* @param {Array} patterns Array of GLOB patterns
* @param {Object} [options] GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @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) => {
let 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
};

@@ -72,4 +74,4 @@ trace.globCall();

promises.push(new Promise((resolve, reject) => {
let fsPath = path.join(this._fsBasePath, matches[i]);
let virPath = (this._virBasePath + matches[i]);
const fsPath = path.join(this._fsBasePath, matches[i]);
const virPath = (this._virBasePath + matches[i]);

@@ -95,3 +97,3 @@ // Workaround for not getting the stat from the glob

Promise.all(promises).then(function(results) {
let flat = Array.prototype.concat.apply([], results);
const flat = Array.prototype.concat.apply([], results);
resolve(flat);

@@ -113,4 +115,4 @@ }, function(err) {

* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/

@@ -151,3 +153,3 @@ _byPath(virPath, options, trace) {

} else {
let options = {
const options = {
project: this._project,

@@ -176,3 +178,3 @@ statInfo: stat,

* @private
* @param {Resource} resource The Resource
* @param {module:@ui5/fs.Resource} resource The Resource
* @returns {Promise<undefined>} Promise resolving once data has been written

@@ -191,7 +193,7 @@ */

return new Promise((resolve, reject) => {
let contentStream = resource.getStream();
const contentStream = resource.getStream();
contentStream.on("error", function(err) {
reject(err);
});
let write = fs.createWriteStream(fsPath);
const write = fs.createWriteStream(fsPath);
write.on("error", function(err) {

@@ -198,0 +200,0 @@ reject(err);

@@ -9,3 +9,5 @@ const log = require("@ui5/logger").getLogger("resources:adapters:Memory");

*
* @augments AbstractAdapter
* @public
* @memberof module:@ui5/fs.adapters
* @augments module:@ui5/fs.adapters.AbstractAdapter
*/

@@ -16,2 +18,3 @@ class Memory extends AbstractAdapter {

*
* @public
* @param {Object} parameters Parameters

@@ -31,7 +34,8 @@ * @param {string} parameters.virBasePath Virtual base path

* @param {Array} patterns array of GLOB patterns
* @param {Object} [options] GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @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

@@ -58,3 +62,3 @@ return Promise.resolve([

// TODO: Add tests for all this
let dirPaths = Object.keys(this._virDirs);
const dirPaths = Object.keys(this._virDirs);
const matchedDirs = micromatch(dirPaths, patterns, {

@@ -77,4 +81,4 @@ dot: true

* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/

@@ -92,3 +96,3 @@ _byPath(virPath, options, trace) {

let resource = this._virFiles[relPath];
const resource = this._virFiles[relPath];

@@ -107,3 +111,3 @@ if (!resource || (options.nodir && resource.getStatInfo().isDirectory())) {

* @private
* @param {Resource} resource The Resource to write
* @param {module:@ui5/fs.Resource} resource The Resource to write
* @returns {Promise<undefined>} Promise resolving once data has been written

@@ -110,0 +114,0 @@ */

@@ -7,3 +7,5 @@ const AbstractReaderWriter = require("./AbstractReaderWriter");

*
* @augments AbstractReaderWriter
* @public
* @memberof module:@ui5/fs
* @augments module:@ui5/fs.AbstractReaderWriter
*/

@@ -15,4 +17,4 @@ class DuplexCollection extends AbstractReaderWriter {

* @param {Object} parameters
* @param {AbstractReader} parameters.reader Single reader or collection of readers
* @param {AbstractReaderWriter} parameters.writer A ReaderWriter instance which is only used for writing files
* @param {module:@ui5/fs.AbstractReader} parameters.reader Single reader or collection of readers
* @param {module:@ui5/fs.AbstractReaderWriter} parameters.writer A ReaderWriter instance which is only used for writing files
* @param {string} [parameters.name=""] The collection name

@@ -40,4 +42,4 @@ */

* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving with a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with a list of resources
*/

@@ -54,3 +56,3 @@ _byGlob(virPattern, options, trace) {

* @param {Object} [options={}] GLOB options
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/

@@ -73,4 +75,4 @@ byGlobSource(virPattern, options = {}) {

* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/

@@ -85,3 +87,3 @@ _byPath(virPath, options, trace) {

* @private
* @param {Resource} resource The Resource to write
* @param {module:@ui5/fs.Resource} resource The Resource to write
* @returns {Promise<undefined>} Promise resolving once data has been written

@@ -88,0 +90,0 @@ */

/**
* Wraps readers to access them like a node fs-interface.
*
* @module resources/fsInterface
* @param {AbstractReader} reader Resource Reader or Collection
* @returns {Object} Object with wrapped fs functions
* @public
* @alias module:@ui5/fs.fsInterface
* @param {module:@ui5/fs.AbstractReader} reader Resource Reader or Collection
* @returns {Object} Object with fs-style functions <code>readFile</code>, <code>stat</code> and <code>readdir</code>
*/
const fsInterface = (reader) => {
module.exports = (reader) => {
return {

@@ -70,3 +71,1 @@ readFile(path, options, callback) {

};
module.exports = fsInterface;

@@ -6,3 +6,5 @@ const AbstractReader = require("./AbstractReader");

*
* @augments AbstractReader
* @public
* @memberof module:@ui5/fs
* @augments module:@ui5/fs.AbstractReader
*/

@@ -14,3 +16,3 @@ class ReaderCollection extends AbstractReader {

* @param {Object} parameters Parameters
* @param {AbstractReader[]} parameters.readers List of resource readers (all tried in parallel)
* @param {module:@ui5/fs.AbstractReader[]} parameters.readers List of resource readers (all tried in parallel)
* @param {string} parameters.name The collection name

@@ -30,4 +32,4 @@ */

* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/

@@ -49,8 +51,8 @@ _byGlob(pattern, options, trace) {

* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
let that = this;
let resourceLocatorCount = this._readers.length;
const that = this;
const resourceLocatorCount = this._readers.length;
let resolveCount = 0;

@@ -67,9 +69,9 @@

return Promise.race(this._readers.map(function(resourceLocator) {
return resourceLocator._byPath(virPath, options, trace).then(function(result) {
return resourceLocator._byPath(virPath, options, trace).then(function(resource) {
return new Promise(function(resolve, reject) {
trace.collection(that._name);
resolveCount++;
if (result) {
result.pushCollection(that._name);
resolve(result);
if (resource) {
resource.pushCollection(that._name);
resolve(resource);
} else if (resolveCount === resourceLocatorCount) {

@@ -76,0 +78,0 @@ resolve(null);

@@ -6,3 +6,5 @@ const AbstractReader = require("./AbstractReader");

*
* @augments AbstractReader
* @public
* @memberof module:@ui5/fs
* @augments module:@ui5/fs.AbstractReader
*/

@@ -15,3 +17,3 @@ class ReaderCollectionPrioritized extends AbstractReader {

* @param {string} parameters.name The collection name
* @param {AbstractReader[]} parameters.readers Prioritized list of resource readers (first is tried first)
* @param {module:@ui5/fs.AbstractReader[]} parameters.readers Prioritized list of resource readers (first is tried first)
*/

@@ -30,4 +32,4 @@ constructor({readers, name}) {

* @param {Object} options GLOB options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving to list of resources
*/

@@ -38,9 +40,9 @@ _byGlob(pattern, options, trace) {

})).then((result) => {
let files = {};
let resources = [];
const files = {};
const resources = [];
// Prefer files found in preceding resource locators
for (let i = 0; i < result.length; i++) {
for (let j = 0; j < result[i].length; j++) {
let resource = result[i][j];
let path = resource.getPath();
const resource = result[i][j];
const path = resource.getPath();
if (!files[path]) {

@@ -64,6 +66,7 @@ files[path] = true;

* @param {Object} options Options
* @param {Trace} trace Trace instance
* @returns {Promise<Resource[]>} Promise resolving to a list of resources
* @param {module:@ui5/fs.tracing.Trace} trace Trace instance
* @returns {Promise<module:@ui5/fs.Resource>} Promise resolving to a single resource
*/
_byPath(virPath, options, trace) {
const that = this;
const byPath = (i) => {

@@ -73,6 +76,6 @@ if (i > this._readers.length - 1) {

}
return this._readers[i]._byPath(virPath, options, trace).then((result) => {
if (result) {
result.pushCollection(this._name);
return result;
return this._readers[i]._byPath(virPath, options, trace).then((resource) => {
if (resource) {
resource.pushCollection(that._name);
return resource;
} else {

@@ -79,0 +82,0 @@ return byPath(++i);

@@ -10,2 +10,5 @@ const stream = require("stream");

* Resource
*
* @public
* @memberof module:@ui5/fs
*/

@@ -16,2 +19,3 @@ class Resource {

*
* @public
* @param {Object} parameters Parameters

@@ -26,3 +30,3 @@ * @param {string} parameters.path Virtual path

* (cannot be used in conjunction with parameters buffer, string or createStream)
* @param {function} [parameters.createStream] Function callback that returns a readable stream of the content
* @param {Function} [parameters.createStream] Function callback that returns a readable stream of the content
* of this resource (cannot be used in conjunction with parameters buffer, string or stream)

@@ -75,2 +79,3 @@ */

*
* @public
* @returns {Promise<Buffer>} A Promise resolving with a buffer of the resource content.

@@ -93,2 +98,3 @@ */

*
* @public
* @param {Buffer} buffer A buffer instance

@@ -108,2 +114,3 @@ */

*
* @public
* @returns {Promise<string>} A Promise resolving with a string of the resource content.

@@ -118,2 +125,3 @@ */

*
* @public
* @param {string} string A string

@@ -128,2 +136,3 @@ */

*
* @public
* @returns {stream.Readable} A readable stream for the resource content.

@@ -133,3 +142,3 @@ */

if (this._buffer) {
let bufferStream = new stream.PassThrough();
const bufferStream = new stream.PassThrough();
bufferStream.end(this._buffer);

@@ -147,2 +156,3 @@ return bufferStream;

*
* @public
* @param {stream.Readable} stream readable stream

@@ -162,2 +172,3 @@ */

*
* @public
* @returns {string} (Virtual) path of the resource

@@ -172,2 +183,3 @@ */

*
* @public
* @param {string} path (Virtual) path of the resource

@@ -183,2 +195,3 @@ */

*
* @public
* @returns {fs.Stats} An object representing an fs.Stats instance

@@ -206,6 +219,7 @@ */

*
* @returns {Promise<Resource>} A promise resolving the resource.
* @public
* @returns {Promise<module:@ui5/fs.Resource>} A promise resolving the resource.
*/
clone() {
let options = {
const options = {
path: this._path,

@@ -241,3 +255,3 @@ statInfo: clone(this._statInfo)

getPathTree() {
let tree = {};
const tree = {};

@@ -257,3 +271,3 @@ let pointer = tree[this._path] = {};

* @private
* @returns {function} The stream
* @returns {Function} The stream
*/

@@ -275,4 +289,4 @@ _getStream() {

return new Promise((resolve, reject) => {
let contentStream = this._getStream();
let buffers = [];
const contentStream = this._getStream();
const buffers = [];
contentStream.on("data", (data) => {

@@ -285,3 +299,3 @@ buffers.push(data);

contentStream.on("end", () => {
let buffer = Buffer.concat(buffers);
const buffer = Buffer.concat(buffers);
this.setBuffer(buffer);

@@ -288,0 +302,0 @@ resolve(buffer);

@@ -9,145 +9,151 @@ const path = require("path");

/**
* @module resources/resourceFactory
*/
/**
* Creates resource reader collections for a (sub-)tree. Returns an object of resource readers:
* <pre>
* {
* source: Resource reader for source resources
* dependencies: Resource readers for dependency resources
* }
* </pre>
* Resource Factory
*
* @param {Object} tree A (sub-)tree
* @param {Object} [parameters] Parameters
* @param {boolean} [parameters.useNamespaces=false] Use project namespaces as path prefixes
* @returns {Object} Object containing <code>source</code> and <code>dependencies</code> resource readers
* @public
* @namespace
* @alias module:@ui5/fs.resourceFactory
*/
function createCollectionsForTree(tree, {useNamespaces=false} = {}) {
const dependencyCollection = [];
const dependencyPathIndex = {};
const sourceResourceLocators = [];
const resourceFactory = {
/**
* Creates resource reader collections for a (sub-)tree. Returns an object of resource readers:
* <pre>
* {
* source: Resource reader for source resources
* dependencies: Resource readers for dependency resources
* }
* </pre>
*
* @public
* @param {Object} tree A (sub-)tree
* @param {Object} [parameters] Parameters
* @param {boolean} [parameters.useNamespaces=false] Use project namespaces as path prefixes
* @returns {Object} Object containing <code>source</code> and <code>dependencies</code> resource readers
*/
createCollectionsForTree(tree, {useNamespaces=false} = {}) {
const dependencyCollection = [];
const dependencyPathIndex = {};
const sourceResourceLocators = [];
function processDependencies(project) {
if (project.resources && project.resources.pathMappings) {
for (let virBasePath in project.resources.pathMappings) {
if (project.resources.pathMappings.hasOwnProperty(virBasePath)) {
const fsPath = project.resources.pathMappings[virBasePath];
const fsBasePath = path.join(project.path, fsPath);
function processDependencies(project) {
if (project.resources && project.resources.pathMappings) {
for (let virBasePath in project.resources.pathMappings) {
if (project.resources.pathMappings.hasOwnProperty(virBasePath)) {
const fsPath = project.resources.pathMappings[virBasePath];
const fsBasePath = path.join(project.path, fsPath);
if (useNamespaces && project.metadata.namespace) { // Prefix resource paths with namespace
virBasePath = "/resources/" + project.metadata.namespace + virBasePath;
}
if (useNamespaces && project.metadata.namespace) { // Prefix resource paths with namespace
virBasePath = "/resources/" + project.metadata.namespace + virBasePath;
}
// Prevent duplicate dependency resource locators
const key = virBasePath + fsBasePath;
if (dependencyPathIndex[key]) {
continue;
// Prevent duplicate dependency resource locators
const key = virBasePath + fsBasePath;
if (dependencyPathIndex[key]) {
continue;
}
dependencyPathIndex[key] = true;
dependencyCollection.push(resourceFactory.createAdapter({fsBasePath, virBasePath, project}));
}
dependencyPathIndex[key] = true;
dependencyCollection.push(createAdapter({fsBasePath, virBasePath, project}));
}
}
project.dependencies.forEach(function(depProject) {
processDependencies(depProject);
});
}
project.dependencies.forEach(function(depProject) {
processDependencies(depProject);
});
}
if (tree.resources && tree.resources.pathMappings) {
for (let virBasePath in tree.resources.pathMappings) {
if (tree.resources.pathMappings.hasOwnProperty(virBasePath)) {
const fsBasePath = path.join(tree.path, tree.resources.pathMappings[virBasePath]);
if (tree.resources && tree.resources.pathMappings) {
for (let virBasePath in tree.resources.pathMappings) {
if (tree.resources.pathMappings.hasOwnProperty(virBasePath)) {
let fsBasePath = path.join(tree.path, tree.resources.pathMappings[virBasePath]);
if (useNamespaces && tree.metadata.namespace) { // Prefix resource paths with namespace
virBasePath = "/resources/" + tree.metadata.namespace + virBasePath;
if (useNamespaces && tree.metadata.namespace) { // Prefix resource paths with namespace
virBasePath = "/resources/" + tree.metadata.namespace + virBasePath;
}
sourceResourceLocators.push(resourceFactory.createAdapter({
fsBasePath, virBasePath, project: tree
}));
}
sourceResourceLocators.push(createAdapter({fsBasePath, virBasePath, project: tree}));
}
}
}
tree.dependencies.forEach(function(project) {
processDependencies(project);
});
tree.dependencies.forEach(function(project) {
processDependencies(project);
});
let source = new ReaderCollection({
name: "source of " + tree.metadata.name,
readers: sourceResourceLocators
});
let dependencies = new ReaderCollection({
name: "dependencies of " + tree.metadata.name,
readers: dependencyCollection
});
return {
source,
dependencies
};
}
const source = new ReaderCollection({
name: "source of " + tree.metadata.name,
readers: sourceResourceLocators
});
const dependencies = new ReaderCollection({
name: "dependencies of " + tree.metadata.name,
readers: dependencyCollection
});
return {
source,
dependencies
};
},
/**
* Creates a resource <code>ReaderWriter</code>.
*
* If a file system base path is given, file system resource <code>ReaderWriter</code> is returned.
* In any other case a virtual one.
*
* @param {Object} parameters Parameters
* @param {string} parameters.virBasePath Virtual base path
* @param {string} [parameters.fsBasePath] File system base path
* @returns {FileSystem|Memory} File System- or Virtual Adapter
*/
function createAdapter({fsBasePath, virBasePath, project}) {
if (fsBasePath) {
return new FsAdapter({fsBasePath, virBasePath, project});
} else {
return new MemAdapter({virBasePath, project});
}
}
/**
* Creates a resource <code>ReaderWriter</code>.
*
* If a file system base path is given, file system resource <code>ReaderWriter</code> is returned.
* In any other case a virtual one.
*
* @public
* @param {Object} parameters Parameters
* @param {string} parameters.virBasePath Virtual base path
* @param {string} [parameters.fsBasePath] File system base path
* @returns {module:@ui5/fs.adapters.FileSystem|module:@ui5/fs.adapters.Memory} File System- or Virtual Adapter
*/
createAdapter({fsBasePath, virBasePath, project}) {
if (fsBasePath) {
return new FsAdapter({fsBasePath, virBasePath, project});
} else {
return new MemAdapter({virBasePath, project});
}
},
/**
* Creates a <code>Resource</code>. Accepts the same parameters as the Resource constructor.
*
* @param {Object} parameters Parameters to be passed to the resource constructor
* @returns {Resource} Resource
*/
function createResource(parameters) {
return new Resource(parameters);
}
/**
* Creates a <code>Resource</code>. Accepts the same parameters as the Resource constructor.
*
* @public
* @param {Object} parameters Parameters to be passed to the resource constructor
* @returns {module:@ui5/fs.Resource} Resource
*/
createResource(parameters) {
return new Resource(parameters);
},
/**
* Creates a Workspace
*
* A workspace is a DuplexCollection which reads from the project sources. It is used during the build process
* to write modified files into a seperate writer, this is usually a Memory adapter. If a file already exists it is
* fetched from the memory to work on it in further build steps.
*
* @param {Object} parameters
* @param {AbstractReader} parameters.reader The reader
* @param {string} [parameters.name="vir & fs source"] Name of the collection
* @param {string} [parameters.virBasePath="/"] Virtual base path
* @returns {DuplexCollection} DuplexCollection which wraps the provided resource locators
*/
function createWorkspace({reader, writer, virBasePath = "/", name = "vir & fs source"}) {
if (!writer) {
writer = new MemAdapter({
virBasePath
/**
* Creates a Workspace
*
* A workspace is a DuplexCollection which reads from the project sources. It is used during the build process
* to write modified files into a seperate writer, this is usually a Memory adapter. If a file already exists it is
* fetched from the memory to work on it in further build steps.
*
* @public
* @param {Object} parameters
* @param {module:@ui5/fs.AbstractReader} parameters.reader The reader
* @param {string} [parameters.name="vir & fs source"] Name of the collection
* @param {string} [parameters.virBasePath="/"] Virtual base path
* @returns {module:@ui5/fs.DuplexCollection} DuplexCollection which wraps the provided resource locators
*/
createWorkspace({reader, writer, virBasePath = "/", name = "vir & fs source"}) {
if (!writer) {
writer = new MemAdapter({
virBasePath
});
}
return new DuplexCollection({
reader,
writer,
name
});
}
};
return new DuplexCollection({
reader,
writer,
name
});
}
module.exports = {
createCollectionsForTree,
createAdapter,
createWorkspace,
createResource
};
module.exports = resourceFactory;

@@ -10,2 +10,3 @@ const log = require("@ui5/logger").getLogger("resources:tracing:Trace");

*
* @memberof module:@ui5/fs.tracing
* @class

@@ -34,3 +35,3 @@ */

collection(name) {
let collection = this._collections[name];
const collection = this._collections[name];
if (collection) {

@@ -48,5 +49,5 @@ this._collections[name].calls++;

let report = "";
let timeDiff = process.hrtime(this._startTime);
let time = prettyHrtime(timeDiff);
let colCount = Object.keys(this._collections).length;
const timeDiff = process.hrtime(this._startTime);
const time = prettyHrtime(timeDiff);
const colCount = Object.keys(this._collections).length;

@@ -63,3 +64,3 @@ report += `[Trace: ${this._name}\n`;

for (let coll in this._collections) {
for (const coll in this._collections) {
if (this._collections.hasOwnProperty(coll)) {

@@ -66,0 +67,0 @@ report += ` ${this._collections[coll].calls}x ${coll}\n`;

@@ -26,4 +26,4 @@ const log = require("@ui5/logger").getLogger("resources:tracing:total");

let report = "";
let time = prettyHrtime(traceData.timeDiff);
let colCount = Object.keys(traceData.collections).length;
const time = prettyHrtime(traceData.timeDiff);
const colCount = Object.keys(traceData.collections).length;

@@ -41,3 +41,3 @@ report += "==========================\n[=> TRACE SUMMARY:\n";

for (let coll in traceData.collections) {
for (const coll in traceData.collections) {
if (traceData.collections.hasOwnProperty(coll)) {

@@ -64,15 +64,18 @@ report += ` ${traceData.collections[coll].calls}x ${coll}\n`;

function someTraceEnded() {
tracesRunning--;
if (tracesRunning > 0) {
return;
}
return new Promise(function(resolve, reject) {
tracesRunning--;
if (tracesRunning > 0) {
resolve();
}
if (timeoutId) {
clearTimeout(timeoutId);
}
traceData.timeDiff = process.hrtime(traceData.startTime);
timeoutId = setTimeout(function() {
report();
reset();
}, 2000);
if (timeoutId) {
clearTimeout(timeoutId);
}
traceData.timeDiff = process.hrtime(traceData.startTime);
timeoutId = setTimeout(function() {
report();
reset();
resolve();
}, 2000);
});
}

@@ -98,3 +101,3 @@

}
let collection = traceData.collections[name];
const collection = traceData.collections[name];
if (collection) {

@@ -101,0 +104,0 @@ traceData.collections[name].calls++;

@@ -1,1 +0,1 @@

Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved.
Copyright (c) 2018-2019 SAP SE or an SAP affiliate company. All rights reserved.
{
"name": "@ui5/fs",
"version": "0.2.0",
"version": "1.0.0",
"description": "UI5 Build and Development Tooling - File System Abstraction",

@@ -24,6 +24,6 @@ "author": "SAP SE (https://www.sap.com)",

"unit": "rimraf test/tmp && ava",
"unit-verbose": "rimraf test/tmp && cross-env UI5_LOG_LVL=verbose ava --verbose --serial",
"unit-watch": "rimraf test/tmp && ava --watch",
"unit-nyan": "npm run unit -- --tap | tnyan",
"unit-debug": "rimraf test/tmp && cross-env DEBUG=*,-babel,-ava ava",
"unit-inspect": "cross-env DEBUG=*,-babel,-ava node --inspect-brk node_modules/ava/profile.js",
"unit-nyan": "rimraf test/tmp && ava --tap | tnyan",
"unit-inspect": "cross-env UI5_LOG_LVL=verbose node --inspect-brk node_modules/ava/profile.js",
"coverage": "nyc npm run unit",

@@ -36,3 +36,3 @@ "jsdoc": "npm run jsdoc-generate && opn jsdocs/index.html",

"release-note": "git-chglog -c .chglog/release-config.yml v$npm_package_version",
"report-coveralls": "nyc report --reporter=text-lcov | coveralls"
"report-coveralls": "nyc report --reporter=text-lcov | COVERALLS_PARALLEL=true coveralls"
},

@@ -97,7 +97,7 @@ "files": [

"dependencies": {
"@ui5/logger": "^0.2.0",
"@ui5/logger": "^1.0.0",
"clone": "^2.1.0",
"defaults": "^1.0.3",
"dir-glob": "2.0.0",
"globby": "^7.1.1",
"graceful-fs": "^4.1.11",
"graceful-fs": "^4.1.15",
"make-dir": "^1.1.0",

@@ -115,11 +115,13 @@ "micromatch": "^3.1.4",

"cross-env": "^5.1.1",
"docdash": "^0.4.0",
"eslint": "^5.0.1",
"eslint-config-google": "^0.9.1",
"docdash": "^1.0.2",
"eslint": "^5.12.0",
"eslint-config-google": "^0.11.0",
"eslint-plugin-jsdoc": "^3.15.1",
"jsdoc": "^3.5.5",
"nyc": "^12.0.2",
"opn-cli": "^3.1.0",
"rimraf": "^2.6.2",
"nyc": "^13.1.0",
"opn-cli": "^4.0.0",
"rimraf": "^2.6.3",
"sinon": "^7.2.2",
"tap-nyan": "^1.1.0"
}
}

@@ -13,11 +13,8 @@ ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-tooling/master/docs/images/UI5_logo_wide.png)

**This is an alpha release!**
**The UI5 Build and Development Tooling described here is not intended for productive use yet. Breaking changes are to be expected.**
## Resources
During build phase a modified resource gets kept in memory for further processing in other build steps.
During the build phase, a modified resource is kept in memory for further processing in other build steps.
This ensures performance, as physical read and write access for a high number of resources gets kept to a minimum.
This ensures performance, as physical read and write access for a high number of resources are kept to a minimum.
The virtual file system offers an abstraction layer from the physical file system. Among others it can combine a bunch of scattered file locations into a well defined, virtualized structure.
The virtual file system offers an abstraction layer from the physical file system. Amongst others, it can combine a bunch of scattered file locations into a well defined, virtualized structure.

@@ -27,3 +24,3 @@ ### Adapters

The [memory adapter](lib/resources/adapters/Memory.js) represents a virtual filesystem which maintains respective resources inside a data structure, whereas the [file system adapter](lib/resources/adapters/FileSystem.js) has direct access to the physical filesytem.
The [memory adapter](lib/resources/adapters/Memory.js) represents a virtual file system, which maintains respective resources inside a data structure, whereas the [file system adapter](lib/resources/adapters/FileSystem.js) has direct access to the physical file sytem.

@@ -34,15 +31,14 @@ ### Resource Readers

### Collections
Multiple resource readers can be bundled to a collection. There are multiple types of Collections which differ in their capability of having read or write access and in the order of how they obtain resources.
Multiple resource readers can be bundled to a collection. There are multiple types of collections which differ in their capability of having read or write access and in the order of how they obtain resources.
#### Collection
The Collection has only read access.
The collection has only read access.
The collection takes a list of readers.
Those readers get accessed in parallel where the reader which returns the resource first, gets used.
The collection takes a list of readers. Readers are accessed in parallel: the reader which returns the resource first is used.
#### Prioritized Collection
The Prioritized Collection has only read access.
The prioritized collection has only read access.
The collection takes a list of readers.
Those readers get accessed prioritized in the same order as they got passed to the collection.
The readers are accessed prioritized in the same order as they are passed to the collection.

@@ -49,0 +45,0 @@ #### Duplex Collection

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc