asset-pipe-js-reader
Advanced tools
Comparing version 1.0.0-alpha.5 to 1.0.0-beta.1
@@ -9,46 +9,41 @@ 'use strict'; | ||
const depsSort = require('deps-sort'); | ||
const assert = require('assert'); | ||
const pump = require('pump'); | ||
const Reader = module.exports = function (streams) { | ||
if (!(this instanceof Reader)) { return new Reader(streams); } | ||
assert(streams, '"streams" must be provided'); | ||
module.exports = class Reader { | ||
constructor (streams = []) { | ||
const merged = mergeStream(); | ||
streams.forEach((strm) => { | ||
merged.add(strm.pipe(JSONStream.parse('*'))); | ||
}); | ||
// let start = process.hrtime(); | ||
const merged = mergeStream(); | ||
streams.forEach((strm) => { | ||
merged.add(strm.pipe(JSONStream.parse('*'))); | ||
}); | ||
if (merged.isEmpty()) { | ||
// console.log('stream empty'); | ||
} | ||
if (merged.isEmpty()) { | ||
// console.log('stream empty'); | ||
} | ||
// we need to manipulate order in all bundles to make sure that the | ||
// order is an increased value accross all bundles. | ||
let order = 0; | ||
const fixOrder = new stream.Transform({ | ||
objectMode: true, | ||
transform (obj, encoding, next) { | ||
if (!isUndefined(obj.order)) { | ||
obj.order = order; | ||
order += 1; | ||
} | ||
this.push(obj); | ||
next(); | ||
}, | ||
}); | ||
// we need to manipulate order in all bundles to make sure that the | ||
// order is an increased value accross all bundles. | ||
let order = 0; | ||
const fixOrder = new stream.Transform({ | ||
objectMode: true, | ||
transform (obj, encoding, next) { | ||
if (!isUndefined(obj.order)) { | ||
obj.order = order; | ||
order += 1; | ||
} | ||
this.push(obj); | ||
next(); | ||
}, | ||
}); | ||
const sort = depsSort({ dedupe: true }); | ||
const packer = pack({ raw: true }); | ||
const sort = depsSort({ dedupe: true }); | ||
const packer = pack({ raw: true }); | ||
return pump(merged, fixOrder, sort, packer, (error) => { | ||
if (error) { | ||
console.log(error); | ||
} | ||
// let end = process.hrtime(start); | ||
// console.log("loading time:", end[0] + 'sec', end[1]/1000000 + 'ms'); | ||
}); | ||
return pump(merged, fixOrder, sort, packer, (error) => { | ||
if (error) { | ||
console.log(error); | ||
} | ||
}); | ||
} | ||
}; |
{ | ||
"name": "asset-pipe-js-reader", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-beta.1", | ||
"author": { | ||
@@ -29,3 +29,3 @@ "name": "Trygve Lie", | ||
"dependencies": { | ||
"JSONStream": "1.2.1", | ||
"JSONStream": "1.3.1", | ||
"browser-pack": "6.0.2", | ||
@@ -36,4 +36,3 @@ "deps-sort": "2.0.0", | ||
"pump": "1.0.2", | ||
"readable-stream": "2.2.2", | ||
"request": "2.79.0" | ||
"readable-stream": "2.2.6" | ||
}, | ||
@@ -43,3 +42,3 @@ "devDependencies": { | ||
"eslint-config-finn": "^1.0.1", | ||
"tap": "10.0.2" | ||
"tap": "10.3.0" | ||
}, | ||
@@ -46,0 +45,0 @@ "scripts": { |
@@ -1,1 +0,97 @@ | ||
# asset-pipe-js-reader | ||
# asset-pipe-js-reader | ||
This is an internal module intended for use by other modules in the [asset-pipe project][asset-pipe]. | ||
This module can take one or multiple asset feed stream(s), as produced by the [asset-pipe-js-writer][asset-pipe-js-writer], and produced an executable javascript bundle for the browser. | ||
## Data format | ||
What we refere to as an asset feed is the internal data format used in [Browserify][browserify]. We | ||
use the exact same data format as Browserify in the [asset-pipe project][asset-pipe]. | ||
When Browserify resolves [CommonJS modules][commonjs] each dependency will be read and transformed | ||
into an object which looks something like this: | ||
```json | ||
{ | ||
"id":"c645cf572a8f5acf8716e4846b408d3b1ca45c58", | ||
"source":"\"use strict\";module.exports.world=function(){return\"world\"};", | ||
"deps":{}, | ||
"file":"./assets/js/bar.js" | ||
} | ||
``` | ||
Each such object is emitted on a stream for each dependency. This is the asset feed. | ||
## Installation | ||
```bash | ||
$ npm install asset-pipe-js-writer | ||
``` | ||
## Usage | ||
Make an JavaScript bundle out of two asset feeds stored as JSON and save it as a file: | ||
```js | ||
const Reader = require('asset-pipe-js-reader'); | ||
const fs = require('fs'); | ||
const feedA = fs.createReadStream('./feed/a.json'); | ||
const feedB = fs.createReadStream('./feed/b.json'); | ||
const reader = new Reader([feedA, feedB]); | ||
reader.pipe(fs.createWriteStream('./build/browser.bundle.js')); | ||
``` | ||
## API | ||
This module have the following API: | ||
### constructor(streams) | ||
Supported arguments are: | ||
* `streams` - Array - An Array of streams . | ||
Returns a `Transform stream`. | ||
## License | ||
The MIT License (MIT) | ||
Copyright (c) 2017 - Trygve Lie - post@trygve-lie.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
[commonjs]: https://nodejs.org/docs/latest/api/modules.html | ||
[asset-pipe]: https://github.com/asset-pipe | ||
[browserify]: https://github.com/substack/node-browserify | ||
[asset-pipe-js-writer]: https://github.com/asset-pipe/asset-pipe-js-writer |
5331
7
98
40
+ AddedJSONStream@1.3.1(transitive)
+ Addedreadable-stream@2.2.6(transitive)
- Removedrequest@2.79.0
- RemovedJSONStream@1.2.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@0.2.01.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.6.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedboom@2.10.1(transitive)
- Removedcaseless@0.11.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removedcryptiles@2.0.5(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.1.4(transitive)
- Removedgenerate-function@2.3.1(transitive)
- Removedgenerate-object-property@1.2.0(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-validator@2.0.6(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhawk@3.1.3(transitive)
- Removedhoek@2.16.3(transitive)
- Removedhttp-signature@1.1.1(transitive)
- Removedis-my-ip-valid@1.0.1(transitive)
- Removedis-my-json-valid@2.20.6(transitive)
- Removedis-property@1.0.2(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.8.2(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedqs@6.3.3(transitive)
- Removedreadable-stream@2.2.2(transitive)
- Removedrequest@2.79.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsntp@1.0.9(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedstringstream@0.0.6(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedtough-cookie@2.3.4(transitive)
- Removedtunnel-agent@0.4.3(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
UpdatedJSONStream@1.3.1
Updatedreadable-stream@2.2.6