Skip to content

Commit bb3865f

Browse files
leeyehwangxiao
authored andcommitted
fix: move AV to a standalone file to avoid circular dependencies (#316)
React Native packager can not deel with such situation: 1. A -> B -> A 2. A export something by overwriting module.exports B will get an empty export by `requir('A')` fix #313
1 parent 8769342 commit bb3865f

File tree

5 files changed

+57
-56
lines changed

5 files changed

+57
-56
lines changed

gulpfile.babel.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import browserify from 'browserify';
2222
import browserSync from 'browser-sync';
2323
import sourcemaps from 'gulp-sourcemaps';
2424
import babel from 'gulp-babel';
25-
import lc from './src/av';
25+
import { version } from './package.json';
2626

2727
const reload = browserSync.reload;
2828

2929
// 获取当前版本号
30-
const getAVVersion = () => {
31-
return lc.version.replace('js', '');
32-
};
30+
const getAVVersion = () => version;
3331

3432
const uploadCDN = (file, version, cb) => {
3533
qiniu.conf.ACCESS_KEY = process.env.CDN_QINIU_KEY;
@@ -65,7 +63,7 @@ gulp.task('clean-dist', () => {
6563

6664
gulp.task('browserify', ['clean-dist'], () => {
6765
const bundle = browserify({
68-
entries: './src/av.js',
66+
entries: './src/index.js',
6967
standalone: 'AV'
7068
});
7169
return bundle.bundle()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "leancloud-storage",
33
"version": "1.1.0",
4-
"main": "./dist/node/av.js",
4+
"main": "./dist/node/index.js",
55
"description": "LeanCloud JavaScript SDK.",
66
"repository": {
77
"type": "git",

src/av.js

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,2 @@
1-
/*!
2-
* LeanCloud JavaScript SDK
3-
* https://leancloud.cn
4-
*
5-
* Copyright 2016 LeanCloud.cn, Inc.
6-
* The LeanCloud JavaScript SDK is freely distributable under the MIT license.
7-
*/
1+
module.exports = global.AV || {};
82

9-
/**
10-
* 每位工程师都有保持代码优雅的义务
11-
* Each engineer has a duty to keep the code elegant
12-
**/
13-
14-
const AV = module.exports = global.AV || {};
15-
AV._ = require('underscore');
16-
AV.version = require('./version');
17-
AV.Promise = require('./promise');
18-
AV.localStorage = require('./localstorage');
19-
AV.Cache = require('./cache');
20-
21-
// All internal configuration items
22-
AV._config = AV._config || {};
23-
24-
require('./utils').init(AV);
25-
26-
require('./event')(AV);
27-
require('./geopoint')(AV);
28-
require('./acl')(AV);
29-
require('./op')(AV);
30-
require('./relation')(AV);
31-
require('./file')(AV);
32-
require('./object')(AV);
33-
require('./role')(AV);
34-
require('./user')(AV);
35-
require('./query')(AV);
36-
require('./cloudfunction')(AV);
37-
require('./push')(AV);
38-
require('./status')(AV);
39-
require('./search')(AV);
40-
require('./insight')(AV);
41-
42-
// TODO: deprecated AV.Error()
43-
const AVError = require('./error');
44-
/**
45-
* @deprecated AV.Error() is deprecated, and will be removed in next release.
46-
*/
47-
AV.Error = (...args) => {
48-
console.warn('AV.Error() is deprecated, and will be removed in next release.');
49-
new AVError(...args);
50-
};

src/index.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*!
2+
* LeanCloud JavaScript SDK
3+
* https://leancloud.cn
4+
*
5+
* Copyright 2016 LeanCloud.cn, Inc.
6+
* The LeanCloud JavaScript SDK is freely distributable under the MIT license.
7+
*/
8+
9+
/**
10+
* 每位工程师都有保持代码优雅的义务
11+
* Each engineer has a duty to keep the code elegant
12+
**/
13+
14+
const AV = module.exports = require('./av');
15+
16+
AV._ = require('underscore');
17+
AV.version = require('./version');
18+
AV.Promise = require('./promise');
19+
AV.localStorage = require('./localstorage');
20+
AV.Cache = require('./cache');
21+
22+
// All internal configuration items
23+
AV._config = AV._config || {};
24+
25+
require('./utils').init(AV);
26+
27+
require('./event')(AV);
28+
require('./geopoint')(AV);
29+
require('./acl')(AV);
30+
require('./op')(AV);
31+
require('./relation')(AV);
32+
require('./file')(AV);
33+
require('./object')(AV);
34+
require('./role')(AV);
35+
require('./user')(AV);
36+
require('./query')(AV);
37+
require('./cloudfunction')(AV);
38+
require('./push')(AV);
39+
require('./status')(AV);
40+
require('./search')(AV);
41+
require('./insight')(AV);
42+
43+
// TODO: deprecated AV.Error()
44+
const AVError = require('./error');
45+
/**
46+
* @deprecated AV.Error() is deprecated, and will be removed in next release.
47+
*/
48+
AV.Error = (...args) => {
49+
console.warn('AV.Error() is deprecated, and will be removed in next release.');
50+
new AVError(...args);
51+
};

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (typeof require !== 'undefined') {
44
GLOBAL.debug = require('debug')('test');
55
GLOBAL.expect = require('expect.js');
66
GLOBAL.serverURL = 'http://192.168.1.216:3000';
7-
GLOBAL.AV = require('../dist/node/av');
7+
GLOBAL.AV = require('..');
88
}
99

1010
// AV._config.APIServerURL = 'https://cn-stg1.avoscloud.com';

0 commit comments

Comments
 (0)