-
Notifications
You must be signed in to change notification settings - Fork 1
/
BespinEmbedded.uncompressed.js
7835 lines (6633 loc) · 248 KB
/
BespinEmbedded.uncompressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Bespin.
*
* The Initial Developer of the Original Code is
* Mozilla.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bespin Team ([email protected])
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if (typeof(bespin) === 'undefined') {
bespin = {};
}
if (typeof(document) !== 'undefined') {
var link = document.getElementById("bespin_base");
if (link) {
var href = link.href;
bespin.base = href.substring(href.length - 1) !== "/" ? href + "/" : href;
} else {
bespin.base = "";
}
}
(function() {
/*! @license
==========================================================================
Tiki 1.0 - CommonJS Runtime
copyright 2009-2010, Apple Inc., Sprout Systems Inc., and contributors.
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.
Tiki is part of the SproutCore project.
SproutCore and the SproutCore logo are trademarks of Sprout Systems, Inc.
For more information visit http://www.sproutcore.com/tiki
==========================================================================
@license */
/*globals tiki ENV ARGV ARGS */
"use modules false";
"use loader false";
/**
Implements a very simple handler for the loader registration API so that
additional scripts can load without throwing exceptions. This loader can
also return module instances for modules registered with an actual factory
function.
Note that this stub loader cannot be used on its own. You must load the
regular tiki package as well, which will replace this loader as soon as it
is fetched.
*/
if ("undefined" === typeof tiki) { var tiki = function() {
var T_UNDEFINED = 'undefined',
queue = [];
// save a registration method in a queue to be replayed later once the
// real loader is available.
function _record(method, args) {
queue.push({ m: method, a: args });
}
var tiki = {
// used to detect when real loader should replace this one
isBootstrap: true,
// log of actions to be replayed later
queue: queue,
// helpers just record into queue
register: function(packageId, opts) {
// this hack will make unit tests work for tiki by adding core_test to
// the list of dependencies.
if (packageId.match(/^tiki/) && this.ENV) {
if ((this.ENV.app === 'tiki') && (this.ENV.mode === 'test')) {
if (!opts.dependencies) opts.dependencies = {};
opts.dependencies['core_test'] = '~';
}
}
_record('register', arguments);
return this;
},
// Keep these around just in case we need them in the end...
// script: function() {
// _record('script', arguments);
// return this;
// },
//
// stylesheet: function() {
// _record('stylesheet', arguments);
// return this;
// },
// modules actually get saved as well a recorded so you can use them.
module: function(moduleId, factory) {
if (moduleId.match(/\:tiki$/)) this.tikiFactory = factory;
_record('module', arguments);
return this ;
},
// load the tikiFactory
start: function() {
var exp = {}, ret;
this.tikiFactory(null, exp, null); // no require or module!
ret = exp.Browser.start(this.ENV, this.ARGS, queue);
queue = null;
return ret ;
}
};
if (T_UNDEFINED !== typeof ENV) tiki.ENV = ENV;
if (T_UNDEFINED !== typeof ARGV) tiki.ARGS = ARGV; // for older versions
if (T_UNDEFINED !== typeof ARGS) tiki.ARGS = ARGS;
return tiki;
}(); }
tiki.register('::tiki/1.0.0', {
"name": "tiki",
"version": "1.0.0"
});
tiki.module('::tiki/1.0.0:tiki', function(require, exports, module) {
// ==========================================================================
// Project: Tiki - CommonJS Runtime
// Copyright: ©2009-2010 Apple Inc. All rights reserved.
// License: Licened under MIT license (see __preamble__.js)
// ==========================================================================
/*jslint evil:true */
/**
@file
This file implements the core building blocks needed to implement the
tiki runtime in an environment. If you can require this one module, you can
setup a runtime that will load additional packages.
It is important that this module NOT require() any other modules since a
functioning require() statement may not be available. The module can
populate, but not replace, the exports object.
To configure a Tiki runtime, you need to create a Sandbox and Loader
instance from this API with one or more loader Sources. The BrowserSource
object implements the basic source you need to work in the browser. The
Repository object implemented in the server-side only 'file' API can be
used to load from a local repository of packages.
*/
// used for type checking. This allows the type strings to be minified.
var T_FUNCTION = 'function',
T_STRING = 'string',
T_UNDEFINED = 'undefined';
var IS_CANONICAL = /^::/; // must begin with ::
var isCanonicalId = function(id) {
return !!IS_CANONICAL.exec(id);
};
var DEBUG = function() {
exports.debug.apply(this, arguments);
};
exports.debug = function() {
var msg = Array.prototype.join.call(arguments, '');
require('sys').debug(msg);
};
// ..........................................................
// CORE UTILITIES
//
var TMP_ARY = [];
/**
Tests whether the passed object is an array or not.
*/
var isArray;
if (Array.isArray) {
isArray = Array.isArray;
} else {
isArray = function(obj) {
if ('object' !== typeof obj) return false;
if (obj instanceof Array) return true;
return obj.constructor && (obj.constructor.name==='Array');
};
}
exports.isArray = isArray;
/**
Create a new object with the passed object as the prototype.
*/
var createObject;
if (Object.create) {
createObject = Object.create;
} else {
var K = function() {},
Kproto = K.prototype;
createObject = function(obj) {
if (!obj) obj = Object.prototype;
K.prototype = obj;
var ret = new K();
ret.prototype = obj;
K.prototype = Kproto;
return ret ;
};
}
exports.createObject = createObject;
var _constructor, _extend, extend;
// returns a new constructor function with clean closure...
_constructor = function() {
return function() {
if (this.init) return this.init.apply(this, arguments);
else return this;
};
};
_extend = function() {
return extend(this);
};
/**
Creates a "subclass" of the passed constructor. The default constructor
will call look for a local "init" method and call it.
If you don't pass an initial constructor, this will create a new based
object.
*/
extend = function(Constructor) {
var Ret = _constructor();
Ret.prototype = createObject(Constructor.prototype);
Ret.prototype.constructor = Ret;
Ret.super_ = Constructor;
Ret.extend = _extend;
return Ret;
};
exports.extend = extend;
/**
Invokes the passed fn on each item in the array in parallel. Invokes
done when finished.
# Example
parallel([1,2,3], function(item, done) {
// do something with item
done();
})(function(err) {
// invoked when done, err if there was an error
});
@param {Array} array
items to iterate
@param {Function} fn
callback to invoke
@returns {void}
*/
var parallel = function(array, fn) {
if (fn && !fn.displayName) fn.displayName = 'parallel#fn';
return function(done) {
if (array.length === 0) return done(null, []);
var len = array.length,
cnt = len,
cancelled = false,
idx;
var tail = function(err) {
if (cancelled) return; // nothing to do
if (err) {
cancelled = true;
return done(err);
}
if (--cnt <= 0) done();
};
tail.displayName = 'parallel#tail';
for(idx=0;idx<len;idx++) fn(array[idx], tail);
};
};
parallel.displayName = 'parallel';
/**
@private
Implements the sync map() on all platforms
*/
var map;
if (Array.prototype.map) {
map = function(array, fn) {
return array.map(fn);
};
} else {
map = function(array, fn) {
var idx, len = array.length, ret = [];
for(idx=0;idx<len;idx++) {
ret[idx] = fn(array[idx], idx);
}
return ret ;
};
}
map.displayName = 'map';
var PENDING = 'pending',
READY = 'ready',
RUNNING = 'running';
/**
Returns a function that will execute the continuable exactly once and
then cache the result. Invoking the same return function more than once
will simply return the old result.
This is a good replacement for promises in many cases.
h3. Example
{{{
// load a file only once
var loadit = Co.once(Co.fs.loadFile(pathToFile));
loadit(function(content) {
// loads the file
});
loadit(function(content) {
// if already loaded, just invokes with past content
});
}}}
@param {Function} cont
Continuable to invoke
@returns {Function}
A new continuable that will only execute once then returns the cached
result.
*/
var once = function(action, context) {
var state = PENDING,
queue = [],
makePending = false,
args = null;
var ret = function(callback) {
if (!context) context = this;
// cont has already finished, just invoke callback based on result
switch(state) {
// already resolved, invoke callback immediately
case READY:
callback.apply(null, args);
break;
// action has started running but hasn't finished yet
case RUNNING:
queue.push(callback);
break;
// action has not started yet
case PENDING:
queue.push(callback);
state = RUNNING;
action.call(context, function(err) {
args = Array.prototype.slice.call(arguments);
var oldQueue = queue, oldArgs = args;
if (makePending) {
state = PENDING;
queue = [];
args = null;
makePending = false;
} else {
state = READY;
queue = null;
}
if (oldQueue) {
oldQueue.forEach(function(q) { q.apply(null, oldArgs); });
}
});
break;
}
return this;
};
ret.displayName = 'once#handler';
// allow the action to be reset so it is called again
ret.reset = function() {
switch(state) {
// already run, need to reset
case READY:
state = PENDING;
queue = [];
args = null;
break;
// in process - set makePending so that resolving will reset to pending
case RUNNING:
makePending = true;
break;
// otherwise ignore pending since there is nothing to reset
}
};
ret.reset.displayName = 'once#handler.reset';
return ret ;
};
exports.once = once;
/**
Iterate over a property, setting display names on functions as needed.
Call this on your own exports to setup display names for debugging.
*/
var displayNames = function(obj, root) {
var k,v;
for(k in obj) {
if (!obj.hasOwnProperty(k)) continue ;
v = obj[k];
if ('function' === typeof v) {
if (!v.displayName) {
v.displayName = root ? (root+'.'+k) : k;
displayNames(v.prototype, v.displayName);
}
}
}
return obj;
};
// ..........................................................
// ERRORS
//
var NotFound = extend(Error);
NotFound.prototype.init = function(canonicalId, pkgId) {
var msg = canonicalId+' not found';
if (pkgId) {
if (T_STRING === typeof pkgId) msg = msg+' '+pkgId;
else msg = msg+' in package '+(pkgId.id || '(unknown)');
}
this.message = msg;
return this;
};
exports.NotFound = NotFound;
var InvalidPackageDef = extend(Error);
InvalidPackageDef.prototype.init = function(def, reason) {
if ('undefined' !== typeof JSON) def = JSON.stringify(def);
this.message = "Invalid package definition. "+reason+" "+def;
};
exports.InvalidPackageDef = InvalidPackageDef;
// ..........................................................
// semver
//
// ..........................................................
// NATCOMPARE
//
// Used with thanks to Kristof Coomans
// Find online at http://sourcefrog.net/projects/natsort/natcompare.js
// Cleaned up JSLint errors
/*
natcompare.js -- Perform 'natural order' comparisons of strings in JavaScript.
Copyright (C) 2005 by SCK-CEN (Belgian Nucleair Research Centre)
Written by Kristof Coomans <kristof[dot]coomans[at]sckcen[dot]be>
Based on the Java version by Pierre-Luc Paour, of which this is more or less a straight conversion.
Copyright (C) 2003 by Pierre-Luc Paour <[email protected]>
The Java version was based on the C version by Martin Pool.
Copyright (C) 2000 by Martin Pool <[email protected]>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
var natcompare = function() {
var isWhitespaceChar = function(a) {
var charCode = a.charCodeAt(0);
return charCode <= 32;
};
var isDigitChar = function(a) {
var charCode = a.charCodeAt(0);
return ( charCode >= 48 && charCode <= 57 );
};
var compareRight = function(a,b) {
var bias = 0,
ia = 0,
ib = 0,
ca, cb;
// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
// both numbers to know that they have the same magnitude, so we
// remember it in BIAS.
for (;; ia++, ib++) {
ca = a.charAt(ia);
cb = b.charAt(ib);
if (!isDigitChar(ca) && !isDigitChar(cb)) return bias;
else if (!isDigitChar(ca)) return -1;
else if (!isDigitChar(cb)) return +1;
else if (ca < cb) if (bias === 0) bias = -1;
else if (ca > cb) if (bias === 0) bias = +1;
else if (ca === 0 && cb === 0) return bias;
}
};
var natcompare = function(a,b) {
var ia = 0,
ib = 0,
nza = 0,
nzb = 0,
ca, cb, result;
while (true) {
// only count the number of zeroes leading the last number compared
nza = nzb = 0;
ca = a.charAt(ia);
cb = b.charAt(ib);
// skip over leading spaces or zeros
while ( isWhitespaceChar( ca ) || ca =='0' ) {
if (ca == '0') nza++;
else nza = 0; // only count consecutive zeroes
ca = a.charAt(++ia);
}
while ( isWhitespaceChar( cb ) || cb == '0') {
if (cb == '0') nzb++;
else nzb = 0; // only count consecutive zeroes
cb = b.charAt(++ib);
}
// process run of digits
if (isDigitChar(ca) && isDigitChar(cb)) {
if ((result = compareRight(a.substring(ia), b.substring(ib))) !== 0) {
return result;
}
}
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
if (ca === 0 && cb === 0) return nza - nzb;
if (ca < cb) return -1;
else if (ca > cb) return +1;
++ia; ++ib;
}
};
return natcompare;
}();
exports.natcompare = natcompare;
// ..........................................................
// PUBLIC API
//
// Support Methods
var invalidVers = function(vers) {
return new Error('' + vers + ' is an invalid version string');
};
invalidVers.displayName = 'invalidVers';
var compareNum = function(vers1, vers2, num1, num2) {
num1 = Number(num1);
num2 = Number(num2);
if (isNaN(num1)) throw invalidVers(vers1);
if (isNaN(num2)) throw invalidVers(vers2);
return num1 - num2 ;
};
compareNum.displayName = 'compareNum';
var vparse;
var semver = {
/**
Parse the version number into its components. Returns result of a regex.
*/
parse: function(vers) {
var ret = vers.match(/^(=|~)?([\d]+?)(\.([\d]+?)(\.(.+))?)?$/);
if (!ret) return null; // no match
return [ret, ret[2], ret[4] || '0', ret[6] || '0', ret[1]];
},
/**
Returns the major version number of a version string.
@param {String} vers
version string
@returns {Number} version number or null if could not be parsed
*/
major: function(vers) {
return Number(vparse(vers)[1]);
},
/**
Returns the minor version number of a version string
@param {String} vers
version string
@returns {Number} version number or null if could not be parsed
*/
minor: function(vers) {
return Number(vparse(vers)[2]);
},
/**
Returns the patch of a version string. The patch value is always a string
not a number
*/
patch: function(vers) {
var ret = vparse(vers)[3];
return isNaN(Number(ret)) ? ret : Number(ret);
},
STRICT: 'strict',
NORMAL: 'normal',
/**
Returns the comparison mode. Will be one of NORMAL or STRICT
*/
mode: function(vers) {
var ret = vparse(vers)[4];
return ret === '=' ? semver.STRICT : semver.NORMAL;
},
/**
Compares two patch strings using the proper matching formula defined by
semver.org. Returns:
@param {String} patch1 first patch to compare
@param {String} patch2 second patch to compare
@returns {Number} -1 if patch1 < patch2, 1 if patch1 > patch2, 0 if equal
*/
comparePatch: function(patch1, patch2) {
var num1, num2;
if (patch1 === patch2) return 0; // equal
num1 = Number(patch1);
num2 = Number(patch2);
if (isNaN(num1)) {
if (isNaN(num2)) {
// do lexigraphic comparison
return natcompare(patch1, patch2);
} else return -1; // num2 is a number therefore num1 < num2
// num1 is a number but num2 is not so num1 > num2
} else if (isNaN(num2)) {
return 1 ;
} else {
return num1<num2 ? -1 : (num1>num2 ? 1 : 0) ;
}
},
/**
Compares two version strings, using natural sorting for the patch.
*/
compare: function(vers1, vers2) {
var ret ;
if (vers1 === vers2) return 0;
if (vers1) vers1 = vparse(vers1);
if (vers2) vers2 = vparse(vers2);
if (!vers1 && !vers2) return 0;
if (!vers1) return -1;
if (!vers2) return 1;
ret = compareNum(vers1[0], vers2[0], vers1[1], vers2[1]);
if (ret === 0) {
ret = compareNum(vers1[0], vers2[0], vers1[2], vers2[2]);
if (ret === 0) ret = semver.comparePatch(vers1[3], vers2[3]);
}
return (ret < 0) ? -1 : (ret>0 ? 1 : 0);
},
/**
Returns true if the second version string represents a version compatible
with the first version. In general this means the second version must be
greater than or equal to the first version but its major version must not
be different.
*/
compatible: function(reqVers, curVers) {
if (!reqVers) return true; // always compatible with no version
if (reqVers === curVers) return true; // fast path
// make sure these parse - or else treat them like null
if (reqVers && !vparse(reqVers)) reqVers = null;
if (curVers && !vparse(curVers)) curVers = null;
// try fast paths again in case they changed state
if (!reqVers) return true; // always compatible with no version
if (reqVers === curVers) return true; // fast path
// strict mode, must be an exact (semantic) match
if (semver.mode(reqVers) === semver.STRICT) {
return curVers && (semver.compare(reqVers, curVers)===0);
} else {
if (!curVers) return true; // if no vers, always assume compat
// major vers
if (semver.major(reqVers) !== semver.major(curVers)) return false;
return semver.compare(reqVers, curVers) <= 0;
}
},
/**
Normalizes version numbers so that semantically equivalent will be treated
the same.
*/
normalize: function(vers) {
var patch;
if (!vers || vers.length===0) return null;
vers = semver.parse(vers);
if (!vers) return null;
patch = Number(vers[3]);
if (isNaN(patch)) patch = vers[3];
return [Number(vers[1]), Number(vers[2]), patch].join('.');
}
};
exports.semver = semver;
vparse = semver.parse;
// ..........................................................
// FACTORY
//
/**
@constructor
A factory knows how to instantiate a new module for a sandbox, including
generating the require() method used by the module itself. You can return
custom factories when you install a plugin. Your module should export
loadFactory().
The default factory here actually expects to receive a module descriptor
as generated by the build tools.
*/
var Factory = exports.extend(Object);
exports.Factory = Factory;
Factory.prototype.init = function(moduleId, pkg, factory) {
this.id = moduleId;
this.pkg = pkg;
this.factory = factory;
};
/**
Actually generates a new set of exports for the named sandbox. The sandbox
must return a module object that can be used to generate the factory.
If the current value of the local factory is a string, then we will actually
eval/compile the factory as well.
@param sandbox {Sandbox}
The sandbox the will own the module instance
@param module {Module}
The module object the exports will belong to
@returns {Hash} exports from instantiated module
*/
Factory.prototype.call = function(sandbox, module) {
// get the factory function, evaluate if needed
var func = this.factory,
filename = this.__filename,
dirname = this.__dirname;
if (T_STRING === typeof(func)) {
func = this.factory = Factory.compile(func, this.pkg.id+':'+this.id);
}
// generate a nested require for this puppy
var req = sandbox.createRequire(module),
exp = module.exports;
func.call(exp, req, exp, module, filename, dirname);
return module.exports;
};
// standard wrapper around a module. replace item[1] with a string and join.
var MODULE_WRAPPER = [
'(function(require, exports, module) {',
null,
'\n});\n//@ sourceURL=',
null,
'\n'];
/**
Evaluates the passed string. Returns a function.
@param moduleText {String}
The module text to compile
@param moduleId {String}
Optional moduleId. If provided will be used for debug
@returns {Function} compiled factory
*/
Factory.compile = function(moduleText, moduleId) {
var ret;
MODULE_WRAPPER[1] = moduleText;
MODULE_WRAPPER[3] = moduleId || '(unknown module)';
ret = MODULE_WRAPPER.join('');
ret = eval(ret);
MODULE_WRAPPER[1] = MODULE_WRAPPER[3] = null;
return ret;
};
exports.Factory = Factory;
// ..........................................................
// MODULE
//
/**
A Module describes a single module, including its id, ownerPackage, and
the actual module exports once the module has been instantiated. It also
implements the resource() method which can lookup a resource on the module's
package.
*/
var Module = exports.extend(Object);
exports.Module = Module;
Module.prototype.init = function(id, ownerPackage, sandbox) {
this.id = id;
this.ownerPackage = ownerPackage;
this.exports = {};
var module = this;
/**
Lookup a resource on the module's ownerPackage. Returns a URL or path
for the discovered resource. The method used to detect the module or
package is implemented in the package.
Note that this method is generated for each module we create because some
code will try to pluck this method off of the module and call it in a
different context.
@param resourceId {String}
Full or partial name of resource to retrieve
@param done {Function}
Optional. Makes the resource discovery asyncronous
@returns {String} url or path if not called async
*/
this.resource = function(id) {
return sandbox.resource(id, module.id, ownerPackage);
};
};
// ..........................................................
// PACKAGE
//
/**
Package expects you to register the package with a config having the
following keys:
{
"name": "name-of-package" (vs canonical id)
"version": current version of package (if known)
// these are dependencies you require to run. If the package is
// async loaded, these will be the ones loaded
"dependencies": {
"package-name": "version"
},
// these map a specific package-name/version to a canonicalId that must
// be registered for the package to be loaded. You may include
// additional packages here that may be referenced but are not required
// to run (for example - lazy loaded packages)
//
// This also forms the universe of packages this particular package can
// reference.
//
"tiki:packages": {
"package-name": [
{ "version": "1.0.0", "id": "canonicalId", "url": "url" }
]
},