-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
3,143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"istanbul" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
# 2 space indentation | ||
[{.,}*.{js,yml,yaml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
coverage/ | ||
lib/ | ||
.nyc_output | ||
tests-report/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# vim: syntax=yaml | ||
|
||
# | ||
# List of very light restrictions designed to prevent obvious errors, | ||
# not impose our own code style upon other contributors. | ||
# | ||
# This is supposed to be used with `eslint --reset` | ||
# | ||
# Created to work with eslint@0.18.0 | ||
# | ||
|
||
extends: ["eslint:recommended", "google"] | ||
|
||
env: | ||
node: true | ||
browser: true | ||
es6: true | ||
mocha: true | ||
|
||
parserOptions: | ||
sourceType: "module" | ||
ecmaVersion: 8 | ||
ecmaFeatures: | ||
modules: true | ||
|
||
rules: | ||
# useful to have in node.js, | ||
# if you're sure you don't need to handle error, rename it to "_err" | ||
handle-callback-err: 2 | ||
|
||
padded-blocks: 0 | ||
|
||
# just to make sure we don't forget to remove them when releasing | ||
no-debugger: 2 | ||
|
||
# add "falls through" for those | ||
no-fallthrough: 2 | ||
|
||
# enforce use curly always | ||
# curly: 1 | ||
|
||
# just warnings about whitespace weirdness here | ||
eol-last: 1 | ||
no-irregular-whitespace: 1 | ||
no-mixed-spaces-and-tabs: [1, smart-tabs] | ||
no-trailing-spaces: 1 | ||
|
||
# probably always an error, tell me if it's not | ||
no-new-require: 2 | ||
|
||
# single most important rule here, without it linting won't even | ||
# make any sense | ||
no-undef: 2 | ||
|
||
# in practice, those are always errors | ||
no-unreachable: 2 | ||
|
||
# useful for code clean-up | ||
no-unused-vars: [2, {"vars": "all", "args": "none"}] | ||
|
||
max-len: [1, 160] | ||
|
||
# camelcase is standard, but this should be 1 and then 2 soon | ||
camelcase: 0 | ||
|
||
# jsdoc is mandatory | ||
require-jsdoc: 0 | ||
valid-jsdoc: 0 | ||
|
||
# this feature is cool but not supported by Node 4, disable via comments | ||
prefer-spread: 1 | ||
prefer-rest-params: 1 | ||
|
||
# encorage use es6 | ||
no-var: 2 | ||
|
||
# configuration that should be upgraded progresivelly | ||
no-constant-condition: 2 | ||
no-empty: 2 | ||
|
||
# loop over objects http://eslint.org/docs/rules/guard-for-in | ||
guard-for-in: 2 | ||
|
||
# this must be used within classes | ||
no-invalid-this: 2 | ||
|
||
# All object must be uppercase | ||
new-cap: 2 | ||
|
||
# readbility is important, no multiple inline declarations | ||
one-var: 2 | ||
|
||
# console not allowed unless for testing | ||
no-console: [2, {"allow": ["log", "warn"]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
npm-debug.log | ||
.DS_Store | ||
|
||
lib/ | ||
node_modules/ | ||
|
||
# Istanbul | ||
.nyc* | ||
tests-report | ||
|
||
# IDE | ||
.vscode/* | ||
.idea/ | ||
*.log | ||
*.tar | ||
*.gz | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
src/ | ||
tests-report/ | ||
.nyc_output | ||
.editorconfig | ||
.gitignore | ||
yarn-error.log | ||
yarn.lock | ||
.eslintrc | ||
.babelrc | ||
test/ | ||
.eslintignore | ||
.eslintrc.yml | ||
.npmignore | ||
.travis.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
language: node_js | ||
node_js: | ||
- '4' | ||
- '6' | ||
- '7' | ||
- '8' | ||
sudo: false | ||
script: npm install . && npm run cover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "@verdaccio/streams", | ||
"version": "0.0.1", | ||
"description": "helper to delay streams", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "npm run lint && mocha --require babel-polyfill --compilers js:babel-core/register ./test/**/*.spec.js", | ||
"lint": "eslint .", | ||
"build": "babel src/ --out-dir lib/ --copy-files", | ||
"cover": "cross-env NODE_ENV=test nyc npm t" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "6.24.1", | ||
"babel-core": "6.25.0", | ||
"babel-plugin-istanbul": "4.1.4", | ||
"babel-polyfill": "6.23.0", | ||
"babel-preset-es2015": "6.24.1", | ||
"cross-env": "5.0.1", | ||
"eslint": "4.1.1", | ||
"eslint-config-google": "0.9.1", | ||
"mocha": "3.4.2", | ||
"nyc": "11.0.3" | ||
}, | ||
"nyc": { | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"all": true, | ||
"cache": true, | ||
"sourceMap": false, | ||
"instrument": false, | ||
"report-dir": "./tests-report", | ||
"reporter": [ | ||
"text", | ||
"html" | ||
] | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"keywords": [ | ||
"streams" | ||
], | ||
"author": "Juan Picado <juanpicado19@gmail.com>", | ||
"private": false, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
'use strict'; | ||
|
||
const Stream = require('stream'); | ||
|
||
/** | ||
* This stream is used to read tarballs from repository. | ||
* @param {*} options | ||
* @return {Stream} | ||
*/ | ||
class ReadTarball extends Stream.PassThrough { | ||
|
||
/** | ||
* | ||
* @param {Object} options | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
// called when data is not needed anymore | ||
addAbstractMethods(this, 'abort'); | ||
} | ||
} | ||
|
||
/** | ||
* This stream is used to upload tarballs to a repository. | ||
* @param {*} options | ||
* @return {Stream} | ||
*/ | ||
class UploadTarball extends Stream.PassThrough { | ||
|
||
/** | ||
* | ||
* @param {Object} options | ||
*/ | ||
constructor(options) { | ||
super(options); | ||
// called when user closes connection before upload finishes | ||
addAbstractMethods(this, 'abort'); | ||
|
||
// called when upload finishes successfully | ||
addAbstractMethods(this, 'done'); | ||
} | ||
} | ||
|
||
/** | ||
* This function intercepts abstract calls and replays them allowing. | ||
* us to attach those functions after we are ready to do so | ||
* @param {*} self | ||
* @param {*} name | ||
*/ | ||
function addAbstractMethods(self, name) { | ||
self._called_methods = self._called_methods || {}; | ||
self.__defineGetter__(name, function() { | ||
return function() { | ||
self._called_methods[name] = true; | ||
}; | ||
}); | ||
self.__defineSetter__(name, function(fn) { | ||
delete self[name]; | ||
self[name] = fn; | ||
if (self._called_methods && self._called_methods[name]) { | ||
delete self._called_methods[name]; | ||
self[name](); | ||
} | ||
}); | ||
} | ||
|
||
export {ReadTarball, UploadTarball}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
let ReadTarball = require('../src/index').ReadTarball; | ||
|
||
describe('mystreams', function() { | ||
it('should delay events', function(cb) { | ||
let test = new ReadTarball(); | ||
test.abort(); | ||
setTimeout(function() { | ||
test.abort = function() { | ||
cb(); | ||
}; | ||
test.abort = function() { | ||
throw Error('fail'); | ||
}; | ||
}, 10); | ||
}); | ||
}); | ||
|
Oops, something went wrong.