Ben Hsieh 7 年 前
コミット
2ddaff61c9
共有8 個のファイルを変更した0 個の追加258 個の削除を含む
  1. 0
    6
      scripts/test.sh
  2. 0
    80
      src/node-polyfill/Readable.js
  3. 0
    19
      src/node-polyfill/Stream.js
  4. 0
    36
      src/node-polyfill/events.js
  5. 0
    14
      src/node-polyfill/fs.js
  6. 0
    58
      src/node-polyfill/path.js
  7. 0
    28
      src/node-polyfill/util.js
  8. 0
    17
      test/.babelrc

+ 0
- 6
scripts/test.sh ファイルの表示

@@ -43,12 +43,6 @@ npm install --save react-native-fetch-blob
43 43
 npm install --save firebase
44 44
 # libs that requires Node polyfills
45 45
 npm install --save oboe
46
-npm install --save nedb
47
-# for node polyfills
48
-npm install crypto-js --save
49
-npm install babel-plugin-add-module-exports --save-dev
50
-npm install babel-plugin-modue-alias --save-dev
51
-npm install path-parse --save
52 46
 
53 47
 rnpm link
54 48
 

+ 0
- 80
src/node-polyfill/Readable.js ファイルの表示

@@ -1,80 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-
5
-import RNFetchBlob from '../index.js'
6
-import fs from '../fs.js'
7
-import getUUID from '../utils/uuid'
8
-import Log from '../utils/log.js'
9
-import Stream from './Stream.js'
10
-import EventEmitter from 'EventEmitter'
11
-
12
-const log = new Log('Readable')
13
-
14
-// log.disable()
15
-log.level(3)
16
-
17
-/**
18
- * A RNFetchBlob style nodejs ReadableStream polyfill class
19
- */
20
-export default class Readable {
21
-
22
-  constructor() {
23
-
24
-    this._emitter = new EventEmitter()
25
-    this._encoding = 'utf8'
26
-    this._readableState = null
27
-    this._isPaused = true
28
-
29
-  }
30
-
31
-  pipe(stream:Readable):Readable {
32
-    this._emitter.addListener('data', (chunk) => {
33
-      stream.emit('data', chunk)
34
-    })
35
-  }
36
-
37
-  unpipe(stream:Readable, options:any):Readable {
38
-
39
-  }
40
-
41
-  setEncoding(encoding:'utf8' | 'base64' | 'ascii'):Readable {
42
-    this._encoding = encoding
43
-  }
44
-
45
-  resume():Readable {
46
-    this._readableState = true
47
-  }
48
-
49
-  read(size:number) {
50
-
51
-  }
52
-
53
-  isPaused():boolean {
54
-    return this._isPaused
55
-  }
56
-
57
-  pause():Readable {
58
-    this._readableState = false
59
-    return this
60
-  }
61
-
62
-  emit(event:string, data:any):Readable {
63
-    this._emitter.emit(event, data)
64
-    return this
65
-  }
66
-
67
-  on(event:string, fn:() => void):Readable {
68
-    this._emitter.addListener(event, fn)
69
-    return this
70
-  }
71
-
72
-  unshift(chunk:any):Readable {
73
-
74
-  }
75
-
76
-  wrap(stream:Stream) {
77
-
78
-  }
79
-
80
-}

+ 0
- 19
src/node-polyfill/Stream.js ファイルの表示

@@ -1,19 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-
5
-import RNFetchBlob from '../index.js'
6
-import fs from '../fs.js'
7
-import getUUID from '../utils/uuid'
8
-import Log from '../utils/log.js'
9
-
10
-const log = new Log('Stream')
11
-
12
-log.disable()
13
-// log.level(3)
14
-
15
-/**
16
- * A RNFetchBlob style nodejs Stream polyfill class
17
- */
18
-export default class Stream {
19
-}

+ 0
- 36
src/node-polyfill/events.js ファイルの表示

@@ -1,36 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-// @flow
5
-import Log from '../utils/log'
6
-import EventEmitter from 'eventemitter3'
7
-const log = new Log('node-event')
8
-
9
-log.level(3)
10
-log.info('polyfill loaded')
11
-
12
-// class EventEmitter {
13
-//
14
-//   static defaultMaxListeners:number = 10;
15
-//
16
-//   static listenerCount(emitter:EventEmitter, eventName:string):number {
17
-//     return emitter._listeners ? emitter._listeners.length : 0
18
-//   }
19
-//
20
-//   constructor() {
21
-//     log.verbose('new EventEmitter created')
22
-//     this._emitter = new ee()
23
-//   }
24
-//
25
-//   emit() {
26
-//
27
-//   }
28
-//
29
-//
30
-// }
31
-
32
-
33
-// since nodejs modules uses es5 export by default, we should use es5 export here
34
-export {
35
-  EventEmitter
36
-}

+ 0
- 14
src/node-polyfill/fs.js ファイルの表示

@@ -1,14 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-// @flow
5
-import Log from '../utils/log'
6
-const log = new Log('node-fs')
7
-
8
-log.level(3)
9
-log.info('polyfill loaded')
10
-
11
-// since nodejs modules uses es5 export by default, we should use es5 export here
12
-export {
13
-
14
-}

+ 0
- 58
src/node-polyfill/path.js ファイルの表示

@@ -1,58 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-// @flow
5
-import Log from '../utils/log'
6
-const parse = require('path-parse')
7
-const log = new Log('node-path')
8
-log.level(3)
9
-log.info('polyfill loaded')
10
-
11
-const sep = '/'
12
-
13
-function basename(str:string):string {
14
-  log.verbose('basename', str)
15
-  return parse(str).base
16
-}
17
-
18
-function dirname(str:string):string {
19
-  log.verbose('dirname', str)
20
-  return parse(str).dir
21
-}
22
-
23
-function extname(str:string):string {
24
-  log.verbose('extname', str)
25
-  return parse(str).ext
26
-}
27
-
28
-function format(args:any):string {
29
-  log.verbose('format', args)
30
-  // TODO :
31
-}
32
-
33
-function isAbsolute(str:string):boolean {
34
-  log.verbose('isAbsolute', str)
35
-  // TODO :
36
-  return true
37
-}
38
-
39
-function join(arr:Array):string {
40
-  log.verbose('join', arr)
41
-  // TODO : error handling and type checking
42
-  return arr.join('')
43
-}
44
-
45
-function normalize(str:string):string {
46
-  log.verbose('normalize', str)
47
-  // TODO
48
-  return str
49
-}
50
-
51
-// since nodejs modules uses es5 export by default, we should use es5 export here
52
-export {
53
-  extname,
54
-  dirname,
55
-  basename,
56
-  // TODOs
57
-  normalize,
58
-}

+ 0
- 28
src/node-polyfill/util.js ファイルの表示

@@ -1,28 +0,0 @@
1
-// Copyright 2016 wkh237@github. All rights reserved.
2
-// Use of this source code is governed by a MIT-style license that can be
3
-// found in the LICENSE file.
4
-// @flow
5
-import Log from '../utils/log'
6
-const log = new Log('node-util')
7
-
8
-log.level(1)
9
-log.info('polyfill loaded')
10
-
11
-function inherits(ctor, superCtor):any {
12
-  log.verbose('inherits', superCtor, superCtor)
13
-  if(superCtor) {
14
-    ctor.prototype = superCtor.prototype
15
-    ctor.super_ = superCtor
16
-  }
17
-  return ctor
18
-}
19
-
20
-function isArray(arr:any):boolean {
21
-  return Array.isArray(arr)
22
-}
23
-
24
-// since nodejs modules uses es5 export by default, we should use es5 export here
25
-export {
26
-  inherits,
27
-  isArray
28
-}

+ 0
- 17
test/.babelrc ファイルの表示

@@ -1,17 +0,0 @@
1
-{
2
-  "plugins": [
3
-    ["module-alias", [
4
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/events.js", "expose": "events" },
5
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/http.js", "expose": "http" },
6
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/path.js", "expose": "path" },
7
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/fs.js", "expose": "fs" },
8
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/url.js", "expose": "url" },
9
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/querystring.js", "expose": "querystring" },
10
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/net.js", "expose": "net" },
11
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/util.js", "expose": "util" },
12
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/crypto.js", "expose": "crypto" },
13
-      { "src": "./node_modules/react-native-fetch-blob/node-polyfill/stream.js", "expose": "stream" }
14
-    ]]
15
-  ],
16
-  "extends": "./node_modules/react-native/packager/react-packager/rn-babelrc.json"
17
-}